Skip to content

Commit

Permalink
chore: migrate oop to new handler
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelmaddock committed May 17, 2024
1 parent 79b158b commit 3ef3ad0
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/main/scheme.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { normalize, join, relative } from 'path';
import { protocol } from 'electron';
import { net, protocol } from 'electron';

export function registerSchemePrivilege() {
protocol.registerSchemesAsPrivileged([
{ scheme: 'oop', privileges: { standard: true } },
{ scheme: 'oop', privileges: { standard: true, supportFetchAPI: true } },
]);
}

Expand All @@ -13,11 +13,11 @@ export function registerSchemePrivilege() {
* protecting against Sleuth freezes
*/
export function registerScheme() {
protocol.registerFileProtocol('oop', (request, callback) => {
protocol.handle('oop', (request) => {
const url = new URL(request.url);
if (url.host !== 'oop') {
// request did not match known path, cowardly refusing
callback('Not found');
return new Response(null, { status: 400 });
}

const dist = normalize(`${__dirname}/../..`);
Expand All @@ -26,9 +26,9 @@ export function registerScheme() {
const relation = relative(dist, path);
if (relation.includes('..')) {
// request appears to be try to be navigating outside of dist
callback('Not found');
return new Response(null, { status: 400 });
} else {
callback({ path });
return net.fetch(`file://${path}`);
}
});
}

0 comments on commit 3ef3ad0

Please sign in to comment.