mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-15 09:04:04 +02:00
3407a31cf6
* Improving CLI build * Improving CLI build * Remove requirement to build the tools * Moved Electron app one level down * Clean up Electron build * Moved tools to sub-dir * Updated root script * update root * update root * update root * update root * update root * update root * Updated build * Added doc * Update CI config * Should not lint index.js * Fixing jetify * Fixed linter errors * Fixed pod build * Fixed Windows build
41 lines
1.6 KiB
JavaScript
41 lines
1.6 KiB
JavaScript
// In order to give access to the webview to certain functions of the main process, we need
|
|
// this bridge which listens from the main process and sends to the webview and the other
|
|
// way around. This is necessary after having enabled the "contextIsolation" option, which
|
|
// prevents the webview from accessing low-level methods in the main process.
|
|
|
|
const ipcRenderer = require('electron').ipcRenderer;
|
|
|
|
ipcRenderer.on('setHtml', (event, html, options) => {
|
|
window.postMessage({ target: 'webview', name: 'setHtml', data: { html: html, options: options } }, '*');
|
|
});
|
|
|
|
ipcRenderer.on('scrollToHash', (event, hash) => {
|
|
window.postMessage({ target: 'webview', name: 'scrollToHash', data: { hash: hash } }, '*');
|
|
});
|
|
|
|
ipcRenderer.on('setPercentScroll', (event, percent) => {
|
|
window.postMessage({ target: 'webview', name: 'setPercentScroll', data: { percent: percent } }, '*');
|
|
});
|
|
|
|
ipcRenderer.on('setMarkers', (event, keywords, options) => {
|
|
window.postMessage({ target: 'webview', name: 'setMarkers', data: { keywords: keywords, options: options } }, '*');
|
|
});
|
|
|
|
window.addEventListener('message', event => {
|
|
// Here we only deal with messages that are sent from the webview to the main Electron process
|
|
if (!event.data || event.data.target !== 'main') return;
|
|
|
|
const callName = event.data.name;
|
|
const args = event.data.args;
|
|
|
|
if (args.length === 0) {
|
|
ipcRenderer.sendToHost(callName);
|
|
} else if (args.length === 1) {
|
|
ipcRenderer.sendToHost(callName, args[0]);
|
|
} else if (args.length === 2) {
|
|
ipcRenderer.sendToHost(callName, args[1]);
|
|
} else {
|
|
throw new Error('Unsupported number of args');
|
|
}
|
|
});
|