| 
									
										
										
										
											2021-01-27 15:13:33 -06:00
										 |  |  | // Copyright 2017-2021 Signal Messenger, LLC
 | 
					
						
							| 
									
										
										
										
											2020-10-30 15:34:04 -05:00
										 |  |  | // SPDX-License-Identifier: AGPL-3.0-only
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-16 15:14:06 -07:00
										 |  |  | /* global Whisper, window */ | 
					
						
							| 
									
										
										
										
											2018-04-03 15:03:57 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-26 17:53:39 -08:00
										 |  |  | /* eslint-disable global-require, no-inner-declarations */ | 
					
						
							| 
									
										
										
										
											2018-04-03 15:03:57 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-07 15:40:12 -07:00
										 |  |  | const preloadStartTime = Date.now(); | 
					
						
							|  |  |  | let preloadEndTime = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-26 17:53:39 -08:00
										 |  |  | try { | 
					
						
							|  |  |  |   const electron = require('electron'); | 
					
						
							|  |  |  |   const semver = require('semver'); | 
					
						
							| 
									
										
										
										
											2020-03-05 13:14:58 -08:00
										 |  |  |   const _ = require('lodash'); | 
					
						
							| 
									
										
										
										
											2021-08-28 08:27:38 -05:00
										 |  |  |   const { strictAssert } = require('./ts/util/assert'); | 
					
						
							| 
									
										
										
										
											2021-09-13 12:00:32 -07:00
										 |  |  |   const { parseIntWithFallback } = require('./ts/util/parseIntWithFallback'); | 
					
						
							| 
									
										
										
										
											2021-08-18 16:08:14 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |   // It is important to call this as early as possible
 | 
					
						
							|  |  |  |   require('./ts/windows/context'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 13:54:03 -06:00
										 |  |  |   const { | 
					
						
							|  |  |  |     getEnvironment, | 
					
						
							|  |  |  |     setEnvironment, | 
					
						
							|  |  |  |     parseEnvironment, | 
					
						
							|  |  |  |     Environment, | 
					
						
							|  |  |  |   } = require('./ts/environment'); | 
					
						
							| 
									
										
										
										
											2021-06-30 11:57:43 -07:00
										 |  |  |   const ipc = electron.ipcRenderer; | 
					
						
							| 
									
										
										
										
											2018-04-03 15:03:57 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-26 17:53:39 -08:00
										 |  |  |   const { remote } = electron; | 
					
						
							|  |  |  |   const { app } = remote; | 
					
						
							| 
									
										
										
										
											2018-06-01 17:55:35 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-04 16:44:57 -05:00
										 |  |  |   window.sqlInitializer = require('./ts/sql/initialize'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-26 17:53:39 -08:00
										 |  |  |   const config = require('url').parse(window.location.toString(), true).query; | 
					
						
							| 
									
										
										
										
											2019-05-16 15:32:38 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 13:54:03 -06:00
										 |  |  |   setEnvironment(parseEnvironment(config.environment)); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-17 14:27:53 -04:00
										 |  |  |   const log = require('./ts/logging/log'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-26 17:53:39 -08:00
										 |  |  |   let title = config.name; | 
					
						
							| 
									
										
										
										
											2021-02-04 13:54:03 -06:00
										 |  |  |   if (getEnvironment() !== Environment.Production) { | 
					
						
							|  |  |  |     title += ` - ${getEnvironment()}`; | 
					
						
							| 
									
										
										
										
											2020-02-26 17:53:39 -08:00
										 |  |  |   } | 
					
						
							|  |  |  |   if (config.appInstance) { | 
					
						
							|  |  |  |     title += ` - ${config.appInstance}`; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-05-16 15:32:38 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-18 11:27:43 -08:00
										 |  |  |   // Flags for testing
 | 
					
						
							|  |  |  |   window.GV2_ENABLE_SINGLE_CHANGE_PROCESSING = true; | 
					
						
							|  |  |  |   window.GV2_ENABLE_CHANGE_PROCESSING = true; | 
					
						
							|  |  |  |   window.GV2_ENABLE_STATE_PROCESSING = true; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 07:44:44 -08:00
										 |  |  |   window.GV2_MIGRATION_DISABLE_ADD = false; | 
					
						
							|  |  |  |   window.GV2_MIGRATION_DISABLE_INVITE = false; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-15 16:48:09 -07:00
										 |  |  |   window.RETRY_DELAY = false; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-26 17:53:39 -08:00
										 |  |  |   window.platform = process.platform; | 
					
						
							|  |  |  |   window.getTitle = () => title; | 
					
						
							| 
									
										
										
										
											2021-02-18 08:40:26 -08:00
										 |  |  |   window.getLocale = () => config.locale; | 
					
						
							| 
									
										
										
										
											2021-02-04 13:54:03 -06:00
										 |  |  |   window.getEnvironment = getEnvironment; | 
					
						
							| 
									
										
										
										
											2020-02-26 17:53:39 -08:00
										 |  |  |   window.getAppInstance = () => config.appInstance; | 
					
						
							|  |  |  |   window.getVersion = () => config.version; | 
					
						
							| 
									
										
										
										
											2021-09-13 12:00:32 -07:00
										 |  |  |   window.getBuildCreation = () => parseIntWithFallback(config.buildCreation, 0); | 
					
						
							| 
									
										
										
										
											2020-09-09 18:50:44 -04:00
										 |  |  |   window.getExpiration = () => { | 
					
						
							| 
									
										
										
										
											2021-08-23 18:45:11 -04:00
										 |  |  |     const sixtyDays = 60 * 86400 * 1000; | 
					
						
							| 
									
										
										
										
											2020-09-09 18:50:44 -04:00
										 |  |  |     const remoteBuildExpiration = window.storage.get('remoteBuildExpiration'); | 
					
						
							| 
									
										
										
										
											2021-08-23 18:45:11 -04:00
										 |  |  |     const localBuildExpiration = window.Events.getAutoDownloadUpdate() | 
					
						
							|  |  |  |       ? config.buildExpiration | 
					
						
							|  |  |  |       : config.buildExpiration - sixtyDays; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-09 18:50:44 -04:00
										 |  |  |     if (remoteBuildExpiration) { | 
					
						
							|  |  |  |       return remoteBuildExpiration < config.buildExpiration | 
					
						
							|  |  |  |         ? remoteBuildExpiration | 
					
						
							| 
									
										
										
										
											2021-08-23 18:45:11 -04:00
										 |  |  |         : localBuildExpiration; | 
					
						
							| 
									
										
										
										
											2020-09-09 18:50:44 -04:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-08-23 18:45:11 -04:00
										 |  |  |     return localBuildExpiration; | 
					
						
							| 
									
										
										
										
											2020-09-09 18:50:44 -04:00
										 |  |  |   }; | 
					
						
							| 
									
										
										
										
											2020-02-26 17:53:39 -08:00
										 |  |  |   window.getNodeVersion = () => config.node_version; | 
					
						
							|  |  |  |   window.getHostName = () => config.hostname; | 
					
						
							|  |  |  |   window.getServerTrustRoot = () => config.serverTrustRoot; | 
					
						
							| 
									
										
										
										
											2020-04-15 16:12:28 -07:00
										 |  |  |   window.getServerPublicParams = () => config.serverPublicParams; | 
					
						
							| 
									
										
										
										
											2020-12-07 13:40:11 -06:00
										 |  |  |   window.getSfuUrl = () => config.sfuUrl; | 
					
						
							| 
									
										
										
										
											2020-02-26 17:53:39 -08:00
										 |  |  |   window.isBehindProxy = () => Boolean(config.proxyUrl); | 
					
						
							| 
									
										
										
										
											2021-05-11 15:59:21 -05:00
										 |  |  |   window.getAutoLaunch = () => app.getLoginItemSettings().openAtLogin; | 
					
						
							|  |  |  |   window.setAutoLaunch = value => { | 
					
						
							|  |  |  |     app.setLoginItemSettings({ openAtLogin: Boolean(value) }); | 
					
						
							|  |  |  |   }; | 
					
						
							| 
									
										
										
										
											2020-02-26 17:53:39 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   window.isBeforeVersion = (toCheck, baseVersion) => { | 
					
						
							|  |  |  |     try { | 
					
						
							|  |  |  |       return semver.lt(toCheck, baseVersion); | 
					
						
							|  |  |  |     } catch (error) { | 
					
						
							| 
									
										
										
										
											2021-09-17 14:27:53 -04:00
										 |  |  |       log.error( | 
					
						
							| 
									
										
										
										
											2020-02-26 17:53:39 -08:00
										 |  |  |         `isBeforeVersion error: toCheck: ${toCheck}, baseVersion: ${baseVersion}`, | 
					
						
							|  |  |  |         error && error.stack ? error.stack : error | 
					
						
							|  |  |  |       ); | 
					
						
							|  |  |  |       return true; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   }; | 
					
						
							| 
									
										
										
										
											2020-07-24 16:32:08 -07:00
										 |  |  |   window.isAfterVersion = (toCheck, baseVersion) => { | 
					
						
							|  |  |  |     try { | 
					
						
							|  |  |  |       return semver.gt(toCheck, baseVersion); | 
					
						
							|  |  |  |     } catch (error) { | 
					
						
							| 
									
										
										
										
											2021-09-17 14:27:53 -04:00
										 |  |  |       log.error( | 
					
						
							| 
									
										
										
										
											2020-07-24 16:32:08 -07:00
										 |  |  |         `isBeforeVersion error: toCheck: ${toCheck}, baseVersion: ${baseVersion}`, | 
					
						
							|  |  |  |         error && error.stack ? error.stack : error | 
					
						
							|  |  |  |       ); | 
					
						
							|  |  |  |       return true; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   }; | 
					
						
							| 
									
										
										
										
											2018-07-20 14:52:52 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-26 17:53:39 -08:00
										 |  |  |   const localeMessages = ipc.sendSync('locale-data'); | 
					
						
							| 
									
										
										
										
											2018-04-03 15:03:57 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-26 17:53:39 -08:00
										 |  |  |   window.setBadgeCount = count => ipc.send('set-badge-count', count); | 
					
						
							| 
									
										
										
										
											2018-04-03 15:03:57 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-13 16:43:56 -07:00
										 |  |  |   let connectStartTime = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-28 14:37:09 -07:00
										 |  |  |   window.logAuthenticatedConnect = () => { | 
					
						
							| 
									
										
										
										
											2021-04-13 16:43:56 -07:00
										 |  |  |     if (connectStartTime === 0) { | 
					
						
							|  |  |  |       connectStartTime = Date.now(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   window.logAppLoadedEvent = ({ processedCount }) => | 
					
						
							| 
									
										
										
										
											2021-04-07 15:40:12 -07:00
										 |  |  |     ipc.send('signal-app-loaded', { | 
					
						
							|  |  |  |       preloadTime: preloadEndTime - preloadStartTime, | 
					
						
							| 
									
										
										
										
											2021-04-13 16:43:56 -07:00
										 |  |  |       connectTime: connectStartTime - preloadEndTime, | 
					
						
							|  |  |  |       processedCount, | 
					
						
							| 
									
										
										
										
											2021-04-07 15:40:12 -07:00
										 |  |  |     }); | 
					
						
							| 
									
										
										
										
											2021-01-15 12:30:58 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-26 17:53:39 -08:00
										 |  |  |   // We never do these in our code, so we'll prevent it everywhere
 | 
					
						
							|  |  |  |   window.open = () => null; | 
					
						
							|  |  |  |   // eslint-disable-next-line no-eval, no-multi-assign
 | 
					
						
							|  |  |  |   window.eval = global.eval = () => null; | 
					
						
							| 
									
										
										
										
											2018-05-18 18:21:02 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-26 17:53:39 -08:00
										 |  |  |   window.drawAttention = () => { | 
					
						
							| 
									
										
										
										
											2021-09-17 14:27:53 -04:00
										 |  |  |     log.info('draw attention'); | 
					
						
							| 
									
										
										
										
											2020-02-26 17:53:39 -08:00
										 |  |  |     ipc.send('draw-attention'); | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  |   window.showWindow = () => { | 
					
						
							| 
									
										
										
										
											2021-09-17 14:27:53 -04:00
										 |  |  |     log.info('show window'); | 
					
						
							| 
									
										
										
										
											2020-02-26 17:53:39 -08:00
										 |  |  |     ipc.send('show-window'); | 
					
						
							|  |  |  |   }; | 
					
						
							| 
									
										
										
										
											2018-04-03 15:03:57 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-01 14:01:25 -06:00
										 |  |  |   window.titleBarDoubleClick = () => { | 
					
						
							|  |  |  |     ipc.send('title-bar-double-click'); | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-26 17:53:39 -08:00
										 |  |  |   window.setAutoHideMenuBar = autoHide => | 
					
						
							|  |  |  |     ipc.send('set-auto-hide-menu-bar', autoHide); | 
					
						
							| 
									
										
										
										
											2018-04-03 15:03:57 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-26 17:53:39 -08:00
										 |  |  |   window.setMenuBarVisibility = visibility => | 
					
						
							|  |  |  |     ipc.send('set-menu-bar-visibility', visibility); | 
					
						
							| 
									
										
										
										
											2018-04-03 15:03:57 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-29 12:18:03 -05:00
										 |  |  |   window.updateSystemTraySetting = ( | 
					
						
							|  |  |  |     systemTraySetting /* : Readonly<SystemTraySetting> */ | 
					
						
							|  |  |  |   ) => { | 
					
						
							|  |  |  |     ipc.send('update-system-tray-setting', systemTraySetting); | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-26 17:53:39 -08:00
										 |  |  |   window.restart = () => { | 
					
						
							| 
									
										
										
										
											2021-09-17 14:27:53 -04:00
										 |  |  |     log.info('restart'); | 
					
						
							| 
									
										
										
										
											2020-02-26 17:53:39 -08:00
										 |  |  |     ipc.send('restart'); | 
					
						
							|  |  |  |   }; | 
					
						
							| 
									
										
										
										
											2020-04-28 14:18:41 -07:00
										 |  |  |   window.shutdown = () => { | 
					
						
							| 
									
										
										
										
											2021-09-17 14:27:53 -04:00
										 |  |  |     log.info('shutdown'); | 
					
						
							| 
									
										
										
										
											2020-04-28 14:18:41 -07:00
										 |  |  |     ipc.send('shutdown'); | 
					
						
							|  |  |  |   }; | 
					
						
							| 
									
										
										
										
											2021-07-15 16:48:09 -07:00
										 |  |  |   window.showDebugLog = () => { | 
					
						
							| 
									
										
										
										
											2021-09-17 14:27:53 -04:00
										 |  |  |     log.info('showDebugLog'); | 
					
						
							| 
									
										
										
										
											2021-07-15 16:48:09 -07:00
										 |  |  |     ipc.send('show-debug-log'); | 
					
						
							|  |  |  |   }; | 
					
						
							| 
									
										
										
										
											2018-04-03 15:03:57 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-26 17:53:39 -08:00
										 |  |  |   window.closeAbout = () => ipc.send('close-about'); | 
					
						
							|  |  |  |   window.readyForUpdates = () => ipc.send('ready-for-updates'); | 
					
						
							| 
									
										
										
										
											2018-04-03 15:03:57 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-26 17:53:39 -08:00
										 |  |  |   window.updateTrayIcon = unreadCount => | 
					
						
							|  |  |  |     ipc.send('update-tray-icon', unreadCount); | 
					
						
							| 
									
										
										
										
											2018-04-03 15:03:57 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-30 11:43:16 -05:00
										 |  |  |   ipc.on('additional-log-data-request', async event => { | 
					
						
							|  |  |  |     const ourConversation = window.ConversationController.getOurConversation(); | 
					
						
							|  |  |  |     const ourCapabilities = ourConversation | 
					
						
							|  |  |  |       ? ourConversation.get('capabilities') | 
					
						
							|  |  |  |       : undefined; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const remoteConfig = window.storage.get('remoteConfig') || {}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     let statistics; | 
					
						
							|  |  |  |     try { | 
					
						
							|  |  |  |       statistics = await window.Signal.Data.getStatisticsForLogging(); | 
					
						
							|  |  |  |     } catch (error) { | 
					
						
							|  |  |  |       statistics = {}; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-09 19:38:11 -07:00
										 |  |  |     const ourUuid = window.textsecure.storage.user.getUuid(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-30 11:43:16 -05:00
										 |  |  |     event.sender.send('additional-log-data-response', { | 
					
						
							|  |  |  |       capabilities: ourCapabilities || {}, | 
					
						
							| 
									
										
										
										
											2021-08-06 17:34:48 -07:00
										 |  |  |       remoteConfig: _.mapValues(remoteConfig, ({ value, enabled }) => { | 
					
						
							|  |  |  |         const enableString = enabled ? 'enabled' : 'disabled'; | 
					
						
							|  |  |  |         const valueString = value && value !== 'TRUE' ? ` ${value}` : ''; | 
					
						
							|  |  |  |         return `${enableString}${valueString}`; | 
					
						
							|  |  |  |       }), | 
					
						
							| 
									
										
										
										
											2021-07-30 11:43:16 -05:00
										 |  |  |       statistics, | 
					
						
							|  |  |  |       user: { | 
					
						
							|  |  |  |         deviceId: window.textsecure.storage.user.getDeviceId(), | 
					
						
							|  |  |  |         e164: window.textsecure.storage.user.getNumber(), | 
					
						
							| 
									
										
										
										
											2021-09-09 19:38:11 -07:00
										 |  |  |         uuid: ourUuid && ourUuid.toString(), | 
					
						
							| 
									
										
										
										
											2021-07-30 11:43:16 -05:00
										 |  |  |         conversationId: ourConversation && ourConversation.id, | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-26 17:53:39 -08:00
										 |  |  |   ipc.on('set-up-as-new-device', () => { | 
					
						
							|  |  |  |     Whisper.events.trigger('setupAsNewDevice'); | 
					
						
							|  |  |  |   }); | 
					
						
							| 
									
										
										
										
											2018-04-03 15:03:57 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-26 17:53:39 -08:00
										 |  |  |   ipc.on('set-up-as-standalone', () => { | 
					
						
							|  |  |  |     Whisper.events.trigger('setupAsStandalone'); | 
					
						
							|  |  |  |   }); | 
					
						
							| 
									
										
										
										
											2018-04-03 15:03:57 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-05 17:09:29 -07:00
										 |  |  |   ipc.on('challenge:response', (_event, response) => { | 
					
						
							|  |  |  |     Whisper.events.trigger('challengeResponse', response); | 
					
						
							|  |  |  |   }); | 
					
						
							| 
									
										
										
										
											2021-06-09 15:28:54 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |   ipc.on('power-channel:suspend', () => { | 
					
						
							|  |  |  |     Whisper.events.trigger('powerMonitorSuspend'); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   ipc.on('power-channel:resume', () => { | 
					
						
							|  |  |  |     Whisper.events.trigger('powerMonitorResume'); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-05 17:09:29 -07:00
										 |  |  |   window.sendChallengeRequest = request => | 
					
						
							|  |  |  |     ipc.send('challenge:request', request); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-01 14:01:25 -06:00
										 |  |  |   { | 
					
						
							|  |  |  |     let isFullScreen = config.isFullScreen === 'true'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     window.isFullScreen = () => isFullScreen; | 
					
						
							|  |  |  |     // This is later overwritten.
 | 
					
						
							|  |  |  |     window.onFullScreenChange = _.noop; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ipc.on('full-screen-change', (_event, isFull) => { | 
					
						
							|  |  |  |       isFullScreen = Boolean(isFull); | 
					
						
							|  |  |  |       window.onFullScreenChange(isFullScreen); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-26 17:53:39 -08:00
										 |  |  |   // Settings-related events
 | 
					
						
							| 
									
										
										
										
											2018-07-03 15:33:50 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-26 17:53:39 -08:00
										 |  |  |   window.showSettings = () => ipc.send('show-settings'); | 
					
						
							|  |  |  |   window.showPermissionsPopup = () => ipc.send('show-permissions-popup'); | 
					
						
							| 
									
										
										
										
											2020-06-04 11:16:19 -07:00
										 |  |  |   window.showCallingPermissionsPopup = forCamera => | 
					
						
							|  |  |  |     ipc.invoke('show-calling-permissions-popup', forCamera); | 
					
						
							| 
									
										
										
										
											2018-07-03 15:33:50 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-26 17:53:39 -08:00
										 |  |  |   ipc.on('show-keyboard-shortcuts', () => { | 
					
						
							|  |  |  |     window.Events.showKeyboardShortcuts(); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  |   ipc.on('add-dark-overlay', () => { | 
					
						
							|  |  |  |     window.Events.addDarkOverlay(); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  |   ipc.on('remove-dark-overlay', () => { | 
					
						
							|  |  |  |     window.Events.removeDarkOverlay(); | 
					
						
							|  |  |  |   }); | 
					
						
							| 
									
										
										
										
											2018-04-03 15:03:57 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-18 16:08:14 -04:00
										 |  |  |   require('./ts/windows/preload'); | 
					
						
							| 
									
										
										
										
											2020-06-04 11:16:19 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-26 17:53:39 -08:00
										 |  |  |   window.getBuiltInImages = () => | 
					
						
							|  |  |  |     new Promise((resolve, reject) => { | 
					
						
							|  |  |  |       ipc.once('get-success-built-in-images', (_event, error, value) => { | 
					
						
							|  |  |  |         if (error) { | 
					
						
							|  |  |  |           return reject(new Error(error)); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2019-10-04 11:06:17 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-26 17:53:39 -08:00
										 |  |  |         return resolve(value); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       ipc.send('get-built-in-images'); | 
					
						
							| 
									
										
										
										
											2019-10-04 11:06:17 -07:00
										 |  |  |     }); | 
					
						
							| 
									
										
										
										
											2020-02-26 17:53:39 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-13 13:54:54 -07:00
										 |  |  |   ipc.on('delete-all-data', async () => { | 
					
						
							| 
									
										
										
										
											2020-02-26 17:53:39 -08:00
										 |  |  |     const { deleteAllData } = window.Events; | 
					
						
							| 
									
										
										
										
											2021-05-13 13:54:54 -07:00
										 |  |  |     if (!deleteAllData) { | 
					
						
							|  |  |  |       return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     try { | 
					
						
							|  |  |  |       await deleteAllData(); | 
					
						
							|  |  |  |     } catch (error) { | 
					
						
							| 
									
										
										
										
											2021-09-17 14:27:53 -04:00
										 |  |  |       log.error('delete-all-data: error', error && error.stack); | 
					
						
							| 
									
										
										
										
											2020-02-26 17:53:39 -08:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-10-04 11:06:17 -07:00
										 |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-26 17:53:39 -08:00
										 |  |  |   ipc.on('show-sticker-pack', (_event, info) => { | 
					
						
							|  |  |  |     const { packId, packKey } = info; | 
					
						
							|  |  |  |     const { showStickerPack } = window.Events; | 
					
						
							|  |  |  |     if (showStickerPack) { | 
					
						
							|  |  |  |       showStickerPack(packId, packKey); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   }); | 
					
						
							| 
									
										
										
										
											2018-07-03 15:33:50 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-29 14:16:48 -08:00
										 |  |  |   ipc.on('show-group-via-link', (_event, info) => { | 
					
						
							|  |  |  |     const { hash } = info; | 
					
						
							|  |  |  |     const { showGroupViaLink } = window.Events; | 
					
						
							|  |  |  |     if (showGroupViaLink) { | 
					
						
							|  |  |  |       showGroupViaLink(hash); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-28 08:27:38 -05:00
										 |  |  |   ipc.on('show-conversation-via-signal.me', (_event, info) => { | 
					
						
							|  |  |  |     const { hash } = info; | 
					
						
							|  |  |  |     strictAssert(typeof hash === 'string', 'Got an invalid hash over IPC'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const { showConversationViaSignalDotMe } = window.Events; | 
					
						
							|  |  |  |     if (showConversationViaSignalDotMe) { | 
					
						
							|  |  |  |       showConversationViaSignalDotMe(hash); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-29 14:16:48 -08:00
										 |  |  |   ipc.on('unknown-sgnl-link', () => { | 
					
						
							|  |  |  |     const { unknownSignalLink } = window.Events; | 
					
						
							|  |  |  |     if (unknownSignalLink) { | 
					
						
							|  |  |  |       unknownSignalLink(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-26 17:53:39 -08:00
										 |  |  |   ipc.on('install-sticker-pack', (_event, info) => { | 
					
						
							|  |  |  |     const { packId, packKey } = info; | 
					
						
							|  |  |  |     const { installStickerPack } = window.Events; | 
					
						
							|  |  |  |     if (installStickerPack) { | 
					
						
							|  |  |  |       installStickerPack(packId, packKey); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   }); | 
					
						
							| 
									
										
										
										
											2018-04-03 15:03:57 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-26 17:53:39 -08:00
										 |  |  |   ipc.on('get-ready-for-shutdown', async () => { | 
					
						
							|  |  |  |     const { shutdown } = window.Events || {}; | 
					
						
							|  |  |  |     if (!shutdown) { | 
					
						
							| 
									
										
										
										
											2021-09-17 14:27:53 -04:00
										 |  |  |       log.error('preload shutdown handler: shutdown method not found'); | 
					
						
							| 
									
										
										
										
											2020-02-26 17:53:39 -08:00
										 |  |  |       ipc.send('now-ready-for-shutdown'); | 
					
						
							|  |  |  |       return; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-05-16 15:32:11 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-26 17:53:39 -08:00
										 |  |  |     try { | 
					
						
							|  |  |  |       await shutdown(); | 
					
						
							|  |  |  |       ipc.send('now-ready-for-shutdown'); | 
					
						
							|  |  |  |     } catch (error) { | 
					
						
							|  |  |  |       ipc.send( | 
					
						
							|  |  |  |         'now-ready-for-shutdown', | 
					
						
							|  |  |  |         error && error.stack ? error.stack : error | 
					
						
							|  |  |  |       ); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   }); | 
					
						
							| 
									
										
										
										
											2018-11-05 11:06:12 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-26 17:53:39 -08:00
										 |  |  |   window.addSetupMenuItems = () => ipc.send('add-setup-menu-items'); | 
					
						
							|  |  |  |   window.removeSetupMenuItems = () => ipc.send('remove-setup-menu-items'); | 
					
						
							| 
									
										
										
										
											2018-11-05 11:06:12 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-26 17:53:39 -08:00
										 |  |  |   // We pull these dependencies in now, from here, because they have Node.js dependencies
 | 
					
						
							| 
									
										
										
										
											2018-04-03 15:03:57 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-04 16:44:57 -05:00
										 |  |  |   require('./ts/logging/set_up_renderer_logging').initialize(); | 
					
						
							| 
									
										
										
										
											2018-04-03 15:03:57 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-26 17:53:39 -08:00
										 |  |  |   if (config.proxyUrl) { | 
					
						
							| 
									
										
										
										
											2021-09-17 14:27:53 -04:00
										 |  |  |     log.info('Using provided proxy url'); | 
					
						
							| 
									
										
										
										
											2020-02-26 17:53:39 -08:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2018-04-03 15:03:57 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-26 17:53:39 -08:00
										 |  |  |   window.nodeSetImmediate = setImmediate; | 
					
						
							| 
									
										
										
										
											2018-04-03 15:03:57 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-16 16:13:13 -07:00
										 |  |  |   window.Backbone = require('backbone'); | 
					
						
							| 
									
										
										
										
											2020-04-13 10:37:29 -07:00
										 |  |  |   window.textsecure = require('./ts/textsecure').default; | 
					
						
							| 
									
										
										
										
											2019-08-19 15:26:45 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-13 10:37:29 -07:00
										 |  |  |   window.WebAPI = window.textsecure.WebAPI.initialize({ | 
					
						
							| 
									
										
										
										
											2020-02-26 17:53:39 -08:00
										 |  |  |     url: config.serverUrl, | 
					
						
							| 
									
										
										
										
											2020-07-06 20:56:56 -04:00
										 |  |  |     storageUrl: config.storageUrl, | 
					
						
							| 
									
										
										
										
											2020-09-03 21:25:19 -04:00
										 |  |  |     directoryUrl: config.directoryUrl, | 
					
						
							|  |  |  |     directoryEnclaveId: config.directoryEnclaveId, | 
					
						
							|  |  |  |     directoryTrustAnchor: config.directoryTrustAnchor, | 
					
						
							| 
									
										
										
										
											2020-04-17 15:51:39 -07:00
										 |  |  |     cdnUrlObject: { | 
					
						
							| 
									
										
										
										
											2020-11-18 07:15:42 -08:00
										 |  |  |       0: config.cdnUrl0, | 
					
						
							|  |  |  |       2: config.cdnUrl2, | 
					
						
							| 
									
										
										
										
											2020-04-17 15:51:39 -07:00
										 |  |  |     }, | 
					
						
							| 
									
										
										
										
											2020-02-26 17:53:39 -08:00
										 |  |  |     certificateAuthority: config.certificateAuthority, | 
					
						
							|  |  |  |     contentProxyUrl: config.contentProxyUrl, | 
					
						
							|  |  |  |     proxyUrl: config.proxyUrl, | 
					
						
							|  |  |  |     version: config.version, | 
					
						
							|  |  |  |   }); | 
					
						
							| 
									
										
										
										
											2019-08-19 15:26:45 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-26 17:53:39 -08:00
										 |  |  |   // Linux seems to periodically let the event loop stop, so this is a global workaround
 | 
					
						
							|  |  |  |   setInterval(() => { | 
					
						
							|  |  |  |     window.nodeSetImmediate(() => {}); | 
					
						
							|  |  |  |   }, 1000); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-27 17:37:06 -04:00
										 |  |  |   const { imageToBlurHash } = require('./ts/util/imageToBlurHash'); | 
					
						
							| 
									
										
										
										
											2021-06-22 07:46:42 -07:00
										 |  |  |   const { isValidGuid } = require('./ts/util/isValidGuid'); | 
					
						
							| 
									
										
										
										
											2020-12-17 17:12:15 -06:00
										 |  |  |   const { ActiveWindowService } = require('./ts/services/ActiveWindowService'); | 
					
						
							| 
									
										
										
										
											2020-02-26 17:53:39 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-27 17:37:06 -04:00
										 |  |  |   window.imageToBlurHash = imageToBlurHash; | 
					
						
							| 
									
										
										
										
											2020-02-26 17:53:39 -08:00
										 |  |  |   window.emojiData = require('emoji-datasource'); | 
					
						
							|  |  |  |   window.libphonenumber = require('google-libphonenumber').PhoneNumberUtil.getInstance(); | 
					
						
							|  |  |  |   window.libphonenumber.PhoneNumberFormat = require('google-libphonenumber').PhoneNumberFormat; | 
					
						
							|  |  |  |   window.getGuid = require('uuid/v4'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-17 17:12:15 -06:00
										 |  |  |   const activeWindowService = new ActiveWindowService(); | 
					
						
							|  |  |  |   activeWindowService.initialize(window.document, ipc); | 
					
						
							|  |  |  |   window.isActive = activeWindowService.isActive.bind(activeWindowService); | 
					
						
							|  |  |  |   window.registerForActive = activeWindowService.registerForActive.bind( | 
					
						
							|  |  |  |     activeWindowService | 
					
						
							|  |  |  |   ); | 
					
						
							|  |  |  |   window.unregisterForActive = activeWindowService.unregisterForActive.bind( | 
					
						
							|  |  |  |     activeWindowService | 
					
						
							|  |  |  |   ); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-27 15:11:59 -07:00
										 |  |  |   window.Accessibility = { | 
					
						
							|  |  |  |     reducedMotionSetting: Boolean(config.reducedMotionSetting), | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-22 07:46:42 -07:00
										 |  |  |   window.isValidGuid = isValidGuid; | 
					
						
							| 
									
										
										
										
											2020-03-05 13:14:58 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-26 17:53:39 -08:00
										 |  |  |   window.React = require('react'); | 
					
						
							|  |  |  |   window.ReactDOM = require('react-dom'); | 
					
						
							|  |  |  |   window.moment = require('moment'); | 
					
						
							|  |  |  |   window.PQueue = require('p-queue').default; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const Signal = require('./js/modules/signal'); | 
					
						
							| 
									
										
										
										
											2021-09-17 20:30:08 -04:00
										 |  |  |   const { setupI18n } = require('./ts/util/setupI18n'); | 
					
						
							| 
									
										
										
										
											2020-02-26 17:53:39 -08:00
										 |  |  |   const Attachments = require('./app/attachments'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const { locale } = config; | 
					
						
							| 
									
										
										
										
											2021-09-17 20:30:08 -04:00
										 |  |  |   window.i18n = setupI18n(locale, localeMessages); | 
					
						
							| 
									
										
										
										
											2020-02-26 17:53:39 -08:00
										 |  |  |   window.moment.updateLocale(locale, { | 
					
						
							|  |  |  |     relativeTime: { | 
					
						
							|  |  |  |       s: window.i18n('timestamp_s'), | 
					
						
							|  |  |  |       m: window.i18n('timestamp_m'), | 
					
						
							|  |  |  |       h: window.i18n('timestamp_h'), | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  |   window.moment.locale(locale); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const userDataPath = app.getPath('userData'); | 
					
						
							|  |  |  |   window.baseAttachmentsPath = Attachments.getPath(userDataPath); | 
					
						
							|  |  |  |   window.baseStickersPath = Attachments.getStickersPath(userDataPath); | 
					
						
							|  |  |  |   window.baseTempPath = Attachments.getTempPath(userDataPath); | 
					
						
							|  |  |  |   window.baseDraftPath = Attachments.getDraftPath(userDataPath); | 
					
						
							| 
									
										
										
										
											2021-06-01 11:15:23 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |   const { addSensitivePath } = require('./ts/util/privacy'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   addSensitivePath(window.baseAttachmentsPath); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-26 17:53:39 -08:00
										 |  |  |   window.Signal = Signal.setup({ | 
					
						
							|  |  |  |     Attachments, | 
					
						
							|  |  |  |     userDataPath, | 
					
						
							|  |  |  |     getRegionCode: () => window.storage.get('regionCode'), | 
					
						
							| 
									
										
										
										
											2021-09-17 14:27:53 -04:00
										 |  |  |     logger: log, | 
					
						
							| 
									
										
										
										
											2020-02-26 17:53:39 -08:00
										 |  |  |   }); | 
					
						
							| 
									
										
										
										
											2021-08-11 12:29:07 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |   if (config.enableCI) { | 
					
						
							|  |  |  |     const { CI, electronRequire } = require('./ts/CI'); | 
					
						
							|  |  |  |     window.CI = new CI(title); | 
					
						
							|  |  |  |     window.electronRequire = electronRequire; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-02-26 17:53:39 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-24 13:57:54 -07:00
										 |  |  |   // these need access to window.Signal:
 | 
					
						
							|  |  |  |   require('./ts/models/messages'); | 
					
						
							|  |  |  |   require('./ts/models/conversations'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-26 13:06:37 -08:00
										 |  |  |   require('./ts/backbone/views/whisper_view'); | 
					
						
							|  |  |  |   require('./ts/views/conversation_view'); | 
					
						
							| 
									
										
										
										
											2021-09-17 14:27:53 -04:00
										 |  |  |   require('./ts/views/inbox_view'); | 
					
						
							|  |  |  |   require('./ts/views/install_view'); | 
					
						
							|  |  |  |   require('./ts/views/recorder_view'); | 
					
						
							|  |  |  |   require('./ts/views/standalone_registration_view'); | 
					
						
							| 
									
										
										
										
											2021-04-16 16:13:13 -07:00
										 |  |  |   require('./ts/SignalProtocolStore'); | 
					
						
							| 
									
										
										
										
											2021-02-26 13:06:37 -08:00
										 |  |  |   require('./ts/background'); | 
					
						
							| 
									
										
										
										
											2021-02-23 14:36:07 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-26 17:53:39 -08:00
										 |  |  |   // Pulling these in separately since they access filesystem, electron
 | 
					
						
							|  |  |  |   window.Signal.Debug = require('./js/modules/debug'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-20 17:00:11 -04:00
										 |  |  |   window.addEventListener('contextmenu', e => { | 
					
						
							|  |  |  |     const editable = e.target.closest( | 
					
						
							|  |  |  |       'textarea, input, [contenteditable="true"]' | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  |     const link = e.target.closest('a'); | 
					
						
							|  |  |  |     const selection = Boolean(window.getSelection().toString()); | 
					
						
							| 
									
										
										
										
											2021-09-07 09:12:26 -07:00
										 |  |  |     const image = e.target.closest('.Lightbox img'); | 
					
						
							| 
									
										
										
										
											2020-11-02 17:47:46 -07:00
										 |  |  |     if (!editable && !selection && !link && !image) { | 
					
						
							| 
									
										
										
										
											2020-03-20 17:00:11 -04:00
										 |  |  |       e.preventDefault(); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-02-26 17:53:39 -08:00
										 |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (config.environment === 'test') { | 
					
						
							| 
									
										
										
										
											2021-08-11 12:29:07 -07:00
										 |  |  |     require('./preload_test'); | 
					
						
							| 
									
										
										
										
											2020-02-26 17:53:39 -08:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2021-09-17 14:27:53 -04:00
										 |  |  |   log.info('preload complete'); | 
					
						
							| 
									
										
										
										
											2020-02-26 17:53:39 -08:00
										 |  |  | } catch (error) { | 
					
						
							| 
									
										
										
										
											2020-03-02 16:09:46 -08:00
										 |  |  |   /* eslint-disable no-console */ | 
					
						
							|  |  |  |   if (console._log) { | 
					
						
							|  |  |  |     console._log('preload error!', error.stack); | 
					
						
							|  |  |  |   } else { | 
					
						
							|  |  |  |     console.log('preload error!', error.stack); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   /* eslint-enable no-console */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-26 17:53:39 -08:00
										 |  |  |   throw error; | 
					
						
							| 
									
										
										
										
											2018-12-13 13:41:42 -08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2020-02-26 17:53:39 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-07 15:40:12 -07:00
										 |  |  | preloadEndTime = Date.now(); |