-
Shazib Hussain authored
Updates to the latest version of electron and moves the backend-frontend communication from node-ipc to websockets. This resolves the previous roadblock regarding `nodeIntegration` . Done - Remove node-ipc in favour of websockets. - Move file copying out of `preload.js` to avoid importing module `fs` there - Bump all electron pacakge versions to the latest - Added new package for finding open ports as node-ipc is gone - Tweaked webpack config for above changes Partially fixes #468 Questions/ Pending: - Literally every single test fails for me, presumably some issue with my setup/environment. - The websocket communication is not using TLS. I'm not sure how to enable this, or if we even need to as its all local. - Still need to create the CI for building/deploying but I'm not sure where start in this regard as i have no exp with it. Presumably we will need to point the electron auto-updater to the github releases url's. If people are happy with this PR I will look at adding the CI before its merged. - In dev mode only, I have disabled TLS security becuase my docker container's cert is not signed. I _assume_ this will be true for other people who spin up the server on thier own hardware. Perhaps I just need to change my cert to one from letsencrypt or something... Notes. I have not touched javascript in eons so my apologies if the commit trail is a bit fragmented. I tried to keep them fairly contained and then there is a slightly gnarly final commit fixing all the linter issues... Please let me know if you want me to squash some commits etc. I initially tried to move this to web workers the same way the web app does it but this was unsuccessful. I have found no way to spin up a worker in one place (frontend/backend) and then pass this worker to the other. The electron ipc channels don't allow you to directly pass objects such as workers, everything is cloned/serialised. Passing a port number so the other end can spin up its own socket works fine. --------- Co-authored-by:
Shazib Hussain <contact@shazib.com> Co-authored-by:
Jed Fox <git@jedfox.com>
Shazib Hussain authoredUpdates to the latest version of electron and moves the backend-frontend communication from node-ipc to websockets. This resolves the previous roadblock regarding `nodeIntegration` . Done - Remove node-ipc in favour of websockets. - Move file copying out of `preload.js` to avoid importing module `fs` there - Bump all electron pacakge versions to the latest - Added new package for finding open ports as node-ipc is gone - Tweaked webpack config for above changes Partially fixes #468 Questions/ Pending: - Literally every single test fails for me, presumably some issue with my setup/environment. - The websocket communication is not using TLS. I'm not sure how to enable this, or if we even need to as its all local. - Still need to create the CI for building/deploying but I'm not sure where start in this regard as i have no exp with it. Presumably we will need to point the electron auto-updater to the github releases url's. If people are happy with this PR I will look at adding the CI before its merged. - In dev mode only, I have disabled TLS security becuase my docker container's cert is not signed. I _assume_ this will be true for other people who spin up the server on thier own hardware. Perhaps I just need to change my cert to one from letsencrypt or something... Notes. I have not touched javascript in eons so my apologies if the commit trail is a bit fragmented. I tried to keep them fairly contained and then there is a slightly gnarly final commit fixing all the linter issues... Please let me know if you want me to squash some commits etc. I initially tried to move this to web workers the same way the web app does it but this was unsuccessful. I have found no way to spin up a worker in one place (frontend/backend) and then pass this worker to the other. The electron ipc channels don't allow you to directly pass objects such as workers, everything is cloned/serialised. Passing a port number so the other end can spin up its own socket works fine. --------- Co-authored-by:
Shazib Hussain <contact@shazib.com> Co-authored-by:
Jed Fox <git@jedfox.com>
preload.js 1.22 KiB
const { ipcRenderer, contextBridge } = require('electron');
let { version: VERSION, isDev: IS_DEV } =
ipcRenderer.sendSync('get-bootstrap-data');
let resolveSocketPromise;
let socketPromise = new Promise(resolve => {
resolveSocketPromise = resolve;
});
ipcRenderer.on('set-socket', (event, { name }) => {
resolveSocketPromise(name);
});
contextBridge.exposeInMainWorld('Actual', {
IS_DEV,
ACTUAL_VERSION: VERSION,
logToTerminal: (...args) => {
require('console').log(...args);
},
relaunch: () => {
ipcRenderer.invoke('relaunch');
},
openFileDialog: opts => {
return ipcRenderer.invoke('open-file-dialog', opts);
},
saveFile: async (contents, filename, dialogTitle) => {
await ipcRenderer.invoke('save-file-dialog', {
title: dialogTitle,
defaultPath: filename,
fileContents: contents,
});
},
openURLInBrowser: url => {
ipcRenderer.invoke('open-external-url', url);
},
onEventFromMain: (type, handler) => {
ipcRenderer.on(type, handler);
},
applyAppUpdate: () => {
ipcRenderer.send('apply-update');
},
updateAppMenu: isBudgetOpen => {
ipcRenderer.send('update-menu', isBudgetOpen);
},
getServerSocket: () => {
return socketPromise;
},
});