77 screen ,
88 Rectangle ,
99 NativeImage ,
10+ WebPreferences ,
1011} from 'electron' ;
1112import i18next from 'i18next' ;
1213import { createStructuredSelector } from 'reselect' ;
@@ -25,6 +26,14 @@ import {
2526} from '../selectors' ;
2627import { getTrayIconPath } from './icons' ;
2728
29+
30+ const webPreferences : WebPreferences = {
31+ nodeIntegration : true ,
32+ nodeIntegrationInSubFrames : true ,
33+ webviewTag : true ,
34+ worldSafeExecuteJavaScript : true ,
35+ } ;
36+
2837const selectRootWindowState = ( { rootWindowState } : RootState ) : WindowState => rootWindowState ?? {
2938 bounds : {
3039 x : 0 ,
@@ -54,12 +63,7 @@ export const createRootWindow = (): BrowserWindow => {
5463 titleBarStyle : 'hidden' ,
5564 backgroundColor : '#2f343d' ,
5665 show : false ,
57- webPreferences : {
58- nodeIntegration : true ,
59- nodeIntegrationInSubFrames : true ,
60- webviewTag : true ,
61- worldSafeExecuteJavaScript : true ,
62- } ,
66+ webPreferences,
6367 } ) ;
6468
6569 rootWindow . addListener ( 'close' , ( event ) => {
@@ -298,8 +302,35 @@ export const showRootWindow = async (rootWindow: BrowserWindow): Promise<void> =
298302
299303 return new Promise ( ( resolve ) => {
300304 rootWindow . addListener ( 'ready-to-show' , ( ) => {
305+ applyRootWindowState ( ) ;
301306 setupRootWindow ( ) ;
302307 resolve ( ) ;
303308 } ) ;
304309 } ) ;
305310} ;
311+
312+ export const exportLocalStorage = async ( ) : Promise < Record < string , string > > => {
313+ try {
314+ const tempWindow = new BrowserWindow ( {
315+ show : false ,
316+ webPreferences,
317+ } ) ;
318+
319+ tempWindow . loadFile ( path . join ( app . getAppPath ( ) , 'app/index.html' ) ) ;
320+
321+ await new Promise ( ( resolve ) => {
322+ tempWindow . addListener ( 'ready-to-show' , ( ) => {
323+ resolve ( ) ;
324+ } ) ;
325+ } ) ;
326+
327+ return tempWindow . webContents . executeJavaScript ( `(() => {
328+ const data = ({...localStorage})
329+ localStorage.clear();
330+ return data;
331+ })()` ) ;
332+ } catch ( error ) {
333+ console . error ( error ) ;
334+ return { } ;
335+ }
336+ } ;
0 commit comments