ipc/store: sync web on load and tweak
This commit is contained in:
parent
6b2a7fb58e
commit
31d0975452
@ -5,7 +5,7 @@ export default ({ browserName, browserInfo, browserType }, { evalInWindow, evalO
|
|||||||
const injection = `(() => {
|
const injection = `(() => {
|
||||||
if (window.Gluon) return;
|
if (window.Gluon) return;
|
||||||
let onIPCReply = {}, ipcListeners = {};
|
let onIPCReply = {}, ipcListeners = {};
|
||||||
window.Gluon = {
|
const Gluon = {
|
||||||
versions: {
|
versions: {
|
||||||
gluon: '${process.versions.gluon}',
|
gluon: '${process.versions.gluon}',
|
||||||
builder: '${'GLUGUN_VERSION' === 'G\LUGUN_VERSION' ? 'nothing' : 'Glugun GLUGUN_VERSION'}',
|
builder: '${'GLUGUN_VERSION' === 'G\LUGUN_VERSION' ? 'nothing' : 'Glugun GLUGUN_VERSION'}',
|
||||||
@ -30,7 +30,7 @@ window.Gluon = {
|
|||||||
const isReply = !!id;
|
const isReply = !!id;
|
||||||
id = id ?? Math.random().toString().split('.')[1];
|
id = id ?? Math.random().toString().split('.')[1];
|
||||||
|
|
||||||
window.Gluon.ipc._send(JSON.stringify({
|
Gluon.ipc._send(JSON.stringify({
|
||||||
id,
|
id,
|
||||||
type,
|
type,
|
||||||
data
|
data
|
||||||
@ -82,9 +82,10 @@ window.Gluon = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const _store = {};
|
let _store = {};
|
||||||
|
Gluon.ipc.send('web store sync').then(syncedStore => _store = syncedStore);
|
||||||
const updateBackend = (key, value) => { // update backend with a key/value change
|
const updateBackend = (key, value) => { // update backend with a key/value change
|
||||||
Gluon.ipc.send('web store change', { key, value });
|
Gluon.ipc.send('web store write', { key, value });
|
||||||
};
|
};
|
||||||
|
|
||||||
Gluon.ipc.store = new Proxy({
|
Gluon.ipc.store = new Proxy({
|
||||||
@ -125,11 +126,13 @@ Gluon.ipc.store = new Proxy({
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Gluon.ipc.on('backend store change', ({ key, value }) => {
|
Gluon.ipc.on('backend store write', ({ key, value }) => {
|
||||||
if (value === undefined) delete _store[key];
|
if (value === undefined) delete _store[key];
|
||||||
else _store[key] = value;
|
else _store[key] = value;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
window.Gluon = Gluon;
|
||||||
|
|
||||||
delete window._gluonSend;
|
delete window._gluonSend;
|
||||||
})();`;
|
})();`;
|
||||||
|
|
||||||
@ -237,7 +240,7 @@ delete window._gluonSend;
|
|||||||
const updateWeb = (key, value) => { // update web with a key/value change
|
const updateWeb = (key, value) => { // update web with a key/value change
|
||||||
if (logIPC) log('IPC: store write (backend)', key, value);
|
if (logIPC) log('IPC: store write (backend)', key, value);
|
||||||
|
|
||||||
API.send('backend store change', { key, value });
|
API.send('backend store write', { key, value });
|
||||||
};
|
};
|
||||||
|
|
||||||
API.store = new Proxy({
|
API.store = new Proxy({
|
||||||
@ -278,13 +281,15 @@ delete window._gluonSend;
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
API.on('web store change', ({ key, value }) => {
|
API.on('web store write', ({ key, value }) => {
|
||||||
if (logIPC) log('IPC: store write (web)', key, value);
|
if (logIPC) log('IPC: store write (web)', key, value);
|
||||||
|
|
||||||
if (value === undefined) delete _store[key];
|
if (value === undefined) delete _store[key];
|
||||||
else _store[key] = value;
|
else _store[key] = value;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
API.on('web store sync', () => _store);
|
||||||
|
|
||||||
API = new Proxy(API, { // setter and deleter API
|
API = new Proxy(API, { // setter and deleter API
|
||||||
set(_obj, key, value) {
|
set(_obj, key, value) {
|
||||||
expose(key, value);
|
expose(key, value);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user