This commit is contained in:
parent
ec566bb14a
commit
217781cfe8
File diff suppressed because it is too large
Load Diff
|
|
@ -118,13 +118,13 @@
|
||||||
"@vitejs/plugin-react": "^4.3.1",
|
"@vitejs/plugin-react": "^4.3.1",
|
||||||
"cross-env": "^7.0.3",
|
"cross-env": "^7.0.3",
|
||||||
"daisyui": "^5.4.3",
|
"daisyui": "^5.4.3",
|
||||||
"electron": "^32.1.2",
|
"electron": "^39.2.5",
|
||||||
"electron-builder": "^25.0.5",
|
"electron-builder": "^25.0.5",
|
||||||
"electron-rebuild": "^3.2.9",
|
"electron-rebuild": "^3.2.9",
|
||||||
"npm-run-all": "^4.1.5",
|
"npm-run-all": "^4.1.5",
|
||||||
"rcedit": "^5.0.2",
|
"rcedit": "^5.0.2",
|
||||||
"typescript": "^5.6.2",
|
"typescript": "^5.6.2",
|
||||||
"vite": "^5.4.7",
|
"vite": "^7.2.6",
|
||||||
"vitest": "^2.1.1"
|
"vitest": "^4.0.15"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ test('', () => {
|
||||||
expect(template[0].label).toEqual('Show');
|
expect(template[0].label).toEqual('Show');
|
||||||
template[0]?.click?.(null as any, null as any, null as any);
|
template[0]?.click?.(null as any, null as any, null as any);
|
||||||
expect(mainWindow.show).toHaveBeenCalled();
|
expect(mainWindow.show).toHaveBeenCalled();
|
||||||
expect(app.dock.show).toHaveBeenCalled();
|
expect(app.dock!.show).toHaveBeenCalled();
|
||||||
|
|
||||||
template[1]?.click?.(null as any, null as any, null as any);
|
template[1]?.click?.(null as any, null as any, null as any);
|
||||||
expect(app.quit).toHaveBeenCalled();
|
expect(app.quit).toHaveBeenCalled();
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ export function ipcMainHandle<Key extends keyof EventPayloadMapping>(
|
||||||
handler: () => EventPayloadMapping[Key]
|
handler: () => EventPayloadMapping[Key]
|
||||||
) {
|
) {
|
||||||
ipcMain.handle(key, (event) => {
|
ipcMain.handle(key, (event) => {
|
||||||
validateEventFrame(event.senderFrame);
|
validateEventFrame(event.senderFrame!);
|
||||||
return handler();
|
return handler();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -21,7 +21,7 @@ export function ipcMainOn<Key extends keyof EventPayloadMapping>(
|
||||||
handler: (payload: EventPayloadMapping[Key]) => void
|
handler: (payload: EventPayloadMapping[Key]) => void
|
||||||
) {
|
) {
|
||||||
ipcMain.on(key, (event, payload) => {
|
ipcMain.on(key, (event, payload) => {
|
||||||
validateEventFrame(event.senderFrame);
|
validateEventFrame(event.senderFrame!);
|
||||||
return handler(payload);
|
return handler(payload);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -34,11 +34,16 @@ export function ipcWebContentsSend<Key extends keyof EventPayloadMapping>(
|
||||||
webContents.send(key, payload);
|
webContents.send(key, payload);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function validateEventFrame(frame: WebFrameMain) {
|
export function validateEventFrame(frame: WebFrameMain | null): asserts frame is WebFrameMain {
|
||||||
if (isDev() && new URL(frame.url).host === 'localhost:5123') {
|
if (!frame) throw new Error('Missing frame');
|
||||||
|
|
||||||
|
const url = frame.url;
|
||||||
|
|
||||||
|
if (isDev() && new URL(url).host === 'localhost:5123') {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (frame.url !== pathToFileURL(getUIPath()).toString()) {
|
if (url !== pathToFileURL(getUIPath()).toString()) {
|
||||||
throw new Error('Malicious event');
|
throw new Error('Malicious event');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue