11'use strict'
22
3- const { app, ipcMain } = require ( 'electron' )
4- const fs = require ( 'fs' )
5- const path = require ( 'path' )
3+ const { app } = require ( 'electron' )
4+ const fs = require ( 'node: fs' )
5+ const path = require ( 'node: path' )
66const {
77 DebUpdater,
88 AppImageUpdater,
99 NsisUpdater,
1010 AppUpdater
1111} = require ( 'electron-updater' )
12- const Alert = require ( 'electron-alert' )
1312const yaml = require ( 'js-yaml' )
1413const i18next = require ( 'i18next' )
1514
@@ -21,26 +20,13 @@ const {
2120 showLoadingWindow,
2221 hideLoadingWindow
2322} = require ( '../window-creators/change-loading-win-visibility-state' )
24- const {
25- closeAlert
26- } = require ( '../modal-dialog-src/utils' )
2723const { rootPath } = require ( '../helpers/root-path' )
2824const parseEnvValToBool = require ( '../helpers/parse-env-val-to-bool' )
2925const {
3026 IS_MAC ,
3127 IS_LINUX ,
3228 IS_WIN
3329} = require ( '../helpers/platform-identifiers' )
34- const {
35- WINDOW_EVENT_NAMES ,
36- addOnceProcEventHandler
37- } = require ( '../window-creators/window-event-manager' )
38- const getUIFontsAsCSSString = require (
39- '../helpers/get-ui-fonts-as-css-string'
40- )
41- const ThemeIpcChannelHandlers = require (
42- '../window-creators/main-renderer-ipc-bridge/theme-ipc-channel-handlers'
43- )
4430const AutoUpdateIpcChannelHandlers = require (
4531 '../window-creators/main-renderer-ipc-bridge/auto-update-ipc-channel-handlers'
4632)
@@ -51,27 +37,7 @@ const { changeMenuItemStatesById } = require('../create-menu/utils')
5137const isAutoUpdateDisabled = parseEnvValToBool (
5238 process . env . IS_AUTO_UPDATE_DISABLED
5339)
54- /*
55- * TODO: This is a temporary flag for dev to avoid breaking
56- * the workflow and should be removed after the implementation
57- * of UI along with the old toast implementation
58- */
59- const shouldMainUIAutoUpdateToastBeUsed = parseEnvValToBool (
60- process . env . SHOULD_MAIN_UI_AUTO_UPDATE_TOAST_BE_USED
61- )
6240
63- const fontsStyle = getUIFontsAsCSSString ( )
64- const themesStyle = fs . readFileSync ( path . join (
65- __dirname , '../window-creators/layouts/themes.css'
66- ) )
67- const toastStyle = fs . readFileSync ( path . join (
68- __dirname , 'toast-src/toast.css'
69- ) )
70- const toastScript = fs . readFileSync ( path . join (
71- __dirname , 'toast-src/toast.js'
72- ) )
73-
74- let toast
7541let autoUpdater
7642let uCheckInterval
7743let isIntervalUpdate = false
@@ -82,47 +48,22 @@ try {
8248 electronBuilderConfig = require ( path . join ( rootPath , 'electron-builder-config' ) )
8349} catch ( err ) { }
8450
85- const fonts = `<style>${ fontsStyle } </style>`
86- const themes = `<style>${ themesStyle } </style>`
87- const style = `<style>${ toastStyle } </style>`
88- const script = `<script type="text/javascript">${ toastScript } </script>`
89- const sound = { freq : 'F2' , type : 'triange' , duration : 1.5 }
90-
9151const _sendProgress = ( progress ) => {
9252 if ( ! Number . isFinite ( progress ) ) {
9353 return
9454 }
95- if ( shouldMainUIAutoUpdateToastBeUsed ) {
96- const mainWindow = wins ?. [ WINDOW_NAMES . MAIN_WINDOW ]
97- AutoUpdateIpcChannelHandlers . sendProgressToastEvent ( mainWindow , {
98- progress
99- } )
10055
101- return
102- }
56+ const mainWindow = wins ?. [ WINDOW_NAMES . MAIN_WINDOW ]
10357
104- toast ?. browserWindow ?. webContents . send (
105- 'progress' ,
58+ AutoUpdateIpcChannelHandlers . sendProgressToastEvent ( mainWindow , {
10659 progress
107- )
108- }
109- const _sendUid = ( alert ) => {
110- if ( ! alert ?. uid ) {
111- return
112- }
113-
114- alert ?. browserWindow ?. webContents . send (
115- 'auto-update-toast:uid' ,
116- alert . uid
117- )
60+ } )
11861}
11962
12063const _fireToast = async (
12164 opts = { } ,
12265 hooks = { }
12366) => {
124- closeAlert ( toast )
125-
12667 const mainWindow = wins ?. [ WINDOW_NAMES . MAIN_WINDOW ]
12768
12869 if (
@@ -131,162 +72,23 @@ const _fireToast = async (
13172 ) {
13273 return { dismiss : 'close' }
13374 }
134- if ( shouldMainUIAutoUpdateToastBeUsed ) {
135- return await AutoUpdateIpcChannelHandlers . sendFireToastEvent (
136- mainWindow ,
137- {
138- icon : 'info' ,
139- title : i18next . t ( 'autoUpdater.title' ) ,
140- text : null ,
141- showConfirmButton : true ,
142- showCancelButton : false ,
143- confirmButtonText : i18next . t ( 'common.confirmButtonText' ) ,
144- cancelButtonText : i18next . t ( 'common.cancelButtonText' ) ,
145- timer : null ,
146- progress : null ,
147-
148- ...opts
149- }
150- )
151- }
15275
153- const {
154- didOpen = ( ) => { } ,
155- didClose = ( ) => { }
156- } = hooks ?? { }
157- const height = 44
158-
159- const alert = new Alert ( [ fonts , themes , style , script ] )
160- toast = alert
161-
162- const eventHandlerCtx = addOnceProcEventHandler (
163- WINDOW_EVENT_NAMES . CLOSED ,
164- ( ) => closeAlert ( alert )
165- )
166- const autoUpdateToastWidthHandler = ( event , data ) => {
167- alert . browserWindow ?. setBounds ( {
168- width : Math . round ( data ?. width ?? 0 )
169- } )
170- }
171- const autoUpdateToastRepositionHandler = ( ) => {
172- const macOffset = wins . mainWindow ?. isFullScreen ( )
173- ? 0
174- : 28
175- const heightOffset = IS_MAC ? macOffset : 40
176- const { x, y, width } = mainWindow . getContentBounds ( )
177- const { width : alWidth } = alert . browserWindow . getContentBounds ( )
178-
179- const boundsOpts = {
180- x : ( x + width ) - alWidth ,
181- y : y + heightOffset ,
182- height
183- }
184-
185- alert . browserWindow . setBounds ( boundsOpts )
186- }
187-
188- const bwOptions = {
189- frame : false ,
190- transparent : true ,
191- thickFrame : false ,
192- closable : false ,
193- hasShadow : false ,
194- backgroundColor : ThemeIpcChannelHandlers . getWindowTitleBackgroundColor ( ) ,
195- darkTheme : false ,
196- height,
197- width : opts ?. width ?? 1000 ,
198- parent : mainWindow ,
199- modal : false ,
200- webPreferences : {
201- contextIsolation : false
202- }
203- }
204- const swalOptions = {
205- toast : true ,
206- position : 'top-end' ,
207- allowOutsideClick : false ,
208-
209- title : i18next . t ( 'autoUpdater.title' ) ,
210- showConfirmButton : true ,
211- showCancelButton : false ,
212- confirmButtonText : i18next . t ( 'common.confirmButtonText' ) ,
213- cancelButtonText : i18next . t ( 'common.cancelButtonText' ) ,
214- timerProgressBar : false ,
215-
216- ...opts ,
217-
218- // This is for the transition to a new implementation
219- // since the library does not support loading icon
220- icon : (
221- ! opts ?. icon ||
222- opts . icon === 'loading'
223- )
224- ? 'info'
225- : opts . icon ,
226-
227- willOpen : ( ) => {
228- if (
229- ! alert ||
230- ! alert . browserWindow
231- ) return
232-
233- alert . browserWindow . hide ( )
234- } ,
235- didOpen : ( ) => {
236- didOpen ( alert )
237-
238- if ( opts ?. icon === 'loading' ) {
239- alert ?. showLoading ( )
240- }
241- if (
242- ! alert ||
243- ! alert . browserWindow
244- ) return
245-
246- alert . browserWindow . show ( )
247- } ,
248- willClose : ( ) => {
249- if (
250- ! alert ||
251- ! alert . browserWindow
252- ) return
253-
254- alert . browserWindow . hide ( )
255- } ,
256- didClose : ( ) => {
257- eventHandlerCtx . removeListener ( )
258- ipcMain . removeListener (
259- `${ alert . uid } auto-update-toast:width` ,
260- autoUpdateToastWidthHandler
261- )
262- ipcMain . removeListener (
263- `${ alert . uid } reposition` ,
264- autoUpdateToastRepositionHandler
265- )
266-
267- didClose ( alert )
76+ return await AutoUpdateIpcChannelHandlers . sendFireToastEvent (
77+ mainWindow ,
78+ {
79+ icon : 'info' ,
80+ title : i18next . t ( 'autoUpdater.title' ) ,
81+ text : null ,
82+ showConfirmButton : true ,
83+ showCancelButton : false ,
84+ confirmButtonText : i18next . t ( 'common.confirmButtonText' ) ,
85+ cancelButtonText : i18next . t ( 'common.cancelButtonText' ) ,
86+ timer : null ,
87+ progress : null ,
88+
89+ ...opts
26890 }
269- }
270-
271- const promise = alert . fire (
272- swalOptions ,
273- bwOptions ,
274- null ,
275- true ,
276- false ,
277- sound
27891 )
279-
280- _sendUid ( alert )
281- ipcMain . on ( `${ alert . uid } auto-update-toast:width` , autoUpdateToastWidthHandler )
282- ipcMain . on ( `${ alert . uid } reposition` , autoUpdateToastRepositionHandler )
283-
284- const res = await promise
285- const dismiss = res ?. value
286- ? 'confirm'
287- : res ?. dismiss
288-
289- return { dismiss }
29092}
29193
29294const _switchMenuItem = ( opts ) => {
0 commit comments