mirror of
https://github.com/johannesjo/super-productivity.git
synced 2026-07-27 17:53:50 +00:00
refactor(electronSecurity): make typing work in preload for ipc events
This commit is contained in:
parent
1768d30d57
commit
a0a2f44807
3 changed files with 20 additions and 12 deletions
|
|
@ -35,7 +35,7 @@ if (process.platform === 'darwin') {
|
|||
// ---------
|
||||
ipcMain.on(IPC.SHUTDOWN_NOW, quitApp);
|
||||
ipcMain.on(IPC.EXIT, (ev, exitCode: number) => app.exit(exitCode));
|
||||
ipcMain.on(IPC.RELAUCNH, () => app.relaunch());
|
||||
ipcMain.on(IPC.RELAUNCH, () => app.relaunch());
|
||||
ipcMain.on(IPC.OPEN_DEV_TOOLS, () => getWin().webContents.openDevTools());
|
||||
ipcMain.on(IPC.RELOAD_MAIN_WIN, () => getWin().reload());
|
||||
|
||||
|
|
|
|||
|
|
@ -8,6 +8,14 @@ import {
|
|||
webFrame,
|
||||
} from 'electron';
|
||||
import { ElectronAPI } from './electronAPI.d';
|
||||
import { IPCEventValue } from './shared-with-frontend/ipc-events.const';
|
||||
|
||||
const send: (channel: IPCEventValue, ...args: any[]) => void = (channel, ...args) =>
|
||||
ipcRenderer.send(channel, ...args);
|
||||
const invoke: (channel: IPCEventValue, ...args: any[]) => Promise<unknown> = (
|
||||
channel,
|
||||
...args
|
||||
) => ipcRenderer.invoke(channel, ...args);
|
||||
|
||||
const electronAPI: Partial<ElectronAPI> = {
|
||||
// TODO use full interface
|
||||
|
|
@ -36,19 +44,17 @@ const electronAPI: Partial<ElectronAPI> = {
|
|||
|
||||
isSystemDarkMode: () => nativeTheme.shouldUseDarkColors,
|
||||
|
||||
getUserDataPath: () => ipcRenderer.invoke('GET_PATH', 'userData'),
|
||||
relaunch: () => ipcRenderer.send('RELAUNCH'),
|
||||
exit: () => ipcRenderer.send('EXIT'),
|
||||
reloadMainWin: () => ipcRenderer.send('RELOAD_MAIN_WIN'),
|
||||
openDevTools: () => ipcRenderer.send('OPEN_DEV_TOOLS'),
|
||||
getUserDataPath: () => invoke('GET_PATH', 'userData') as Promise<string>,
|
||||
relaunch: () => send('RELAUNCH'),
|
||||
exit: () => send('EXIT'),
|
||||
reloadMainWin: () => send('RELOAD_MAIN_WIN'),
|
||||
openDevTools: () => send('OPEN_DEV_TOOLS'),
|
||||
|
||||
// ALL EVENTS
|
||||
scheduleRegisterBeforeClose: (id) => ipcRenderer.send('REGISTER_BEFORE_CLOSE', { id }),
|
||||
unscheduleRegisterBeforeClose: (id) =>
|
||||
ipcRenderer.send('UNREGISTER_BEFORE_CLOSE', { id }),
|
||||
setDoneRegisterBeforeClose: (id) => ipcRenderer.send('BEFORE_CLOSE_DONE', { id }),
|
||||
scheduleRegisterBeforeClose: (id) => send('REGISTER_BEFORE_CLOSE', { id }),
|
||||
unscheduleRegisterBeforeClose: (id) => send('UNREGISTER_BEFORE_CLOSE', { id }),
|
||||
setDoneRegisterBeforeClose: (id) => send('BEFORE_CLOSE_DONE', { id }),
|
||||
};
|
||||
|
||||
contextBridge.exposeInMainWorld('electronAPI', electronAPI);
|
||||
|
||||
// contextBridge.exposeInIsolatedWorld();
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
export enum IPC {
|
||||
SHUTDOWN_NOW = 'SHUTDOWN_NOW',
|
||||
EXIT = 'EXIT',
|
||||
RELAUCNH = 'RELAUCNH',
|
||||
RELAUNCH = 'RELAUNCH',
|
||||
|
||||
JIRA_CB_EVENT = 'JIRA_RESPONSE',
|
||||
JIRA_MAKE_REQUEST_EVENT = 'JIRA',
|
||||
|
|
@ -68,3 +68,5 @@ export enum IPC {
|
|||
// maybe_PROJECT_CHANGED = 'PROJECT_CHANGED',
|
||||
// maybe_COMPLETE_DATA_RELOAD = 'COMPLETE_DATA_RELOAD',
|
||||
}
|
||||
|
||||
export type IPCEventValue = `${IPC}`;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue