mirror of
https://github.com/kiwix/kiwix-js-pwa.git
synced 2025-09-10 12:53:54 -04:00

Former-commit-id: 842ea4bb0d517b5f5d124647211a288bf28c0fc6 [formerly 727e0dda9b5bfc9c7a982b47e2e14a3ab77ff2ac [formerly aaa590e94c9ed69a0051623dae5fec7960a8b378]] Former-commit-id: 869197935b7a67b7296db68531f1210859f2b3c6 [formerly 2dfa4f6189f30915d4eadb651060585f3e91143d] Former-commit-id: cadf16ec6acd51b67444046a37fa819b8a822e94
56 lines
1.7 KiB
JavaScript
56 lines
1.7 KiB
JavaScript
// All of the Node.js APIs are available in the preload process.
|
|
// It has the same sandbox as a Chrome extension.
|
|
|
|
'use strict';
|
|
|
|
// DEV: TO SUPPORT ELECTRON ^12 YOU WILL NEED THIS
|
|
const { ipcRenderer, contextBridge } = require('electron');
|
|
const { open, read, close, stat, readdir } = require('fs');
|
|
|
|
console.log("Inserting required Electron functions into DOM...");
|
|
|
|
// DEV: FOR ELECTRON ^12 DO IT THIS WAY:
|
|
contextBridge.exposeInMainWorld('fs', {
|
|
open: open,
|
|
read: read,
|
|
readdir: readdir,
|
|
close: close,
|
|
stat: stat
|
|
});
|
|
// Exposed events and Event callback for electronAPI (you can add events to listen to, so long as main.js sends a message with name of the event)
|
|
contextBridge.exposeInMainWorld('electronAPI', {
|
|
checkForUpdates: function () {
|
|
ipcRenderer.send('check-updates');
|
|
},
|
|
on: function (event, callback) {
|
|
ipcRenderer.on(event, function (_, data) {
|
|
callback(data);
|
|
});
|
|
}
|
|
});
|
|
|
|
// Adapted from: https://stackoverflow.com/questions/69717365/using-electron-save-dialog-in-renderer-with-context-isolation
|
|
contextBridge.exposeInMainWorld('dialog', {
|
|
openFile: function () {
|
|
ipcRenderer.send('file-dialog'); // adjust naming for your project
|
|
},
|
|
openDirectory: function () {
|
|
ipcRenderer.send('dir-dialog'); // adjust naming for your project
|
|
},
|
|
// Provide an easier way to listen to events
|
|
on: function (channel, callback) {
|
|
ipcRenderer.on(channel, function (_, data) {
|
|
callback(data);
|
|
});
|
|
}
|
|
});
|
|
|
|
// window.Buffer = Buffer;
|
|
|
|
// console.log(win.session.cookies);
|
|
|
|
// win.session.cookies.get({}, (error, cookies) => {
|
|
// console.log(cookies);
|
|
// });
|
|
|