This repository has been archived by the owner on Feb 7, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathelectron.mjs
106 lines (96 loc) · 3.49 KB
/
electron.mjs
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/**
* notion-enhancer: api
* (c) 2021 dragonwocky <[email protected]> (https://dragonwocky.me/)
* (https://notion-enhancer.github.io/) under the MIT license
*/
'use strict';
/**
* access to electron renderer apis
* @namespace electron
*/
import * as _api from './index.mjs'; // trick jsdoc
/**
* access to the electron BrowserWindow instance for the current window
* see https://www.electronjs.org/docs/latest/api/browser-window
* @type {BrowserWindow}
* @process electron (renderer process)
*/
export const browser = globalThis.__enhancerElectronApi?.browser;
/**
* access to the electron webFrame instance for the current page
* see https://www.electronjs.org/docs/latest/api/web-frame
* @type {webFrame}
* @process electron (renderer process)
*/
export const webFrame = globalThis.__enhancerElectronApi?.webFrame;
/**
* send a message to the main electron process
* @param {string} channel - the message identifier
* @param {any} data - the data to pass along with the message
* @param {string=} namespace - a prefix for the message to categorise
* it as e.g. enhancer-related. this should not be changed unless replicating
* builtin ipc events.
* @process electron (renderer process)
*/
export const sendMessage = (channel, data, namespace = 'notion-enhancer') => {
if (globalThis.__enhancerElectronApi) {
globalThis.__enhancerElectronApi.ipcRenderer.sendMessage(channel, data, namespace);
}
};
/**
* send a message to the webview's parent renderer process
* @param {string} channel - the message identifier
* @param {any} data - the data to pass along with the message
* @param {string=} namespace - a prefix for the message to categorise
* it as e.g. enhancer-related. this should not be changed unless replicating
* builtin ipc events.
* @process electron (renderer process)
*/
export const sendMessageToHost = (channel, data, namespace = 'notion-enhancer') => {
if (globalThis.__enhancerElectronApi) {
globalThis.__enhancerElectronApi.ipcRenderer.sendMessageToHost(channel, data, namespace);
}
};
/**
* receive a message from either the main process or
* the webview's parent renderer process
* @param {string} channel - the message identifier to listen for
* @param {function} callback - the message handler, passed the args (event, data)
* @param {string=} namespace - a prefix for the message to categorise
* it as e.g. enhancer-related. this should not be changed unless replicating
* builtin ipc events.
* @process electron (renderer process)
*/
export const onMessage = (channel, callback, namespace = 'notion-enhancer') => {
if (globalThis.__enhancerElectronApi) {
globalThis.__enhancerElectronApi.ipcRenderer.onMessage(channel, callback, namespace);
}
};
/**
* require() notion app files
* @param {string} path - within notion/resources/app/ e.g. main/createWindow.js
* @process electron (main process)
*/
export const notionRequire = (path) => {
return globalThis.__enhancerElectronApi
? globalThis.__enhancerElectronApi.notionRequire(path)
: null;
};
/**
* get all available app windows excluding the menu
* @process electron (main process)
*/
export const getNotionWindows = () => {
return globalThis.__enhancerElectronApi
? globalThis.__enhancerElectronApi.getNotionWindows()
: null;
};
/**
* get the currently focused notion window
* @process electron (main process)
*/
export const getFocusedNotionWindow = () => {
return globalThis.__enhancerElectronApi
? globalThis.__enhancerElectronApi.getFocusedNotionWindow()
: null;
};