2023-01-03 19:55:46 +00:00
|
|
|
// Copyright 2017 Signal Messenger, LLC
|
2020-10-30 20:34:04 +00:00
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2023-06-14 20:55:07 +00:00
|
|
|
import { join, normalize, extname, dirname, basename } from 'path';
|
2021-10-01 18:49:59 +00:00
|
|
|
import { pathToFileURL } from 'url';
|
|
|
|
import * as os from 'os';
|
2021-10-06 16:16:51 +00:00
|
|
|
import { chmod, realpath, writeFile } from 'fs-extra';
|
2021-10-01 18:49:59 +00:00
|
|
|
import { randomBytes } from 'crypto';
|
2023-06-14 22:57:50 +00:00
|
|
|
import { createParser } from 'dashdash';
|
2021-10-01 18:49:59 +00:00
|
|
|
|
|
|
|
import normalizePath from 'normalize-path';
|
|
|
|
import fastGlob from 'fast-glob';
|
|
|
|
import PQueue from 'p-queue';
|
|
|
|
import { get, pick, isNumber, isBoolean, some, debounce, noop } from 'lodash';
|
|
|
|
import {
|
2018-05-23 23:26:40 +00:00
|
|
|
app,
|
2022-01-28 22:27:18 +00:00
|
|
|
BrowserWindow,
|
2021-03-04 21:44:57 +00:00
|
|
|
clipboard,
|
2019-12-17 20:25:57 +00:00
|
|
|
dialog,
|
2021-10-01 18:49:59 +00:00
|
|
|
ipcMain as ipc,
|
2018-05-24 19:13:16 +00:00
|
|
|
Menu,
|
2022-05-11 22:58:14 +00:00
|
|
|
nativeTheme,
|
2023-05-30 23:57:16 +00:00
|
|
|
net,
|
2021-12-10 22:53:10 +00:00
|
|
|
powerSaveBlocker,
|
2021-10-01 18:49:59 +00:00
|
|
|
screen,
|
2022-01-28 22:27:18 +00:00
|
|
|
session,
|
2018-05-24 19:13:16 +00:00
|
|
|
shell,
|
2020-12-04 17:31:42 +00:00
|
|
|
systemPreferences,
|
2022-09-06 22:09:52 +00:00
|
|
|
Notification,
|
2024-07-08 23:41:26 +00:00
|
|
|
safeStorage,
|
2024-07-11 19:44:09 +00:00
|
|
|
protocol as electronProtocol,
|
2021-10-01 18:49:59 +00:00
|
|
|
} from 'electron';
|
2024-02-22 21:19:37 +00:00
|
|
|
import type { MenuItemConstructorOptions, Settings } from 'electron';
|
2021-10-01 18:49:59 +00:00
|
|
|
import { z } from 'zod';
|
2017-03-30 19:01:30 +00:00
|
|
|
|
2021-10-01 18:49:59 +00:00
|
|
|
import packageJson from '../package.json';
|
|
|
|
import * as GlobalErrors from './global_errors';
|
2022-01-11 20:02:46 +00:00
|
|
|
import { setup as setupCrashReports } from './crashReports';
|
2021-10-01 18:49:59 +00:00
|
|
|
import { setup as setupSpellChecker } from './spell_check';
|
2024-02-28 00:53:58 +00:00
|
|
|
import { getDNSFallback } from './dns-fallback';
|
2021-10-01 18:49:59 +00:00
|
|
|
import { redactAll, addSensitivePath } from '../ts/util/privacy';
|
2022-06-02 23:24:35 +00:00
|
|
|
import { createSupportUrl } from '../ts/util/createSupportUrl';
|
2022-05-11 22:58:14 +00:00
|
|
|
import { missingCaseError } from '../ts/util/missingCaseError';
|
2021-11-10 00:56:56 +00:00
|
|
|
import { strictAssert } from '../ts/util/assert';
|
2022-12-21 18:41:48 +00:00
|
|
|
import { drop } from '../ts/util/drop';
|
2023-03-28 22:22:06 +00:00
|
|
|
import { createBufferedConsoleLogger } from '../ts/util/consoleLogger';
|
2022-06-13 21:39:35 +00:00
|
|
|
import type { ThemeSettingType } from '../ts/types/StorageUIKeys';
|
2022-05-11 22:58:14 +00:00
|
|
|
import { ThemeType } from '../ts/types/Util';
|
2022-11-22 18:43:43 +00:00
|
|
|
import * as Errors from '../ts/types/errors';
|
2023-03-02 18:43:25 +00:00
|
|
|
import { resolveCanonicalLocales } from '../ts/util/resolveCanonicalLocales';
|
2023-04-20 21:23:19 +00:00
|
|
|
import * as debugLog from '../ts/logging/debuglogs';
|
|
|
|
import * as uploadDebugLog from '../ts/logging/uploadDebugLog';
|
2023-04-20 15:59:17 +00:00
|
|
|
import { explodePromise } from '../ts/util/explodePromise';
|
2020-03-19 17:57:50 +00:00
|
|
|
|
2021-10-01 18:49:59 +00:00
|
|
|
import './startup_config';
|
2017-04-13 19:10:42 +00:00
|
|
|
|
2022-06-13 21:39:35 +00:00
|
|
|
import type { RendererConfigType } from '../ts/types/RendererConfig';
|
2022-06-15 01:15:33 +00:00
|
|
|
import {
|
|
|
|
directoryConfigSchema,
|
|
|
|
rendererConfigSchema,
|
|
|
|
} from '../ts/types/RendererConfig';
|
2021-10-26 19:15:33 +00:00
|
|
|
import config from './config';
|
2021-10-01 18:49:59 +00:00
|
|
|
import {
|
|
|
|
Environment,
|
|
|
|
getEnvironment,
|
|
|
|
isTestEnvironment,
|
|
|
|
} from '../ts/environment';
|
2017-06-22 01:04:19 +00:00
|
|
|
|
2018-08-16 17:07:38 +00:00
|
|
|
// Very important to put before the single instance check, since it is based on the
|
2021-10-01 18:49:59 +00:00
|
|
|
// userData directory. (see requestSingleInstanceLock below)
|
|
|
|
import * as userConfig from './user_config';
|
2021-03-26 02:02:53 +00:00
|
|
|
|
2018-08-16 17:07:38 +00:00
|
|
|
// We generally want to pull in our own modules after this point, after the user
|
|
|
|
// data directory has been set.
|
2021-10-01 18:49:59 +00:00
|
|
|
import * as attachments from './attachments';
|
|
|
|
import * as attachmentChannel from './attachment_channel';
|
|
|
|
import * as bounce from '../ts/services/bounce';
|
|
|
|
import * as updater from '../ts/updater/index';
|
2022-01-28 22:27:18 +00:00
|
|
|
import { updateDefaultSession } from './updateDefaultSession';
|
2021-12-10 22:53:10 +00:00
|
|
|
import { PreventDisplaySleepService } from './PreventDisplaySleepService';
|
2023-08-01 16:06:29 +00:00
|
|
|
import { SystemTrayService, focusAndForceToTop } from './SystemTrayService';
|
2021-10-01 18:49:59 +00:00
|
|
|
import { SystemTraySettingCache } from './SystemTraySettingCache';
|
2024-03-21 16:35:54 +00:00
|
|
|
import { OptionalResourceService } from './OptionalResourceService';
|
2024-06-21 22:35:56 +00:00
|
|
|
import { EmojiService } from './EmojiService';
|
2021-10-01 18:49:59 +00:00
|
|
|
import {
|
2021-06-29 17:18:03 +00:00
|
|
|
SystemTraySetting,
|
|
|
|
shouldMinimizeToSystemTray,
|
|
|
|
parseSystemTraySetting,
|
2021-10-01 18:49:59 +00:00
|
|
|
} from '../ts/types/SystemTraySetting';
|
2024-03-14 17:01:40 +00:00
|
|
|
import {
|
|
|
|
getDefaultSystemTraySetting,
|
|
|
|
isSystemTraySupported,
|
|
|
|
} from '../ts/types/Settings';
|
2021-10-01 18:49:59 +00:00
|
|
|
import * as ephemeralConfig from './ephemeral_config';
|
|
|
|
import * as logging from '../ts/logging/main_process_logging';
|
|
|
|
import { MainSQL } from '../ts/sql/main';
|
|
|
|
import * as sqlChannels from './sql_channel';
|
|
|
|
import * as windowState from './window_state';
|
2022-06-08 22:00:32 +00:00
|
|
|
import type { CreateTemplateOptionsType } from './menu';
|
2021-10-26 19:15:33 +00:00
|
|
|
import { createTemplate } from './menu';
|
2021-10-01 18:49:59 +00:00
|
|
|
import { installFileHandler, installWebHandler } from './protocol_filter';
|
2023-04-20 21:23:19 +00:00
|
|
|
import OS from '../ts/util/os/osMain';
|
2023-03-16 00:59:30 +00:00
|
|
|
import { isProduction } from '../ts/util/version';
|
2022-02-25 18:37:15 +00:00
|
|
|
import { clearTimeoutIfNecessary } from '../ts/util/clearTimeoutIfNecessary';
|
2021-10-01 18:49:59 +00:00
|
|
|
import { toggleMaximizedBrowserWindow } from '../ts/util/toggleMaximizedBrowserWindow';
|
|
|
|
import { ChallengeMainHandler } from '../ts/main/challengeMain';
|
|
|
|
import { NativeThemeNotifier } from '../ts/main/NativeThemeNotifier';
|
|
|
|
import { PowerChannel } from '../ts/main/powerChannel';
|
|
|
|
import { SettingsChannel } from '../ts/main/settingsChannel';
|
|
|
|
import { maybeParseUrl, setUrlSearchParams } from '../ts/util/url';
|
|
|
|
import { getHeicConverter } from '../ts/workers/heicConverterMain';
|
|
|
|
|
2023-12-12 19:41:14 +00:00
|
|
|
import type { LocaleDirection, LocaleType } from './locale';
|
2021-10-26 19:15:33 +00:00
|
|
|
import { load as loadLocale } from './locale';
|
2021-10-01 18:49:59 +00:00
|
|
|
|
|
|
|
import type { LoggerType } from '../ts/types/Logging';
|
2023-07-31 16:23:19 +00:00
|
|
|
import { HourCyclePreference } from '../ts/types/I18N';
|
2024-05-06 21:48:31 +00:00
|
|
|
import { ScreenShareStatus } from '../ts/types/Calling';
|
2023-11-02 19:42:31 +00:00
|
|
|
import type { ParsedSignalRoute } from '../ts/util/signalRoutes';
|
|
|
|
import { parseSignalRoute } from '../ts/util/signalRoutes';
|
2024-02-28 00:53:58 +00:00
|
|
|
import * as dns from '../ts/util/dns';
|
2023-12-22 20:27:49 +00:00
|
|
|
import { ZoomFactorService } from '../ts/services/ZoomFactorService';
|
2024-07-24 16:23:17 +00:00
|
|
|
import { SafeStorageBackendChangeError } from '../ts/types/SafeStorageBackendChangeError';
|
|
|
|
import { LINUX_PASSWORD_STORE_FLAGS } from '../ts/util/linuxPasswordStoreFlags';
|
|
|
|
import { getOwn } from '../ts/util/getOwn';
|
2024-10-02 19:03:10 +00:00
|
|
|
import { safeParseLoose, safeParseUnknown } from '../ts/util/schemas';
|
2021-10-01 18:49:59 +00:00
|
|
|
|
|
|
|
const animationSettings = systemPreferences.getAnimationSettings();
|
|
|
|
|
2023-02-23 22:37:55 +00:00
|
|
|
if (OS.isMacOS()) {
|
2023-01-24 01:09:09 +00:00
|
|
|
systemPreferences.setUserDefault(
|
|
|
|
'SquirrelMacEnableDirectContentsWrite',
|
|
|
|
'boolean',
|
|
|
|
true
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-10-01 18:49:59 +00:00
|
|
|
// Keep a global reference of the window object, if you don't, the window will
|
|
|
|
// be closed automatically when the JavaScript object is garbage collected.
|
|
|
|
let mainWindow: BrowserWindow | undefined;
|
|
|
|
let mainWindowCreated = false;
|
|
|
|
let loadingWindow: BrowserWindow | undefined;
|
|
|
|
|
2023-03-28 22:22:06 +00:00
|
|
|
// Create a buffered logger to hold our log lines until we fully initialize
|
|
|
|
// the logger in `app.on('ready')`
|
|
|
|
const consoleLogger = createBufferedConsoleLogger();
|
|
|
|
|
|
|
|
// These will be set after app fires the 'ready' event
|
|
|
|
let logger: LoggerType | undefined;
|
|
|
|
let preferredSystemLocales: Array<string> | undefined;
|
2023-11-07 01:02:13 +00:00
|
|
|
let localeOverride: string | null | undefined;
|
2023-12-12 19:41:14 +00:00
|
|
|
|
2023-03-28 22:22:06 +00:00
|
|
|
let resolvedTranslationsLocale: LocaleType | undefined;
|
|
|
|
let settingsChannel: SettingsChannel | undefined;
|
|
|
|
|
2021-10-01 18:49:59 +00:00
|
|
|
const activeWindows = new Set<BrowserWindow>();
|
|
|
|
|
|
|
|
function getMainWindow() {
|
|
|
|
return mainWindow;
|
|
|
|
}
|
|
|
|
|
|
|
|
const development =
|
|
|
|
getEnvironment() === Environment.Development ||
|
|
|
|
getEnvironment() === Environment.Staging;
|
|
|
|
|
2023-07-20 22:37:56 +00:00
|
|
|
const ciMode = config.get<'full' | 'benchmark' | false>('ciMode');
|
2022-02-11 22:32:51 +00:00
|
|
|
const forcePreloadBundle = config.get<boolean>('forcePreloadBundle');
|
2023-12-12 19:41:14 +00:00
|
|
|
const localeDirectionTestingOverride = config.has(
|
|
|
|
'localeDirectionTestingOverride'
|
|
|
|
)
|
|
|
|
? config.get<LocaleDirection>('localeDirectionTestingOverride')
|
|
|
|
: null;
|
Beta versions support: SxS support, in-app env/instance display (#1606)
* Script for beta config; unique data dir, in-app env/type display
To release a beta build, increment the version and add -beta-N to the
end, then go through all the standard release activities.
The prepare-build npm script then updates key bits of the package.json
to ensure that the beta build can be installed alongside a production
build. This includes a new name ('Signal Beta') and a different location
for application data.
Note: Beta builds can be installed alongside production builds.
As part of this, a couple new bits of data are shown across the app:
- Environment (development or test, not shown if production)
- App Instance (disabled in production; used for multiple accounts)
These are shown in:
- The window title - both environment and app instance. You can tell
beta builds because the app name, preceding these data bits, is
different.
- The about window - both environment and app instance. You can tell
beta builds from the version number.
- The header added to the debug log - just environment. The version
number will tell us if it's a beta build, and app instance isn't
helpful.
* Turn on single-window mode in non-production modes
Because it's really frightening when you see 'unable to read from db'
errors in the console.
* aply.sh: More instructions for initial setup and testing
* Gruntfile: Get consistent with use of package.json datas
* Linux: manually update desktop keys, since macros not available
2017-10-30 20:57:13 +00:00
|
|
|
|
2021-12-10 22:53:10 +00:00
|
|
|
const preventDisplaySleepService = new PreventDisplaySleepService(
|
|
|
|
powerSaveBlocker
|
|
|
|
);
|
|
|
|
|
2021-05-06 00:09:29 +00:00
|
|
|
const challengeHandler = new ChallengeMainHandler();
|
2021-04-05 22:18:19 +00:00
|
|
|
|
2021-06-30 18:57:43 +00:00
|
|
|
const nativeThemeNotifier = new NativeThemeNotifier();
|
|
|
|
nativeThemeNotifier.initialize();
|
|
|
|
|
2020-03-20 21:00:11 +00:00
|
|
|
let appStartInitialSpellcheckSetting = true;
|
|
|
|
|
2024-07-12 14:28:12 +00:00
|
|
|
let macInitialOpenUrlRoute: ParsedSignalRoute | undefined;
|
|
|
|
|
2023-06-14 22:57:50 +00:00
|
|
|
const cliParser = createParser({
|
|
|
|
allowUnknown: true,
|
|
|
|
options: [
|
|
|
|
{
|
|
|
|
name: 'lang',
|
|
|
|
type: 'string',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
});
|
|
|
|
|
|
|
|
const cliOptions = cliParser.parse(process.argv);
|
|
|
|
|
2021-03-03 19:13:35 +00:00
|
|
|
const defaultWebPrefs = {
|
|
|
|
devTools:
|
|
|
|
process.argv.some(arg => arg === '--enable-dev-tools') ||
|
2024-09-04 18:12:45 +00:00
|
|
|
getEnvironment() !== Environment.PackagedApp ||
|
2021-08-06 21:21:01 +00:00
|
|
|
!isProduction(app.getVersion()),
|
2022-01-28 22:27:18 +00:00
|
|
|
spellcheck: false,
|
2023-08-09 00:53:06 +00:00
|
|
|
// https://chromium.googlesource.com/chromium/src/+/main/third_party/blink/renderer/platform/runtime_enabled_features.json5
|
|
|
|
enableBlinkFeatures: [
|
|
|
|
'CSSPseudoDir', // status=experimental, needed for RTL (ex: :dir(rtl))
|
|
|
|
'CSSLogical', // status=experimental, needed for RTL (ex: margin-inline-start)
|
|
|
|
].join(','),
|
2023-12-22 20:27:49 +00:00
|
|
|
enablePreferredSizeMode: true,
|
2021-03-03 19:13:35 +00:00
|
|
|
};
|
|
|
|
|
2022-11-14 19:29:53 +00:00
|
|
|
const DISABLE_GPU =
|
|
|
|
OS.isLinux() && !process.argv.some(arg => arg === '--enable-gpu');
|
|
|
|
|
2024-04-11 17:06:54 +00:00
|
|
|
const DISABLE_IPV6 = process.argv.some(arg => arg === '--disable-ipv6');
|
2024-05-02 19:52:53 +00:00
|
|
|
const FORCE_ENABLE_CRASH_REPORTS = process.argv.some(
|
|
|
|
arg => arg === '--enable-crash-reports'
|
|
|
|
);
|
2024-04-11 17:06:54 +00:00
|
|
|
|
2023-06-14 22:57:50 +00:00
|
|
|
const CLI_LANG = cliOptions.lang as string | undefined;
|
|
|
|
|
2024-05-02 19:52:53 +00:00
|
|
|
setupCrashReports(getLogger, showDebugLogWindow, FORCE_ENABLE_CRASH_REPORTS);
|
2023-03-28 22:22:06 +00:00
|
|
|
|
2023-08-01 16:06:29 +00:00
|
|
|
let sendDummyKeystroke: undefined | (() => void);
|
|
|
|
if (OS.isWindows()) {
|
|
|
|
try {
|
|
|
|
// eslint-disable-next-line global-require, @typescript-eslint/no-var-requires
|
|
|
|
const windowsNotifications = require('./WindowsNotifications');
|
|
|
|
sendDummyKeystroke = windowsNotifications.sendDummyKeystroke;
|
|
|
|
} catch (error) {
|
|
|
|
getLogger().error(
|
2023-08-18 11:17:38 +00:00
|
|
|
'Failed to initialize Windows Notifications:',
|
2023-08-01 16:06:29 +00:00
|
|
|
error.stack
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-14 20:27:52 +00:00
|
|
|
function showWindow() {
|
2018-01-04 02:18:13 +00:00
|
|
|
if (!mainWindow) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-12-14 20:27:52 +00:00
|
|
|
// Using focus() instead of show() seems to be important on Windows when our window
|
|
|
|
// has been docked using Aero Snap/Snap Assist. A full .show() call here will cause
|
|
|
|
// the window to reposition:
|
2018-01-30 22:22:51 +00:00
|
|
|
// https://github.com/signalapp/Signal-Desktop/issues/1429
|
2017-12-14 20:27:52 +00:00
|
|
|
if (mainWindow.isVisible()) {
|
2023-08-01 16:06:29 +00:00
|
|
|
focusAndForceToTop(mainWindow);
|
2017-12-14 20:27:52 +00:00
|
|
|
} else {
|
|
|
|
mainWindow.show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Beta versions support: SxS support, in-app env/instance display (#1606)
* Script for beta config; unique data dir, in-app env/type display
To release a beta build, increment the version and add -beta-N to the
end, then go through all the standard release activities.
The prepare-build npm script then updates key bits of the package.json
to ensure that the beta build can be installed alongside a production
build. This includes a new name ('Signal Beta') and a different location
for application data.
Note: Beta builds can be installed alongside production builds.
As part of this, a couple new bits of data are shown across the app:
- Environment (development or test, not shown if production)
- App Instance (disabled in production; used for multiple accounts)
These are shown in:
- The window title - both environment and app instance. You can tell
beta builds because the app name, preceding these data bits, is
different.
- The about window - both environment and app instance. You can tell
beta builds from the version number.
- The header added to the debug log - just environment. The version
number will tell us if it's a beta build, and app instance isn't
helpful.
* Turn on single-window mode in non-production modes
Because it's really frightening when you see 'unable to read from db'
errors in the console.
* aply.sh: More instructions for initial setup and testing
* Gruntfile: Get consistent with use of package.json datas
* Linux: manually update desktop keys, since macros not available
2017-10-30 20:57:13 +00:00
|
|
|
if (!process.mas) {
|
2017-04-26 03:16:51 +00:00
|
|
|
console.log('making app single instance');
|
2019-02-21 22:41:17 +00:00
|
|
|
const gotLock = app.requestSingleInstanceLock();
|
|
|
|
if (!gotLock) {
|
Beta versions support: SxS support, in-app env/instance display (#1606)
* Script for beta config; unique data dir, in-app env/type display
To release a beta build, increment the version and add -beta-N to the
end, then go through all the standard release activities.
The prepare-build npm script then updates key bits of the package.json
to ensure that the beta build can be installed alongside a production
build. This includes a new name ('Signal Beta') and a different location
for application data.
Note: Beta builds can be installed alongside production builds.
As part of this, a couple new bits of data are shown across the app:
- Environment (development or test, not shown if production)
- App Instance (disabled in production; used for multiple accounts)
These are shown in:
- The window title - both environment and app instance. You can tell
beta builds because the app name, preceding these data bits, is
different.
- The about window - both environment and app instance. You can tell
beta builds from the version number.
- The header added to the debug log - just environment. The version
number will tell us if it's a beta build, and app instance isn't
helpful.
* Turn on single-window mode in non-production modes
Because it's really frightening when you see 'unable to read from db'
errors in the console.
* aply.sh: More instructions for initial setup and testing
* Gruntfile: Get consistent with use of package.json datas
* Linux: manually update desktop keys, since macros not available
2017-10-30 20:57:13 +00:00
|
|
|
console.log('quitting; we are the second instance');
|
2018-01-30 18:55:49 +00:00
|
|
|
app.exit();
|
2019-02-21 22:41:17 +00:00
|
|
|
} else {
|
2021-10-01 18:49:59 +00:00
|
|
|
app.on('second-instance', (_e: Electron.Event, argv: Array<string>) => {
|
2023-08-01 16:06:29 +00:00
|
|
|
// Workaround to let AllowSetForegroundWindow succeed.
|
2023-08-08 00:39:57 +00:00
|
|
|
// See https://www.npmjs.com/package/@signalapp/windows-dummy-keystroke for a full explanation of why this is needed.
|
2023-08-01 16:06:29 +00:00
|
|
|
sendDummyKeystroke?.();
|
|
|
|
|
2019-02-21 22:41:17 +00:00
|
|
|
// Someone tried to run a second instance, we should focus our window
|
|
|
|
if (mainWindow) {
|
|
|
|
if (mainWindow.isMinimized()) {
|
|
|
|
mainWindow.restore();
|
|
|
|
}
|
|
|
|
|
|
|
|
showWindow();
|
|
|
|
}
|
2021-10-20 20:40:12 +00:00
|
|
|
if (!logger) {
|
|
|
|
console.log(
|
|
|
|
'second-instance: logger not initialized; skipping further checks'
|
|
|
|
);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-11-02 19:42:31 +00:00
|
|
|
const route = maybeGetIncomingSignalRoute(argv);
|
|
|
|
if (route != null) {
|
|
|
|
handleSignalRoute(route);
|
2019-12-18 19:21:35 +00:00
|
|
|
}
|
2019-02-21 22:41:17 +00:00
|
|
|
return true;
|
|
|
|
});
|
2023-12-11 21:03:07 +00:00
|
|
|
|
2024-07-12 14:28:12 +00:00
|
|
|
// This event is received in macOS packaged builds.
|
2023-12-11 21:03:07 +00:00
|
|
|
app.on('open-url', (event, incomingHref) => {
|
|
|
|
event.preventDefault();
|
|
|
|
const route = parseSignalRoute(incomingHref);
|
2024-07-12 14:28:12 +00:00
|
|
|
|
2023-12-11 21:03:07 +00:00
|
|
|
if (route != null) {
|
2024-07-12 14:28:12 +00:00
|
|
|
// When the app isn't open and you click a signal link to open the app, then
|
|
|
|
// this event will emit before mainWindow is ready. We save the value for later.
|
|
|
|
if (mainWindow == null || !mainWindow.webContents) {
|
|
|
|
macInitialOpenUrlRoute = route;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-12-11 21:03:07 +00:00
|
|
|
handleSignalRoute(route);
|
|
|
|
}
|
|
|
|
});
|
2017-04-25 00:26:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-14 16:23:46 +00:00
|
|
|
let sqlInitTimeStart = 0;
|
|
|
|
let sqlInitTimeEnd = 0;
|
|
|
|
|
|
|
|
const sql = new MainSQL();
|
|
|
|
const heicConverter = getHeicConverter();
|
|
|
|
|
2022-11-17 00:29:15 +00:00
|
|
|
async function getSpellCheckSetting(): Promise<boolean> {
|
2024-03-07 17:36:08 +00:00
|
|
|
const value = ephemeralConfig.get('spell-check');
|
|
|
|
if (typeof value === 'boolean') {
|
|
|
|
getLogger().info('got fast spellcheck setting', value);
|
|
|
|
return value;
|
2022-01-14 16:23:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Default to `true` if setting doesn't exist yet
|
2024-03-07 17:36:08 +00:00
|
|
|
ephemeralConfig.set('spell-check', true);
|
2022-01-14 16:23:46 +00:00
|
|
|
|
2024-03-07 17:36:08 +00:00
|
|
|
getLogger().info('initializing spellcheck setting', true);
|
2022-01-14 16:23:46 +00:00
|
|
|
|
2024-03-07 17:36:08 +00:00
|
|
|
return true;
|
2022-01-14 16:23:46 +00:00
|
|
|
}
|
|
|
|
|
2022-05-11 22:58:14 +00:00
|
|
|
type GetThemeSettingOptionsType = Readonly<{
|
|
|
|
ephemeralOnly?: boolean;
|
|
|
|
}>;
|
|
|
|
|
|
|
|
async function getThemeSetting({
|
|
|
|
ephemeralOnly = false,
|
|
|
|
}: GetThemeSettingOptionsType = {}): Promise<ThemeSettingType> {
|
2024-03-07 17:36:08 +00:00
|
|
|
const value = ephemeralConfig.get('theme-setting');
|
|
|
|
if (value !== undefined) {
|
|
|
|
getLogger().info('got fast theme-setting value', value);
|
2023-09-06 20:54:44 +00:00
|
|
|
} else if (ephemeralOnly) {
|
2022-05-11 22:58:14 +00:00
|
|
|
return 'system';
|
2023-09-06 20:54:44 +00:00
|
|
|
}
|
2022-05-11 22:58:14 +00:00
|
|
|
|
2022-05-25 22:19:16 +00:00
|
|
|
// Default to `system` if setting doesn't exist or is invalid
|
2023-09-06 20:54:44 +00:00
|
|
|
const validatedResult =
|
2024-03-07 17:36:08 +00:00
|
|
|
value === 'light' || value === 'dark' || value === 'system'
|
|
|
|
? value
|
2022-05-25 22:19:16 +00:00
|
|
|
: 'system';
|
2022-05-11 22:58:14 +00:00
|
|
|
|
2024-03-07 17:36:08 +00:00
|
|
|
if (value !== validatedResult) {
|
2023-09-06 20:54:44 +00:00
|
|
|
ephemeralConfig.set('theme-setting', validatedResult);
|
2024-03-07 17:36:08 +00:00
|
|
|
getLogger().info('saving theme-setting value', validatedResult);
|
2023-09-06 20:54:44 +00:00
|
|
|
}
|
2022-05-11 22:58:14 +00:00
|
|
|
|
2023-09-06 20:54:44 +00:00
|
|
|
return validatedResult;
|
2022-05-11 22:58:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
async function getResolvedThemeSetting(
|
|
|
|
options?: GetThemeSettingOptionsType
|
|
|
|
): Promise<ThemeType> {
|
|
|
|
const theme = await getThemeSetting(options);
|
|
|
|
if (theme === 'system') {
|
|
|
|
return nativeTheme.shouldUseDarkColors ? ThemeType.dark : ThemeType.light;
|
|
|
|
}
|
|
|
|
return ThemeType[theme];
|
|
|
|
}
|
|
|
|
|
2024-08-05 18:48:15 +00:00
|
|
|
type GetBackgroundColorOptionsType = GetThemeSettingOptionsType &
|
|
|
|
Readonly<{
|
|
|
|
signalColors?: boolean;
|
|
|
|
}>;
|
|
|
|
|
2022-05-11 22:58:14 +00:00
|
|
|
async function getBackgroundColor(
|
2024-08-05 18:48:15 +00:00
|
|
|
options?: GetBackgroundColorOptionsType
|
2022-05-11 22:58:14 +00:00
|
|
|
): Promise<string> {
|
|
|
|
const theme = await getResolvedThemeSetting(options);
|
|
|
|
|
|
|
|
if (theme === 'light') {
|
2024-08-05 18:48:15 +00:00
|
|
|
return options?.signalColors ? '#3a76f0' : '#ffffff';
|
2022-05-11 22:58:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (theme === 'dark') {
|
|
|
|
return '#121212';
|
|
|
|
}
|
|
|
|
|
|
|
|
throw missingCaseError(theme);
|
|
|
|
}
|
|
|
|
|
2023-11-06 21:19:23 +00:00
|
|
|
async function getLocaleOverrideSetting(): Promise<string | null> {
|
2024-03-07 17:36:08 +00:00
|
|
|
const value = ephemeralConfig.get('localeOverride');
|
2023-11-06 21:19:23 +00:00
|
|
|
// eslint-disable-next-line eqeqeq -- Checking for null explicitly
|
2024-03-07 17:36:08 +00:00
|
|
|
if (typeof value === 'string' || value === null) {
|
|
|
|
getLogger().info('got fast localeOverride setting', value);
|
|
|
|
return value;
|
2023-11-06 21:19:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Default to `null` if setting doesn't exist yet
|
2024-03-07 17:36:08 +00:00
|
|
|
ephemeralConfig.set('localeOverride', null);
|
2023-11-06 21:19:23 +00:00
|
|
|
|
2024-03-07 17:36:08 +00:00
|
|
|
getLogger().info('initializing localeOverride setting', null);
|
2023-11-06 21:19:23 +00:00
|
|
|
|
2024-03-07 17:36:08 +00:00
|
|
|
return null;
|
2023-11-06 21:19:23 +00:00
|
|
|
}
|
|
|
|
|
2023-12-22 20:27:49 +00:00
|
|
|
const zoomFactorService = new ZoomFactorService({
|
|
|
|
async getZoomFactorSetting() {
|
2024-07-22 18:16:33 +00:00
|
|
|
const item = await sql.sqlRead('getItemById', 'zoomFactor');
|
2023-12-22 20:27:49 +00:00
|
|
|
if (typeof item?.value !== 'number') {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return item.value;
|
|
|
|
},
|
|
|
|
async setZoomFactorSetting(zoomFactor) {
|
2024-07-22 18:16:33 +00:00
|
|
|
await sql.sqlWrite('createOrUpdateItem', {
|
2023-12-22 20:27:49 +00:00
|
|
|
id: 'zoomFactor',
|
|
|
|
value: zoomFactor,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2022-01-14 16:23:46 +00:00
|
|
|
let systemTrayService: SystemTrayService | undefined;
|
|
|
|
const systemTraySettingCache = new SystemTraySettingCache(
|
|
|
|
ephemeralConfig,
|
2024-03-14 17:01:40 +00:00
|
|
|
process.argv
|
2022-01-14 16:23:46 +00:00
|
|
|
);
|
|
|
|
|
2018-08-28 21:53:05 +00:00
|
|
|
const windowFromUserConfig = userConfig.get('window');
|
|
|
|
const windowFromEphemeral = ephemeralConfig.get('window');
|
2021-10-01 18:49:59 +00:00
|
|
|
export const windowConfigSchema = z.object({
|
|
|
|
maximized: z.boolean().optional(),
|
|
|
|
autoHideMenuBar: z.boolean().optional(),
|
|
|
|
fullscreen: z.boolean().optional(),
|
|
|
|
width: z.number(),
|
|
|
|
height: z.number(),
|
|
|
|
x: z.number(),
|
|
|
|
y: z.number(),
|
|
|
|
});
|
|
|
|
type WindowConfigType = z.infer<typeof windowConfigSchema>;
|
|
|
|
|
|
|
|
let windowConfig: WindowConfigType | undefined;
|
2024-10-02 19:03:10 +00:00
|
|
|
const windowConfigParsed = safeParseUnknown(
|
|
|
|
windowConfigSchema,
|
2021-10-01 18:49:59 +00:00
|
|
|
windowFromEphemeral || windowFromUserConfig
|
|
|
|
);
|
|
|
|
if (windowConfigParsed.success) {
|
|
|
|
windowConfig = windowConfigParsed.data;
|
|
|
|
}
|
|
|
|
|
2018-08-28 21:53:05 +00:00
|
|
|
if (windowFromUserConfig) {
|
|
|
|
userConfig.set('window', null);
|
|
|
|
ephemeralConfig.set('window', windowConfig);
|
|
|
|
}
|
|
|
|
|
2022-06-08 22:00:32 +00:00
|
|
|
let menuOptions: CreateTemplateOptionsType | undefined;
|
|
|
|
|
2021-10-01 18:49:59 +00:00
|
|
|
function getLogger(): LoggerType {
|
|
|
|
if (!logger) {
|
2021-10-21 19:49:53 +00:00
|
|
|
console.warn('getLogger: Logger not yet initialized!');
|
|
|
|
return consoleLogger;
|
2021-10-01 18:49:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return logger;
|
|
|
|
}
|
|
|
|
|
2023-01-25 00:54:46 +00:00
|
|
|
function getPreferredSystemLocales(): Array<string> {
|
|
|
|
if (!preferredSystemLocales) {
|
|
|
|
throw new Error('getPreferredSystemLocales: Locales not yet initialized!');
|
|
|
|
}
|
|
|
|
return preferredSystemLocales;
|
|
|
|
}
|
|
|
|
|
2023-11-07 01:02:13 +00:00
|
|
|
function getLocaleOverride(): string | null {
|
|
|
|
if (typeof localeOverride === 'undefined') {
|
|
|
|
throw new Error('getLocaleOverride: Locale not yet initialized!');
|
|
|
|
}
|
|
|
|
return localeOverride;
|
|
|
|
}
|
|
|
|
|
2023-01-25 00:54:46 +00:00
|
|
|
function getResolvedMessagesLocale(): LocaleType {
|
|
|
|
if (!resolvedTranslationsLocale) {
|
|
|
|
throw new Error('getResolvedMessagesLocale: Locale not yet initialized!');
|
2021-10-01 18:49:59 +00:00
|
|
|
}
|
|
|
|
|
2023-01-25 00:54:46 +00:00
|
|
|
return resolvedTranslationsLocale;
|
2021-10-01 18:49:59 +00:00
|
|
|
}
|
2017-06-09 19:37:01 +00:00
|
|
|
|
2023-07-31 16:23:19 +00:00
|
|
|
function getHourCyclePreference(): HourCyclePreference {
|
|
|
|
if (process.platform !== 'darwin') {
|
|
|
|
return HourCyclePreference.UnknownPreference;
|
|
|
|
}
|
|
|
|
if (systemPreferences.getUserDefault('AppleICUForce24HourTime', 'boolean')) {
|
|
|
|
return HourCyclePreference.Prefer24;
|
|
|
|
}
|
|
|
|
if (systemPreferences.getUserDefault('AppleICUForce12HourTime', 'boolean')) {
|
|
|
|
return HourCyclePreference.Prefer12;
|
|
|
|
}
|
|
|
|
return HourCyclePreference.UnknownPreference;
|
|
|
|
}
|
|
|
|
|
2023-04-20 21:23:19 +00:00
|
|
|
type PrepareUrlOptions = {
|
|
|
|
forCalling?: boolean;
|
|
|
|
forCamera?: boolean;
|
|
|
|
sourceName?: string;
|
|
|
|
};
|
2022-06-13 21:39:35 +00:00
|
|
|
|
|
|
|
async function prepareFileUrl(
|
2021-10-01 18:49:59 +00:00
|
|
|
pathSegments: ReadonlyArray<string>,
|
2022-06-13 21:39:35 +00:00
|
|
|
options: PrepareUrlOptions = {}
|
|
|
|
): Promise<string> {
|
2021-10-01 18:49:59 +00:00
|
|
|
const filePath = join(...pathSegments);
|
2024-01-24 00:11:12 +00:00
|
|
|
const fileUrl = pathToFileURL(filePath) as URL;
|
2022-06-13 21:39:35 +00:00
|
|
|
return prepareUrl(fileUrl, options);
|
2021-05-13 17:18:51 +00:00
|
|
|
}
|
|
|
|
|
2022-06-13 21:39:35 +00:00
|
|
|
async function prepareUrl(
|
2021-10-01 18:49:59 +00:00
|
|
|
url: URL,
|
2023-04-20 21:23:19 +00:00
|
|
|
{ forCalling, forCamera, sourceName }: PrepareUrlOptions = {}
|
2022-06-13 21:39:35 +00:00
|
|
|
): Promise<string> {
|
2023-04-20 21:23:19 +00:00
|
|
|
return setUrlSearchParams(url, { forCalling, forCamera, sourceName }).href;
|
2017-10-13 23:49:16 +00:00
|
|
|
}
|
|
|
|
|
2022-12-15 21:31:43 +00:00
|
|
|
async function handleUrl(rawTarget: string) {
|
2022-02-02 18:29:01 +00:00
|
|
|
const parsedUrl = maybeParseUrl(rawTarget);
|
2021-05-13 17:18:51 +00:00
|
|
|
if (!parsedUrl) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-11-02 19:42:31 +00:00
|
|
|
const signalRoute = parseSignalRoute(rawTarget);
|
2022-02-02 18:29:01 +00:00
|
|
|
|
2019-12-17 20:25:57 +00:00
|
|
|
// We only want to specially handle urls that aren't requesting the dev server
|
2023-11-02 19:42:31 +00:00
|
|
|
if (signalRoute != null) {
|
|
|
|
handleSignalRoute(signalRoute);
|
2021-02-10 22:39:26 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-11-02 19:42:31 +00:00
|
|
|
const { protocol, hostname } = parsedUrl;
|
|
|
|
const isDevServer =
|
|
|
|
process.env.SIGNAL_ENABLE_HTTP && hostname === 'localhost';
|
|
|
|
|
2019-12-17 20:25:57 +00:00
|
|
|
if ((protocol === 'http:' || protocol === 'https:') && !isDevServer) {
|
2019-12-03 20:02:50 +00:00
|
|
|
try {
|
2023-11-02 19:42:31 +00:00
|
|
|
await shell.openExternal(rawTarget);
|
2019-12-03 20:02:50 +00:00
|
|
|
} catch (error) {
|
2022-11-22 18:43:43 +00:00
|
|
|
getLogger().error(`Failed to open url: ${Errors.toLogFormat(error)}`);
|
2019-12-03 20:02:50 +00:00
|
|
|
}
|
2017-10-13 23:49:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-16 21:32:38 +00:00
|
|
|
async function handleCommonWindowEvents(window: BrowserWindow) {
|
2022-12-15 21:31:43 +00:00
|
|
|
window.webContents.on('will-navigate', (event, rawTarget) => {
|
|
|
|
event.preventDefault();
|
|
|
|
|
2022-12-21 18:41:48 +00:00
|
|
|
drop(handleUrl(rawTarget));
|
2022-12-15 21:31:43 +00:00
|
|
|
});
|
|
|
|
window.webContents.setWindowOpenHandler(({ url }) => {
|
2022-12-21 18:41:48 +00:00
|
|
|
drop(handleUrl(url));
|
2022-12-15 21:31:43 +00:00
|
|
|
return { action: 'deny' };
|
|
|
|
});
|
2021-10-01 18:49:59 +00:00
|
|
|
window.webContents.on(
|
|
|
|
'preload-error',
|
|
|
|
(_event: Electron.Event, preloadPath: string, error: Error) => {
|
|
|
|
getLogger().error(`Preload error in ${preloadPath}: `, error.message);
|
|
|
|
}
|
|
|
|
);
|
2021-06-30 18:57:43 +00:00
|
|
|
|
2021-09-29 18:37:30 +00:00
|
|
|
activeWindows.add(window);
|
|
|
|
window.on('closed', () => activeWindows.delete(window));
|
|
|
|
|
2022-07-05 16:44:53 +00:00
|
|
|
const setWindowFocus = () => {
|
|
|
|
window.webContents.send('set-window-focus', window.isFocused());
|
|
|
|
};
|
|
|
|
window.on('focus', setWindowFocus);
|
|
|
|
window.on('blur', setWindowFocus);
|
|
|
|
|
|
|
|
window.once('ready-to-show', setWindowFocus);
|
|
|
|
// This is a fallback in case we drop an event for some reason.
|
|
|
|
const focusInterval = setInterval(setWindowFocus, 10000);
|
|
|
|
window.on('closed', () => clearInterval(focusInterval));
|
|
|
|
|
2023-12-22 20:27:49 +00:00
|
|
|
await zoomFactorService.syncWindow(window);
|
2023-10-04 17:24:41 +00:00
|
|
|
|
2021-06-30 18:57:43 +00:00
|
|
|
nativeThemeNotifier.addWindow(window);
|
2017-10-13 23:49:16 +00:00
|
|
|
}
|
|
|
|
|
2023-07-20 22:37:56 +00:00
|
|
|
const DEFAULT_WIDTH = ciMode ? 1024 : 800;
|
|
|
|
const DEFAULT_HEIGHT = ciMode ? 1024 : 610;
|
2022-09-22 16:43:36 +00:00
|
|
|
|
|
|
|
// We allow for smaller sizes because folks with OS-level zoom and HighDPI/Large Text
|
|
|
|
// can really cause weirdness around window pixel-sizes. The app is very broken if you
|
|
|
|
// make the window this small and do nothing else. But if you zoom out and collapse the
|
|
|
|
// left pane, even this window size can work!
|
|
|
|
const MIN_WIDTH = 300;
|
|
|
|
const MIN_HEIGHT = 200;
|
2017-11-30 19:58:00 +00:00
|
|
|
const BOUNDS_BUFFER = 100;
|
|
|
|
|
2021-10-01 18:49:59 +00:00
|
|
|
type BoundsType = {
|
|
|
|
width: number;
|
|
|
|
height: number;
|
|
|
|
x: number;
|
|
|
|
y: number;
|
|
|
|
};
|
|
|
|
|
|
|
|
function isVisible(window: BoundsType, bounds: BoundsType) {
|
2022-05-25 18:15:09 +00:00
|
|
|
const boundsX = bounds?.x || 0;
|
|
|
|
const boundsY = bounds?.y || 0;
|
|
|
|
const boundsWidth = bounds?.width || DEFAULT_WIDTH;
|
|
|
|
const boundsHeight = bounds?.height || DEFAULT_HEIGHT;
|
2017-11-30 19:58:00 +00:00
|
|
|
|
|
|
|
// requiring BOUNDS_BUFFER pixels on the left or right side
|
2018-04-27 21:25:04 +00:00
|
|
|
const rightSideClearOfLeftBound =
|
|
|
|
window.x + window.width >= boundsX + BOUNDS_BUFFER;
|
|
|
|
const leftSideClearOfRightBound =
|
|
|
|
window.x <= boundsX + boundsWidth - BOUNDS_BUFFER;
|
2017-11-30 19:58:00 +00:00
|
|
|
|
|
|
|
// top can't be offscreen, and must show at least BOUNDS_BUFFER pixels at bottom
|
|
|
|
const topClearOfUpperBound = window.y >= boundsY;
|
2018-04-27 21:25:04 +00:00
|
|
|
const topClearOfLowerBound =
|
|
|
|
window.y <= boundsY + boundsHeight - BOUNDS_BUFFER;
|
2017-11-30 19:58:00 +00:00
|
|
|
|
2018-04-27 21:25:04 +00:00
|
|
|
return (
|
|
|
|
rightSideClearOfLeftBound &&
|
Auto-orient image attachments based on EXIF metadata
As described in #998, images are sometimes displayed with an incorrect
orientation. This is because cameras often write files in the native sensor byte
order and attach the `Orientation` EXIF metadata to tell end-user devices how to
display the images based on the original author’s capture orientation.
Electron/Chromium (and therefore Signal Desktop) currently doesn’t support
applying this metadata for `<img>` tags, e.g. CSS `image-orientation: from-
image`. As a workaround, this change uses the `loadImage` library with the
`orientation: true` flag to auto-orient images ~~before display~~ upon receipt
and before sending.
**Changes**
- [x] ~~Auto-orient images during display in message list view~~
- [x] Ensure image is not displayed until loaded (to prevent layout reflow) .
- [x] Auto-orient images upon receipt and before storing in IndexedDB
(~~or preserve original data until Chromium offers native fix?~~)
- [x] Auto-orient images in compose area preview.
- [x] ~~Auto-orient images in lightbox view~~
- [x] Auto-orient images before sending / storage.
- [x] Add EditorConfig for sharing code styles across editors.
- [x] Fix ESLint ignore file.
- [x] Change `function-paren-newline` ESLint rule from
`consistent` to `multiline`.
- [x] Add `operator-linebreak` ESLint rule for consistency.
- [x] Added `blob-util` dependency for converting between array buffers,
blobs, etc.
- [x] Extracted `createMessageHandler` to consolidate logic for
`onMessageReceived` and `onSentMessage`.
- [x] Introduce `async` / `await` to simplify async coding (restore control flow
for branching, loops, and exceptions).
- [x] Introduce `window.Signal` namespace for exposing ES2015+ CommonJS modules.
- [x] Introduce rudimentary `Message` and `Attachment` types to begin defining a
schema and versioning. This will allow us to track which changes, e.g.
auto-orient JPEGs, per message / attachment as well as which fields
are stored.
- [x] Renamed `window.dataURLtoBlob` to `window.dataURLToBlobSync` to both fix
the strange `camelCase` as well as to highlight that this operation is
synchronous and therefore blocks the user thread.
- [x] Normalize all JPEG MIME types to `image/jpeg`, eliminating the
invalid `image/jpg`.
- [x] Add `npm run test-modules` command for testing non-browser specific
CommonJS modules.
- **Stretch Goals**
- [ ] ~~Restrict `autoOrientImage` to `Blob` to narrow API interface.~~ Do
this once we use PureScript.
- [ ] ~~Return non-JPEGs as no-op from `autoOrientImage`.~~ Skipping
`autoOrientImage` for non-JPEGs altogether.
- [ ] Retroactively auto-orient existing JPEG image attachments in the
background.
---
Fixes #998
---
- **Blog:** EXIF Orientation Handling Is a Ghetto:
https://www.daveperrett.com/articles/2012/07/28/exif-orientation-handling-is-a-ghetto/
- **Chromium Bug:** EXIF orientation is ignored:
https://bugs.chromium.org/p/chromium/issues/detail?id=56845
- **Chromium Bug:** Support for the CSS image-orientation CSS property:
https://bugs.chromium.org/p/chromium/issues/detail?id=158753
---
commit ce5090b473a2448229dc38e4c3f15d7ad0137714
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 16 10:35:36 2018 -0500
Inline message descriptors
commit 329036e59c138c1e950ec7c654eebd7d87076de5
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Thu Feb 15 17:34:40 2018 -0500
Clarify order of operations
Semantically, it makes more sense to do `getFile` before `clearForm`
even though it seems to work either way.
commit f9d4cfb2ba0d8aa308b0923bbe6066ea34cb97bd
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Thu Feb 15 17:18:26 2018 -0500
Simplify `operator-linebreak` configuration
Enabling `before` caused more code changes and it turns out our previous
configuration is already the default.
commit db588997acdd90ed2ad829174ecbba744383c78b
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Thu Feb 15 17:15:59 2018 -0500
Remove obsolete TODO
commit 799c8817633f6afa0b731fc3b5434e463bd850e3
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Thu Feb 15 17:12:18 2018 -0500
Enable ESLint `function-paren-newline` `multiline`
Per discussion.
commit b660b6bc8ef41df7601a411213d6cda80821df87
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Thu Feb 15 17:10:48 2018 -0500
Use `messageDescriptor.id` not `source`
commit 5e7309d176f4a7e97d3dc4c738e6b0ccd4792871
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Wed Feb 14 16:29:01 2018 -0500
Remove unnecessary `eslint-env`
commit 393b3da55eabd7413596c86cc3971b063a0efe31
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Wed Feb 14 16:19:17 2018 -0500
Refactor `onSentMessage` and `onMessageReceived`
Since they are so similar, we create the handlers using new
`createMessageHandler` function. This allows us to ensure both synced and
received messages go through schema upgrade pipeline.
commit b3db0bf179c9a5bea96480cde28c6fa7193ac117
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Wed Feb 14 16:18:21 2018 -0500
Add `Message` descriptor functions
commit 8febf125b1b42fe4ae1888dd50fcee2749dc1ff0
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Wed Feb 14 14:46:56 2018 -0500
Fix typo
commit 98d951ef77bd578b313a4ff4b496b793e82e88d5
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Wed Feb 14 12:22:39 2018 -0500
Remove `promises` reference
commit a0e9559ed5bed947dabf28cb672e63d39948d854
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Wed Feb 14 12:22:13 2018 -0500
Fix `AttachmentView::mediaType` fall-through
commit 67be916a83951b8a1f9b22efe78a6da6b1825f38
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Wed Feb 14 12:03:41 2018 -0500
Remove minor TODOs
commit 0af186e118256b62905de38487ffacc41693ff47
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Wed Feb 14 11:44:41 2018 -0500
Enable ESLint for `js/views/attachment_view.js`
commit 28a2dc5b8a28e1a087924fdc7275bf7d9a577b92
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Wed Feb 14 11:44:12 2018 -0500
Remove dynamic type checks
commit f4ce36fcfc2737de32d911cd6103f889097813f6
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Wed Feb 14 11:27:56 2018 -0500
Rename `process` to `upgradeSchema`
- `Message.process` -> `Message.upgradeSchema`
- `Attachment.process` -> `Attachment.upgradeSchema`
- `Attachment::processVersion` -> `Attachment::schemaVersion`
Document version history.
commit 41b92c0a31050ba05ddb1c43171d651f3568b9ac
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Wed Feb 14 11:11:50 2018 -0500
Add `operator-linebreak` ESLint rule
Based on the following discussion:
https://github.com/signalapp/Signal-Desktop/pull/2040#discussion_r168029106
commit 462defbe55879060fe25bc69103d4429bae2b2f6
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Wed Feb 14 11:01:30 2018 -0500
Add missing `await` for `ConversationController.getOrCreateAndWait`
Tested this by setting `if` condition to `true` and confirming it works.
It turns rotating a profile key is more involved and might require
registering a new account according to Matthew.
commit c08058ee4b883b3e23a40683de802ac81ed74874
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 16:32:24 2018 -0500
Convert `FileList` to `Array`
commit 70a6c4201925f57be1f94d9da3547fdefc7bbb53
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 15:46:34 2018 -0500
:art: Fix lint errors
commit 2ca7cdbc31d4120d6c6a838a6dcf43bc209d9788
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 15:07:09 2018 -0500
Skip `autoOrientImage` for non-JPEG images
commit 58eac383013c16ca363a4ed33dca5c7ba61284e5
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 14:55:35 2018 -0500
Move new-style modules to `window.Signal` namespace
commit 02c9328877dce289d6116a18b1c223891bd3cd0b
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 14:35:23 2018 -0500
Extract `npm run test-modules` command
commit 2c708eb94fba468b81ea9427734896114f5a7807
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 13:25:51 2018 -0500
Extract `Message.process`
commit 4a2e52f68a77536a0fa04aa3c29ad3e541a8fa7e
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 13:25:12 2018 -0500
Fix EditorConfig
commit a346bab5db082720f5d47363f06301380e870425
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 13:13:02 2018 -0500
Remove `vim` directives on ESLint-ed files
commit 7ec885c6359e495b407d5bc3eac9431d47c37fc6
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 13:08:24 2018 -0500
Remove CSP whitelisting of `blob:`
We no longer use `autoOrientImage` using blob URLs. Bring this back if we
decide to auto-orient legacy attachments.
commit 879b6f58f4a3f4a9ed6915af6b1be46c1e90e0ca
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 12:57:05 2018 -0500
Use `Message` type to determine send function
Throws on invalid message type.
commit 5203d945c98fd2562ae4e22c5c9838d27dec305b
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 12:56:48 2018 -0500
Whitelist `Whisper` global
commit 8ad0b066a3690d3382b86bf6ac00c03df7d1e20b
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 12:56:32 2018 -0500
Add `Whisper.Types` namespace
This avoids namespace collision for `Whisper.Message`.
commit 785a949fce2656ca7dcaf0869d6b9e0648114e80
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 12:55:43 2018 -0500
Add `Message` type
commit 674a7357abf0dcc365455695d56c0479998ebf27
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 12:35:23 2018 -0500
Run ESLint on `Conversation::sendMessage`
commit cd985aa700caa80946245b17ea1b856449f152a0
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 12:34:38 2018 -0500
Document type signature of `FileInputView::readFile`
commit d70d70e52c49588a1dc9833dfe5dd7128e13607f
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 12:31:16 2018 -0500
Move attachment processing closer to sending
This helps ensure processing happens uniformly, regardless of which code
paths are taken to send an attachment.
commit 532ac3e273a26b97f831247f9ee3412621b5c112
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 12:22:29 2018 -0500
Process attachment before it’s sent
Picked this place since it already had various async steps, similar to
`onMessageReceived` for the incoming `Attachment.process`.
Could we try have this live closer to where we store it in IndexedDB, e.g.
`Conversation::sendMessage`?
commit a4582ae2fb6e1d3487131ba1f8fa6a00170cb32c
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 12:21:42 2018 -0500
Refactor `getFile` and `getFiles`
Lint them using ESLint.
commit 07e9114e65046d791fc4f6ed90d6e2e938ad559d
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 11:37:31 2018 -0500
Document incoming and outgoing attachments fields
Note how outgoing message attachments only have 4 fields. This presumably
means the others are not used in our code and could be discarded for
simplicity.
commit fdc3ef289d6ec1be344a12d496839d5ba747bb6a
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 11:36:21 2018 -0500
Highlight that `dataURLToBlob` is synchronous
commit b9c6bf600fcecedfd649ef2ae3c8629cced4e45a
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 11:35:49 2018 -0500
Add EditorConfig configuration
commit e56101e229d56810c8e31ad7289043a152c6c449
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 11:34:23 2018 -0500
Replace custom with `blob-util` functions
IMPORTANT: All of them are async so we need to use `await`, otherwise we get
strange or silent errors.
commit f95150f6a9569fabcb31f3acd9f6b7bf50b5d145
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 11:17:30 2018 -0500
Revert "Replace custom functions with `blob-util`"
This reverts commit 8a81e9c01bfe80c0e1bf76737092206c06949512.
commit 33860d93f3d30ec55c32f3f4a58729df2eb43f0d
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 11:13:02 2018 -0500
Revert "Replace `blueimp-canvas-to-blob` with `blob-util`"
This reverts commit 31b3e853e4afc78fe80995921aa4152d9f6e4783.
commit 7a0ba6fed622d76a3c39c7f03de541a7edb5b8dd
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 11:12:58 2018 -0500
Replace `blueimp-canvas-to-blob` with `blob-util`
commit 47a5f2bfd8b3f546e27e8d2b7e1969755d825a66
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 10:55:34 2018 -0500
Replace custom functions with `blob-util`
commit 1cfa0efdb4fb1265369e2bf243c21f04f044fa01
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 10:47:02 2018 -0500
Add `blob-util` dependency
commit 9ac26be1bd783cd5070d886de107dd3ad9c91ad1
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 10:46:44 2018 -0500
Document why we drop original image data during auto-orient
commit 4136d6c382b99f41760a4da519d0db537fa7de8d
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 10:46:27 2018 -0500
Extract `DEFAULT_JPEG_QUALITY`
commit 4a7156327eb5f94dba80cb300b344ac591226b0e
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 10:37:11 2018 -0500
Drop support for invalid `image/jpg` MIME type
commit 69fe96581f25413194032232f1bf704312e4754c
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 09:54:30 2018 -0500
Document `window.onInvalidStateError` global
commit a48ba1c77458da38583ee9cd488f70a59f6ee0fd
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 09:54:04 2018 -0500
Selectively run ESLint on `js/background.js`
Enabling ESLint on a per function basis allows us to incrementally improve
the codebase without requiring large and potentially risky refactorings.
commit e6d1cf826befc17ad4ec72fda8e761701665635e
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 09:16:23 2018 -0500
Move async attachment processing to `onMessageReceived`
We previously processed attachments in `handleDataMessage` which is mostly a
synchronous function, except for the saving of the model. Moving the
processing into the already async `onMessageReceived` improves code clarity.
commit be6ca2a9aae5b59c360817deb1e18d39d705755e
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 09:14:49 2018 -0500
Document import of ES2015+ modules
commit eaaf7c41608fb988b8f4bbaa933cff110115610e
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 09:14:29 2018 -0500
:art: Fix lint error
commit a25b0e2e3d0f72c6a7bf0a15683f02450d5209ee
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 09:13:57 2018 -0500
:art: Organize `require`s
commit e0cc3d8fab6529d01b388acddf8605908c3d236b
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 09:07:17 2018 -0500
Implement attachment process version
Instead of keeping track of last normalization (processing) date, we now
keep track of an internal processing version that will help us understand
what kind of processing has already been completed for a given attachment.
This will let us retroactively upgrade existing attachments.
As we add more processing steps, we can build a processing pipeline that can
convert any attachment processing version into a higher one,
e.g. 4 -> 5 -> 6 -> 7.
commit ad9083d0fdb880bc518e02251e51a39f7e1c585f
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 08:50:31 2018 -0500
Ignore ES2015+ files during JSCS linting
commit 96641205f734927aaebc2342d977c555799c3e3b
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 08:48:07 2018 -0500
Improve ESLint ignore rules
Apparently, using unqualified `/**` patterns prevents `!` include patterns.
Using qualified glob patterns, e.g. `js/models/**/*.js`, lets us work
around this.
commit 255e0ab15bd1a0ca8ca5746e42d23977c8765d01
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 08:44:59 2018 -0500
:abc: ESLint ignored files
commit ebcb70258a26f234bd602072ac7c0a1913128132
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 08:35:47 2018 -0500
Whitelist `browser` environment for ESLint
commit 3eaace6f3a21421c5aaaaf01592408c7ed83ecd3
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 08:35:05 2018 -0500
Use `MIME` module
commit ba2cf7770e614415733414a2dcc48f110b929892
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 08:32:54 2018 -0500
:art: Fix lint errors
commit 65acc86e8580e88f7a6611eb4b8fa5d7291f7a3f
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 08:30:42 2018 -0500
Add ES2015+ files to JSHint ignored list
commit 8b6494ae6c9247acdfa059a9b361ec5ffcdb39f0
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 08:29:20 2018 -0500
Document potentially unexpected `autoScale` behavior
commit 8b4c69b2002d1777d3621be10f92cbf432f9d4d6
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 08:26:47 2018 -0500
Test CommonJS modules separately
Not sure how to test them as part of Grunt `unit-tests` task as
`test/index.html` doesn’t allow for inclusion of CommonJS modules that use
`require`. The tests are silently skipped.
commit 213400e4b2bba3efee856a25b40e269221c3c39d
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Tue Feb 13 08:24:27 2018 -0500
Add `MIME` type module
commit 37a726e4fb4b3ed65914463122a5662847b5adee
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 20:18:05 2018 -0500
Return proper `Error` from `blobArrayToBuffer`
commit 164752db5612220e4dcf58d57bcd682cb489a399
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 20:15:41 2018 -0500
:art: Fix ESLint errors
commit d498dd79a067c75098dd3179814c914780e5cb4f
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 20:14:33 2018 -0500
Update `Attachment` type field definitions
commit 141155a1533ff8fb616b70ea313432781bbebffd
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 20:12:50 2018 -0500
Move `blueimp-canvas-to-blob` from Bower to npm
commit 7ccb833e5d286ddd6235d3e491c62ac1e4544510
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 16:33:50 2018 -0500
:art: Clarify data flow
commit e7da41591fde5a830467bebf1b6f51c1f7293e74
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 16:31:21 2018 -0500
Use `blobUrl` for consistency
commit 523a80eefe0e2858aa1fb2bb9539ec44da502963
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 16:28:06 2018 -0500
Remove just-in-time image auto-orient for lightbox
We can bring this back if our users would like auto-orient for old
attachments.
commit 0739feae9c47dd523c10740d6cdf746d539f270c
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 16:27:21 2018 -0500
Remove just-in-time auto-orient of message attachments
We can bring this back if our users would like auto-orient for old
attachments. But better yet, we might implement this as database migration.
commit ed43c66f92830ee233d5a94d0545eea4da43894d
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 16:26:24 2018 -0500
Auto-orient JPEG attachments upon receipt
commit e2eb8e36b017b048d57602fca14e45d657e0e1a1
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 16:25:26 2018 -0500
Expose `Attachment` type through `Whisper.Attachment`
commit 9638fbc987b84f143ca34211dc4666d96248ea2f
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 16:23:39 2018 -0500
Use `contentType` from `model`
commit 032c0ced46c3876cb9474b26f9d53d6f1c6b16a0
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 16:23:04 2018 -0500
Return `Error` object for `autoOrientImage` failures
commit ff04bad8510c4b21aef350bed2b1887d0e055b98
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 16:22:32 2018 -0500
Add `options` for `autoOrientImage` output type / quality
commit 87745b5586d1e182b51c9f9bc5e4eaf6dbc16722
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 16:18:46 2018 -0500
Add `Attachment` type
Defines various functions on attachments, e.g. normalization
(auto-orient JPEGs, etc.)
commit de27fdc10a53bc8882a9c978e82265db9ac6d6f5
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 16:16:34 2018 -0500
Add `yarn grunt` shortcut
This allows us to use local `grunt-cli` for `grunt dev`.
commit 59974db5a5da0d8f4cdc8ce5c4e3c974ecd5e754
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 10:10:11 2018 -0500
Improve readability
commit b5ba96f1e6f40f2e1fa77490c583217768e1f412
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 10:08:12 2018 -0500
Use `snake_case` for module names
Prevents problems across case-sensitive and case-insensitive file systems.
We can work around this in the future using a lint rule such as
`eslint-plugin-require-path-exists`.
See discussion:
https://github.com/signalapp/Signal-Desktop/pull/2040#discussion_r167365931
commit 48c5d3155c96ef628b00d99b52975e580d1d5501
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Mon Feb 12 10:05:44 2018 -0500
:art: Use destructuring
commit 4822f49f22382a99ebf142b337375f7c25251d76
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 17:41:40 2018 -0500
Auto-orient images in lightbox view
commit 7317110809677dddbbef3fadbf912cdba1c010bf
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 17:40:14 2018 -0500
Document magic number for escape key
commit c790d07389a7d0bbf5298de83dbcfa8be1e7696b
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 17:38:35 2018 -0500
Make second `View` argument an `options` object
commit fbe010bb63d0088af9dfe11f153437fab34247e0
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 17:27:40 2018 -0500
Allow `loadImage` to fetch `blob://` URLs
commit ec35710d002b019a273eeb48f94dcaf2babe5d96
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 16:57:48 2018 -0500
:art: Shorten `autoOrientImage` import
commit d07433e3cf316c6a143a0c9393ba26df9e3af17b
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 16:57:19 2018 -0500
Make `autoOrientImage` module standalone
commit c285bf5e33cdf10e0ef71e72cd6f55aef0df96ef
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 16:55:44 2018 -0500
Replace `loadImage` with `autoOrientImage`
commit 44318549235af01fd061c25f557c93fd21cebb7a
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 16:53:23 2018 -0500
Add `autoOrientImage` module
This module exposes `loadImage` with a `Promise` based interface and pre-
populates `orientation: true` option to auto-orient input. Returns data URL
as string.
The module uses a named export as refactoring references of modules with
`default` (`module.exports`) export references can be error-prone.
See: https://basarat.gitbooks.io/typescript/docs/tips/defaultIsBad.html
commit c77063afc6366fe49615052796fe46f9b369de39
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 16:44:30 2018 -0500
Auto-orient preview images
See: #998
commit 06dba5eb8f662c11af3a9ba8395bb453ab2e5f8d
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 16:43:23 2018 -0500
TODO: Use native `Canvas::toBlob`
One challenge is that `Canvas::toBlob` is async whereas
`dataURLtoBlob` is sync.
commit b15c304a3125dd023fd90990e6225a7303f3596f
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 16:42:45 2018 -0500
Make `null` check strict
Appeases JSHint. ESLint has a nice `smart` option for `eqeqeq` rule:
https://eslint.org/docs/rules/eqeqeq#smart
commit ea70b92d9b18201758e11fdc25b09afc97b50055
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 15:23:58 2018 -0500
Use `Canvas::toDataURL` to preserve `ImageView` logic
This way, all the other code paths remain untouched in case we want to
remove the auto-orient code once Chrome supports the `image-orientation`
CSS property.
See:
- #998
- https://developer.mozilla.org/en-US/docs/Web/CSS/image-orientation
commit 62fd744f9f27d951573a68d2cdfe7ba2a3784b41
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 14:38:04 2018 -0500
Use CSS to constrain auto-oriented images
commit f4d3392687168c237441b29140c7968b49dbef9e
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 14:35:02 2018 -0500
Replace `ImageView` `el` with auto-oriented `canvas`
See: #998
commit 1602d7f610e4993ad1291f88197f9ead1e25e776
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 14:25:48 2018 -0500
Pass `Blob` to `View` (for `ImageView`)
This allows us to do JPEG auto-orientation based on EXIF metadata.
commit e6a414f2b2a80da1137b839b348a38510efd04bb
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 14:25:12 2018 -0500
:hocho: Remove newline
commit 5f0d9570d7862fc428ff89c2ecfd332a744537e5
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 11:17:02 2018 -0500
Expose `blueimp-load-image` as `window.loadImage`
commit 1e1c62fe2f6a76dbcf1998dd468c26187c9871dc
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 11:16:46 2018 -0500
Add `blueimp-load-image` npm dependency
commit ad17fa8a68a21ca5ddec336801b8568009bef3d4
Author: Daniel Gasienica <daniel@gasienica.ch>
Date: Fri Feb 9 11:14:40 2018 -0500
Remove `blueimp-load-image` Bower dependency
2018-02-21 15:26:59 +00:00
|
|
|
leftSideClearOfRightBound &&
|
|
|
|
topClearOfUpperBound &&
|
2018-04-27 21:25:04 +00:00
|
|
|
topClearOfLowerBound
|
|
|
|
);
|
2017-11-30 19:58:00 +00:00
|
|
|
}
|
|
|
|
|
2021-10-01 18:49:59 +00:00
|
|
|
let windowIcon: string;
|
2020-04-20 21:07:16 +00:00
|
|
|
|
2021-02-01 20:01:25 +00:00
|
|
|
if (OS.isWindows()) {
|
2021-10-01 18:49:59 +00:00
|
|
|
windowIcon = join(__dirname, '../build/icons/win/icon.ico');
|
2021-02-01 20:01:25 +00:00
|
|
|
} else if (OS.isLinux()) {
|
2021-10-01 18:49:59 +00:00
|
|
|
windowIcon = join(__dirname, '../images/signal-logo-desktop-linux.png');
|
2020-04-20 21:07:16 +00:00
|
|
|
} else {
|
2021-10-01 18:49:59 +00:00
|
|
|
windowIcon = join(__dirname, '../build/icons/png/512x512.png');
|
2020-04-20 21:07:16 +00:00
|
|
|
}
|
|
|
|
|
2022-07-28 16:35:09 +00:00
|
|
|
// The titlebar is hidden on:
|
|
|
|
// - Windows < 10 (7, 8)
|
|
|
|
// - macOS (but no custom titlebar is displayed, see
|
|
|
|
// `--title-bar-drag-area-height` in `stylesheets/_titlebar.scss`
|
2024-01-16 21:32:38 +00:00
|
|
|
const mainTitleBarStyle = OS.isMacOS()
|
2022-06-08 22:00:32 +00:00
|
|
|
? ('hidden' as const)
|
|
|
|
: ('default' as const);
|
|
|
|
|
2024-01-16 21:32:38 +00:00
|
|
|
const nonMainTitleBarStyle = 'default' as const;
|
2022-06-08 22:00:32 +00:00
|
|
|
|
2023-02-14 02:16:49 +00:00
|
|
|
async function safeLoadURL(window: BrowserWindow, url: string): Promise<void> {
|
2023-02-27 18:46:00 +00:00
|
|
|
let wasDestroyed = false;
|
|
|
|
const onDestroyed = () => {
|
|
|
|
wasDestroyed = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
window.webContents.on('did-stop-loading', onDestroyed);
|
|
|
|
window.webContents.on('destroyed', onDestroyed);
|
2023-02-14 02:16:49 +00:00
|
|
|
try {
|
|
|
|
await window.loadURL(url);
|
|
|
|
} catch (error) {
|
2023-02-27 18:46:00 +00:00
|
|
|
if (
|
|
|
|
(wasDestroyed || windowState.readyForShutdown()) &&
|
|
|
|
error?.code === 'ERR_FAILED'
|
|
|
|
) {
|
2023-02-14 02:16:49 +00:00
|
|
|
getLogger().warn(
|
|
|
|
'safeLoadURL: ignoring ERR_FAILED because we are shutting down',
|
|
|
|
error
|
|
|
|
);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
throw error;
|
2023-02-27 18:46:00 +00:00
|
|
|
} finally {
|
2023-03-09 19:29:33 +00:00
|
|
|
try {
|
|
|
|
window.webContents.removeListener('did-stop-loading', onDestroyed);
|
|
|
|
window.webContents.removeListener('destroyed', onDestroyed);
|
|
|
|
} catch {
|
|
|
|
// We already logged or thrown an error - don't bother with handling the
|
|
|
|
// error here.
|
|
|
|
}
|
2023-02-14 02:16:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-20 21:00:11 +00:00
|
|
|
async function createWindow() {
|
2022-02-11 22:32:51 +00:00
|
|
|
const usePreloadBundle =
|
|
|
|
!isTestEnvironment(getEnvironment()) || forcePreloadBundle;
|
|
|
|
|
2024-07-15 22:42:20 +00:00
|
|
|
const primaryDisplay = screen.getPrimaryDisplay();
|
|
|
|
const { width: maxWidth, height: maxHeight } = primaryDisplay.workAreaSize;
|
|
|
|
const width = windowConfig
|
|
|
|
? Math.min(windowConfig.width, maxWidth)
|
|
|
|
: DEFAULT_WIDTH;
|
|
|
|
const height = windowConfig
|
|
|
|
? Math.min(windowConfig.height, maxHeight)
|
|
|
|
: DEFAULT_HEIGHT;
|
|
|
|
|
2021-10-01 18:49:59 +00:00
|
|
|
const windowOptions: Electron.BrowserWindowConstructorOptions = {
|
2021-04-08 23:27:41 +00:00
|
|
|
show: false,
|
2024-07-15 22:42:20 +00:00
|
|
|
width,
|
|
|
|
height,
|
2020-09-09 00:46:29 +00:00
|
|
|
minWidth: MIN_WIDTH,
|
|
|
|
minHeight: MIN_HEIGHT,
|
|
|
|
autoHideMenuBar: false,
|
2022-06-08 22:00:32 +00:00
|
|
|
titleBarStyle: mainTitleBarStyle,
|
2021-10-01 18:49:59 +00:00
|
|
|
backgroundColor: isTestEnvironment(getEnvironment())
|
2021-07-28 23:46:25 +00:00
|
|
|
? '#ffffff' // Tests should always be rendered on a white background
|
2024-08-05 18:48:15 +00:00
|
|
|
: await getBackgroundColor({ signalColors: true }),
|
2020-09-09 00:46:29 +00:00
|
|
|
webPreferences: {
|
2021-03-03 19:13:35 +00:00
|
|
|
...defaultWebPrefs,
|
2020-09-09 00:46:29 +00:00
|
|
|
nodeIntegration: false,
|
|
|
|
nodeIntegrationInWorker: false,
|
2022-08-29 16:28:41 +00:00
|
|
|
sandbox: false,
|
2023-01-13 00:24:59 +00:00
|
|
|
contextIsolation: !isTestEnvironment(getEnvironment()),
|
2021-10-01 18:49:59 +00:00
|
|
|
preload: join(
|
2021-04-07 22:40:12 +00:00
|
|
|
__dirname,
|
2022-06-13 21:39:35 +00:00
|
|
|
usePreloadBundle
|
2024-09-08 21:09:57 +00:00
|
|
|
? '../preload.wrapper.js'
|
2022-06-13 21:39:35 +00:00
|
|
|
: '../ts/windows/main/preload.js'
|
2021-04-07 22:40:12 +00:00
|
|
|
),
|
2020-09-09 00:46:29 +00:00
|
|
|
spellcheck: await getSpellCheckSetting(),
|
2023-01-10 17:48:17 +00:00
|
|
|
backgroundThrottling: true,
|
2022-05-12 19:41:37 +00:00
|
|
|
disableBlinkFeatures: 'Accelerated2dCanvas,AcceleratedSmallCanvases',
|
2017-11-09 01:33:20 +00:00
|
|
|
},
|
2020-09-09 00:46:29 +00:00
|
|
|
icon: windowIcon,
|
2024-07-15 22:42:20 +00:00
|
|
|
...pick(windowConfig, ['autoHideMenuBar', 'x', 'y']),
|
2020-09-09 00:46:29 +00:00
|
|
|
};
|
2017-11-30 19:58:00 +00:00
|
|
|
|
2021-10-01 18:49:59 +00:00
|
|
|
if (!isNumber(windowOptions.width) || windowOptions.width < MIN_WIDTH) {
|
2017-11-30 19:58:00 +00:00
|
|
|
windowOptions.width = DEFAULT_WIDTH;
|
|
|
|
}
|
2021-10-01 18:49:59 +00:00
|
|
|
if (!isNumber(windowOptions.height) || windowOptions.height < MIN_HEIGHT) {
|
2017-11-30 19:58:00 +00:00
|
|
|
windowOptions.height = DEFAULT_HEIGHT;
|
|
|
|
}
|
2021-10-01 18:49:59 +00:00
|
|
|
if (!isBoolean(windowOptions.autoHideMenuBar)) {
|
2017-11-30 19:58:00 +00:00
|
|
|
delete windowOptions.autoHideMenuBar;
|
|
|
|
}
|
|
|
|
|
2021-06-29 17:18:03 +00:00
|
|
|
const startInTray =
|
2023-10-04 00:12:57 +00:00
|
|
|
isTestEnvironment(getEnvironment()) ||
|
2021-06-29 17:18:03 +00:00
|
|
|
(await systemTraySettingCache.get()) ===
|
2023-10-04 00:12:57 +00:00
|
|
|
SystemTraySetting.MinimizeToAndStartInSystemTray;
|
2021-06-29 17:18:03 +00:00
|
|
|
|
2024-09-18 00:36:50 +00:00
|
|
|
const haveFullWindowsBounds =
|
|
|
|
isNumber(windowOptions.x) &&
|
|
|
|
isNumber(windowOptions.y) &&
|
|
|
|
isNumber(windowOptions.width) &&
|
|
|
|
isNumber(windowOptions.height);
|
|
|
|
if (haveFullWindowsBounds) {
|
|
|
|
getLogger().info(
|
|
|
|
`visibleOnAnyScreen(window): x=${windowOptions.x}, y=${windowOptions.y}, ` +
|
|
|
|
`width=${windowOptions.width}, height=${windowOptions.height}`
|
2021-10-01 18:49:59 +00:00
|
|
|
);
|
2024-09-18 00:36:50 +00:00
|
|
|
|
|
|
|
const visibleOnAnyScreen = some(screen.getAllDisplays(), display => {
|
|
|
|
const displayBounds = get(display, 'bounds');
|
|
|
|
getLogger().info(
|
|
|
|
`visibleOnAnyScreen(display #${display.id}): ` +
|
|
|
|
`x=${displayBounds.x}, y=${displayBounds.y}, ` +
|
|
|
|
`width=${displayBounds.width}, height=${displayBounds.height}`
|
|
|
|
);
|
|
|
|
|
|
|
|
return isVisible(windowOptions as BoundsType, displayBounds);
|
|
|
|
});
|
|
|
|
if (!visibleOnAnyScreen) {
|
|
|
|
getLogger().info('visibleOnAnyScreen: Location reset needed');
|
|
|
|
delete windowOptions.x;
|
|
|
|
delete windowOptions.y;
|
|
|
|
}
|
2017-11-30 19:58:00 +00:00
|
|
|
}
|
2017-05-19 23:49:31 +00:00
|
|
|
|
2021-10-01 18:49:59 +00:00
|
|
|
getLogger().info(
|
|
|
|
'Initializing BrowserWindow config:',
|
2018-04-27 21:25:04 +00:00
|
|
|
JSON.stringify(windowOptions)
|
|
|
|
);
|
2017-10-03 18:07:40 +00:00
|
|
|
|
2017-05-19 23:49:31 +00:00
|
|
|
// Create the browser window.
|
2022-01-28 22:27:18 +00:00
|
|
|
mainWindow = new BrowserWindow(windowOptions);
|
2021-10-01 18:49:59 +00:00
|
|
|
if (settingsChannel) {
|
|
|
|
settingsChannel.setMainWindow(mainWindow);
|
|
|
|
}
|
2021-08-18 20:08:14 +00:00
|
|
|
|
2020-04-06 23:45:39 +00:00
|
|
|
mainWindowCreated = true;
|
2023-03-31 22:36:14 +00:00
|
|
|
setupSpellChecker(
|
|
|
|
mainWindow,
|
|
|
|
getPreferredSystemLocales(),
|
2023-11-07 01:02:13 +00:00
|
|
|
getLocaleOverride(),
|
2023-09-26 16:35:14 +00:00
|
|
|
getResolvedMessagesLocale().i18n,
|
|
|
|
getLogger()
|
2023-03-31 22:36:14 +00:00
|
|
|
);
|
2021-07-06 19:28:27 +00:00
|
|
|
if (!startInTray && windowConfig && windowConfig.maximized) {
|
2019-09-16 21:18:39 +00:00
|
|
|
mainWindow.maximize();
|
|
|
|
}
|
2021-06-29 17:18:03 +00:00
|
|
|
if (!startInTray && windowConfig && windowConfig.fullscreen) {
|
2019-11-14 22:01:52 +00:00
|
|
|
mainWindow.setFullScreen(true);
|
|
|
|
}
|
2021-06-29 17:18:03 +00:00
|
|
|
if (systemTrayService) {
|
|
|
|
systemTrayService.setMainWindow(mainWindow);
|
|
|
|
}
|
2017-05-19 23:49:31 +00:00
|
|
|
|
2022-06-08 22:00:32 +00:00
|
|
|
function saveWindowStats() {
|
|
|
|
if (!windowConfig) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
getLogger().info(
|
|
|
|
'Updating BrowserWindow config: %s',
|
|
|
|
JSON.stringify(windowConfig)
|
|
|
|
);
|
|
|
|
ephemeralConfig.set('window', windowConfig);
|
|
|
|
}
|
|
|
|
const debouncedSaveStats = debounce(saveWindowStats, 500);
|
|
|
|
|
|
|
|
function captureWindowStats() {
|
2018-02-21 22:18:04 +00:00
|
|
|
if (!mainWindow) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-05-19 23:49:31 +00:00
|
|
|
const size = mainWindow.getSize();
|
|
|
|
const position = mainWindow.getPosition();
|
|
|
|
|
2022-06-08 22:00:32 +00:00
|
|
|
const newWindowConfig = {
|
2017-05-19 23:49:31 +00:00
|
|
|
maximized: mainWindow.isMaximized(),
|
2020-03-19 17:57:50 +00:00
|
|
|
autoHideMenuBar: mainWindow.autoHideMenuBar,
|
2019-11-14 22:01:52 +00:00
|
|
|
fullscreen: mainWindow.isFullScreen(),
|
2017-05-19 23:49:31 +00:00
|
|
|
width: size[0],
|
|
|
|
height: size[1],
|
|
|
|
x: position[0],
|
2018-01-08 21:19:25 +00:00
|
|
|
y: position[1],
|
2017-05-19 23:49:31 +00:00
|
|
|
};
|
|
|
|
|
2022-06-08 22:00:32 +00:00
|
|
|
if (
|
|
|
|
newWindowConfig.fullscreen !== windowConfig?.fullscreen ||
|
|
|
|
newWindowConfig.maximized !== windowConfig?.maximized
|
|
|
|
) {
|
|
|
|
mainWindow.webContents.send('window:set-window-stats', {
|
|
|
|
isMaximized: newWindowConfig.maximized,
|
|
|
|
isFullScreen: newWindowConfig.fullscreen,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// so if we need to recreate the window, we have the most recent settings
|
|
|
|
windowConfig = newWindowConfig;
|
|
|
|
|
2022-06-30 21:33:58 +00:00
|
|
|
if (!windowState.requestedShutdown()) {
|
|
|
|
debouncedSaveStats();
|
|
|
|
}
|
2017-05-19 23:49:31 +00:00
|
|
|
}
|
|
|
|
|
2022-06-08 22:00:32 +00:00
|
|
|
mainWindow.on('resize', captureWindowStats);
|
|
|
|
mainWindow.on('move', captureWindowStats);
|
2017-04-25 00:14:38 +00:00
|
|
|
|
2023-07-20 22:37:56 +00:00
|
|
|
if (!ciMode && config.get<boolean>('openDevTools')) {
|
2017-04-05 18:42:30 +00:00
|
|
|
// Open the DevTools.
|
2018-01-08 21:19:25 +00:00
|
|
|
mainWindow.webContents.openDevTools();
|
2017-04-05 18:42:30 +00:00
|
|
|
}
|
2017-03-02 22:04:38 +00:00
|
|
|
|
2024-01-16 21:32:38 +00:00
|
|
|
await handleCommonWindowEvents(mainWindow);
|
2017-06-22 01:04:19 +00:00
|
|
|
|
2020-06-04 18:16:19 +00:00
|
|
|
// App dock icon bounce
|
|
|
|
bounce.init(mainWindow);
|
|
|
|
|
2017-04-22 22:58:50 +00:00
|
|
|
// Emitted when the window is about to be closed.
|
2018-11-05 19:06:12 +00:00
|
|
|
// Note: We do most of our shutdown logic here because all windows are closed by
|
|
|
|
// Electron before the app quits.
|
|
|
|
mainWindow.on('close', async e => {
|
2021-10-01 18:49:59 +00:00
|
|
|
if (!mainWindow) {
|
|
|
|
getLogger().info('close event: no main window');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
getLogger().info('close event', {
|
|
|
|
readyForShutdown: windowState.readyForShutdown(),
|
2018-11-05 19:06:12 +00:00
|
|
|
shouldQuit: windowState.shouldQuit(),
|
|
|
|
});
|
2017-11-27 22:48:09 +00:00
|
|
|
// If the application is terminating, just do the default
|
2018-04-27 21:25:04 +00:00
|
|
|
if (
|
2021-10-01 18:49:59 +00:00
|
|
|
isTestEnvironment(getEnvironment()) ||
|
|
|
|
(windowState.readyForShutdown() && windowState.shouldQuit())
|
2018-04-27 21:25:04 +00:00
|
|
|
) {
|
2017-11-27 22:48:09 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-11-05 19:06:12 +00:00
|
|
|
// Prevent the shutdown
|
|
|
|
e.preventDefault();
|
2020-06-30 16:41:29 +00:00
|
|
|
|
2024-08-02 16:52:06 +00:00
|
|
|
// Disable media playback
|
|
|
|
mainWindow.webContents.send('set-media-playback-disabled', true);
|
|
|
|
|
2024-02-19 14:44:05 +00:00
|
|
|
// In certain cases such as during an active call, we ask the user to confirm close
|
|
|
|
// which includes shutdown, clicking X on MacOS or closing to tray.
|
|
|
|
let shouldClose = true;
|
|
|
|
try {
|
|
|
|
shouldClose = await maybeRequestCloseConfirmation();
|
|
|
|
} catch (error) {
|
|
|
|
getLogger().warn(
|
|
|
|
'Error while requesting close confirmation.',
|
|
|
|
Errors.toLogFormat(error)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
if (!shouldClose) {
|
2024-02-27 00:18:50 +00:00
|
|
|
updater.onRestartCancelled();
|
2024-02-19 14:44:05 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-06-30 16:41:29 +00:00
|
|
|
/**
|
|
|
|
* if the user is in fullscreen mode and closes the window, not the
|
|
|
|
* application, we need them leave fullscreen first before closing it to
|
|
|
|
* prevent a black screen.
|
2024-07-16 21:00:11 +00:00
|
|
|
* Also check for mainWindow because it might become undefined while
|
|
|
|
* waiting for close confirmation.
|
2020-06-30 16:41:29 +00:00
|
|
|
*
|
|
|
|
* issue: https://github.com/signalapp/Signal-Desktop/issues/4348
|
|
|
|
*/
|
2024-07-16 21:00:11 +00:00
|
|
|
if (mainWindow) {
|
|
|
|
if (mainWindow.isFullScreen()) {
|
|
|
|
mainWindow.once('leave-full-screen', () => mainWindow?.hide());
|
|
|
|
mainWindow.setFullScreen(false);
|
|
|
|
} else {
|
|
|
|
mainWindow.hide();
|
|
|
|
}
|
2020-06-30 16:41:29 +00:00
|
|
|
}
|
2018-11-05 19:06:12 +00:00
|
|
|
|
2017-11-27 22:48:09 +00:00
|
|
|
// On Mac, or on other platforms when the tray icon is in use, the window
|
|
|
|
// should be only hidden, not closed, when the user clicks the close button
|
2021-06-29 17:18:03 +00:00
|
|
|
const usingTrayIcon = shouldMinimizeToSystemTray(
|
|
|
|
await systemTraySettingCache.get()
|
|
|
|
);
|
2024-07-16 21:00:11 +00:00
|
|
|
if (
|
|
|
|
mainWindow &&
|
|
|
|
!windowState.shouldQuit() &&
|
|
|
|
(usingTrayIcon || OS.isMacOS())
|
|
|
|
) {
|
2022-09-06 22:09:52 +00:00
|
|
|
if (usingTrayIcon) {
|
|
|
|
const shownTrayNotice = ephemeralConfig.get('shown-tray-notice');
|
|
|
|
if (shownTrayNotice) {
|
|
|
|
getLogger().info('close: not showing tray notice');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ephemeralConfig.set('shown-tray-notice', true);
|
|
|
|
getLogger().info('close: showing tray notice');
|
|
|
|
|
|
|
|
const n = new Notification({
|
2023-01-25 00:54:46 +00:00
|
|
|
title: getResolvedMessagesLocale().i18n(
|
2023-03-30 00:03:25 +00:00
|
|
|
'icu:minimizeToTrayNotification--title'
|
2023-01-25 00:54:46 +00:00
|
|
|
),
|
|
|
|
body: getResolvedMessagesLocale().i18n(
|
2023-03-30 00:03:25 +00:00
|
|
|
'icu:minimizeToTrayNotification--body'
|
2023-01-25 00:54:46 +00:00
|
|
|
),
|
2022-09-06 22:09:52 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
n.show();
|
|
|
|
}
|
2018-11-05 19:06:12 +00:00
|
|
|
return;
|
2017-04-22 22:58:50 +00:00
|
|
|
}
|
2018-11-05 19:06:12 +00:00
|
|
|
|
2022-06-30 21:33:58 +00:00
|
|
|
windowState.markRequestedShutdown();
|
2018-11-05 19:06:12 +00:00
|
|
|
await requestShutdown();
|
2021-10-01 18:49:59 +00:00
|
|
|
windowState.markReadyForShutdown();
|
|
|
|
|
2021-04-05 22:18:19 +00:00
|
|
|
await sql.close();
|
2018-11-05 19:06:12 +00:00
|
|
|
app.quit();
|
2017-04-22 22:58:50 +00:00
|
|
|
});
|
2017-06-22 01:04:19 +00:00
|
|
|
|
2017-03-02 22:04:38 +00:00
|
|
|
// Emitted when the window is closed.
|
2018-01-08 21:19:25 +00:00
|
|
|
mainWindow.on('closed', () => {
|
2017-03-02 22:04:38 +00:00
|
|
|
// Dereference the window object, usually you would store windows
|
|
|
|
// in an array if your app supports multi windows, this is the time
|
|
|
|
// when you should delete the corresponding element.
|
2023-12-04 20:53:54 +00:00
|
|
|
getLogger().info('main window closed event');
|
2021-06-29 17:18:03 +00:00
|
|
|
mainWindow = undefined;
|
2021-10-01 18:49:59 +00:00
|
|
|
if (settingsChannel) {
|
|
|
|
settingsChannel.setMainWindow(mainWindow);
|
|
|
|
}
|
2021-06-29 17:18:03 +00:00
|
|
|
if (systemTrayService) {
|
|
|
|
systemTrayService.setMainWindow(mainWindow);
|
|
|
|
}
|
2017-04-28 01:03:22 +00:00
|
|
|
});
|
2021-02-01 20:01:25 +00:00
|
|
|
|
|
|
|
mainWindow.on('enter-full-screen', () => {
|
2023-12-04 20:53:54 +00:00
|
|
|
getLogger().info('mainWindow enter-full-screen event');
|
2021-10-01 18:49:59 +00:00
|
|
|
if (mainWindow) {
|
|
|
|
mainWindow.webContents.send('full-screen-change', true);
|
|
|
|
}
|
2021-02-01 20:01:25 +00:00
|
|
|
});
|
|
|
|
mainWindow.on('leave-full-screen', () => {
|
2023-12-04 20:53:54 +00:00
|
|
|
getLogger().info('mainWindow leave-full-screen event');
|
2021-10-01 18:49:59 +00:00
|
|
|
if (mainWindow) {
|
|
|
|
mainWindow.webContents.send('full-screen-change', false);
|
|
|
|
}
|
2021-02-01 20:01:25 +00:00
|
|
|
});
|
2021-04-08 23:27:41 +00:00
|
|
|
|
2024-02-02 23:39:32 +00:00
|
|
|
mainWindow.on('show', () => {
|
|
|
|
if (mainWindow) {
|
|
|
|
mainWindow.webContents.send('set-media-playback-disabled', false);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-04-08 23:27:41 +00:00
|
|
|
mainWindow.once('ready-to-show', async () => {
|
2021-10-01 18:49:59 +00:00
|
|
|
getLogger().info('main window is ready-to-show');
|
2021-04-08 23:27:41 +00:00
|
|
|
|
2021-05-07 18:42:21 +00:00
|
|
|
// Ignore sql errors and show the window anyway
|
|
|
|
await sqlInitPromise;
|
2021-04-08 23:27:41 +00:00
|
|
|
|
|
|
|
if (!mainWindow) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-10-30 19:27:29 +00:00
|
|
|
mainWindow.webContents.send('ci:event', 'db-initialized', {});
|
|
|
|
|
2021-12-06 17:19:47 +00:00
|
|
|
const shouldShowWindow =
|
2024-09-12 23:48:27 +00:00
|
|
|
!app.getLoginItemSettings().wasOpenedAsHidden &&
|
|
|
|
!startInTray &&
|
|
|
|
!config.get<boolean>('ciIsBackupIntegration');
|
2021-12-06 17:19:47 +00:00
|
|
|
|
|
|
|
if (shouldShowWindow) {
|
2021-10-01 18:49:59 +00:00
|
|
|
getLogger().info('showing main window');
|
2021-04-08 23:27:41 +00:00
|
|
|
mainWindow.show();
|
|
|
|
}
|
|
|
|
});
|
2022-12-21 18:41:48 +00:00
|
|
|
|
2023-02-14 02:16:49 +00:00
|
|
|
await safeLoadURL(
|
|
|
|
mainWindow,
|
2024-02-29 22:01:12 +00:00
|
|
|
getEnvironment() === Environment.Test
|
2023-02-14 02:16:49 +00:00
|
|
|
? await prepareFileUrl([__dirname, '../test/index.html'])
|
|
|
|
: await prepareFileUrl([__dirname, '../background.html'])
|
|
|
|
);
|
2017-03-02 22:04:38 +00:00
|
|
|
}
|
|
|
|
|
2021-04-08 23:27:41 +00:00
|
|
|
// Renderer asks if we are done with the database
|
2022-11-17 00:29:15 +00:00
|
|
|
ipc.handle('database-ready', async () => {
|
2021-10-01 18:49:59 +00:00
|
|
|
if (!sqlInitPromise) {
|
|
|
|
getLogger().error('database-ready requested, but sqlInitPromise is falsey');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-05-07 18:42:21 +00:00
|
|
|
const { error } = await sqlInitPromise;
|
|
|
|
if (error) {
|
2021-10-01 18:49:59 +00:00
|
|
|
getLogger().error(
|
2021-05-07 18:42:21 +00:00
|
|
|
'database-ready requested, but got sql error',
|
2022-11-22 18:43:43 +00:00
|
|
|
Errors.toLogFormat(error)
|
2021-05-07 18:42:21 +00:00
|
|
|
);
|
2021-04-08 23:27:41 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-10-01 18:49:59 +00:00
|
|
|
getLogger().info('sending `database-ready`');
|
2021-04-08 23:27:41 +00:00
|
|
|
});
|
|
|
|
|
2024-05-15 22:26:37 +00:00
|
|
|
ipc.handle(
|
|
|
|
'art-creator:uploadStickerPack',
|
|
|
|
(_event: Electron.Event, data: unknown) => {
|
|
|
|
const { promise, resolve } = explodePromise<unknown>();
|
|
|
|
strictAssert(mainWindow, 'Main window did not exist');
|
2023-04-20 15:59:17 +00:00
|
|
|
|
2024-05-15 22:26:37 +00:00
|
|
|
mainWindow.webContents.send('art-creator:uploadStickerPack', data);
|
2023-04-20 15:59:17 +00:00
|
|
|
|
2024-05-15 22:26:37 +00:00
|
|
|
ipc.once('art-creator:uploadStickerPack:done', (_doneEvent, response) => {
|
|
|
|
resolve(response);
|
2023-04-20 15:59:17 +00:00
|
|
|
});
|
|
|
|
|
2024-05-15 22:26:37 +00:00
|
|
|
return promise;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
ipc.on('art-creator:onUploadProgress', () => {
|
|
|
|
stickerCreatorWindow?.webContents.send('art-creator:onUploadProgress');
|
2023-02-27 22:34:43 +00:00
|
|
|
});
|
|
|
|
|
2019-03-28 17:09:26 +00:00
|
|
|
ipc.on('show-window', () => {
|
|
|
|
showWindow();
|
|
|
|
});
|
|
|
|
|
2024-10-28 17:11:19 +00:00
|
|
|
ipc.on('start-tracking-query-stats', () => {
|
|
|
|
sql.startTrackingQueryStats();
|
|
|
|
});
|
|
|
|
|
|
|
|
ipc.on('stop-tracking-query-stats', (_event, options) => {
|
|
|
|
sql.stopTrackingQueryStats(options);
|
|
|
|
});
|
|
|
|
|
2021-02-01 20:01:25 +00:00
|
|
|
ipc.on('title-bar-double-click', () => {
|
|
|
|
if (!mainWindow) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (OS.isMacOS()) {
|
|
|
|
switch (
|
|
|
|
systemPreferences.getUserDefault('AppleActionOnDoubleClick', 'string')
|
|
|
|
) {
|
|
|
|
case 'Minimize':
|
|
|
|
mainWindow.minimize();
|
|
|
|
break;
|
|
|
|
case 'Maximize':
|
|
|
|
toggleMaximizedBrowserWindow(mainWindow);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
// If this is disabled, it'll be 'None'. If it's anything else, that's unexpected,
|
|
|
|
// but we'll just no-op.
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// This is currently only supported on macOS. This `else` branch is just here when/if
|
|
|
|
// we add support for other operating systems.
|
|
|
|
toggleMaximizedBrowserWindow(mainWindow);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-09-28 19:00:22 +00:00
|
|
|
ipc.on('set-is-call-active', (_event, isCallActive) => {
|
2021-12-10 22:53:10 +00:00
|
|
|
preventDisplaySleepService.setEnabled(isCallActive);
|
|
|
|
|
2021-09-28 19:00:22 +00:00
|
|
|
if (!mainWindow) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-10-01 18:49:59 +00:00
|
|
|
let backgroundThrottling: boolean;
|
2021-09-28 19:00:22 +00:00
|
|
|
if (isCallActive) {
|
2021-10-01 18:49:59 +00:00
|
|
|
getLogger().info('Background throttling disabled because a call is active');
|
2021-09-28 19:00:22 +00:00
|
|
|
backgroundThrottling = false;
|
|
|
|
} else {
|
2021-10-01 18:49:59 +00:00
|
|
|
getLogger().info('Background throttling enabled because no call is active');
|
2021-09-28 19:00:22 +00:00
|
|
|
backgroundThrottling = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
mainWindow.webContents.setBackgroundThrottling(backgroundThrottling);
|
|
|
|
});
|
|
|
|
|
2021-08-09 20:06:21 +00:00
|
|
|
ipc.on('convert-image', async (event, uuid, data) => {
|
|
|
|
const { error, response } = await heicConverter(uuid, data);
|
|
|
|
event.reply(`convert-image:${uuid}`, { error, response });
|
|
|
|
});
|
|
|
|
|
2019-10-03 19:07:35 +00:00
|
|
|
let isReadyForUpdates = false;
|
|
|
|
async function readyForUpdates() {
|
|
|
|
if (isReadyForUpdates) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
isReadyForUpdates = true;
|
|
|
|
|
2024-07-12 14:28:12 +00:00
|
|
|
// First, handle requested signal URLs
|
2023-11-02 19:42:31 +00:00
|
|
|
const incomingHref = maybeGetIncomingSignalRoute(process.argv);
|
2020-08-27 19:44:51 +00:00
|
|
|
if (incomingHref) {
|
2023-11-02 19:42:31 +00:00
|
|
|
handleSignalRoute(incomingHref);
|
2024-07-12 14:28:12 +00:00
|
|
|
} else if (macInitialOpenUrlRoute) {
|
|
|
|
handleSignalRoute(macInitialOpenUrlRoute);
|
2019-03-28 17:09:26 +00:00
|
|
|
}
|
|
|
|
|
2024-07-12 14:28:12 +00:00
|
|
|
// Discard value even if we don't handle a saved URL.
|
|
|
|
macInitialOpenUrlRoute = undefined;
|
|
|
|
|
2019-05-16 22:32:11 +00:00
|
|
|
// Second, start checking for app updates
|
2019-03-28 17:09:26 +00:00
|
|
|
try {
|
2021-11-10 00:56:56 +00:00
|
|
|
strictAssert(
|
|
|
|
settingsChannel !== undefined,
|
|
|
|
'SettingsChannel must be initialized'
|
|
|
|
);
|
2023-12-12 02:15:36 +00:00
|
|
|
await updater.start({
|
|
|
|
settingsChannel,
|
|
|
|
logger: getLogger(),
|
|
|
|
getMainWindow,
|
|
|
|
canRunSilently: () => {
|
|
|
|
return (
|
|
|
|
systemTrayService?.isVisible() === true &&
|
2023-12-19 17:40:27 +00:00
|
|
|
mainWindow?.isVisible() !== true &&
|
|
|
|
mainWindow?.webContents?.getBackgroundThrottling() !== false
|
2023-12-12 02:15:36 +00:00
|
|
|
);
|
|
|
|
},
|
|
|
|
});
|
2019-03-28 17:09:26 +00:00
|
|
|
} catch (error) {
|
2021-10-01 18:49:59 +00:00
|
|
|
getLogger().error(
|
2019-03-28 17:09:26 +00:00
|
|
|
'Error starting update checks:',
|
2022-11-22 18:43:43 +00:00
|
|
|
Errors.toLogFormat(error)
|
2019-03-28 17:09:26 +00:00
|
|
|
);
|
|
|
|
}
|
2019-10-03 19:07:35 +00:00
|
|
|
}
|
|
|
|
|
2021-06-30 21:27:18 +00:00
|
|
|
async function forceUpdate() {
|
|
|
|
try {
|
2021-10-01 18:49:59 +00:00
|
|
|
getLogger().info('starting force update');
|
2021-06-30 21:27:18 +00:00
|
|
|
await updater.force();
|
|
|
|
} catch (error) {
|
2022-11-22 18:43:43 +00:00
|
|
|
getLogger().error('Error during force update:', Errors.toLogFormat(error));
|
2021-06-30 21:27:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-03 19:07:35 +00:00
|
|
|
ipc.once('ready-for-updates', readyForUpdates);
|
|
|
|
|
|
|
|
const TEN_MINUTES = 10 * 60 * 1000;
|
|
|
|
setTimeout(readyForUpdates, TEN_MINUTES);
|
2019-03-28 17:09:26 +00:00
|
|
|
|
2020-06-10 16:56:10 +00:00
|
|
|
function openContactUs() {
|
2022-12-21 18:41:48 +00:00
|
|
|
drop(shell.openExternal(createSupportUrl({ locale: app.getLocale() })));
|
2020-06-10 16:56:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function openJoinTheBeta() {
|
2020-06-25 01:42:40 +00:00
|
|
|
// If we omit the language, the site will detect the language and redirect
|
2022-12-21 18:41:48 +00:00
|
|
|
drop(
|
|
|
|
shell.openExternal('https://support.signal.org/hc/articles/360007318471')
|
|
|
|
);
|
2020-06-10 16:56:10 +00:00
|
|
|
}
|
|
|
|
|
2017-10-13 23:49:16 +00:00
|
|
|
function openReleaseNotes() {
|
2021-10-23 00:41:45 +00:00
|
|
|
if (mainWindow && mainWindow.isVisible()) {
|
|
|
|
mainWindow.webContents.send('show-release-notes');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-12-21 18:41:48 +00:00
|
|
|
drop(
|
|
|
|
shell.openExternal(
|
|
|
|
`https://github.com/signalapp/Signal-Desktop/releases/tag/v${app.getVersion()}`
|
|
|
|
)
|
2018-04-27 21:25:04 +00:00
|
|
|
);
|
2017-10-13 23:49:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function openSupportPage() {
|
2020-06-25 01:42:40 +00:00
|
|
|
// If we omit the language, the site will detect the language and redirect
|
2022-12-21 18:41:48 +00:00
|
|
|
drop(
|
|
|
|
shell.openExternal('https://support.signal.org/hc/sections/360001602812')
|
|
|
|
);
|
2017-10-13 23:49:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function openForums() {
|
2022-12-21 18:41:48 +00:00
|
|
|
drop(shell.openExternal('https://community.signalusers.org/'));
|
2017-10-13 23:49:16 +00:00
|
|
|
}
|
|
|
|
|
2019-11-07 21:36:16 +00:00
|
|
|
function showKeyboardShortcuts() {
|
|
|
|
if (mainWindow) {
|
|
|
|
mainWindow.webContents.send('show-keyboard-shortcuts');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
New design for import/install, 'light' import (#2053)
- A new design for the import flow. It features:
- Icons at the top of every screen
- Gray background, blue buttons, thinner text
- Simpler copy
- A new design for the install flow. It features:
- Immediate entry into the QR code screen
- Animated dots to show that we're loading the QR code from the server
- Fewer screens: 1) QR 2) device name 3) sync-in-progress
- When not set up, the app opens directly into the install screen, which has been streamlined. The `--import` command-line argument will cause the app to open directly into the import flow.
- Support for two different flavors of builds - the normal build will open into the standard registration flow, and the import flavor will be exactly the same except during setup it will open directly into the import flow.
- A new design for the (dev-only) standalone registration view
- When these install sequences are active, the OS File menu has entries to allow you to switch the method of setup you'd like to use. These go away as soon as the first step is taken in any of these flows.
- The device name (chosen on initial setup) is now shown in the settings panel
- At the end of a light import, we hand off to the normal device link screen, starting at the QR code. On a full import, we remove the sensitive encryption information in the export to prevent conflicts on multiple imports.
- `Whisper.Backup.exportToDirectory()` takes an options object so you can tell it to do a light export.
- `Whisper.Backup.importFromDirectory()` takes an options object so you can force it to load only the light components found on disk. It also returns an object so you can tell whether a given import was a full import or light import.
- On start of import, we build a list of all the ids present in the messages, conversations, and groups stores in IndexedDB. This can take some time if a lot of data is in the database already, but it makes the subsequent deduplicated import very fast.
- Disappearing messages are now excluded when exporting
- Remove some TODOs in the tests
2018-02-22 18:40:32 +00:00
|
|
|
function setupAsNewDevice() {
|
|
|
|
if (mainWindow) {
|
|
|
|
mainWindow.webContents.send('set-up-as-new-device');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function setupAsStandalone() {
|
|
|
|
if (mainWindow) {
|
|
|
|
mainWindow.webContents.send('set-up-as-standalone');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-01 18:49:59 +00:00
|
|
|
let screenShareWindow: BrowserWindow | undefined;
|
2024-09-20 01:03:44 +00:00
|
|
|
async function showScreenShareWindow(sourceName: string | undefined) {
|
2021-05-20 21:54:03 +00:00
|
|
|
if (screenShareWindow) {
|
2021-06-04 15:20:42 +00:00
|
|
|
screenShareWindow.showInactive();
|
2021-05-20 21:54:03 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const width = 480;
|
|
|
|
|
|
|
|
const display = screen.getPrimaryDisplay();
|
|
|
|
const options = {
|
|
|
|
alwaysOnTop: true,
|
|
|
|
autoHideMenuBar: true,
|
|
|
|
backgroundColor: '#2e2e2e',
|
|
|
|
darkTheme: true,
|
|
|
|
frame: false,
|
|
|
|
fullscreenable: false,
|
|
|
|
height: 44,
|
|
|
|
maximizable: false,
|
|
|
|
minimizable: false,
|
|
|
|
resizable: false,
|
|
|
|
show: false,
|
2023-03-30 00:03:25 +00:00
|
|
|
title: getResolvedMessagesLocale().i18n('icu:screenShareWindow'),
|
2022-06-08 22:00:32 +00:00
|
|
|
titleBarStyle: nonMainTitleBarStyle,
|
2021-05-20 21:54:03 +00:00
|
|
|
width,
|
|
|
|
webPreferences: {
|
|
|
|
...defaultWebPrefs,
|
|
|
|
nodeIntegration: false,
|
|
|
|
nodeIntegrationInWorker: false,
|
2023-04-20 21:23:19 +00:00
|
|
|
sandbox: true,
|
2021-09-16 15:52:56 +00:00
|
|
|
contextIsolation: true,
|
2023-04-20 21:23:19 +00:00
|
|
|
preload: join(__dirname, '../bundles/screenShare/preload.js'),
|
2021-05-20 21:54:03 +00:00
|
|
|
},
|
|
|
|
x: Math.floor(display.size.width / 2) - width / 2,
|
|
|
|
y: 24,
|
|
|
|
};
|
|
|
|
|
2022-01-28 22:27:18 +00:00
|
|
|
screenShareWindow = new BrowserWindow(options);
|
2021-05-20 21:54:03 +00:00
|
|
|
|
2023-12-22 20:27:49 +00:00
|
|
|
await handleCommonWindowEvents(screenShareWindow);
|
2021-05-20 21:54:03 +00:00
|
|
|
|
|
|
|
screenShareWindow.on('closed', () => {
|
2021-10-01 18:49:59 +00:00
|
|
|
screenShareWindow = undefined;
|
2021-05-20 21:54:03 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
screenShareWindow.once('ready-to-show', () => {
|
2021-10-01 18:49:59 +00:00
|
|
|
if (screenShareWindow) {
|
2023-04-20 21:23:19 +00:00
|
|
|
screenShareWindow.show();
|
2021-10-01 18:49:59 +00:00
|
|
|
}
|
2021-05-20 21:54:03 +00:00
|
|
|
});
|
2022-12-21 18:41:48 +00:00
|
|
|
|
2023-02-14 02:16:49 +00:00
|
|
|
await safeLoadURL(
|
|
|
|
screenShareWindow,
|
2023-04-20 21:23:19 +00:00
|
|
|
await prepareFileUrl([__dirname, '../screenShare.html'], { sourceName })
|
2022-12-21 18:41:48 +00:00
|
|
|
);
|
2021-05-20 21:54:03 +00:00
|
|
|
}
|
|
|
|
|
2024-05-23 00:28:01 +00:00
|
|
|
let callingDevToolsWindow: BrowserWindow | undefined;
|
|
|
|
async function showCallingDevToolsWindow() {
|
|
|
|
if (callingDevToolsWindow) {
|
|
|
|
callingDevToolsWindow.show();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const options = {
|
|
|
|
height: 1200,
|
|
|
|
width: 1000,
|
|
|
|
alwaysOnTop: false,
|
|
|
|
autoHideMenuBar: true,
|
|
|
|
backgroundColor: '#ffffff',
|
|
|
|
darkTheme: false,
|
|
|
|
frame: true,
|
|
|
|
fullscreenable: true,
|
|
|
|
maximizable: true,
|
|
|
|
minimizable: true,
|
|
|
|
resizable: true,
|
|
|
|
show: false,
|
|
|
|
title: getResolvedMessagesLocale().i18n('icu:callingDeveloperTools'),
|
|
|
|
titleBarStyle: nonMainTitleBarStyle,
|
|
|
|
webPreferences: {
|
|
|
|
...defaultWebPrefs,
|
|
|
|
nodeIntegration: false,
|
|
|
|
nodeIntegrationInWorker: false,
|
|
|
|
sandbox: true,
|
|
|
|
contextIsolation: true,
|
|
|
|
nativeWindowOpen: true,
|
2024-05-23 22:19:12 +00:00
|
|
|
preload: join(__dirname, '../bundles/calling-tools/preload.js'),
|
2024-05-23 00:28:01 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
callingDevToolsWindow = new BrowserWindow(options);
|
|
|
|
|
|
|
|
await handleCommonWindowEvents(callingDevToolsWindow);
|
|
|
|
|
|
|
|
callingDevToolsWindow.once('closed', () => {
|
|
|
|
callingDevToolsWindow = undefined;
|
|
|
|
|
|
|
|
mainWindow?.webContents.send('calling:set-rtc-stats-interval', null);
|
|
|
|
});
|
|
|
|
|
|
|
|
ipc.on('calling:set-rtc-stats-interval', (_, intervalMillis: number) => {
|
|
|
|
mainWindow?.webContents.send(
|
|
|
|
'calling:set-rtc-stats-interval',
|
|
|
|
intervalMillis
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
ipc.on('calling:rtc-stats-report', (_, report) => {
|
|
|
|
callingDevToolsWindow?.webContents.send('calling:rtc-stats-report', report);
|
|
|
|
});
|
|
|
|
|
|
|
|
await safeLoadURL(
|
|
|
|
callingDevToolsWindow,
|
|
|
|
await prepareFileUrl([__dirname, '../calling_tools.html'])
|
|
|
|
);
|
|
|
|
callingDevToolsWindow.show();
|
|
|
|
}
|
|
|
|
|
2021-10-01 18:49:59 +00:00
|
|
|
let aboutWindow: BrowserWindow | undefined;
|
2022-05-11 22:58:14 +00:00
|
|
|
async function showAbout() {
|
2017-10-13 23:49:16 +00:00
|
|
|
if (aboutWindow) {
|
|
|
|
aboutWindow.show();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const options = {
|
|
|
|
width: 500,
|
2020-09-16 16:40:15 +00:00
|
|
|
height: 500,
|
2017-10-13 23:49:16 +00:00
|
|
|
resizable: false,
|
2023-03-30 00:03:25 +00:00
|
|
|
title: getResolvedMessagesLocale().i18n('icu:aboutSignalDesktop'),
|
2022-06-08 22:00:32 +00:00
|
|
|
titleBarStyle: nonMainTitleBarStyle,
|
2017-10-13 23:49:16 +00:00
|
|
|
autoHideMenuBar: true,
|
2024-08-05 18:48:15 +00:00
|
|
|
backgroundColor: await getBackgroundColor({ signalColors: true }),
|
2017-10-13 23:49:16 +00:00
|
|
|
show: false,
|
|
|
|
webPreferences: {
|
2021-03-03 19:13:35 +00:00
|
|
|
...defaultWebPrefs,
|
2017-10-13 23:49:16 +00:00
|
|
|
nodeIntegration: false,
|
2018-05-19 00:52:20 +00:00
|
|
|
nodeIntegrationInWorker: false,
|
2023-04-20 21:23:19 +00:00
|
|
|
sandbox: true,
|
2021-09-16 15:52:56 +00:00
|
|
|
contextIsolation: true,
|
2023-04-20 21:23:19 +00:00
|
|
|
preload: join(__dirname, '../bundles/about/preload.js'),
|
2018-05-23 22:54:10 +00:00
|
|
|
nativeWindowOpen: true,
|
2017-11-21 23:23:18 +00:00
|
|
|
},
|
2017-10-13 23:49:16 +00:00
|
|
|
};
|
|
|
|
|
2022-01-28 22:27:18 +00:00
|
|
|
aboutWindow = new BrowserWindow(options);
|
2017-10-13 23:49:16 +00:00
|
|
|
|
2024-01-16 21:32:38 +00:00
|
|
|
await handleCommonWindowEvents(aboutWindow);
|
2017-10-13 23:49:16 +00:00
|
|
|
|
2018-01-08 21:19:25 +00:00
|
|
|
aboutWindow.on('closed', () => {
|
2021-10-01 18:49:59 +00:00
|
|
|
aboutWindow = undefined;
|
2017-10-13 23:49:16 +00:00
|
|
|
});
|
|
|
|
|
2018-01-08 21:19:25 +00:00
|
|
|
aboutWindow.once('ready-to-show', () => {
|
2021-10-01 18:49:59 +00:00
|
|
|
if (aboutWindow) {
|
|
|
|
aboutWindow.show();
|
|
|
|
}
|
2017-10-13 23:49:16 +00:00
|
|
|
});
|
2022-12-21 18:41:48 +00:00
|
|
|
|
2023-02-14 02:16:49 +00:00
|
|
|
await safeLoadURL(
|
|
|
|
aboutWindow,
|
|
|
|
await prepareFileUrl([__dirname, '../about.html'])
|
|
|
|
);
|
2017-10-13 23:49:16 +00:00
|
|
|
}
|
|
|
|
|
2021-10-01 18:49:59 +00:00
|
|
|
let settingsWindow: BrowserWindow | undefined;
|
2022-05-11 22:58:14 +00:00
|
|
|
async function showSettingsWindow() {
|
2018-07-03 22:33:50 +00:00
|
|
|
if (settingsWindow) {
|
|
|
|
settingsWindow.show();
|
|
|
|
return;
|
|
|
|
}
|
2019-10-17 18:22:07 +00:00
|
|
|
|
2018-07-03 22:33:50 +00:00
|
|
|
const options = {
|
2021-08-18 20:08:14 +00:00
|
|
|
width: 700,
|
|
|
|
height: 700,
|
|
|
|
frame: true,
|
2018-07-03 22:33:50 +00:00
|
|
|
resizable: false,
|
2023-03-30 00:03:25 +00:00
|
|
|
title: getResolvedMessagesLocale().i18n('icu:signalDesktopPreferences'),
|
2023-02-23 21:32:19 +00:00
|
|
|
titleBarStyle: mainTitleBarStyle,
|
2018-07-03 22:33:50 +00:00
|
|
|
autoHideMenuBar: true,
|
2022-05-11 22:58:14 +00:00
|
|
|
backgroundColor: await getBackgroundColor(),
|
2018-07-03 22:33:50 +00:00
|
|
|
show: false,
|
|
|
|
webPreferences: {
|
2021-03-03 19:13:35 +00:00
|
|
|
...defaultWebPrefs,
|
2018-07-03 22:33:50 +00:00
|
|
|
nodeIntegration: false,
|
|
|
|
nodeIntegrationInWorker: false,
|
2023-04-20 21:23:19 +00:00
|
|
|
sandbox: true,
|
2021-09-16 15:52:56 +00:00
|
|
|
contextIsolation: true,
|
2023-04-20 21:23:19 +00:00
|
|
|
preload: join(__dirname, '../bundles/settings/preload.js'),
|
2018-07-03 22:33:50 +00:00
|
|
|
nativeWindowOpen: true,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2022-01-28 22:27:18 +00:00
|
|
|
settingsWindow = new BrowserWindow(options);
|
2018-07-03 22:33:50 +00:00
|
|
|
|
2024-01-16 21:32:38 +00:00
|
|
|
await handleCommonWindowEvents(settingsWindow);
|
2018-07-03 22:33:50 +00:00
|
|
|
|
|
|
|
settingsWindow.on('closed', () => {
|
2021-10-01 18:49:59 +00:00
|
|
|
settingsWindow = undefined;
|
2018-07-03 22:33:50 +00:00
|
|
|
});
|
|
|
|
|
2021-09-02 15:48:53 +00:00
|
|
|
ipc.once('settings-done-rendering', () => {
|
|
|
|
if (!settingsWindow) {
|
2021-10-01 18:49:59 +00:00
|
|
|
getLogger().warn('settings-done-rendering: no settingsWindow available!');
|
2021-09-02 15:48:53 +00:00
|
|
|
return;
|
2021-08-18 20:08:14 +00:00
|
|
|
}
|
2021-09-02 15:48:53 +00:00
|
|
|
|
|
|
|
settingsWindow.show();
|
2018-07-03 22:33:50 +00:00
|
|
|
});
|
2022-12-21 18:41:48 +00:00
|
|
|
|
2023-02-14 02:16:49 +00:00
|
|
|
await safeLoadURL(
|
|
|
|
settingsWindow,
|
2022-12-21 18:41:48 +00:00
|
|
|
await prepareFileUrl([__dirname, '../settings.html'])
|
|
|
|
);
|
2018-07-03 22:33:50 +00:00
|
|
|
}
|
|
|
|
|
2019-12-17 20:25:57 +00:00
|
|
|
async function getIsLinked() {
|
|
|
|
try {
|
2024-07-22 18:16:33 +00:00
|
|
|
const number = await sql.sqlRead('getItemById', 'number_id');
|
|
|
|
const password = await sql.sqlRead('getItemById', 'password');
|
2019-12-17 20:25:57 +00:00
|
|
|
return Boolean(number && password);
|
|
|
|
} catch (e) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-27 22:34:43 +00:00
|
|
|
async function openArtCreator() {
|
|
|
|
if (!(await getIsLinked())) {
|
|
|
|
const message = getResolvedMessagesLocale().i18n(
|
|
|
|
'icu:ArtCreator--Authentication--error'
|
|
|
|
);
|
|
|
|
|
|
|
|
await dialog.showMessageBox({
|
|
|
|
type: 'warning',
|
|
|
|
message,
|
|
|
|
});
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-04-20 15:59:17 +00:00
|
|
|
await showStickerCreatorWindow();
|
2023-02-27 22:34:43 +00:00
|
|
|
}
|
|
|
|
|
2021-10-01 18:49:59 +00:00
|
|
|
let debugLogWindow: BrowserWindow | undefined;
|
2018-07-13 15:57:30 +00:00
|
|
|
async function showDebugLogWindow() {
|
2018-07-03 22:33:50 +00:00
|
|
|
if (debugLogWindow) {
|
2023-08-23 17:39:47 +00:00
|
|
|
doShowDebugLogWindow();
|
2018-07-03 22:33:50 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-08-23 17:39:47 +00:00
|
|
|
function doShowDebugLogWindow() {
|
|
|
|
if (debugLogWindow) {
|
|
|
|
// Electron has [a macOS bug][0] that causes parent windows to become unresponsive
|
|
|
|
// if it's fullscreen and opens a fullscreen child window. Until that's fixed, we
|
|
|
|
// only set the parent on MacOS is if the mainWindow is not fullscreen
|
|
|
|
// [0]: https://github.com/electron/electron/issues/32374
|
|
|
|
if (OS.isMacOS() && mainWindow?.isFullScreen()) {
|
|
|
|
debugLogWindow.setParentWindow(null);
|
|
|
|
} else {
|
|
|
|
debugLogWindow.setParentWindow(mainWindow ?? null);
|
|
|
|
}
|
|
|
|
debugLogWindow.show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const options: Electron.BrowserWindowConstructorOptions = {
|
2021-10-15 18:11:59 +00:00
|
|
|
width: 700,
|
|
|
|
height: 500,
|
2018-07-03 22:33:50 +00:00
|
|
|
resizable: false,
|
2023-03-30 00:03:25 +00:00
|
|
|
title: getResolvedMessagesLocale().i18n('icu:debugLog'),
|
2022-06-08 22:00:32 +00:00
|
|
|
titleBarStyle: nonMainTitleBarStyle,
|
2018-07-03 22:33:50 +00:00
|
|
|
autoHideMenuBar: true,
|
2022-05-11 22:58:14 +00:00
|
|
|
backgroundColor: await getBackgroundColor(),
|
2018-07-03 22:33:50 +00:00
|
|
|
show: false,
|
|
|
|
webPreferences: {
|
2021-03-03 19:13:35 +00:00
|
|
|
...defaultWebPrefs,
|
2018-07-03 22:33:50 +00:00
|
|
|
nodeIntegration: false,
|
|
|
|
nodeIntegrationInWorker: false,
|
2023-04-20 21:23:19 +00:00
|
|
|
sandbox: true,
|
2021-10-06 16:16:51 +00:00
|
|
|
contextIsolation: true,
|
2023-04-20 21:23:19 +00:00
|
|
|
preload: join(__dirname, '../bundles/debuglog/preload.js'),
|
2018-07-03 22:33:50 +00:00
|
|
|
},
|
|
|
|
parent: mainWindow,
|
|
|
|
};
|
|
|
|
|
2022-01-28 22:27:18 +00:00
|
|
|
debugLogWindow = new BrowserWindow(options);
|
2018-07-03 22:33:50 +00:00
|
|
|
|
2024-01-16 21:32:38 +00:00
|
|
|
await handleCommonWindowEvents(debugLogWindow);
|
2018-07-03 22:33:50 +00:00
|
|
|
|
|
|
|
debugLogWindow.on('closed', () => {
|
2021-10-01 18:49:59 +00:00
|
|
|
debugLogWindow = undefined;
|
2018-07-03 22:33:50 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
debugLogWindow.once('ready-to-show', () => {
|
2021-10-01 18:49:59 +00:00
|
|
|
if (debugLogWindow) {
|
2023-08-23 17:39:47 +00:00
|
|
|
doShowDebugLogWindow();
|
2022-01-07 15:30:47 +00:00
|
|
|
|
|
|
|
// Electron sometimes puts the window in a strange spot until it's shown.
|
|
|
|
debugLogWindow.center();
|
2021-10-01 18:49:59 +00:00
|
|
|
}
|
2018-07-03 22:33:50 +00:00
|
|
|
});
|
2022-12-21 18:41:48 +00:00
|
|
|
|
2023-02-14 02:16:49 +00:00
|
|
|
await safeLoadURL(
|
|
|
|
debugLogWindow,
|
2022-12-21 18:41:48 +00:00
|
|
|
await prepareFileUrl([__dirname, '../debug_log.html'])
|
|
|
|
);
|
2018-07-03 22:33:50 +00:00
|
|
|
}
|
|
|
|
|
2021-10-01 18:49:59 +00:00
|
|
|
let permissionsPopupWindow: BrowserWindow | undefined;
|
|
|
|
function showPermissionsPopupWindow(forCalling: boolean, forCamera: boolean) {
|
2020-09-09 00:46:29 +00:00
|
|
|
// eslint-disable-next-line no-async-promise-executor
|
2022-03-21 21:19:37 +00:00
|
|
|
return new Promise<void>(async (resolveFn, reject) => {
|
2020-06-04 18:16:19 +00:00
|
|
|
if (permissionsPopupWindow) {
|
|
|
|
permissionsPopupWindow.show();
|
|
|
|
reject(new Error('Permission window already showing'));
|
2021-10-01 18:49:59 +00:00
|
|
|
return;
|
2020-06-04 18:16:19 +00:00
|
|
|
}
|
|
|
|
if (!mainWindow) {
|
|
|
|
reject(new Error('No main window'));
|
2021-10-01 18:49:59 +00:00
|
|
|
return;
|
2020-06-04 18:16:19 +00:00
|
|
|
}
|
2018-07-03 22:33:50 +00:00
|
|
|
|
2020-06-04 18:16:19 +00:00
|
|
|
const size = mainWindow.getSize();
|
|
|
|
const options = {
|
|
|
|
width: Math.min(400, size[0]),
|
|
|
|
height: Math.min(150, size[1]),
|
|
|
|
resizable: false,
|
2023-03-30 00:03:25 +00:00
|
|
|
title: getResolvedMessagesLocale().i18n('icu:allowAccess'),
|
2022-06-08 22:00:32 +00:00
|
|
|
titleBarStyle: nonMainTitleBarStyle,
|
2020-06-04 18:16:19 +00:00
|
|
|
autoHideMenuBar: true,
|
2022-05-11 22:58:14 +00:00
|
|
|
backgroundColor: await getBackgroundColor(),
|
2020-06-04 18:16:19 +00:00
|
|
|
show: false,
|
|
|
|
modal: true,
|
|
|
|
webPreferences: {
|
2021-03-03 19:13:35 +00:00
|
|
|
...defaultWebPrefs,
|
2020-06-04 18:16:19 +00:00
|
|
|
nodeIntegration: false,
|
|
|
|
nodeIntegrationInWorker: false,
|
2023-04-20 21:23:19 +00:00
|
|
|
sandbox: true,
|
2021-09-17 22:24:21 +00:00
|
|
|
contextIsolation: true,
|
2023-04-20 21:23:19 +00:00
|
|
|
preload: join(__dirname, '../bundles/permissions/preload.js'),
|
2020-06-04 18:16:19 +00:00
|
|
|
nativeWindowOpen: true,
|
|
|
|
},
|
|
|
|
parent: mainWindow,
|
|
|
|
};
|
2018-07-03 22:33:50 +00:00
|
|
|
|
2022-01-28 22:27:18 +00:00
|
|
|
permissionsPopupWindow = new BrowserWindow(options);
|
2018-07-03 22:33:50 +00:00
|
|
|
|
2023-12-22 20:27:49 +00:00
|
|
|
await handleCommonWindowEvents(permissionsPopupWindow);
|
2018-07-03 22:33:50 +00:00
|
|
|
|
2020-06-04 18:16:19 +00:00
|
|
|
permissionsPopupWindow.on('closed', () => {
|
|
|
|
removeDarkOverlay();
|
2021-10-01 18:49:59 +00:00
|
|
|
permissionsPopupWindow = undefined;
|
2018-07-03 22:33:50 +00:00
|
|
|
|
2022-03-21 21:19:37 +00:00
|
|
|
resolveFn();
|
2020-06-04 18:16:19 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
permissionsPopupWindow.once('ready-to-show', () => {
|
2021-10-01 18:49:59 +00:00
|
|
|
if (permissionsPopupWindow) {
|
|
|
|
addDarkOverlay();
|
|
|
|
permissionsPopupWindow.show();
|
|
|
|
}
|
2020-06-04 18:16:19 +00:00
|
|
|
});
|
2022-12-21 18:41:48 +00:00
|
|
|
|
2023-02-14 02:16:49 +00:00
|
|
|
await safeLoadURL(
|
|
|
|
permissionsPopupWindow,
|
2022-12-21 18:41:48 +00:00
|
|
|
await prepareFileUrl([__dirname, '../permissions_popup.html'], {
|
|
|
|
forCalling,
|
|
|
|
forCamera,
|
|
|
|
})
|
|
|
|
);
|
2018-07-03 22:33:50 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-05-03 19:06:47 +00:00
|
|
|
const runSQLCorruptionHandler = async () => {
|
|
|
|
// This is a glorified event handler. Normally, this promise never resolves,
|
|
|
|
// but if there is a corruption error triggered by any query that we run
|
|
|
|
// against the database - the promise will resolve and we will call
|
|
|
|
// `onDatabaseError`.
|
|
|
|
const error = await sql.whenCorrupted();
|
|
|
|
|
|
|
|
getLogger().error(
|
|
|
|
'Detected sql corruption in main process. ' +
|
|
|
|
`Restarting the application immediately. Error: ${error.message}`
|
|
|
|
);
|
|
|
|
|
2024-07-24 16:23:17 +00:00
|
|
|
await onDatabaseError(error);
|
2022-05-03 19:06:47 +00:00
|
|
|
};
|
|
|
|
|
2023-03-02 17:59:18 +00:00
|
|
|
const runSQLReadonlyHandler = async () => {
|
|
|
|
// This is a glorified event handler. Normally, this promise never resolves,
|
|
|
|
// but if there is a corruption error triggered by any query that we run
|
|
|
|
// against the database - the promise will resolve and we will call
|
|
|
|
// `onDatabaseError`.
|
|
|
|
const error = await sql.whenReadonly();
|
|
|
|
|
|
|
|
getLogger().error(
|
|
|
|
`Detected readonly sql database in main process: ${error.message}`
|
|
|
|
);
|
|
|
|
|
|
|
|
throw error;
|
|
|
|
};
|
|
|
|
|
2024-07-08 23:41:26 +00:00
|
|
|
function generateSQLKey(): string {
|
|
|
|
getLogger().info(
|
|
|
|
'key/initialize: Generating new encryption key, since we did not find it on disk'
|
|
|
|
);
|
|
|
|
// https://www.zetetic.net/sqlcipher/sqlcipher-api/#key
|
|
|
|
return randomBytes(32).toString('hex');
|
|
|
|
}
|
|
|
|
|
|
|
|
function getSQLKey(): string {
|
|
|
|
let update = false;
|
2024-07-24 16:23:17 +00:00
|
|
|
const isLinux = OS.isLinux();
|
2024-07-08 23:41:26 +00:00
|
|
|
const legacyKeyValue = userConfig.get('key');
|
|
|
|
const modernKeyValue = userConfig.get('encryptedKey');
|
2024-07-24 16:23:17 +00:00
|
|
|
const previousBackend = isLinux
|
|
|
|
? userConfig.get('safeStorageBackend')
|
|
|
|
: undefined;
|
2024-07-08 23:41:26 +00:00
|
|
|
|
2024-07-24 16:23:17 +00:00
|
|
|
const safeStorageBackend: string | undefined = isLinux
|
|
|
|
? safeStorage.getSelectedStorageBackend()
|
|
|
|
: undefined;
|
2024-07-08 23:41:26 +00:00
|
|
|
const isEncryptionAvailable =
|
|
|
|
safeStorage.isEncryptionAvailable() &&
|
2024-07-24 16:23:17 +00:00
|
|
|
(!isLinux || safeStorageBackend !== 'basic_text');
|
|
|
|
|
|
|
|
// On Linux the backend can change based on desktop environment and command line flags.
|
|
|
|
// If the backend changes we won't be able to decrypt the key.
|
|
|
|
if (
|
|
|
|
isLinux &&
|
|
|
|
typeof previousBackend === 'string' &&
|
|
|
|
previousBackend !== safeStorageBackend
|
|
|
|
) {
|
|
|
|
console.error(
|
|
|
|
`Detected change in safeStorage backend, can't decrypt DB key (previous: ${previousBackend}, current: ${safeStorageBackend})`
|
|
|
|
);
|
|
|
|
throw new SafeStorageBackendChangeError({
|
|
|
|
currentBackend: String(safeStorageBackend),
|
|
|
|
previousBackend,
|
|
|
|
});
|
|
|
|
}
|
2024-07-08 23:41:26 +00:00
|
|
|
|
|
|
|
let key: string;
|
|
|
|
if (typeof modernKeyValue === 'string') {
|
|
|
|
if (!isEncryptionAvailable) {
|
|
|
|
throw new Error("Can't decrypt database key");
|
|
|
|
}
|
|
|
|
|
|
|
|
getLogger().info('getSQLKey: decrypting key');
|
|
|
|
const encrypted = Buffer.from(modernKeyValue, 'hex');
|
|
|
|
key = safeStorage.decryptString(encrypted);
|
2024-07-11 16:40:56 +00:00
|
|
|
|
|
|
|
if (legacyKeyValue != null) {
|
|
|
|
getLogger().info('getSQLKey: removing legacy key');
|
|
|
|
userConfig.set('key', undefined);
|
|
|
|
}
|
2024-07-24 16:23:17 +00:00
|
|
|
|
|
|
|
if (isLinux && previousBackend == null) {
|
|
|
|
getLogger().info(
|
|
|
|
`getSQLKey: saving safeStorageBackend: ${safeStorageBackend}`
|
|
|
|
);
|
|
|
|
userConfig.set('safeStorageBackend', safeStorageBackend);
|
|
|
|
}
|
2024-07-08 23:41:26 +00:00
|
|
|
} else if (typeof legacyKeyValue === 'string') {
|
|
|
|
key = legacyKeyValue;
|
|
|
|
update = isEncryptionAvailable;
|
|
|
|
if (update) {
|
|
|
|
getLogger().info('getSQLKey: migrating key');
|
|
|
|
} else {
|
|
|
|
getLogger().info('getSQLKey: using legacy key');
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
getLogger().warn("getSQLKey: got key from config, but it wasn't a string");
|
|
|
|
key = generateSQLKey();
|
|
|
|
update = true;
|
2021-10-01 18:49:59 +00:00
|
|
|
}
|
2024-07-08 23:41:26 +00:00
|
|
|
|
|
|
|
if (!update) {
|
|
|
|
return key;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isEncryptionAvailable) {
|
|
|
|
getLogger().info('getSQLKey: updating encrypted key in the config');
|
|
|
|
const encrypted = safeStorage.encryptString(key).toString('hex');
|
|
|
|
userConfig.set('encryptedKey', encrypted);
|
2024-07-15 15:49:41 +00:00
|
|
|
userConfig.set('key', undefined);
|
2024-07-24 16:23:17 +00:00
|
|
|
|
|
|
|
if (isLinux && safeStorageBackend) {
|
|
|
|
getLogger().info(
|
|
|
|
`getSQLKey: saving safeStorageBackend: ${safeStorageBackend}`
|
|
|
|
);
|
|
|
|
userConfig.set('safeStorageBackend', safeStorageBackend);
|
|
|
|
}
|
2024-07-08 23:41:26 +00:00
|
|
|
} else {
|
|
|
|
getLogger().info('getSQLKey: updating plaintext key in the config');
|
2021-04-08 23:27:41 +00:00
|
|
|
userConfig.set('key', key);
|
|
|
|
}
|
|
|
|
|
2024-07-08 23:41:26 +00:00
|
|
|
return key;
|
|
|
|
}
|
|
|
|
|
|
|
|
async function initializeSQL(
|
|
|
|
userDataPath: string
|
|
|
|
): Promise<{ ok: true; error: undefined } | { ok: false; error: Error }> {
|
2021-04-08 23:27:41 +00:00
|
|
|
sqlInitTimeStart = Date.now();
|
2024-07-15 23:15:18 +00:00
|
|
|
|
2024-07-22 19:55:35 +00:00
|
|
|
let key: string;
|
|
|
|
try {
|
|
|
|
key = getSQLKey();
|
|
|
|
} catch (error) {
|
|
|
|
try {
|
|
|
|
// Initialize with *some* key to setup paths
|
|
|
|
await sql.initialize({
|
|
|
|
appVersion: app.getVersion(),
|
|
|
|
configDir: userDataPath,
|
|
|
|
key: 'abcd',
|
|
|
|
logger: getLogger(),
|
|
|
|
});
|
|
|
|
} catch {
|
|
|
|
// Do nothing, we fail right below anyway.
|
|
|
|
}
|
|
|
|
|
|
|
|
if (error instanceof Error) {
|
|
|
|
return { ok: false, error };
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
ok: false,
|
|
|
|
error: new Error(`initializeSQL: Caught a non-error '${error}'`),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-05-07 18:42:21 +00:00
|
|
|
try {
|
2021-10-20 19:56:49 +00:00
|
|
|
// This should be the first awaited call in this function, otherwise
|
2024-07-22 18:16:33 +00:00
|
|
|
// `sql.sqlRead` will throw an uninitialized error instead of waiting for
|
2021-10-20 19:56:49 +00:00
|
|
|
// init to finish.
|
2021-05-07 18:42:21 +00:00
|
|
|
await sql.initialize({
|
2023-10-10 23:55:32 +00:00
|
|
|
appVersion: app.getVersion(),
|
2021-05-07 18:42:21 +00:00
|
|
|
configDir: userDataPath,
|
2024-07-22 19:55:35 +00:00
|
|
|
key,
|
2021-10-01 18:49:59 +00:00
|
|
|
logger: getLogger(),
|
2021-05-07 18:42:21 +00:00
|
|
|
});
|
2021-10-01 18:49:59 +00:00
|
|
|
} catch (error: unknown) {
|
|
|
|
if (error instanceof Error) {
|
|
|
|
return { ok: false, error };
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
ok: false,
|
|
|
|
error: new Error(`initializeSQL: Caught a non-error '${error}'`),
|
|
|
|
};
|
2021-05-07 18:42:21 +00:00
|
|
|
} finally {
|
|
|
|
sqlInitTimeEnd = Date.now();
|
|
|
|
}
|
|
|
|
|
2024-10-10 16:51:40 +00:00
|
|
|
sql.startTrackingQueryStats();
|
|
|
|
|
2022-05-03 19:06:47 +00:00
|
|
|
// Only if we've initialized things successfully do we set up the corruption handler
|
2022-12-21 18:41:48 +00:00
|
|
|
drop(runSQLCorruptionHandler());
|
2023-03-02 17:59:18 +00:00
|
|
|
drop(runSQLReadonlyHandler());
|
2022-05-03 19:06:47 +00:00
|
|
|
|
2021-10-01 18:49:59 +00:00
|
|
|
return { ok: true, error: undefined };
|
2021-04-08 23:27:41 +00:00
|
|
|
}
|
|
|
|
|
2024-07-24 16:23:17 +00:00
|
|
|
const onDatabaseError = async (error: Error) => {
|
2021-09-08 20:39:14 +00:00
|
|
|
// Prevent window from re-opening
|
|
|
|
ready = false;
|
|
|
|
|
|
|
|
if (mainWindow) {
|
|
|
|
mainWindow.close();
|
|
|
|
}
|
|
|
|
mainWindow = undefined;
|
|
|
|
|
2023-09-21 14:13:25 +00:00
|
|
|
const { i18n } = getResolvedMessagesLocale();
|
|
|
|
|
|
|
|
let deleteAllDataButtonIndex: number | undefined;
|
|
|
|
let messageDetail: string;
|
|
|
|
|
|
|
|
const buttons = [i18n('icu:copyErrorAndQuit')];
|
|
|
|
const copyErrorAndQuitButtonIndex = 0;
|
2023-11-15 17:54:51 +00:00
|
|
|
const SIGNAL_SUPPORT_LINK = 'https://support.signal.org/error';
|
2023-09-21 14:13:25 +00:00
|
|
|
|
2024-08-13 20:42:20 +00:00
|
|
|
// Note that this error is thrown by the worker process and thus instanceof
|
|
|
|
// check won't work.
|
|
|
|
if (error.name === 'DBVersionFromFutureError') {
|
2023-09-21 14:13:25 +00:00
|
|
|
// If the DB version is too new, the user likely opened an older version of Signal,
|
|
|
|
// and they would almost never want to delete their data as a result, so we don't show
|
|
|
|
// that option
|
|
|
|
messageDetail = i18n('icu:databaseError__startOldVersion');
|
2024-07-24 16:23:17 +00:00
|
|
|
} else if (error instanceof SafeStorageBackendChangeError) {
|
|
|
|
const { currentBackend, previousBackend } = error;
|
|
|
|
const previousBackendFlag = getOwn(
|
|
|
|
LINUX_PASSWORD_STORE_FLAGS,
|
|
|
|
previousBackend
|
|
|
|
);
|
|
|
|
messageDetail = previousBackendFlag
|
|
|
|
? i18n('icu:databaseError__safeStorageBackendChangeWithPreviousFlag', {
|
|
|
|
currentBackend,
|
|
|
|
previousBackend,
|
|
|
|
previousBackendFlag,
|
|
|
|
})
|
|
|
|
: i18n('icu:databaseError__safeStorageBackendChange', {
|
|
|
|
currentBackend,
|
|
|
|
previousBackend,
|
|
|
|
});
|
2023-09-21 14:13:25 +00:00
|
|
|
} else {
|
|
|
|
// Otherwise, this is some other kind of DB error, let's give them the option to
|
|
|
|
// delete.
|
2024-07-15 23:15:18 +00:00
|
|
|
messageDetail = i18n(
|
|
|
|
'icu:databaseError__detail',
|
|
|
|
{ link: SIGNAL_SUPPORT_LINK },
|
|
|
|
{ bidi: 'strip' }
|
|
|
|
);
|
2023-09-21 14:13:25 +00:00
|
|
|
|
|
|
|
buttons.push(i18n('icu:deleteAndRestart'));
|
|
|
|
deleteAllDataButtonIndex = 1;
|
|
|
|
}
|
|
|
|
|
2021-08-24 20:31:06 +00:00
|
|
|
const buttonIndex = dialog.showMessageBoxSync({
|
2023-09-21 14:13:25 +00:00
|
|
|
buttons,
|
|
|
|
defaultId: copyErrorAndQuitButtonIndex,
|
|
|
|
cancelId: copyErrorAndQuitButtonIndex,
|
|
|
|
message: i18n('icu:databaseError'),
|
|
|
|
detail: messageDetail,
|
2021-08-24 20:31:06 +00:00
|
|
|
noLink: true,
|
|
|
|
type: 'error',
|
|
|
|
});
|
|
|
|
|
2023-09-21 14:13:25 +00:00
|
|
|
if (buttonIndex === copyErrorAndQuitButtonIndex) {
|
2024-07-24 16:23:17 +00:00
|
|
|
clipboard.writeText(
|
2024-08-20 19:45:43 +00:00
|
|
|
`Database startup error:\n\n${redactAll(Errors.toLogFormat(error))}\n\n` +
|
|
|
|
`App Version: ${app.getVersion()}\n` +
|
|
|
|
`OS: ${os.platform()}`
|
2024-07-24 16:23:17 +00:00
|
|
|
);
|
2023-09-21 14:13:25 +00:00
|
|
|
} else if (
|
|
|
|
typeof deleteAllDataButtonIndex === 'number' &&
|
|
|
|
buttonIndex === deleteAllDataButtonIndex
|
|
|
|
) {
|
|
|
|
const confirmationButtons = [
|
|
|
|
i18n('icu:cancel'),
|
|
|
|
i18n('icu:deleteAndRestart'),
|
|
|
|
];
|
|
|
|
const cancelButtonIndex = 0;
|
|
|
|
const confirmDeleteAllDataButtonIndex = 1;
|
|
|
|
const confirmationButtonIndex = dialog.showMessageBoxSync({
|
|
|
|
buttons: confirmationButtons,
|
|
|
|
defaultId: cancelButtonIndex,
|
|
|
|
cancelId: cancelButtonIndex,
|
|
|
|
message: i18n('icu:databaseError__deleteDataConfirmation'),
|
|
|
|
detail: i18n('icu:databaseError__deleteDataConfirmation__detail'),
|
|
|
|
noLink: true,
|
|
|
|
type: 'warning',
|
|
|
|
});
|
|
|
|
|
|
|
|
if (confirmationButtonIndex === confirmDeleteAllDataButtonIndex) {
|
|
|
|
getLogger().error('onDatabaseError: Deleting all data');
|
|
|
|
await sql.removeDB();
|
|
|
|
userConfig.remove();
|
|
|
|
getLogger().error(
|
|
|
|
'onDatabaseError: Requesting immediate restart after quit'
|
|
|
|
);
|
|
|
|
app.relaunch();
|
|
|
|
}
|
2021-08-24 20:31:06 +00:00
|
|
|
}
|
|
|
|
|
2022-05-03 19:06:47 +00:00
|
|
|
getLogger().error('onDatabaseError: Quitting application');
|
2021-08-24 20:31:06 +00:00
|
|
|
app.exit(1);
|
|
|
|
};
|
|
|
|
|
2021-10-01 18:49:59 +00:00
|
|
|
let sqlInitPromise:
|
|
|
|
| Promise<{ ok: true; error: undefined } | { ok: false; error: Error }>
|
|
|
|
| undefined;
|
2021-09-08 20:39:14 +00:00
|
|
|
|
2023-03-02 17:59:18 +00:00
|
|
|
ipc.on('database-readonly', (_event: Electron.Event, error: string) => {
|
|
|
|
// Just let global_errors.ts handle it
|
|
|
|
throw new Error(error);
|
|
|
|
});
|
|
|
|
|
2023-01-25 00:54:46 +00:00
|
|
|
function loadPreferredSystemLocales(): Array<string> {
|
2023-06-14 22:57:50 +00:00
|
|
|
if (CLI_LANG != null) {
|
|
|
|
try {
|
|
|
|
// Normalizes locales so its safe to pass them into Intl apis.
|
|
|
|
return Intl.getCanonicalLocales(CLI_LANG);
|
|
|
|
} catch {
|
|
|
|
// Ignore, totally invalid locale, fallback to system languages.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (getEnvironment() === Environment.Test) {
|
|
|
|
return ['en'];
|
|
|
|
}
|
|
|
|
|
|
|
|
return app.getPreferredSystemLanguages();
|
2022-01-11 19:05:22 +00:00
|
|
|
}
|
|
|
|
|
2024-02-22 21:19:37 +00:00
|
|
|
async function getDefaultLoginItemSettings(): Promise<Settings> {
|
2022-09-06 22:09:52 +00:00
|
|
|
if (!OS.isWindows()) {
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
const systemTraySetting = await systemTraySettingCache.get();
|
|
|
|
if (
|
|
|
|
systemTraySetting !== SystemTraySetting.MinimizeToSystemTray &&
|
|
|
|
// This is true when we just started with `--start-in-tray`
|
|
|
|
systemTraySetting !== SystemTraySetting.MinimizeToAndStartInSystemTray
|
|
|
|
) {
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
// The effect of this is that if both auto-launch and minimize to system tray
|
|
|
|
// are enabled on Windows - we will start the app in tray automatically,
|
|
|
|
// letting the Desktop shortcuts still start the Signal not in tray.
|
|
|
|
return { args: ['--start-in-tray'] };
|
|
|
|
}
|
|
|
|
|
2022-03-02 16:57:23 +00:00
|
|
|
// Signal doesn't really use media keys so we set this switch here to unblock
|
|
|
|
// them so that other apps can use them if they need to.
|
2023-12-11 19:56:05 +00:00
|
|
|
const featuresToDisable = `HardwareMediaKeyHandling,${app.commandLine.getSwitchValue(
|
|
|
|
'disable-features'
|
|
|
|
)}`;
|
2023-10-02 13:42:24 +00:00
|
|
|
app.commandLine.appendSwitch('disable-features', featuresToDisable);
|
2022-06-15 16:40:01 +00:00
|
|
|
|
2022-09-28 00:55:42 +00:00
|
|
|
// <canvas/> rendering is often utterly broken on Linux when using GPU
|
|
|
|
// acceleration.
|
2022-11-14 19:29:53 +00:00
|
|
|
if (DISABLE_GPU) {
|
2022-09-28 00:55:42 +00:00
|
|
|
app.disableHardwareAcceleration();
|
|
|
|
}
|
|
|
|
|
2024-07-11 19:44:09 +00:00
|
|
|
// This has to run before the 'ready' event.
|
|
|
|
electronProtocol.registerSchemesAsPrivileged([
|
|
|
|
{
|
|
|
|
scheme: 'attachment',
|
|
|
|
privileges: {
|
|
|
|
supportFetchAPI: true,
|
|
|
|
stream: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
|
2017-03-02 22:04:38 +00:00
|
|
|
// This method will be called when Electron has finished
|
|
|
|
// initialization and is ready to create browser windows.
|
|
|
|
// Some APIs can only be used after this event occurs.
|
2017-11-02 15:13:41 +00:00
|
|
|
let ready = false;
|
2018-06-14 20:39:44 +00:00
|
|
|
app.on('ready', async () => {
|
2024-02-28 00:53:58 +00:00
|
|
|
dns.setFallback(await getDNSFallback());
|
2024-04-11 17:06:54 +00:00
|
|
|
if (DISABLE_IPV6) {
|
|
|
|
dns.setIPv6Enabled(false);
|
|
|
|
}
|
2024-02-28 00:53:58 +00:00
|
|
|
|
2023-04-20 15:59:17 +00:00
|
|
|
const [userDataPath, crashDumpsPath, installPath] = await Promise.all([
|
2022-01-20 01:50:16 +00:00
|
|
|
realpath(app.getPath('userData')),
|
|
|
|
realpath(app.getPath('crashDumps')),
|
2023-04-20 15:59:17 +00:00
|
|
|
realpath(app.getAppPath()),
|
2022-01-20 01:50:16 +00:00
|
|
|
]);
|
2021-10-20 19:56:49 +00:00
|
|
|
|
2024-09-20 01:03:44 +00:00
|
|
|
updateDefaultSession(session.defaultSession, getLogger);
|
2023-04-20 15:59:17 +00:00
|
|
|
|
2024-05-15 22:26:37 +00:00
|
|
|
if (getEnvironment() !== Environment.Test) {
|
|
|
|
installFileHandler({
|
|
|
|
session: session.defaultSession,
|
|
|
|
userDataPath,
|
|
|
|
installPath,
|
|
|
|
isWindows: OS.isWindows(),
|
|
|
|
});
|
2023-04-20 15:59:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
installWebHandler({
|
|
|
|
enableHttp: Boolean(process.env.SIGNAL_ENABLE_HTTP),
|
|
|
|
session: session.defaultSession,
|
|
|
|
});
|
|
|
|
|
2021-09-16 21:54:06 +00:00
|
|
|
logger = await logging.initialize(getMainWindow);
|
|
|
|
|
2023-03-28 22:22:06 +00:00
|
|
|
// Write buffered information into newly created logger.
|
|
|
|
consoleLogger.writeBufferInto(logger);
|
2022-01-11 20:02:46 +00:00
|
|
|
|
2024-06-21 22:35:56 +00:00
|
|
|
const resourceService = OptionalResourceService.create(
|
|
|
|
join(userDataPath, 'optionalResources')
|
|
|
|
);
|
|
|
|
await EmojiService.create(resourceService);
|
2024-03-21 16:35:54 +00:00
|
|
|
|
2023-01-25 00:54:46 +00:00
|
|
|
if (!resolvedTranslationsLocale) {
|
2023-03-02 18:43:25 +00:00
|
|
|
preferredSystemLocales = resolveCanonicalLocales(
|
|
|
|
loadPreferredSystemLocales()
|
|
|
|
);
|
|
|
|
|
2023-11-07 01:02:13 +00:00
|
|
|
localeOverride = await getLocaleOverrideSetting();
|
2023-11-06 21:19:23 +00:00
|
|
|
|
2023-07-31 16:23:19 +00:00
|
|
|
const hourCyclePreference = getHourCyclePreference();
|
|
|
|
logger.info(`app.ready: hour cycle preference: ${hourCyclePreference}`);
|
|
|
|
|
2023-01-25 00:54:46 +00:00
|
|
|
logger.info(
|
|
|
|
`app.ready: preferred system locales: ${preferredSystemLocales.join(
|
|
|
|
', '
|
2023-02-02 20:09:34 +00:00
|
|
|
)}`
|
2023-01-25 00:54:46 +00:00
|
|
|
);
|
|
|
|
resolvedTranslationsLocale = loadLocale({
|
|
|
|
preferredSystemLocales,
|
2023-11-06 21:19:23 +00:00
|
|
|
localeOverride,
|
2023-12-12 19:41:14 +00:00
|
|
|
localeDirectionTestingOverride,
|
2023-07-31 16:23:19 +00:00
|
|
|
hourCyclePreference,
|
2023-01-25 00:54:46 +00:00
|
|
|
logger: getLogger(),
|
|
|
|
});
|
2021-11-29 18:04:14 +00:00
|
|
|
}
|
|
|
|
|
2024-07-08 23:41:26 +00:00
|
|
|
sqlInitPromise = initializeSQL(userDataPath);
|
|
|
|
|
2022-09-06 22:09:52 +00:00
|
|
|
// First run: configure Signal to minimize to tray. Additionally, on Windows
|
|
|
|
// enable auto-start with start-in-tray so that starting from a Desktop icon
|
|
|
|
// would still show the window.
|
|
|
|
// (User can change these settings later)
|
|
|
|
if (
|
2024-03-14 17:01:40 +00:00
|
|
|
isSystemTraySupported(OS) &&
|
2022-09-06 22:09:52 +00:00
|
|
|
(await systemTraySettingCache.get()) === SystemTraySetting.Uninitialized
|
|
|
|
) {
|
2024-03-14 17:01:40 +00:00
|
|
|
const newValue = getDefaultSystemTraySetting(OS, app.getVersion());
|
2022-09-06 22:09:52 +00:00
|
|
|
getLogger().info(`app.ready: setting system-tray-setting to ${newValue}`);
|
|
|
|
systemTraySettingCache.set(newValue);
|
|
|
|
|
|
|
|
ephemeralConfig.set('system-tray-setting', newValue);
|
|
|
|
|
|
|
|
if (OS.isWindows()) {
|
|
|
|
getLogger().info('app.ready: enabling open at login');
|
|
|
|
app.setLoginItemSettings({
|
|
|
|
...(await getDefaultLoginItemSettings()),
|
|
|
|
openAtLogin: true,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-15 17:30:58 +00:00
|
|
|
const startTime = Date.now();
|
|
|
|
|
2021-08-18 20:08:14 +00:00
|
|
|
settingsChannel = new SettingsChannel();
|
|
|
|
settingsChannel.install();
|
|
|
|
|
2024-03-07 17:36:08 +00:00
|
|
|
settingsChannel.on('change:systemTraySetting', async rawSystemTraySetting => {
|
|
|
|
const { openAtLogin } = app.getLoginItemSettings(
|
|
|
|
await getDefaultLoginItemSettings()
|
|
|
|
);
|
|
|
|
|
|
|
|
const systemTraySetting = parseSystemTraySetting(rawSystemTraySetting);
|
|
|
|
systemTraySettingCache.set(systemTraySetting);
|
|
|
|
|
|
|
|
if (systemTrayService) {
|
|
|
|
const isEnabled = shouldMinimizeToSystemTray(systemTraySetting);
|
|
|
|
systemTrayService.setEnabled(isEnabled);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Default login item settings might have changed, so update the object.
|
|
|
|
getLogger().info('refresh-auto-launch: new value', openAtLogin);
|
|
|
|
app.setLoginItemSettings({
|
|
|
|
...(await getDefaultLoginItemSettings()),
|
|
|
|
openAtLogin,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
settingsChannel.on(
|
|
|
|
'ephemeral-setting-changed',
|
|
|
|
sendPreferencesChangedEventToWindows
|
|
|
|
);
|
|
|
|
|
2021-01-15 17:30:58 +00:00
|
|
|
// We use this event only a single time to log the startup time of the app
|
|
|
|
// from when it's first ready until the loading screen disappears.
|
2021-04-13 23:43:56 +00:00
|
|
|
ipc.once('signal-app-loaded', (event, info) => {
|
|
|
|
const { preloadTime, connectTime, processedCount } = info;
|
|
|
|
|
2021-03-26 02:02:53 +00:00
|
|
|
const loadTime = Date.now() - startTime;
|
2021-04-06 17:29:22 +00:00
|
|
|
const sqlInitTime = sqlInitTimeEnd - sqlInitTimeStart;
|
2021-04-13 23:43:56 +00:00
|
|
|
|
|
|
|
const messageTime = loadTime - preloadTime - connectTime;
|
|
|
|
const messagesPerSec = (processedCount * 1000) / messageTime;
|
|
|
|
|
2021-10-01 18:49:59 +00:00
|
|
|
const innerLogger = getLogger();
|
|
|
|
innerLogger.info('App loaded - time:', loadTime);
|
|
|
|
innerLogger.info('SQL init - time:', sqlInitTime);
|
|
|
|
innerLogger.info('Preload - time:', preloadTime);
|
|
|
|
innerLogger.info('WebSocket connect - time:', connectTime);
|
|
|
|
innerLogger.info('Processed count:', processedCount);
|
|
|
|
innerLogger.info('Messages per second:', messagesPerSec);
|
2021-03-26 02:02:53 +00:00
|
|
|
|
2024-10-28 17:11:19 +00:00
|
|
|
sql.stopTrackingQueryStats({ epochName: 'App Load' });
|
2024-10-10 16:51:40 +00:00
|
|
|
|
2021-08-11 19:29:07 +00:00
|
|
|
event.sender.send('ci:event', 'app-loaded', {
|
|
|
|
loadTime,
|
|
|
|
sqlInitTime,
|
|
|
|
preloadTime,
|
|
|
|
connectTime,
|
|
|
|
processedCount,
|
|
|
|
messagesPerSec,
|
|
|
|
});
|
2021-01-15 17:30:58 +00:00
|
|
|
});
|
|
|
|
|
2021-06-01 18:15:23 +00:00
|
|
|
addSensitivePath(userDataPath);
|
2022-01-20 01:50:16 +00:00
|
|
|
addSensitivePath(crashDumpsPath);
|
2021-06-01 18:15:23 +00:00
|
|
|
|
2021-12-09 08:06:04 +00:00
|
|
|
if (getEnvironment() !== Environment.Test) {
|
2018-05-23 23:26:40 +00:00
|
|
|
installFileHandler({
|
2023-04-20 15:59:17 +00:00
|
|
|
session: session.defaultSession,
|
2018-05-23 23:26:40 +00:00
|
|
|
userDataPath,
|
|
|
|
installPath,
|
2021-02-01 20:01:25 +00:00
|
|
|
isWindows: OS.isWindows(),
|
2018-05-23 23:26:40 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-01-22 17:47:19 +00:00
|
|
|
logger.info('app ready');
|
2019-03-28 17:09:26 +00:00
|
|
|
logger.info(`starting version ${packageJson.version}`);
|
2019-01-22 17:47:19 +00:00
|
|
|
|
2020-12-04 17:31:42 +00:00
|
|
|
// This logging helps us debug user reports about broken devices.
|
|
|
|
{
|
|
|
|
let getMediaAccessStatus;
|
|
|
|
// This function is not supported on Linux, so we have a fallback.
|
|
|
|
if (systemPreferences.getMediaAccessStatus) {
|
2021-11-11 22:43:05 +00:00
|
|
|
getMediaAccessStatus =
|
|
|
|
systemPreferences.getMediaAccessStatus.bind(systemPreferences);
|
2020-12-04 17:31:42 +00:00
|
|
|
} else {
|
2021-10-01 18:49:59 +00:00
|
|
|
getMediaAccessStatus = noop;
|
2020-12-04 17:31:42 +00:00
|
|
|
}
|
|
|
|
logger.info(
|
|
|
|
'media access status',
|
|
|
|
getMediaAccessStatus('microphone'),
|
|
|
|
getMediaAccessStatus('camera')
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-01-25 00:54:46 +00:00
|
|
|
GlobalErrors.updateLocale(resolvedTranslationsLocale);
|
2019-02-20 01:32:44 +00:00
|
|
|
|
2020-03-25 23:45:37 +00:00
|
|
|
// If the sql initialization takes more than three seconds to complete, we
|
|
|
|
// want to notify the user that things are happening
|
2022-03-21 21:19:37 +00:00
|
|
|
const timeout = new Promise(resolveFn =>
|
|
|
|
setTimeout(resolveFn, 3000, 'timeout')
|
|
|
|
);
|
2022-05-11 22:58:14 +00:00
|
|
|
|
|
|
|
// This color is to be used only in loading screen and in this case we should
|
|
|
|
// never wait for the database to be initialized. Thus the theme setting
|
|
|
|
// lookup should be done only in ephemeral config.
|
2024-08-05 18:48:15 +00:00
|
|
|
const backgroundColor = await getBackgroundColor({
|
|
|
|
ephemeralOnly: true,
|
|
|
|
signalColors: true,
|
|
|
|
});
|
2022-05-11 22:58:14 +00:00
|
|
|
|
2022-12-21 18:41:48 +00:00
|
|
|
drop(
|
|
|
|
// eslint-disable-next-line more/no-then
|
|
|
|
Promise.race([sqlInitPromise, timeout]).then(async maybeTimeout => {
|
|
|
|
if (maybeTimeout !== 'timeout') {
|
|
|
|
return;
|
|
|
|
}
|
2020-03-25 23:45:37 +00:00
|
|
|
|
2022-12-21 18:41:48 +00:00
|
|
|
getLogger().info(
|
|
|
|
'sql.initialize is taking more than three seconds; showing loading dialog'
|
|
|
|
);
|
2020-03-25 23:45:37 +00:00
|
|
|
|
2022-12-21 18:41:48 +00:00
|
|
|
loadingWindow = new BrowserWindow({
|
|
|
|
show: false,
|
|
|
|
width: 300,
|
2023-03-28 20:31:24 +00:00
|
|
|
height: 280,
|
2022-12-21 18:41:48 +00:00
|
|
|
resizable: false,
|
|
|
|
frame: false,
|
|
|
|
backgroundColor,
|
|
|
|
webPreferences: {
|
|
|
|
...defaultWebPrefs,
|
|
|
|
nodeIntegration: false,
|
2023-04-20 21:23:19 +00:00
|
|
|
sandbox: true,
|
2022-12-21 18:41:48 +00:00
|
|
|
contextIsolation: true,
|
2023-04-20 21:23:19 +00:00
|
|
|
preload: join(__dirname, '../bundles/loading/preload.js'),
|
2022-12-21 18:41:48 +00:00
|
|
|
},
|
|
|
|
icon: windowIcon,
|
|
|
|
});
|
2020-03-25 23:45:37 +00:00
|
|
|
|
2022-12-21 18:41:48 +00:00
|
|
|
loadingWindow.once('ready-to-show', async () => {
|
|
|
|
if (!loadingWindow) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
loadingWindow.show();
|
|
|
|
// Wait for sql initialization to complete, but ignore errors
|
|
|
|
await sqlInitPromise;
|
|
|
|
loadingWindow.destroy();
|
|
|
|
loadingWindow = undefined;
|
|
|
|
});
|
2020-03-25 23:45:37 +00:00
|
|
|
|
2023-02-14 02:16:49 +00:00
|
|
|
await safeLoadURL(
|
|
|
|
loadingWindow,
|
2022-12-21 18:41:48 +00:00
|
|
|
await prepareFileUrl([__dirname, '../loading.html'])
|
|
|
|
);
|
|
|
|
})
|
|
|
|
);
|
2020-03-25 23:45:37 +00:00
|
|
|
|
2021-06-01 18:06:38 +00:00
|
|
|
try {
|
|
|
|
await attachments.clearTempPath(userDataPath);
|
|
|
|
} catch (err) {
|
|
|
|
logger.error(
|
|
|
|
'main/ready: Error deleting temp dir:',
|
2022-11-22 18:43:43 +00:00
|
|
|
Errors.toLogFormat(err)
|
2021-06-01 18:06:38 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2024-08-19 20:05:35 +00:00
|
|
|
try {
|
|
|
|
await attachments.deleteStaleDownloads(userDataPath);
|
|
|
|
} catch (err) {
|
|
|
|
logger.error(
|
|
|
|
'main/ready: Error deleting stale downloads:',
|
|
|
|
Errors.toLogFormat(err)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-06-01 18:06:38 +00:00
|
|
|
// Initialize IPC channels before creating the window
|
|
|
|
|
|
|
|
attachmentChannel.initialize({
|
2022-11-17 00:29:15 +00:00
|
|
|
sql,
|
2021-06-01 18:06:38 +00:00
|
|
|
configDir: userDataPath,
|
|
|
|
});
|
|
|
|
sqlChannels.initialize(sql);
|
2021-06-09 22:28:54 +00:00
|
|
|
PowerChannel.initialize({
|
|
|
|
send(event) {
|
|
|
|
if (!mainWindow) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mainWindow.webContents.send(event);
|
|
|
|
},
|
|
|
|
});
|
2021-06-01 18:06:38 +00:00
|
|
|
|
2021-04-08 23:27:41 +00:00
|
|
|
// Run window preloading in parallel with database initialization.
|
|
|
|
await createWindow();
|
|
|
|
|
2021-05-07 18:42:21 +00:00
|
|
|
const { error: sqlError } = await sqlInitPromise;
|
|
|
|
if (sqlError) {
|
2021-10-01 18:49:59 +00:00
|
|
|
getLogger().error('sql.initialize was unsuccessful; returning early');
|
2021-03-04 21:44:57 +00:00
|
|
|
|
2024-07-24 16:23:17 +00:00
|
|
|
await onDatabaseError(sqlError);
|
2021-03-04 21:44:57 +00:00
|
|
|
|
2019-02-20 01:32:44 +00:00
|
|
|
return;
|
|
|
|
}
|
2021-03-04 21:44:57 +00:00
|
|
|
|
2020-03-20 21:00:11 +00:00
|
|
|
appStartInitialSpellcheckSetting = await getSpellCheckSetting();
|
2017-06-22 01:04:19 +00:00
|
|
|
|
2018-11-12 22:13:16 +00:00
|
|
|
try {
|
|
|
|
const IDB_KEY = 'indexeddb-delete-needed';
|
2024-07-22 18:16:33 +00:00
|
|
|
const item = await sql.sqlRead('getItemById', IDB_KEY);
|
2018-11-12 22:13:16 +00:00
|
|
|
if (item && item.value) {
|
2024-07-22 18:16:33 +00:00
|
|
|
await sql.sqlWrite('removeIndexedDBFiles');
|
|
|
|
await sql.sqlWrite('removeItemById', IDB_KEY);
|
2018-11-12 22:13:16 +00:00
|
|
|
}
|
2021-03-04 21:44:57 +00:00
|
|
|
} catch (err) {
|
2021-10-01 18:49:59 +00:00
|
|
|
getLogger().error(
|
2018-11-12 22:13:16 +00:00
|
|
|
'(ready event handler) error deleting IndexedDB:',
|
2022-11-22 18:43:43 +00:00
|
|
|
Errors.toLogFormat(err)
|
2018-11-12 22:13:16 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-07-27 01:13:56 +00:00
|
|
|
ready = true;
|
|
|
|
|
|
|
|
setupMenu();
|
2020-02-21 23:40:04 +00:00
|
|
|
|
2023-01-25 00:54:46 +00:00
|
|
|
systemTrayService = new SystemTrayService({
|
|
|
|
i18n: resolvedTranslationsLocale.i18n,
|
|
|
|
});
|
2021-06-29 17:18:03 +00:00
|
|
|
systemTrayService.setMainWindow(mainWindow);
|
|
|
|
systemTrayService.setEnabled(
|
|
|
|
shouldMinimizeToSystemTray(await systemTraySettingCache.get())
|
|
|
|
);
|
|
|
|
|
2022-12-21 18:41:48 +00:00
|
|
|
await ensureFilePermissions([
|
2021-03-31 00:30:23 +00:00
|
|
|
'config.json',
|
|
|
|
'sql/db.sqlite',
|
|
|
|
'sql/db.sqlite-wal',
|
|
|
|
'sql/db.sqlite-shm',
|
|
|
|
]);
|
2018-01-08 21:19:25 +00:00
|
|
|
});
|
|
|
|
|
2022-06-08 22:00:32 +00:00
|
|
|
function setupMenu(options?: Partial<CreateTemplateOptionsType>) {
|
2018-03-02 20:59:39 +00:00
|
|
|
const { platform } = process;
|
2022-06-08 22:00:32 +00:00
|
|
|
menuOptions = {
|
2021-10-01 18:49:59 +00:00
|
|
|
// options
|
New design for import/install, 'light' import (#2053)
- A new design for the import flow. It features:
- Icons at the top of every screen
- Gray background, blue buttons, thinner text
- Simpler copy
- A new design for the install flow. It features:
- Immediate entry into the QR code screen
- Animated dots to show that we're loading the QR code from the server
- Fewer screens: 1) QR 2) device name 3) sync-in-progress
- When not set up, the app opens directly into the install screen, which has been streamlined. The `--import` command-line argument will cause the app to open directly into the import flow.
- Support for two different flavors of builds - the normal build will open into the standard registration flow, and the import flavor will be exactly the same except during setup it will open directly into the import flow.
- A new design for the (dev-only) standalone registration view
- When these install sequences are active, the OS File menu has entries to allow you to switch the method of setup you'd like to use. These go away as soon as the first step is taken in any of these flows.
- The device name (chosen on initial setup) is now shown in the settings panel
- At the end of a light import, we hand off to the normal device link screen, starting at the QR code. On a full import, we remove the sensitive encryption information in the export to prevent conflicts on multiple imports.
- `Whisper.Backup.exportToDirectory()` takes an options object so you can tell it to do a light export.
- `Whisper.Backup.importFromDirectory()` takes an options object so you can force it to load only the light components found on disk. It also returns an object so you can tell whether a given import was a full import or light import.
- On start of import, we build a list of all the ids present in the messages, conversations, and groups stores in IndexedDB. This can take some time if a lot of data is in the database already, but it makes the subsequent deduplicated import very fast.
- Disappearing messages are now excluded when exporting
- Remove some TODOs in the tests
2018-02-22 18:40:32 +00:00
|
|
|
development,
|
2021-03-08 22:44:50 +00:00
|
|
|
devTools: defaultWebPrefs.devTools,
|
2021-10-01 18:49:59 +00:00
|
|
|
includeSetup: false,
|
|
|
|
isProduction: isProduction(app.getVersion()),
|
|
|
|
platform,
|
|
|
|
|
|
|
|
// actions
|
|
|
|
forceUpdate,
|
2023-02-27 22:34:43 +00:00
|
|
|
openArtCreator,
|
2020-06-10 16:56:10 +00:00
|
|
|
openContactUs,
|
2021-10-01 18:49:59 +00:00
|
|
|
openForums,
|
2020-06-10 16:56:10 +00:00
|
|
|
openJoinTheBeta,
|
New design for import/install, 'light' import (#2053)
- A new design for the import flow. It features:
- Icons at the top of every screen
- Gray background, blue buttons, thinner text
- Simpler copy
- A new design for the install flow. It features:
- Immediate entry into the QR code screen
- Animated dots to show that we're loading the QR code from the server
- Fewer screens: 1) QR 2) device name 3) sync-in-progress
- When not set up, the app opens directly into the install screen, which has been streamlined. The `--import` command-line argument will cause the app to open directly into the import flow.
- Support for two different flavors of builds - the normal build will open into the standard registration flow, and the import flavor will be exactly the same except during setup it will open directly into the import flow.
- A new design for the (dev-only) standalone registration view
- When these install sequences are active, the OS File menu has entries to allow you to switch the method of setup you'd like to use. These go away as soon as the first step is taken in any of these flows.
- The device name (chosen on initial setup) is now shown in the settings panel
- At the end of a light import, we hand off to the normal device link screen, starting at the QR code. On a full import, we remove the sensitive encryption information in the export to prevent conflicts on multiple imports.
- `Whisper.Backup.exportToDirectory()` takes an options object so you can tell it to do a light export.
- `Whisper.Backup.importFromDirectory()` takes an options object so you can force it to load only the light components found on disk. It also returns an object so you can tell whether a given import was a full import or light import.
- On start of import, we build a list of all the ids present in the messages, conversations, and groups stores in IndexedDB. This can take some time if a lot of data is in the database already, but it makes the subsequent deduplicated import very fast.
- Disappearing messages are now excluded when exporting
- Remove some TODOs in the tests
2018-02-22 18:40:32 +00:00
|
|
|
openReleaseNotes,
|
|
|
|
openSupportPage,
|
|
|
|
setupAsNewDevice,
|
|
|
|
setupAsStandalone,
|
2021-10-01 18:49:59 +00:00
|
|
|
showAbout,
|
|
|
|
showDebugLog: showDebugLogWindow,
|
2024-05-23 00:28:01 +00:00
|
|
|
showCallingDevTools: showCallingDevToolsWindow,
|
2021-10-01 18:49:59 +00:00
|
|
|
showKeyboardShortcuts,
|
|
|
|
showSettings: showSettingsWindow,
|
|
|
|
showWindow,
|
2023-12-22 20:27:49 +00:00
|
|
|
zoomIn,
|
|
|
|
zoomOut,
|
|
|
|
zoomReset,
|
2021-10-01 18:49:59 +00:00
|
|
|
|
|
|
|
// overrides
|
|
|
|
...options,
|
2019-12-17 20:25:57 +00:00
|
|
|
};
|
2023-01-25 00:54:46 +00:00
|
|
|
const template = createTemplate(
|
|
|
|
menuOptions,
|
|
|
|
getResolvedMessagesLocale().i18n
|
|
|
|
);
|
New design for import/install, 'light' import (#2053)
- A new design for the import flow. It features:
- Icons at the top of every screen
- Gray background, blue buttons, thinner text
- Simpler copy
- A new design for the install flow. It features:
- Immediate entry into the QR code screen
- Animated dots to show that we're loading the QR code from the server
- Fewer screens: 1) QR 2) device name 3) sync-in-progress
- When not set up, the app opens directly into the install screen, which has been streamlined. The `--import` command-line argument will cause the app to open directly into the import flow.
- Support for two different flavors of builds - the normal build will open into the standard registration flow, and the import flavor will be exactly the same except during setup it will open directly into the import flow.
- A new design for the (dev-only) standalone registration view
- When these install sequences are active, the OS File menu has entries to allow you to switch the method of setup you'd like to use. These go away as soon as the first step is taken in any of these flows.
- The device name (chosen on initial setup) is now shown in the settings panel
- At the end of a light import, we hand off to the normal device link screen, starting at the QR code. On a full import, we remove the sensitive encryption information in the export to prevent conflicts on multiple imports.
- `Whisper.Backup.exportToDirectory()` takes an options object so you can tell it to do a light export.
- `Whisper.Backup.importFromDirectory()` takes an options object so you can force it to load only the light components found on disk. It also returns an object so you can tell whether a given import was a full import or light import.
- On start of import, we build a list of all the ids present in the messages, conversations, and groups stores in IndexedDB. This can take some time if a lot of data is in the database already, but it makes the subsequent deduplicated import very fast.
- Disappearing messages are now excluded when exporting
- Remove some TODOs in the tests
2018-02-22 18:40:32 +00:00
|
|
|
const menu = Menu.buildFromTemplate(template);
|
|
|
|
Menu.setApplicationMenu(menu);
|
2022-06-08 22:00:32 +00:00
|
|
|
|
|
|
|
mainWindow?.webContents.send('window:set-menu-options', {
|
|
|
|
development: menuOptions.development,
|
|
|
|
devTools: menuOptions.devTools,
|
|
|
|
includeSetup: menuOptions.includeSetup,
|
|
|
|
isProduction: menuOptions.isProduction,
|
|
|
|
platform: menuOptions.platform,
|
|
|
|
});
|
New design for import/install, 'light' import (#2053)
- A new design for the import flow. It features:
- Icons at the top of every screen
- Gray background, blue buttons, thinner text
- Simpler copy
- A new design for the install flow. It features:
- Immediate entry into the QR code screen
- Animated dots to show that we're loading the QR code from the server
- Fewer screens: 1) QR 2) device name 3) sync-in-progress
- When not set up, the app opens directly into the install screen, which has been streamlined. The `--import` command-line argument will cause the app to open directly into the import flow.
- Support for two different flavors of builds - the normal build will open into the standard registration flow, and the import flavor will be exactly the same except during setup it will open directly into the import flow.
- A new design for the (dev-only) standalone registration view
- When these install sequences are active, the OS File menu has entries to allow you to switch the method of setup you'd like to use. These go away as soon as the first step is taken in any of these flows.
- The device name (chosen on initial setup) is now shown in the settings panel
- At the end of a light import, we hand off to the normal device link screen, starting at the QR code. On a full import, we remove the sensitive encryption information in the export to prevent conflicts on multiple imports.
- `Whisper.Backup.exportToDirectory()` takes an options object so you can tell it to do a light export.
- `Whisper.Backup.importFromDirectory()` takes an options object so you can force it to load only the light components found on disk. It also returns an object so you can tell whether a given import was a full import or light import.
- On start of import, we build a list of all the ids present in the messages, conversations, and groups stores in IndexedDB. This can take some time if a lot of data is in the database already, but it makes the subsequent deduplicated import very fast.
- Disappearing messages are now excluded when exporting
- Remove some TODOs in the tests
2018-02-22 18:40:32 +00:00
|
|
|
}
|
|
|
|
|
2024-02-19 14:44:05 +00:00
|
|
|
async function maybeRequestCloseConfirmation(): Promise<boolean> {
|
|
|
|
if (!mainWindow || !mainWindow.webContents) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
getLogger().info(
|
|
|
|
'maybeRequestCloseConfirmation: Checking to see if close confirmation is needed'
|
|
|
|
);
|
|
|
|
const request = new Promise<boolean>(resolveFn => {
|
|
|
|
let timeout: NodeJS.Timeout | undefined;
|
|
|
|
|
|
|
|
if (!mainWindow) {
|
|
|
|
resolveFn(true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ipc.once('received-close-confirmation', (_event, result) => {
|
|
|
|
getLogger().info('maybeRequestCloseConfirmation: Response received');
|
|
|
|
|
|
|
|
clearTimeoutIfNecessary(timeout);
|
|
|
|
resolveFn(result);
|
|
|
|
});
|
|
|
|
|
|
|
|
ipc.once('requested-close-confirmation', () => {
|
|
|
|
getLogger().info(
|
|
|
|
'maybeRequestCloseConfirmation: Confirmation dialog shown, waiting for user.'
|
|
|
|
);
|
|
|
|
clearTimeoutIfNecessary(timeout);
|
|
|
|
});
|
|
|
|
|
|
|
|
mainWindow.webContents.send('maybe-request-close-confirmation');
|
|
|
|
|
|
|
|
// Wait a short time then proceed. Normally the dialog should be
|
|
|
|
// shown right away.
|
|
|
|
timeout = setTimeout(() => {
|
|
|
|
getLogger().error(
|
|
|
|
'maybeRequestCloseConfirmation: Response never received; continuing with close.'
|
|
|
|
);
|
|
|
|
resolveFn(true);
|
|
|
|
}, 10 * 1000);
|
|
|
|
});
|
|
|
|
|
|
|
|
try {
|
|
|
|
return await request;
|
|
|
|
} catch (error) {
|
|
|
|
getLogger().error(
|
|
|
|
'maybeRequestCloseConfirmation error:',
|
|
|
|
Errors.toLogFormat(error)
|
|
|
|
);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-05 19:06:12 +00:00
|
|
|
async function requestShutdown() {
|
|
|
|
if (!mainWindow || !mainWindow.webContents) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-10-01 18:49:59 +00:00
|
|
|
getLogger().info('requestShutdown: Requesting close of mainWindow...');
|
2022-04-11 17:53:57 +00:00
|
|
|
const request = new Promise<void>(resolveFn => {
|
2021-10-01 18:49:59 +00:00
|
|
|
let timeout: NodeJS.Timeout | undefined;
|
|
|
|
|
|
|
|
if (!mainWindow) {
|
2022-03-21 21:19:37 +00:00
|
|
|
resolveFn();
|
2021-10-01 18:49:59 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-11-05 19:06:12 +00:00
|
|
|
ipc.once('now-ready-for-shutdown', (_event, error) => {
|
2021-10-01 18:49:59 +00:00
|
|
|
getLogger().info('requestShutdown: Response received');
|
2018-11-05 19:06:12 +00:00
|
|
|
|
|
|
|
if (error) {
|
2022-04-11 17:53:57 +00:00
|
|
|
getLogger().error(
|
|
|
|
'requestShutdown: got error, still shutting down.',
|
|
|
|
error
|
|
|
|
);
|
2018-11-05 19:06:12 +00:00
|
|
|
}
|
2022-02-25 18:37:15 +00:00
|
|
|
clearTimeoutIfNecessary(timeout);
|
2018-11-05 19:06:12 +00:00
|
|
|
|
2022-03-21 21:19:37 +00:00
|
|
|
resolveFn();
|
2018-11-05 19:06:12 +00:00
|
|
|
});
|
2021-10-01 18:49:59 +00:00
|
|
|
|
2018-11-05 19:06:12 +00:00
|
|
|
mainWindow.webContents.send('get-ready-for-shutdown');
|
|
|
|
|
|
|
|
// We'll wait two minutes, then force the app to go down. This can happen if someone
|
|
|
|
// exits the app before we've set everything up in preload() (so the browser isn't
|
|
|
|
// yet listening for these events), or if there are a whole lot of stacked-up tasks.
|
|
|
|
// Note: two minutes is also our timeout for SQL tasks in data.js in the browser.
|
2024-07-24 00:31:40 +00:00
|
|
|
timeout = setTimeout(
|
|
|
|
() => {
|
|
|
|
getLogger().error(
|
|
|
|
'requestShutdown: Response never received; forcing shutdown.'
|
|
|
|
);
|
|
|
|
resolveFn();
|
|
|
|
},
|
|
|
|
2 * 60 * 1000
|
|
|
|
);
|
2018-11-05 19:06:12 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
try {
|
|
|
|
await request;
|
|
|
|
} catch (error) {
|
2022-11-22 18:43:43 +00:00
|
|
|
getLogger().error('requestShutdown error:', Errors.toLogFormat(error));
|
2018-11-05 19:06:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-04 20:53:54 +00:00
|
|
|
function getWindowDebugInfo() {
|
|
|
|
const windows = BrowserWindow.getAllWindows();
|
|
|
|
|
2024-07-08 23:41:26 +00:00
|
|
|
try {
|
|
|
|
return {
|
|
|
|
windowCount: windows.length,
|
|
|
|
mainWindowExists: windows.some(win => win === mainWindow),
|
|
|
|
mainWindowIsFullScreen: mainWindow?.isFullScreen(),
|
|
|
|
};
|
|
|
|
} catch {
|
|
|
|
return {
|
|
|
|
windowCount: 0,
|
|
|
|
mainWindowExists: false,
|
|
|
|
mainWindowIsFullScreen: false,
|
|
|
|
};
|
|
|
|
}
|
2023-12-04 20:53:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
app.on('before-quit', e => {
|
2021-10-01 18:49:59 +00:00
|
|
|
getLogger().info('before-quit event', {
|
|
|
|
readyForShutdown: windowState.readyForShutdown(),
|
2018-11-05 19:06:12 +00:00
|
|
|
shouldQuit: windowState.shouldQuit(),
|
2023-12-04 20:53:54 +00:00
|
|
|
hasEventBeenPrevented: e.defaultPrevented,
|
|
|
|
...getWindowDebugInfo(),
|
2018-11-05 19:06:12 +00:00
|
|
|
});
|
2019-02-20 01:32:44 +00:00
|
|
|
|
2022-01-25 00:18:53 +00:00
|
|
|
systemTrayService?.markShouldQuit();
|
2017-06-22 00:26:05 +00:00
|
|
|
windowState.markShouldQuit();
|
2017-04-22 22:58:50 +00:00
|
|
|
});
|
2017-06-22 00:26:05 +00:00
|
|
|
|
2023-12-04 20:53:54 +00:00
|
|
|
app.on('will-quit', e => {
|
|
|
|
getLogger().info('will-quit event', {
|
|
|
|
hasEventBeenPrevented: e.defaultPrevented,
|
|
|
|
...getWindowDebugInfo(),
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
app.on('quit', e => {
|
|
|
|
getLogger().info('quit event', {
|
|
|
|
hasEventBeenPrevented: e.defaultPrevented,
|
|
|
|
...getWindowDebugInfo(),
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-03-02 22:04:38 +00:00
|
|
|
// Quit when all windows are closed.
|
2018-01-08 21:19:25 +00:00
|
|
|
app.on('window-all-closed', () => {
|
2021-10-01 18:49:59 +00:00
|
|
|
getLogger().info('main process handling window-all-closed');
|
2017-03-02 22:04:38 +00:00
|
|
|
// On OS X it is common for applications and their menu bar
|
|
|
|
// to stay active until the user quits explicitly with Cmd + Q
|
2021-10-01 18:49:59 +00:00
|
|
|
const shouldAutoClose = !OS.isMacOS() || isTestEnvironment(getEnvironment());
|
2020-04-06 23:45:39 +00:00
|
|
|
|
|
|
|
// Only automatically quit if the main window has been created
|
|
|
|
// This is necessary because `window-all-closed` can be triggered by the
|
|
|
|
// "optimizing application" window closing
|
|
|
|
if (shouldAutoClose && mainWindowCreated) {
|
2018-01-08 21:19:25 +00:00
|
|
|
app.quit();
|
2017-03-02 22:04:38 +00:00
|
|
|
}
|
2018-01-08 21:19:25 +00:00
|
|
|
});
|
2017-03-02 22:04:38 +00:00
|
|
|
|
2018-01-08 21:19:25 +00:00
|
|
|
app.on('activate', () => {
|
2017-11-02 15:13:41 +00:00
|
|
|
if (!ready) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-03-02 22:04:38 +00:00
|
|
|
// On OS X it's common to re-create a window in the app when the
|
|
|
|
// dock icon is clicked and there are no other windows open.
|
2017-09-07 01:21:38 +00:00
|
|
|
if (mainWindow) {
|
2017-04-22 22:58:50 +00:00
|
|
|
mainWindow.show();
|
2017-09-07 01:21:38 +00:00
|
|
|
} else {
|
2022-12-21 18:41:48 +00:00
|
|
|
drop(createWindow());
|
2017-03-02 22:04:38 +00:00
|
|
|
}
|
2018-01-08 21:19:25 +00:00
|
|
|
});
|
2017-04-25 00:00:17 +00:00
|
|
|
|
2018-05-23 19:29:32 +00:00
|
|
|
// Defense in depth. We never intend to open webviews or windows. Prevent it completely.
|
2021-10-01 18:49:59 +00:00
|
|
|
app.on(
|
|
|
|
'web-contents-created',
|
|
|
|
(_createEvent: Electron.Event, contents: Electron.WebContents) => {
|
|
|
|
contents.on('will-attach-webview', attachEvent => {
|
|
|
|
attachEvent.preventDefault();
|
|
|
|
});
|
2022-12-15 21:31:43 +00:00
|
|
|
contents.setWindowOpenHandler(() => ({ action: 'deny' }));
|
2021-10-01 18:49:59 +00:00
|
|
|
}
|
|
|
|
);
|
2018-03-14 21:23:24 +00:00
|
|
|
|
2019-05-16 22:32:11 +00:00
|
|
|
app.setAsDefaultProtocolClient('sgnl');
|
2021-05-06 00:09:29 +00:00
|
|
|
app.setAsDefaultProtocolClient('signalcaptcha');
|
2022-03-21 21:19:37 +00:00
|
|
|
|
2023-08-14 23:28:47 +00:00
|
|
|
ipc.on(
|
|
|
|
'set-badge',
|
|
|
|
(_event: Electron.Event, badge: number | 'marked-unread') => {
|
|
|
|
if (badge === 'marked-unread') {
|
|
|
|
if (process.platform === 'darwin') {
|
|
|
|
// Will show a ● on macOS when undefined
|
|
|
|
app.setBadgeCount(undefined);
|
|
|
|
} else {
|
|
|
|
// All other OS's need a number
|
|
|
|
app.setBadgeCount(1);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
app.setBadgeCount(badge);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
2017-06-22 01:04:19 +00:00
|
|
|
|
New design for import/install, 'light' import (#2053)
- A new design for the import flow. It features:
- Icons at the top of every screen
- Gray background, blue buttons, thinner text
- Simpler copy
- A new design for the install flow. It features:
- Immediate entry into the QR code screen
- Animated dots to show that we're loading the QR code from the server
- Fewer screens: 1) QR 2) device name 3) sync-in-progress
- When not set up, the app opens directly into the install screen, which has been streamlined. The `--import` command-line argument will cause the app to open directly into the import flow.
- Support for two different flavors of builds - the normal build will open into the standard registration flow, and the import flavor will be exactly the same except during setup it will open directly into the import flow.
- A new design for the (dev-only) standalone registration view
- When these install sequences are active, the OS File menu has entries to allow you to switch the method of setup you'd like to use. These go away as soon as the first step is taken in any of these flows.
- The device name (chosen on initial setup) is now shown in the settings panel
- At the end of a light import, we hand off to the normal device link screen, starting at the QR code. On a full import, we remove the sensitive encryption information in the export to prevent conflicts on multiple imports.
- `Whisper.Backup.exportToDirectory()` takes an options object so you can tell it to do a light export.
- `Whisper.Backup.importFromDirectory()` takes an options object so you can force it to load only the light components found on disk. It also returns an object so you can tell whether a given import was a full import or light import.
- On start of import, we build a list of all the ids present in the messages, conversations, and groups stores in IndexedDB. This can take some time if a lot of data is in the database already, but it makes the subsequent deduplicated import very fast.
- Disappearing messages are now excluded when exporting
- Remove some TODOs in the tests
2018-02-22 18:40:32 +00:00
|
|
|
ipc.on('remove-setup-menu-items', () => {
|
|
|
|
setupMenu();
|
|
|
|
});
|
|
|
|
|
|
|
|
ipc.on('add-setup-menu-items', () => {
|
|
|
|
setupMenu({
|
|
|
|
includeSetup: true,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-09-06 20:04:31 +00:00
|
|
|
ipc.on('draw-attention', () => {
|
2019-10-10 18:51:16 +00:00
|
|
|
if (!mainWindow) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-02-01 20:01:25 +00:00
|
|
|
if (OS.isWindows() || OS.isLinux()) {
|
2019-09-06 20:04:31 +00:00
|
|
|
mainWindow.flashFrame(true);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-01-08 21:19:25 +00:00
|
|
|
ipc.on('restart', () => {
|
2021-10-01 18:49:59 +00:00
|
|
|
getLogger().info('Relaunching application');
|
2017-05-07 21:39:43 +00:00
|
|
|
app.relaunch();
|
|
|
|
app.quit();
|
|
|
|
});
|
2020-04-28 21:18:41 +00:00
|
|
|
ipc.on('shutdown', () => {
|
2024-09-08 23:26:12 +00:00
|
|
|
if (process.env.GENERATE_PRELOAD_CACHE) {
|
|
|
|
windowState.markReadyForShutdown();
|
|
|
|
}
|
2020-04-28 21:18:41 +00:00
|
|
|
app.quit();
|
|
|
|
});
|
2017-10-13 18:39:18 +00:00
|
|
|
|
2021-10-01 18:49:59 +00:00
|
|
|
ipc.on(
|
|
|
|
'set-auto-hide-menu-bar',
|
|
|
|
(_event: Electron.Event, autoHide: boolean) => {
|
|
|
|
if (mainWindow) {
|
|
|
|
mainWindow.autoHideMenuBar = autoHide;
|
|
|
|
}
|
2017-11-30 19:58:00 +00:00
|
|
|
}
|
2021-10-01 18:49:59 +00:00
|
|
|
);
|
2017-10-13 18:39:18 +00:00
|
|
|
|
2021-10-01 18:49:59 +00:00
|
|
|
ipc.on(
|
|
|
|
'set-menu-bar-visibility',
|
|
|
|
(_event: Electron.Event, visibility: boolean) => {
|
|
|
|
if (mainWindow) {
|
|
|
|
mainWindow.setMenuBarVisibility(visibility);
|
|
|
|
}
|
2017-11-30 19:58:00 +00:00
|
|
|
}
|
2021-10-01 18:49:59 +00:00
|
|
|
);
|
2017-11-21 23:23:18 +00:00
|
|
|
|
2024-05-06 21:48:31 +00:00
|
|
|
ipc.on(
|
|
|
|
'screen-share:status-change',
|
|
|
|
(_event: Electron.Event, status: ScreenShareStatus) => {
|
|
|
|
if (!screenShareWindow) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (status === ScreenShareStatus.Disconnected) {
|
|
|
|
screenShareWindow.close();
|
|
|
|
} else {
|
|
|
|
screenShareWindow.webContents.send('status-change', status);
|
|
|
|
}
|
2021-05-20 21:54:03 +00:00
|
|
|
}
|
2024-05-06 21:48:31 +00:00
|
|
|
);
|
2021-05-20 21:54:03 +00:00
|
|
|
|
|
|
|
ipc.on('stop-screen-share', () => {
|
|
|
|
if (mainWindow) {
|
|
|
|
mainWindow.webContents.send('stop-screen-share');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2024-09-20 01:03:44 +00:00
|
|
|
ipc.on(
|
|
|
|
'show-screen-share',
|
|
|
|
(_event: Electron.Event, sourceName: string | undefined) => {
|
|
|
|
drop(showScreenShareWindow(sourceName));
|
|
|
|
}
|
|
|
|
);
|
2021-05-20 21:54:03 +00:00
|
|
|
|
2021-10-01 18:49:59 +00:00
|
|
|
ipc.on('update-tray-icon', (_event: Electron.Event, unreadCount: number) => {
|
2021-06-29 17:18:03 +00:00
|
|
|
if (systemTrayService) {
|
|
|
|
systemTrayService.setUnreadCount(unreadCount);
|
2018-01-17 23:27:58 +00:00
|
|
|
}
|
|
|
|
});
|
2018-07-03 22:33:50 +00:00
|
|
|
|
|
|
|
// Debug Log-related IPC calls
|
|
|
|
|
|
|
|
ipc.on('show-debug-log', showDebugLogWindow);
|
2021-10-06 16:16:51 +00:00
|
|
|
ipc.on(
|
|
|
|
'show-debug-log-save-dialog',
|
|
|
|
async (_event: Electron.Event, logText: string) => {
|
|
|
|
const { filePath } = await dialog.showSaveDialog({
|
|
|
|
defaultPath: 'debuglog.txt',
|
2024-08-13 22:10:00 +00:00
|
|
|
showsTagField: false,
|
2021-10-06 16:16:51 +00:00
|
|
|
});
|
|
|
|
if (filePath) {
|
|
|
|
await writeFile(filePath, logText);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
2018-07-03 22:33:50 +00:00
|
|
|
|
|
|
|
// Permissions Popup-related IPC calls
|
|
|
|
|
2021-10-01 18:49:59 +00:00
|
|
|
ipc.handle(
|
2021-11-05 08:47:32 +00:00
|
|
|
'show-permissions-popup',
|
|
|
|
async (_event: Electron.Event, forCalling: boolean, forCamera: boolean) => {
|
2021-10-01 18:49:59 +00:00
|
|
|
try {
|
2021-11-05 08:47:32 +00:00
|
|
|
await showPermissionsPopupWindow(forCalling, forCamera);
|
2021-10-01 18:49:59 +00:00
|
|
|
} catch (error) {
|
|
|
|
getLogger().error(
|
2021-11-05 08:47:32 +00:00
|
|
|
'show-permissions-popup error:',
|
2022-11-22 18:43:43 +00:00
|
|
|
Errors.toLogFormat(error)
|
2021-10-01 18:49:59 +00:00
|
|
|
);
|
|
|
|
}
|
2020-06-04 18:16:19 +00:00
|
|
|
}
|
2021-10-01 18:49:59 +00:00
|
|
|
);
|
2018-07-03 22:33:50 +00:00
|
|
|
|
|
|
|
// Settings-related IPC calls
|
|
|
|
|
|
|
|
function addDarkOverlay() {
|
|
|
|
if (mainWindow && mainWindow.webContents) {
|
|
|
|
mainWindow.webContents.send('add-dark-overlay');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
function removeDarkOverlay() {
|
|
|
|
if (mainWindow && mainWindow.webContents) {
|
|
|
|
mainWindow.webContents.send('remove-dark-overlay');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ipc.on('show-settings', showSettingsWindow);
|
|
|
|
|
|
|
|
ipc.on('delete-all-data', () => {
|
2021-08-24 20:57:34 +00:00
|
|
|
if (settingsWindow) {
|
|
|
|
settingsWindow.close();
|
|
|
|
}
|
2018-07-03 22:33:50 +00:00
|
|
|
if (mainWindow && mainWindow.webContents) {
|
|
|
|
mainWindow.webContents.send('delete-all-data');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2023-04-07 16:42:12 +00:00
|
|
|
ipc.on('get-config', async event => {
|
|
|
|
const theme = await getResolvedThemeSetting();
|
|
|
|
|
2024-10-02 19:03:10 +00:00
|
|
|
const directoryConfig = safeParseLoose(directoryConfigSchema, {
|
2023-04-07 16:42:12 +00:00
|
|
|
directoryUrl: config.get<string | null>('directoryUrl') || undefined,
|
|
|
|
directoryMRENCLAVE:
|
|
|
|
config.get<string | null>('directoryMRENCLAVE') || undefined,
|
|
|
|
});
|
|
|
|
if (!directoryConfig.success) {
|
|
|
|
throw new Error(
|
|
|
|
`prepareUrl: Failed to parse renderer directory config ${JSON.stringify(
|
|
|
|
directoryConfig.error.flatten()
|
|
|
|
)}`
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2024-10-02 19:03:10 +00:00
|
|
|
const parsed = safeParseLoose(rendererConfigSchema, {
|
2023-04-07 16:42:12 +00:00
|
|
|
name: packageJson.productName,
|
2023-11-06 21:19:23 +00:00
|
|
|
availableLocales: getResolvedMessagesLocale().availableLocales,
|
2023-04-07 16:42:12 +00:00
|
|
|
resolvedTranslationsLocale: getResolvedMessagesLocale().name,
|
2023-04-20 17:03:43 +00:00
|
|
|
resolvedTranslationsLocaleDirection: getResolvedMessagesLocale().direction,
|
2023-07-31 16:23:19 +00:00
|
|
|
hourCyclePreference: getResolvedMessagesLocale().hourCyclePreference,
|
2023-04-07 16:42:12 +00:00
|
|
|
preferredSystemLocales: getPreferredSystemLocales(),
|
2023-11-07 01:02:13 +00:00
|
|
|
localeOverride: getLocaleOverride(),
|
2023-04-07 16:42:12 +00:00
|
|
|
version: app.getVersion(),
|
|
|
|
buildCreation: config.get<number>('buildCreation'),
|
|
|
|
buildExpiration: config.get<number>('buildExpiration'),
|
|
|
|
challengeUrl: config.get<string>('challengeUrl'),
|
|
|
|
serverUrl: config.get<string>('serverUrl'),
|
|
|
|
storageUrl: config.get<string>('storageUrl'),
|
|
|
|
updatesUrl: config.get<string>('updatesUrl'),
|
|
|
|
resourcesUrl: config.get<string>('resourcesUrl'),
|
2024-02-28 00:53:58 +00:00
|
|
|
cdnUrl0: config.get<string>('cdn.0'),
|
|
|
|
cdnUrl2: config.get<string>('cdn.2'),
|
|
|
|
cdnUrl3: config.get<string>('cdn.3'),
|
2023-04-07 16:42:12 +00:00
|
|
|
certificateAuthority: config.get<string>('certificateAuthority'),
|
2023-07-20 22:37:56 +00:00
|
|
|
environment:
|
|
|
|
!isTestEnvironment(getEnvironment()) && ciMode
|
2024-09-04 18:12:45 +00:00
|
|
|
? Environment.PackagedApp
|
2023-07-20 22:37:56 +00:00
|
|
|
: getEnvironment(),
|
2024-04-16 20:13:02 +00:00
|
|
|
isMockTestEnvironment: Boolean(process.env.MOCK_TEST),
|
2023-07-20 22:37:56 +00:00
|
|
|
ciMode,
|
2024-09-23 20:09:12 +00:00
|
|
|
devTools: defaultWebPrefs.devTools,
|
2024-02-28 00:53:58 +00:00
|
|
|
// Should be already computed and cached at this point
|
|
|
|
dnsFallback: await getDNSFallback(),
|
2024-04-11 17:06:54 +00:00
|
|
|
disableIPv6: DISABLE_IPV6,
|
2024-03-15 14:20:33 +00:00
|
|
|
ciBackupPath: config.get<string | null>('ciBackupPath') || undefined,
|
2024-09-12 23:48:27 +00:00
|
|
|
ciIsBackupIntegration: config.get<boolean>('ciIsBackupIntegration'),
|
2023-04-07 16:42:12 +00:00
|
|
|
nodeVersion: process.versions.node,
|
|
|
|
hostname: os.hostname(),
|
2023-04-20 21:23:19 +00:00
|
|
|
osRelease: os.release(),
|
|
|
|
osVersion: os.version(),
|
2023-04-07 16:42:12 +00:00
|
|
|
appInstance: process.env.NODE_APP_INSTANCE || undefined,
|
|
|
|
proxyUrl: process.env.HTTPS_PROXY || process.env.https_proxy || undefined,
|
|
|
|
contentProxyUrl: config.get<string>('contentProxyUrl'),
|
|
|
|
sfuUrl: config.get('sfuUrl'),
|
2023-07-26 22:23:32 +00:00
|
|
|
reducedMotionSetting: DISABLE_GPU || animationSettings.prefersReducedMotion,
|
2023-04-07 16:42:12 +00:00
|
|
|
registrationChallengeUrl: config.get<string>('registrationChallengeUrl'),
|
|
|
|
serverPublicParams: config.get<string>('serverPublicParams'),
|
|
|
|
serverTrustRoot: config.get<string>('serverTrustRoot'),
|
2024-02-22 21:19:50 +00:00
|
|
|
genericServerPublicParams: config.get<string>('genericServerPublicParams'),
|
2024-04-22 21:25:56 +00:00
|
|
|
backupServerPublicParams: config.get<string>('backupServerPublicParams'),
|
2023-04-07 16:42:12 +00:00
|
|
|
theme,
|
|
|
|
appStartInitialSpellcheckSetting,
|
2023-08-01 16:06:29 +00:00
|
|
|
|
|
|
|
// paths
|
2023-04-07 16:42:12 +00:00
|
|
|
crashDumpsPath: app.getPath('crashDumps'),
|
2023-08-01 16:06:29 +00:00
|
|
|
homePath: app.getPath('home'),
|
|
|
|
installPath: app.getAppPath(),
|
|
|
|
userDataPath: app.getPath('userData'),
|
2023-04-07 16:42:12 +00:00
|
|
|
|
|
|
|
directoryConfig: directoryConfig.data,
|
|
|
|
|
|
|
|
// Only used by the main window
|
|
|
|
isMainWindowFullScreen: Boolean(mainWindow?.isFullScreen()),
|
|
|
|
isMainWindowMaximized: Boolean(mainWindow?.isMaximized()),
|
|
|
|
|
|
|
|
// Only for tests
|
|
|
|
argv: JSON.stringify(process.argv),
|
|
|
|
} satisfies RendererConfigType);
|
|
|
|
|
|
|
|
if (!parsed.success) {
|
|
|
|
throw new Error(
|
|
|
|
`prepareUrl: Failed to parse renderer config ${JSON.stringify(
|
|
|
|
parsed.error.flatten()
|
|
|
|
)}`
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// eslint-disable-next-line no-param-reassign
|
|
|
|
event.returnValue = parsed.data;
|
|
|
|
});
|
|
|
|
|
2020-03-25 23:45:37 +00:00
|
|
|
// Ingested in preload.js via a sendSync call
|
|
|
|
ipc.on('locale-data', event => {
|
|
|
|
// eslint-disable-next-line no-param-reassign
|
2023-01-25 00:54:46 +00:00
|
|
|
event.returnValue = getResolvedMessagesLocale().messages;
|
2020-03-25 23:45:37 +00:00
|
|
|
});
|
|
|
|
|
2023-11-08 20:39:56 +00:00
|
|
|
// Ingested in preload.js via a sendSync call
|
|
|
|
ipc.on('locale-display-names', event => {
|
|
|
|
// eslint-disable-next-line no-param-reassign
|
|
|
|
event.returnValue = getResolvedMessagesLocale().localeDisplayNames;
|
|
|
|
});
|
|
|
|
|
2024-02-08 23:19:03 +00:00
|
|
|
// Ingested in preload.js via a sendSync call
|
|
|
|
ipc.on('country-display-names', event => {
|
|
|
|
// eslint-disable-next-line no-param-reassign
|
|
|
|
event.returnValue = getResolvedMessagesLocale().countryDisplayNames;
|
|
|
|
});
|
|
|
|
|
2023-04-20 21:23:19 +00:00
|
|
|
// TODO DESKTOP-5241
|
|
|
|
ipc.on('OS.getClassName', event => {
|
|
|
|
// eslint-disable-next-line no-param-reassign
|
|
|
|
event.returnValue = OS.getClassName();
|
|
|
|
});
|
|
|
|
|
|
|
|
ipc.handle(
|
|
|
|
'DebugLogs.getLogs',
|
|
|
|
async (_event, data: unknown, userAgent: string) => {
|
|
|
|
return debugLog.getLog(
|
|
|
|
data,
|
|
|
|
process.versions.node,
|
|
|
|
app.getVersion(),
|
|
|
|
os.version(),
|
2023-09-06 01:03:30 +00:00
|
|
|
userAgent,
|
2024-10-29 22:29:30 +00:00
|
|
|
process.arch,
|
|
|
|
app.runningUnderARM64Translation,
|
2023-09-06 01:03:30 +00:00
|
|
|
OS.getLinuxName()
|
2023-04-20 21:23:19 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
ipc.handle('DebugLogs.upload', async (_event, content: string) => {
|
|
|
|
return uploadDebugLog.upload({
|
|
|
|
content,
|
|
|
|
appVersion: app.getVersion(),
|
|
|
|
logger: getLogger(),
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-03-04 21:44:57 +00:00
|
|
|
ipc.on('get-user-data-path', event => {
|
|
|
|
// eslint-disable-next-line no-param-reassign
|
|
|
|
event.returnValue = app.getPath('userData');
|
|
|
|
});
|
|
|
|
|
2021-08-18 20:08:14 +00:00
|
|
|
// Refresh the settings window whenever preferences change
|
2024-03-07 17:36:08 +00:00
|
|
|
const sendPreferencesChangedEventToWindows = () => {
|
2021-09-29 18:37:30 +00:00
|
|
|
for (const window of activeWindows) {
|
|
|
|
if (window.webContents) {
|
|
|
|
window.webContents.send('preferences-changed');
|
|
|
|
}
|
2021-08-18 20:08:14 +00:00
|
|
|
}
|
2024-03-07 17:36:08 +00:00
|
|
|
};
|
|
|
|
ipc.on('preferences-changed', sendPreferencesChangedEventToWindows);
|
2019-05-16 22:32:11 +00:00
|
|
|
|
2023-11-02 19:42:31 +00:00
|
|
|
function maybeGetIncomingSignalRoute(argv: Array<string>) {
|
|
|
|
for (const arg of argv) {
|
|
|
|
const route = parseSignalRoute(arg);
|
|
|
|
if (route != null) {
|
|
|
|
return route;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
2021-05-06 00:09:29 +00:00
|
|
|
}
|
|
|
|
|
2023-11-02 19:42:31 +00:00
|
|
|
function handleSignalRoute(route: ParsedSignalRoute) {
|
|
|
|
const log = getLogger();
|
2021-02-10 22:39:26 +00:00
|
|
|
|
2023-11-02 19:42:31 +00:00
|
|
|
if (mainWindow == null || !mainWindow.webContents) {
|
|
|
|
log.error('handleSignalRoute: mainWindow is null or missing webContents');
|
|
|
|
return;
|
2021-02-10 22:39:26 +00:00
|
|
|
}
|
|
|
|
|
2023-11-02 19:42:31 +00:00
|
|
|
log.info('handleSignalRoute: Matched signal route:', route.key);
|
|
|
|
|
|
|
|
if (route.key === 'artAddStickers') {
|
|
|
|
mainWindow.webContents.send('show-sticker-pack', {
|
|
|
|
packId: route.args.packId,
|
|
|
|
packKey: Buffer.from(route.args.packKey, 'hex').toString('base64'),
|
|
|
|
});
|
|
|
|
} else if (route.key === 'groupInvites') {
|
|
|
|
mainWindow.webContents.send('show-group-via-link', {
|
|
|
|
value: route.args.inviteCode,
|
|
|
|
});
|
|
|
|
} else if (route.key === 'contactByPhoneNumber') {
|
|
|
|
mainWindow.webContents.send('show-conversation-via-signal.me', {
|
|
|
|
kind: 'phoneNumber',
|
|
|
|
value: route.args.phoneNumber,
|
|
|
|
});
|
|
|
|
} else if (route.key === 'contactByEncryptedUsername') {
|
|
|
|
mainWindow.webContents.send('show-conversation-via-signal.me', {
|
|
|
|
kind: 'encryptedUsername',
|
|
|
|
value: route.args.encryptedUsername,
|
|
|
|
});
|
|
|
|
} else if (route.key === 'showConversation') {
|
|
|
|
mainWindow.webContents.send('show-conversation-via-notification', {
|
|
|
|
conversationId: route.args.conversationId,
|
|
|
|
messageId: route.args.messageId,
|
|
|
|
storyId: route.args.storyId,
|
|
|
|
});
|
|
|
|
} else if (route.key === 'startCallLobby') {
|
|
|
|
mainWindow.webContents.send('start-call-lobby', {
|
|
|
|
conversationId: route.args.conversationId,
|
|
|
|
});
|
2024-02-22 21:19:50 +00:00
|
|
|
} else if (route.key === 'linkCall') {
|
|
|
|
mainWindow.webContents.send('start-call-link', {
|
|
|
|
key: route.args.key,
|
|
|
|
});
|
2023-11-02 19:42:31 +00:00
|
|
|
} else if (route.key === 'showWindow') {
|
|
|
|
mainWindow.webContents.send('show-window');
|
2024-09-20 01:03:44 +00:00
|
|
|
} else if (route.key === 'cancelPresenting') {
|
|
|
|
mainWindow.webContents.send('cancel-presenting');
|
2023-11-02 19:42:31 +00:00
|
|
|
} else if (route.key === 'captcha') {
|
|
|
|
challengeHandler.handleCaptcha(route.args.captchaId);
|
|
|
|
// Show window after handling captcha
|
|
|
|
showWindow();
|
2019-05-16 22:32:11 +00:00
|
|
|
} else {
|
2023-11-02 19:42:31 +00:00
|
|
|
log.info('handleSignalRoute: Unknown signal route:', route.key);
|
|
|
|
mainWindow.webContents.send('unknown-sgnl-link');
|
2019-05-16 22:32:11 +00:00
|
|
|
}
|
|
|
|
}
|
2019-12-17 20:25:57 +00:00
|
|
|
|
2023-04-20 15:59:17 +00:00
|
|
|
ipc.handle('install-sticker-pack', (_event, packId, packKeyHex) => {
|
2019-12-17 20:25:57 +00:00
|
|
|
const packKey = Buffer.from(packKeyHex, 'hex').toString('base64');
|
2021-10-01 18:49:59 +00:00
|
|
|
if (mainWindow) {
|
|
|
|
mainWindow.webContents.send('install-sticker-pack', { packId, packKey });
|
|
|
|
}
|
2019-12-17 20:25:57 +00:00
|
|
|
});
|
2020-02-21 23:40:04 +00:00
|
|
|
|
2022-11-17 00:29:15 +00:00
|
|
|
ipc.handle('ensure-file-permissions', () => ensureFilePermissions());
|
2020-02-21 23:40:04 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Ensure files in the user's data directory have the proper permissions.
|
|
|
|
* Optionally takes an array of file paths to exclusively affect.
|
|
|
|
*
|
|
|
|
* @param {string[]} [onlyFiles] - Only ensure permissions on these given files
|
|
|
|
*/
|
2021-10-01 18:49:59 +00:00
|
|
|
async function ensureFilePermissions(onlyFiles?: Array<string>) {
|
|
|
|
getLogger().info('Begin ensuring permissions');
|
2020-02-21 23:40:04 +00:00
|
|
|
|
|
|
|
const start = Date.now();
|
2022-01-11 20:02:46 +00:00
|
|
|
const userDataPath = await realpath(app.getPath('userData'));
|
2020-02-21 23:40:04 +00:00
|
|
|
// fast-glob uses `/` for all platforms
|
2021-10-01 18:49:59 +00:00
|
|
|
const userDataGlob = normalizePath(join(userDataPath, '**', '*'));
|
2020-02-21 23:40:04 +00:00
|
|
|
|
|
|
|
// Determine files to touch
|
|
|
|
const files = onlyFiles
|
2021-10-01 18:49:59 +00:00
|
|
|
? onlyFiles.map(f => join(userDataPath, f))
|
|
|
|
: await fastGlob(userDataGlob, {
|
2020-02-21 23:40:04 +00:00
|
|
|
markDirectories: true,
|
|
|
|
onlyFiles: false,
|
|
|
|
ignore: ['**/Singleton*'],
|
|
|
|
});
|
|
|
|
|
2021-10-01 18:49:59 +00:00
|
|
|
getLogger().info(`Ensuring file permissions for ${files.length} files`);
|
2020-02-21 23:40:04 +00:00
|
|
|
|
|
|
|
// Touch each file in a queue
|
2020-09-18 20:40:41 +00:00
|
|
|
const q = new PQueue({ concurrency: 5, timeout: 1000 * 60 * 2 });
|
2022-12-21 18:41:48 +00:00
|
|
|
drop(
|
|
|
|
q.addAll(
|
|
|
|
files.map(f => async () => {
|
|
|
|
const isDir = f.endsWith('/');
|
|
|
|
try {
|
|
|
|
await chmod(normalize(f), isDir ? 0o700 : 0o600);
|
|
|
|
} catch (error) {
|
|
|
|
getLogger().error(
|
|
|
|
'ensureFilePermissions: Error from chmod',
|
|
|
|
error.message
|
|
|
|
);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
)
|
2020-02-21 23:40:04 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
await q.onEmpty();
|
|
|
|
|
2021-10-01 18:49:59 +00:00
|
|
|
getLogger().info(`Finish ensuring permissions in ${Date.now() - start}ms`);
|
2020-02-21 23:40:04 +00:00
|
|
|
}
|
2021-10-27 17:54:16 +00:00
|
|
|
|
2023-11-01 18:03:08 +00:00
|
|
|
ipc.handle('get-media-access-status', async (_event, value) => {
|
|
|
|
// This function is not supported on Linux
|
|
|
|
if (!systemPreferences.getMediaAccessStatus) {
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
return systemPreferences.getMediaAccessStatus(value);
|
|
|
|
});
|
|
|
|
|
2021-10-27 17:54:16 +00:00
|
|
|
ipc.handle('get-auto-launch', async () => {
|
2022-09-06 22:09:52 +00:00
|
|
|
return app.getLoginItemSettings(await getDefaultLoginItemSettings())
|
|
|
|
.openAtLogin;
|
2021-10-27 17:54:16 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
ipc.handle('set-auto-launch', async (_event, value) => {
|
2022-09-06 22:09:52 +00:00
|
|
|
const openAtLogin = Boolean(value);
|
|
|
|
getLogger().info('set-auto-launch: new value', openAtLogin);
|
|
|
|
app.setLoginItemSettings({
|
|
|
|
...(await getDefaultLoginItemSettings()),
|
|
|
|
openAtLogin,
|
|
|
|
});
|
2021-10-27 17:54:16 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
ipc.on('show-message-box', (_event, { type, message }) => {
|
2022-12-21 18:41:48 +00:00
|
|
|
drop(dialog.showMessageBox({ type, message }));
|
2021-10-27 17:54:16 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
ipc.on('show-item-in-folder', (_event, folder) => {
|
|
|
|
shell.showItemInFolder(folder);
|
|
|
|
});
|
|
|
|
|
|
|
|
ipc.handle('show-save-dialog', async (_event, { defaultPath }) => {
|
|
|
|
if (!mainWindow) {
|
|
|
|
getLogger().warn('show-save-dialog: no main window');
|
|
|
|
|
|
|
|
return { canceled: true };
|
|
|
|
}
|
|
|
|
|
2023-06-14 20:55:07 +00:00
|
|
|
const { canceled, filePath: selectedFilePath } = await dialog.showSaveDialog(
|
|
|
|
mainWindow,
|
2024-08-13 22:10:00 +00:00
|
|
|
{
|
|
|
|
defaultPath,
|
|
|
|
showsTagField: false,
|
|
|
|
}
|
2023-06-14 20:55:07 +00:00
|
|
|
);
|
|
|
|
if (canceled || selectedFilePath == null) {
|
|
|
|
return { canceled: true };
|
|
|
|
}
|
|
|
|
|
|
|
|
// On Windows, if you change the path from the default, the extension is
|
|
|
|
// removed. We want to make sure the extension is always there.
|
|
|
|
const defaultExt = extname(defaultPath);
|
|
|
|
const finalDirname = dirname(selectedFilePath);
|
|
|
|
const finalBasename = basename(selectedFilePath, defaultExt);
|
|
|
|
const finalFilePath = join(finalDirname, `${finalBasename}${defaultExt}`);
|
|
|
|
|
|
|
|
return { canceled: false, filePath: finalFilePath };
|
2021-10-27 17:54:16 +00:00
|
|
|
});
|
2021-12-09 08:06:04 +00:00
|
|
|
|
2024-10-23 21:44:12 +00:00
|
|
|
ipc.handle('show-save-multi-dialog', async _event => {
|
|
|
|
if (!mainWindow) {
|
|
|
|
getLogger().warn('show-save-multi-dialog: no main window');
|
|
|
|
|
|
|
|
return { canceled: true };
|
|
|
|
}
|
|
|
|
const { canceled, filePaths: selectedDirPaths } = await dialog.showOpenDialog(
|
|
|
|
mainWindow,
|
|
|
|
{
|
|
|
|
defaultPath: app.getPath('downloads'),
|
|
|
|
properties: ['openDirectory', 'createDirectory'],
|
|
|
|
}
|
|
|
|
);
|
|
|
|
if (canceled || selectedDirPaths.length === 0) {
|
|
|
|
return { canceled: true };
|
|
|
|
}
|
|
|
|
|
|
|
|
if (selectedDirPaths.length > 1) {
|
|
|
|
getLogger().warn('show-save-multi-dialog: multiple directories selected');
|
|
|
|
|
|
|
|
return { canceled: true };
|
|
|
|
}
|
|
|
|
|
|
|
|
return { canceled: false, dirPath: selectedDirPaths[0] };
|
|
|
|
});
|
|
|
|
|
2022-06-08 22:00:32 +00:00
|
|
|
ipc.handle('executeMenuRole', async ({ sender }, untypedRole) => {
|
|
|
|
const role = untypedRole as MenuItemConstructorOptions['role'];
|
|
|
|
|
|
|
|
const senderWindow = BrowserWindow.fromWebContents(sender);
|
|
|
|
|
|
|
|
switch (role) {
|
|
|
|
case 'undo':
|
|
|
|
sender.undo();
|
|
|
|
break;
|
|
|
|
case 'redo':
|
|
|
|
sender.redo();
|
|
|
|
break;
|
|
|
|
case 'cut':
|
|
|
|
sender.cut();
|
|
|
|
break;
|
|
|
|
case 'copy':
|
|
|
|
sender.copy();
|
|
|
|
break;
|
|
|
|
case 'paste':
|
|
|
|
sender.paste();
|
|
|
|
break;
|
|
|
|
case 'pasteAndMatchStyle':
|
|
|
|
sender.pasteAndMatchStyle();
|
|
|
|
break;
|
|
|
|
case 'delete':
|
|
|
|
sender.delete();
|
|
|
|
break;
|
|
|
|
case 'selectAll':
|
|
|
|
sender.selectAll();
|
|
|
|
break;
|
|
|
|
case 'reload':
|
|
|
|
sender.reload();
|
|
|
|
break;
|
|
|
|
case 'toggleDevTools':
|
|
|
|
sender.toggleDevTools();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'togglefullscreen':
|
|
|
|
senderWindow?.setFullScreen(!senderWindow?.isFullScreen());
|
|
|
|
break;
|
|
|
|
case 'minimize':
|
|
|
|
senderWindow?.minimize();
|
|
|
|
break;
|
|
|
|
case 'close':
|
|
|
|
senderWindow?.close();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'quit':
|
|
|
|
app.quit();
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
// ignored
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
ipc.handle('getMainWindowStats', async () => {
|
|
|
|
return {
|
|
|
|
isMaximized: windowConfig?.maximized ?? false,
|
|
|
|
isFullScreen: windowConfig?.fullscreen ?? false,
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
ipc.handle('getMenuOptions', async () => {
|
|
|
|
return {
|
|
|
|
development: menuOptions?.development ?? false,
|
|
|
|
devTools: menuOptions?.devTools ?? false,
|
|
|
|
includeSetup: menuOptions?.includeSetup ?? false,
|
|
|
|
isProduction: menuOptions?.isProduction ?? true,
|
|
|
|
platform: menuOptions?.platform ?? 'unknown',
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
2023-12-22 20:27:49 +00:00
|
|
|
async function zoomIn() {
|
|
|
|
await zoomFactorService.zoomIn();
|
|
|
|
}
|
|
|
|
|
|
|
|
async function zoomOut() {
|
|
|
|
await zoomFactorService.zoomOut();
|
|
|
|
}
|
|
|
|
|
|
|
|
async function zoomReset() {
|
|
|
|
await zoomFactorService.zoomReset();
|
|
|
|
}
|
|
|
|
|
2023-05-30 23:57:16 +00:00
|
|
|
ipc.handle(
|
|
|
|
'net.resolveHost',
|
|
|
|
(_event, hostname: string, queryType?: 'A' | 'AAAA') => {
|
|
|
|
return net.resolveHost(hostname, {
|
|
|
|
queryType,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2023-04-20 15:59:17 +00:00
|
|
|
let stickerCreatorWindow: BrowserWindow | undefined;
|
|
|
|
async function showStickerCreatorWindow() {
|
|
|
|
if (stickerCreatorWindow) {
|
|
|
|
stickerCreatorWindow.show();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const { x = 0, y = 0 } = windowConfig || {};
|
|
|
|
|
|
|
|
const options = {
|
|
|
|
x: x + 100,
|
|
|
|
y: y + 100,
|
|
|
|
width: 800,
|
|
|
|
minWidth: 800,
|
|
|
|
height: 815,
|
|
|
|
minHeight: 750,
|
|
|
|
frame: true,
|
|
|
|
title: getResolvedMessagesLocale().i18n('icu:signalDesktopStickerCreator'),
|
|
|
|
autoHideMenuBar: true,
|
|
|
|
backgroundColor: await getBackgroundColor(),
|
|
|
|
show: false,
|
|
|
|
webPreferences: {
|
|
|
|
...defaultWebPrefs,
|
|
|
|
nodeIntegration: false,
|
|
|
|
nodeIntegrationInWorker: false,
|
|
|
|
sandbox: true,
|
|
|
|
contextIsolation: true,
|
|
|
|
preload: join(__dirname, '../ts/windows/sticker-creator/preload.js'),
|
|
|
|
nativeWindowOpen: true,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
stickerCreatorWindow = new BrowserWindow(options);
|
|
|
|
|
2023-12-22 20:27:49 +00:00
|
|
|
await handleCommonWindowEvents(stickerCreatorWindow);
|
2023-04-20 15:59:17 +00:00
|
|
|
|
|
|
|
stickerCreatorWindow.once('ready-to-show', () => {
|
|
|
|
stickerCreatorWindow?.show();
|
|
|
|
});
|
|
|
|
|
|
|
|
stickerCreatorWindow.on('closed', () => {
|
|
|
|
stickerCreatorWindow = undefined;
|
|
|
|
});
|
|
|
|
|
|
|
|
await safeLoadURL(
|
|
|
|
stickerCreatorWindow,
|
|
|
|
await prepareFileUrl([__dirname, '../sticker-creator/dist/index.html'])
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-12-09 08:06:04 +00:00
|
|
|
if (isTestEnvironment(getEnvironment())) {
|
2024-06-28 00:22:06 +00:00
|
|
|
ipc.on('ci:test-electron:getArgv', event => {
|
|
|
|
// eslint-disable-next-line no-param-reassign
|
|
|
|
event.returnValue = process.argv;
|
2023-10-04 00:12:57 +00:00
|
|
|
});
|
|
|
|
|
2024-07-02 19:56:40 +00:00
|
|
|
ipc.handle('ci:test-electron:debug', async (_event, info) => {
|
|
|
|
process.stdout.write(`ci:test-electron:debug=${JSON.stringify(info)}\n`);
|
|
|
|
});
|
|
|
|
|
2024-06-28 00:22:06 +00:00
|
|
|
ipc.handle('ci:test-electron:event', async (_event, event) => {
|
2021-12-09 08:06:04 +00:00
|
|
|
process.stdout.write(
|
2024-06-28 00:22:06 +00:00
|
|
|
`ci:test-electron:event=${JSON.stringify(event)}\n`,
|
|
|
|
() => {
|
|
|
|
if (event.type !== 'end') {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!process.env.TEST_QUIT_ON_COMPLETE) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
app.quit();
|
|
|
|
}
|
2021-12-09 08:06:04 +00:00
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|