import { contextBridge , shell , ipcRenderer } from "electron" ; import { WetSaveFilesEntry } from "web-ext-translator-shared" ; const extDir = window . location . hash . substr ( 1 ) ; let isDirty = false ; let forceQuit = false ; window . addEventListener ( "beforeunload" , ( evt ) => { if ( ! forceQuit && isDirty ) { evt . returnValue = false ; setTimeout ( ( ) => { if ( ipcRenderer . sendSync ( "close" ) ) { forceQuit = true ; window . close ( ) ; } } ) ; } } ) ; contextBridge . exposeInMainWorld ( "electronBridge" , { loadFiles ( ) { return ipcRenderer . sendSync ( "load-files" , extDir ) ; } , saveFiles ( files ) { const error = ipcRenderer . sendSync ( "save-files" , extDir , files ) ; if ( ! error ) isDirty = false ; return error ; } , setDirty ( dirty ) { isDirty = dirty ; } , openDirectory ( ) { ipcRenderer . send ( "open-directory" ) ; } , openBrowser ( url ) { shell . openExternal ( url ) ; } , } ) ;