kettek / electron-app-settings Goto Github PK
View Code? Open in Web Editor NEWSimple IPC-based settings framework for Electron
License: Mozilla Public License 2.0
Simple IPC-based settings framework for Electron
License: Mozilla Public License 2.0
hey there,
i'm bundling my electron app which contains this package to handle settings with vue-cli-plugin-electron-builder which uses webpack to bundle js code.
i've noticed that my bundled/packaged code doesn't work and throws an exception like this:
since this is an atypical error message, i've managed to trace the cause of this down to this line:
electron-app-settings/lib/Renderer.js
Line 10 in ffd3135
does this qualify as a bug, or should i be trying to mess with webpack in order for this to be dynamically requirable?
When a renderer closes it doesn't unregister for events, this causes a "Object is distroyed" error in the main process if another renderer then tries to get or set settings.
I have worked around this by setting listeners as array and then creating a remove event. e.g
Main.js
let listeners = []; // ---- Register any listeners that request ipcMain.on('configurator-add-listener', (event) => { let listener = event.sender listeners.push(listener) // -- Send our settings over to the listener listener.send('configurator-master-set', {key: main_settings._storage}); }); // ---- Remove any listeners that request ipcMain.on('configurator-remove-listener', (event) => { let listener = event.sender listeners = listeners.filter(item => item !== listener) }); // -- Set our *set master events to listeners main_settings.on('set', (arg) => { listeners.forEach((listener)=>{ listener.send('configurator-master-set', arg); }) }); main_settings.on('unset', (arg) => { listeners.forEach((listener)=>{ listener.send('configurator-master-unset', arg); }) });
and then in Renderer,js
window.addEventListener('beforeunload', ()=>{ ipcRenderer.send('configurator-remove-listener'); return })
My render calls settings.get(key)
on window.DOMContentLoaded but it appears at this point the the render has not received the storage item via ipc channel 'configurator-master-set' yet and hence returns null even though the key exists in settings.
I solved this by waiting for ipcRenderer.on('configurator-master-set',()=>{ });
before calling settings.get(key)
but perhaps settings.get()
could wait for the initial set before it returns any values?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.