mirror of
https://github.com/notion-enhancer/notion-enhancer.git
synced 2025-04-05 13:19:03 +00:00
optionally imitate notion ipc channels
This commit is contained in:
parent
21d4991f38
commit
9b47ede63e
@ -41,6 +41,9 @@ 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.
|
||||
*
|
||||
* @env win32
|
||||
* @env linux
|
||||
@ -48,13 +51,19 @@ export const webFrame = globalThis.__enhancerElectronApi?.webFrame;
|
||||
* @runtime client
|
||||
* @runtime menu
|
||||
*/
|
||||
export const sendMessage = (channel, data) =>
|
||||
globalThis.__enhancerElectronApi.ipcRenderer.sendMessage(channel, data);
|
||||
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.
|
||||
*
|
||||
* @env win32
|
||||
* @env linux
|
||||
@ -62,14 +71,20 @@ export const sendMessage = (channel, data) =>
|
||||
* @runtime client
|
||||
* @runtime menu
|
||||
*/
|
||||
export const sendMessageToHost = (channel, data) =>
|
||||
globalThis.__enhancerElectronApi.ipcRenderer.sendMessageToHost(channel, data);
|
||||
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.
|
||||
*
|
||||
* @env win32
|
||||
* @env linux
|
||||
@ -77,5 +92,8 @@ export const sendMessageToHost = (channel, data) =>
|
||||
* @runtime client
|
||||
* @runtime menu
|
||||
*/
|
||||
export const onMessage = (channel, callback) =>
|
||||
globalThis.__enhancerElectronApi.ipcRenderer.onMessage(channel, callback);
|
||||
export const onMessage = (channel, callback, namespace = 'notion-enhancer') => {
|
||||
if (globalThis.__enhancerElectronApi) {
|
||||
globalThis.__enhancerElectronApi.ipcRenderer.onMessage(channel, callback, namespace);
|
||||
}
|
||||
};
|
||||
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user