Skip to content

Commit

Permalink
[electron] update permission handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Ronny committed Feb 3, 2025
1 parent e81b997 commit 55c89c7
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions app/electron/src/Main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,17 @@ async function CreateApplicationWindow(): Promise<ApplicationWindow> {

win.setMenuBarVisibility(false);
win.on('closed', () => app.quit());
// TODO: May remove workaround when https://github.com/electron/electron/issues/41957 is solved
win.webContents.session.on('file-system-access-restricted', (event, details, callback) => callback('allow'));
win.webContents.session.setPermissionRequestHandler((webContents, permission, callback) => callback(permission === 'fileSystem')); // webContents.getURL().startsWith(argv.origin ?? manifest.url) ? callback(true) : callback(false);

return win;
}

function UpdatePermissions(session: Electron.Session, appURI: URL) {
session.setPermissionCheckHandler((webContents, permission, requestingOrigin) => new URL(requestingOrigin).hostname === appURI.hostname);
session.setPermissionRequestHandler((webContents, permission, callback, details) => callback(new URL(details.requestingUrl).hostname === appURI.hostname));
// TODO: May remove the following workaround when https://github.com/electron/electron/issues/41957 is solved
session.on('file-system-access-restricted', (event, details, callback) => callback(new URL(details.origin).hostname === appURI.hostname ? 'allow' : 'deny'));
}

async function OpenWindow(): Promise<void> {
InitializeMenu();
const argv = ParseCLI();
Expand All @@ -88,12 +92,14 @@ async function OpenWindow(): Promise<void> {
const win = await CreateApplicationWindow();
const ipc = new IPC(win.webContents);
const rpc = new RPCServer('/hakuneko', new RemoteProcedureCallContract(ipc, win.webContents));
const uri = new URL(argv.origin ?? manifest.url ?? 'about:blank');
UpdatePermissions(win.webContents.session, uri);
new RemoteProcedureCallManager(rpc, ipc);
new FetchProvider(ipc, win.webContents);
new RemoteBrowserWindowController(ipc);
new BloatGuard(ipc, win.webContents);
win.RegisterChannels(ipc);
return win.loadURL(argv.origin ?? manifest.url ?? 'about:blank');
return win.loadURL(uri.href);
}

OpenWindow();

0 comments on commit 55c89c7

Please sign in to comment.