-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add ipc invoke & shortcuts (#15)
- Loading branch information
Showing
13 changed files
with
166 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
export enum IpcRenderToMain { | ||
ShowDevTools = "showDevTools", | ||
ShowMainWindow = "showMainWindow", | ||
ClearChildWindows = "clearChildWindows", | ||
} | ||
|
||
export type IpcRenderToMainDataMap = { | ||
[IpcRenderToMain.ShowDevTools]: void; | ||
[IpcRenderToMain.ShowMainWindow]: void; | ||
[IpcRenderToMain.ClearChildWindows]: void; | ||
}; | ||
|
||
export enum IpcRenderToMainSync { | ||
CheckChildWindowStatus = "checkChildWindowStatus", | ||
} | ||
|
||
export type IpcRenderToMainSyncDataMap = { | ||
[IpcRenderToMainSync.CheckChildWindowStatus]: boolean; | ||
}; | ||
|
||
export interface IElectronAPI { | ||
fileExists: (path: string) => boolean; | ||
getPlatform: () => string; | ||
ipcInvoke: <T extends keyof IpcRenderToMainDataMap>( | ||
channel: T, | ||
...arg: unknown[] | ||
) => Promise<IpcRenderToMainDataMap[T]>; | ||
ipcSendSync: <T extends keyof IpcRenderToMainSyncDataMap>( | ||
channel: T, | ||
...arg: unknown[] | ||
) => IpcRenderToMainSyncDataMap[T]; | ||
openFile: (path: string) => Promise<string>; | ||
showFile: (path: string) => void; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { BrowserWindow, ipcMain } from "electron"; | ||
|
||
import { IpcRenderToMain, IpcRenderToMainSync } from "../constants"; | ||
import { | ||
childWindowMap, | ||
clearChildWindows, | ||
showMainWindow, | ||
toggleDevTools, | ||
} from "./windowManage"; | ||
export const setIpcMainListener = () => { | ||
ipcMain.handle(IpcRenderToMain.ShowMainWindow, () => { | ||
showMainWindow(); | ||
}); | ||
|
||
ipcMain.handle(IpcRenderToMain.ShowDevTools, () => { | ||
toggleDevTools(); | ||
}); | ||
|
||
ipcMain.handle(IpcRenderToMain.ClearChildWindows, () => { | ||
clearChildWindows(); | ||
}); | ||
|
||
ipcMain.on(IpcRenderToMainSync.CheckChildWindowStatus, (event, { key }) => { | ||
const childWindow = BrowserWindow.getAllWindows().find( | ||
(win) => win.id === childWindowMap[key], | ||
); | ||
event.returnValue = Boolean(childWindow); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { globalShortcut } from "electron"; | ||
|
||
import { toggleDevTools } from "./windowManage"; | ||
|
||
export const registerShortcuts = () => { | ||
globalShortcut.register("CmdOrCtrl+F12", toggleDevTools); | ||
}; | ||
|
||
export const unregisterShortcuts = () => { | ||
globalShortcut.unregisterAll(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters