@@ -31,7 +31,7 @@ import autoUpdater from './updater'
31
31
import { generateId } from '@hcengineering/core'
32
32
import { DownloadItem } from '@hcengineering/desktop-downloads'
33
33
import { rebuildJumpList , setupWindowsSpecific } from './windowsSpecificSetup'
34
-
34
+ import { readPackedConfig } from './config'
35
35
36
36
let mainWindow : BrowserWindow | undefined
37
37
let winBadge : any
@@ -47,6 +47,9 @@ const preloadScriptPath = path.join(app.getAppPath(), 'dist', 'main', 'preload.j
47
47
const defaultWidth = 1440
48
48
const defaultHeight = 960
49
49
50
+ const packedConfig = readPackedConfig ( )
51
+ log . info ( 'packed config' , packedConfig )
52
+
50
53
const envPath = path . join ( app . getAppPath ( ) , isDev ? '.env-dev' : '.env' )
51
54
console . log ( 'do loading env from' , envPath )
52
55
dotenvConfig ( {
@@ -74,7 +77,7 @@ function readServerUrl (): string {
74
77
return process . env . FRONT_URL ?? 'http://huly.local:8087'
75
78
}
76
79
77
- return ( ( settings as any ) . get ( 'server' , process . env . FRONT_URL ) as string ) ?? 'https://huly.app'
80
+ return ( ( settings as any ) . get ( 'server' ) as string ) ?? packedConfig ?. server ?? process . env . FRONT_URL ?? 'https://huly.app'
78
81
}
79
82
80
83
// Handle creating/removing shortcuts on Windows when installing/uninstalling.
@@ -94,8 +97,8 @@ const disabledFeatures = [
94
97
95
98
app . commandLine . appendSwitch ( 'disable-features' , disabledFeatures . join ( ',' ) )
96
99
97
- function setupWindowTitleBar ( windowOptions : Electron . BrowserWindowConstructorOptions ) : void {
98
- if ( isWindows ) {
100
+ function setupWindowTitleBar ( windowOptions : Electron . BrowserWindowConstructorOptions ) : void {
101
+ if ( isWindows ) {
99
102
// on Windows we use frameless window with custom hand-made title bar
100
103
windowOptions . frame = false
101
104
} else {
@@ -269,31 +272,31 @@ const createWindow = async (): Promise<void> => {
269
272
}
270
273
} )
271
274
272
- function sendWindowMaximizedMessage ( maximized : boolean ) : void {
275
+ function sendWindowMaximizedMessage ( maximized : boolean ) : void {
273
276
mainWindow ?. webContents . send ( 'window-state-changed' , maximized ? 'maximized' : 'unmaximized' )
274
277
}
275
278
276
279
mainWindow . on ( 'blur' , ( ) => {
277
280
mainWindow ?. webContents . send ( 'window-focus-loss' )
278
- } ) ;
281
+ } )
279
282
280
283
mainWindow . on ( 'maximize' , ( ) => {
281
284
sendWindowMaximizedMessage ( true )
282
- } ) ;
285
+ } )
283
286
284
287
mainWindow . on ( 'unmaximize' , ( ) => {
285
288
sendWindowMaximizedMessage ( false )
286
- } ) ;
289
+ } )
287
290
288
291
mainWindow . on ( 'enter-full-screen' , ( ) => {
289
292
sendWindowMaximizedMessage ( true )
290
- } ) ;
293
+ } )
291
294
292
295
mainWindow . on ( 'leave-full-screen' , ( ) => {
293
- if ( mainWindow ) {
294
- sendWindowMaximizedMessage ( mainWindow . isMaximized ( ) )
296
+ if ( mainWindow != null ) {
297
+ sendWindowMaximizedMessage ( mainWindow . isMaximized ( ) )
295
298
}
296
- } ) ;
299
+ } )
297
300
298
301
if ( isMac ) {
299
302
mainWindow . on ( 'close' , ( event ) => {
@@ -309,12 +312,12 @@ const createWindow = async (): Promise<void> => {
309
312
}
310
313
}
311
314
312
- function sendCommand ( cmd : string , ...args : any [ ] ) : void {
315
+ function sendCommand ( cmd : string , ...args : any [ ] ) : void {
313
316
mainWindow ?. webContents . send ( cmd , ...args )
314
317
}
315
318
316
319
function activateWindow ( ) : void {
317
- if ( mainWindow ) {
320
+ if ( mainWindow != null ) {
318
321
if ( mainWindow . isMinimized ( ) ) {
319
322
mainWindow . restore ( )
320
323
}
@@ -373,7 +376,23 @@ ipcMain.on('set-combined-config', (_event: any, config: Config) => {
373
376
setupCookieHandler ( config )
374
377
375
378
const updatesUrl = process . env . DESKTOP_UPDATES_URL ?? config . DESKTOP_UPDATES_URL ?? 'https://dist.huly.io'
376
- const updatesChannel = process . env . DESKTOP_UPDATES_CHANNEL ?? config . DESKTOP_UPDATES_CHANNEL ?? 'huly'
379
+ // NOTE: env format is: default_value;key1:value1;key2:value2...
380
+ const updatesChannels = ( process . env . DESKTOP_UPDATES_CHANNEL ?? config . DESKTOP_UPDATES_CHANNEL ?? 'huly' ) . split ( ';' ) . map ( c => c . trim ( ) . split ( ':' ) )
381
+ const updateChannelsMap : Record < string , string > = { }
382
+ for ( const channelInfo of updatesChannels ) {
383
+ if ( channelInfo . length === 1 ) {
384
+ updateChannelsMap . default = channelInfo [ 0 ]
385
+ } else if ( channelInfo . length === 2 ) {
386
+ const [ key , value ] = channelInfo
387
+ updateChannelsMap [ key ] = value
388
+ }
389
+ }
390
+
391
+ const updatesChannelKey = packedConfig ?. updatesChannelKey ?? 'default'
392
+ const updatesChannel = updateChannelsMap [ updatesChannelKey ] ?? updateChannelsMap . default ?? 'huly'
393
+
394
+ log . info ( 'updates channels' , updatesChannels )
395
+ log . info ( 'updates channel' , updatesChannelKey , updatesChannel )
377
396
378
397
autoUpdater . setFeedURL ( {
379
398
provider : 'generic' ,
@@ -414,35 +433,35 @@ ipcMain.on('set-front-cookie', function (event: any, host: string, name: string,
414
433
} )
415
434
416
435
ipcMain . handle ( 'window-minimize' , ( ) => {
417
- mainWindow ?. minimize ( ) ;
418
- } ) ;
436
+ mainWindow ?. minimize ( )
437
+ } )
419
438
420
439
ipcMain . handle ( 'window-maximize' , ( ) => {
421
- if ( mainWindow ) {
440
+ if ( mainWindow != null ) {
422
441
if ( mainWindow . isMaximized ( ) ) {
423
- mainWindow . unmaximize ( ) ;
442
+ mainWindow . unmaximize ( )
424
443
} else {
425
- mainWindow . maximize ( ) ;
444
+ mainWindow . maximize ( )
426
445
}
427
446
}
428
- } ) ;
447
+ } )
429
448
430
449
ipcMain . handle ( 'window-close' , ( ) => {
431
- mainWindow ?. close ( ) ;
432
- } ) ;
450
+ mainWindow ?. close ( )
451
+ } )
433
452
434
453
ipcMain . handle ( 'get-is-os-using-dark-theme' , ( ) => {
435
- return nativeTheme . shouldUseDarkColors ;
436
- } ) ;
454
+ return nativeTheme . shouldUseDarkColors
455
+ } )
437
456
438
457
ipcMain . handle ( 'menu-action' , async ( _event : any , action : MenuBarAction ) => {
439
458
dipatchMenuBarAction ( mainWindow , action )
440
- } ) ;
459
+ } )
441
460
442
461
if ( isWindows ) {
443
462
ipcMain . on ( 'rebuild-user-jump-list' , ( _event : any , spares : JumpListSpares ) => {
444
463
rebuildJumpList ( spares )
445
- } ) ;
464
+ } )
446
465
}
447
466
448
467
const gotTheLock = app . requestSingleInstanceLock ( )
0 commit comments