[go: up one dir, main page]

Skip to content

Commit

Permalink
window local-storage export
Browse files Browse the repository at this point in the history
  • Loading branch information
mayfield committed Nov 30, 2022
1 parent bd718aa commit 684ffef
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 7 deletions.
Empty file added pages/dummy.html
Empty file.
12 changes: 12 additions & 0 deletions src/preload/storage-proxy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const {ipcRenderer} = require('electron');

ipcRenderer.on('export', ev => {
ev.sender.send('export-response', JSON.parse(JSON.stringify(localStorage)));
});

ipcRenderer.on('import', (ev, localStorage) => {
localStorage.clear();
for (const [key, value] of Object.entries(localStorage)) {
localStorage.setItem(key, value);
}
});
39 changes: 32 additions & 7 deletions src/windows.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ function handleNewSubWindow(parent, spec, webPrefs) {
...bounds,
webPreferences: {
sandbox: true,
preload: path.join(appPath, 'src', 'preload', 'common.js'),
preload: path.join(appPath, 'src/preload/common.js'),
webPrefs,
}
});
Expand All @@ -601,6 +601,31 @@ function handleNewSubWindow(parent, spec, webPrefs) {
}


export async function settingsExport() {
const win = new electron.BrowserWindow({
show: false,
webPreferences: {
sandbox: true,
preload: path.join(appPath, 'src/preload/storage-proxy.js'),
}
});
const p = new Promise(resolve => win.webContents.on('ipc-message',
(ev, ch, localStorage) => resolve(localStorage)));
let windowStorage;
try {
win.webContents.on('did-finish-load', () => win.webContents.send('export'));
win.loadFile('/pages/dummy.html');
windowStorage = await p;
} finally {
win.destroy();
}
return {
windowConfig: storage.load('windows'),
windowStorage,
};
}


function _openWindow(id, spec) {
console.debug("Opening window:", id, spec.type);
const overlayOptions = {
Expand Down Expand Up @@ -634,7 +659,7 @@ function _openWindow(id, spec) {
roundedCorners: false,
webPreferences: {
sandbox: true,
preload: path.join(appPath, 'src', 'preload', 'common.js'),
preload: path.join(appPath, 'src/preload/common.js'),
webgl: false,
...manifest.webPreferences,
...spec.webPreferences,
Expand Down Expand Up @@ -731,7 +756,7 @@ export function makeCaptiveWindow(options={}, webPrefs={}) {
fullscreenable: false,
webPreferences: {
sandbox: true,
preload: path.join(appPath, 'src', 'preload', 'common.js'),
preload: path.join(appPath, 'src/preload/common.js'),
...webPrefs,
},
...options,
Expand Down Expand Up @@ -814,7 +839,7 @@ export async function zwiftLogin(options) {
height: options.monitor ? 720 : 500,
show: false,
}, {
preload: path.join(appPath, 'src', 'preload', 'zwift-login.js'),
preload: path.join(appPath, 'src/preload/zwift-login.js'),
});
let closed;
let setDone;
Expand Down Expand Up @@ -865,7 +890,7 @@ export async function welcomeSplash() {
...getCurrentDisplay().bounds,
webPreferences: {
sandbox: true,
preload: path.join(appPath, 'src', 'preload', 'common.js'),
preload: path.join(appPath, 'src/preload/common.js'),
},
});
welcomeWin.removeMenu();
Expand All @@ -890,7 +915,7 @@ export async function patronLink() {
height: 720,
disableNewWindowHandler: true,
}, {
preload: path.join(appPath, 'src', 'preload', 'patron-link.js'),
preload: path.join(appPath, 'src/preload/patron-link.js'),
partition: 'persist:patreon',
});
// Prevent Patreon's datedome.co bot service from blocking us.
Expand Down Expand Up @@ -965,7 +990,7 @@ export async function systemMessage(msg) {
alwaysOnTop: true,
webPreferences: {
sandbox: true,
preload: path.join(appPath, 'src', 'preload', 'common.js'),
preload: path.join(appPath, 'src/preload/common.js'),
},
});
sysWin.removeMenu();
Expand Down

0 comments on commit 684ffef

Please sign in to comment.