Skip to content
This repository has been archived by the owner on Apr 14, 2023. It is now read-only.

Commit

Permalink
fix: open game directory to main process
Browse files Browse the repository at this point in the history
  • Loading branch information
jojobii-arks committed Apr 11, 2023
1 parent 2d0993e commit 1792d72
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
1 change: 1 addition & 0 deletions app/src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export enum CHANNELS {
ACTION_NEW = 'ACTION_NEW',
ALERT = 'ALERT',
GET_GAME_DIR = 'GET_GAME_DIR',
OPEN_GAME_DIR = 'OPEN_GAME_DIR',
SET_IS_ALWAYS_ON_TOP = 'TOGGLE_ALWAYS_ON_TOP',
}

Expand Down
7 changes: 5 additions & 2 deletions app/src/main/ipcHandlers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BrowserWindow, ipcMain } from 'electron';
import { BrowserWindow, ipcMain, shell } from 'electron';
import getGameDirectory from '../lib/node/utils/getGameDirectory';
import { CHANNELS } from '../lib/types';

Expand All @@ -8,10 +8,13 @@ export type SetItAlwaysOnTopResponse = {
};

export function attachIpcHandlers() {
/** @method CHANNELS.GET_GAME_DIR */
ipcMain.handle(CHANNELS.GET_GAME_DIR, () => {
return getGameDirectory();
});
ipcMain.handle(CHANNELS.OPEN_GAME_DIR, () => {
shell.openPath(getGameDirectory());
return;
});
ipcMain.handle(CHANNELS.SET_IS_ALWAYS_ON_TOP, (_, isAlwaysOnTop: boolean) => {
console.log('Toggling always on top');
const window = BrowserWindow.getFocusedWindow();
Expand Down
2 changes: 1 addition & 1 deletion app/src/preload/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const api = {
return await ipcRenderer.invoke(CHANNELS.GET_GAME_DIR);
},
openGameDirectory: async () => {
shell.openPath(await ipcRenderer.invoke(CHANNELS.GET_GAME_DIR));
return await ipcRenderer.invoke(CHANNELS.OPEN_GAME_DIR);
},
setIsAlwaysOnTop: async (isAlwaysOnTop: boolean) => {
return (await ipcRenderer.invoke(
Expand Down
5 changes: 3 additions & 2 deletions app/src/renderer/app/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,9 @@
Using logs from{' '}
<button
class="link-hover link"
on:click={() => {
api.openGameDirectory();
on:click={async () => {
console.log('clicked');
await api.openGameDirectory();
}}
>
{gameDirectory}
Expand Down

0 comments on commit 1792d72

Please sign in to comment.