forked from adamlaska/electron
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprotocol.ts
More file actions
33 lines (25 loc) · 988 Bytes
/
protocol.ts
File metadata and controls
33 lines (25 loc) · 988 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import { app, session } from 'electron/main';
// Global protocol APIs.
const protocol = process._linkedBinding('electron_browser_protocol');
// Fallback protocol APIs of default session.
Object.setPrototypeOf(protocol, new Proxy({}, {
get (_target, property) {
if (!app.isReady()) return;
const protocol = session.defaultSession!.protocol;
if (!Object.prototype.hasOwnProperty.call(protocol, property)) return;
// Returning a native function directly would throw error.
return (...args: any[]) => (protocol[property as keyof Electron.Protocol] as Function)(...args);
},
ownKeys () {
if (!app.isReady()) return [];
return Reflect.ownKeys(session.defaultSession!.protocol);
},
has: (target, property: string) => {
if (!app.isReady()) return false;
return Reflect.has(session.defaultSession!.protocol, property);
},
getOwnPropertyDescriptor () {
return { configurable: true, enumerable: true };
}
}));
export default protocol;