This commit is contained in:
Bhagwan Singh 2025-12-08 15:24:51 +05:30
parent ec566bb14a
commit 217781cfe8
4 changed files with 2021 additions and 246 deletions

2244
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -118,13 +118,13 @@
"@vitejs/plugin-react": "^4.3.1",
"cross-env": "^7.0.3",
"daisyui": "^5.4.3",
"electron": "^32.1.2",
"electron": "^39.2.5",
"electron-builder": "^25.0.5",
"electron-rebuild": "^3.2.9",
"npm-run-all": "^4.1.5",
"rcedit": "^5.0.2",
"typescript": "^5.6.2",
"vite": "^5.4.7",
"vitest": "^2.1.1"
"vite": "^7.2.6",
"vitest": "^4.0.15"
}
}

View File

@ -35,7 +35,7 @@ test('', () => {
expect(template[0].label).toEqual('Show');
template[0]?.click?.(null as any, null as any, null as any);
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);
expect(app.quit).toHaveBeenCalled();

View File

@ -11,7 +11,7 @@ export function ipcMainHandle<Key extends keyof EventPayloadMapping>(
handler: () => EventPayloadMapping[Key]
) {
ipcMain.handle(key, (event) => {
validateEventFrame(event.senderFrame);
validateEventFrame(event.senderFrame!);
return handler();
});
}
@ -21,7 +21,7 @@ export function ipcMainOn<Key extends keyof EventPayloadMapping>(
handler: (payload: EventPayloadMapping[Key]) => void
) {
ipcMain.on(key, (event, payload) => {
validateEventFrame(event.senderFrame);
validateEventFrame(event.senderFrame!);
return handler(payload);
});
}
@ -34,11 +34,16 @@ export function ipcWebContentsSend<Key extends keyof EventPayloadMapping>(
webContents.send(key, payload);
}
export function validateEventFrame(frame: WebFrameMain) {
if (isDev() && new URL(frame.url).host === 'localhost:5123') {
export function validateEventFrame(frame: WebFrameMain | null): asserts frame is WebFrameMain {
if (!frame) throw new Error('Missing frame');
const url = frame.url;
if (isDev() && new URL(url).host === 'localhost:5123') {
return;
}
if (frame.url !== pathToFileURL(getUIPath()).toString()) {
if (url !== pathToFileURL(getUIPath()).toString()) {
throw new Error('Malicious event');
}
}