kiwix-js-pwa/preload.js
Jaifroid d1371364b0 Add autoUpdate notifications
Former-commit-id: 2833a4fda293950ec2e485ed3b928e8b000f97d1 [formerly bfa3d7e32f14156bd8b57a4b133b3939fc8e6f24] [formerly a21284f53d5ab341823c51dcd8eb8f0f13c4d2e2] [formerly 0164724496dfdc3f0dde1c5e6c7a15c8bb63cb51 [formerly 3e15fb067a5fc9605c4abb82772c6a1216d403c1 [formerly 6c5b0b9f92dfafaf81ececdc5574c31849a2e9ce]]]
Former-commit-id: f34be706d649276651b6bf788d096b22dcf6d5f5 [formerly fd39cc6ba962e8660722fd8d3c9029bbbb39e41a [formerly 817e2c1bfa80531d59e35a92b436fc64b1232985]]
Former-commit-id: 477e9b9596045365f12312225c54488a0de7e757 [formerly fad9edfb45e517c9294a15b492b318b5530140be]
Former-commit-id: 751a3c0bd4cd848c77741997c1122c8f1ecc2261
2022-03-03 18:39:00 +00:00

53 lines
1.6 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
});
// 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', {
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);
// });