Simplify spellcheck download URL, disable spellcheck in most windows
This commit is contained in:
parent
ab9d33cf1a
commit
1c43e7501c
|
@ -122,12 +122,6 @@ const typescriptRules = {
|
|||
'error',
|
||||
{
|
||||
paths: [
|
||||
{
|
||||
name: 'electron',
|
||||
importNames: ['BrowserWindow'],
|
||||
message: 'Please use createBrowserWindow',
|
||||
allowTypeImports: true,
|
||||
},
|
||||
{
|
||||
name: 'chai',
|
||||
importNames: ['expect', 'should', 'Should'],
|
||||
|
|
28
app/main.ts
28
app/main.ts
|
@ -1,4 +1,4 @@
|
|||
// Copyright 2017-2021 Signal Messenger, LLC
|
||||
// Copyright 2017-2022 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import { join, normalize } from 'path';
|
||||
|
@ -11,19 +11,20 @@ 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 type { BrowserWindow } from 'electron';
|
||||
import {
|
||||
app,
|
||||
BrowserWindow,
|
||||
clipboard,
|
||||
desktopCapturer,
|
||||
dialog,
|
||||
ipcMain as ipc,
|
||||
Menu,
|
||||
powerSaveBlocker,
|
||||
protocol as electronProtocol,
|
||||
screen,
|
||||
session,
|
||||
shell,
|
||||
systemPreferences,
|
||||
desktopCapturer,
|
||||
} from 'electron';
|
||||
import { z } from 'zod';
|
||||
|
||||
|
@ -55,6 +56,7 @@ 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';
|
||||
import { updateDefaultSession } from './updateDefaultSession';
|
||||
import { PreventDisplaySleepService } from './PreventDisplaySleepService';
|
||||
import { SystemTrayService } from './SystemTrayService';
|
||||
import { SystemTraySettingCache } from './SystemTraySettingCache';
|
||||
|
@ -72,7 +74,6 @@ import type { MenuOptionsType } from './menu';
|
|||
import { createTemplate } from './menu';
|
||||
import { installFileHandler, installWebHandler } from './protocol_filter';
|
||||
import * as OS from '../ts/OS';
|
||||
import { createBrowserWindow } from '../ts/util/createBrowserWindow';
|
||||
import { isProduction, isAlpha } from '../ts/util/version';
|
||||
import {
|
||||
isSgnlHref,
|
||||
|
@ -137,6 +138,7 @@ const defaultWebPrefs = {
|
|||
process.argv.some(arg => arg === '--enable-dev-tools') ||
|
||||
getEnvironment() !== Environment.Production ||
|
||||
!isProduction(app.getVersion()),
|
||||
spellcheck: false,
|
||||
};
|
||||
|
||||
function showWindow() {
|
||||
|
@ -529,7 +531,7 @@ async function createWindow() {
|
|||
);
|
||||
|
||||
// Create the browser window.
|
||||
mainWindow = createBrowserWindow(windowOptions);
|
||||
mainWindow = new BrowserWindow(windowOptions);
|
||||
if (settingsChannel) {
|
||||
settingsChannel.setMainWindow(mainWindow);
|
||||
}
|
||||
|
@ -965,7 +967,7 @@ function showScreenShareWindow(sourceName: string) {
|
|||
y: 24,
|
||||
};
|
||||
|
||||
screenShareWindow = createBrowserWindow(options);
|
||||
screenShareWindow = new BrowserWindow(options);
|
||||
|
||||
handleCommonWindowEvents(screenShareWindow);
|
||||
|
||||
|
@ -1011,7 +1013,7 @@ function showAbout() {
|
|||
},
|
||||
};
|
||||
|
||||
aboutWindow = createBrowserWindow(options);
|
||||
aboutWindow = new BrowserWindow(options);
|
||||
|
||||
handleCommonWindowEvents(aboutWindow);
|
||||
|
||||
|
@ -1054,7 +1056,7 @@ function showSettingsWindow() {
|
|||
},
|
||||
};
|
||||
|
||||
settingsWindow = createBrowserWindow(options);
|
||||
settingsWindow = new BrowserWindow(options);
|
||||
|
||||
handleCommonWindowEvents(settingsWindow);
|
||||
|
||||
|
@ -1125,7 +1127,7 @@ async function showStickerCreator() {
|
|||
},
|
||||
};
|
||||
|
||||
stickerCreatorWindow = createBrowserWindow(options);
|
||||
stickerCreatorWindow = new BrowserWindow(options);
|
||||
setupSpellChecker(stickerCreatorWindow, getLocale());
|
||||
|
||||
handleCommonWindowEvents(stickerCreatorWindow);
|
||||
|
@ -1190,7 +1192,7 @@ async function showDebugLogWindow() {
|
|||
fullscreenable: !OS.isMacOS(),
|
||||
};
|
||||
|
||||
debugLogWindow = createBrowserWindow(options);
|
||||
debugLogWindow = new BrowserWindow(options);
|
||||
|
||||
handleCommonWindowEvents(debugLogWindow);
|
||||
|
||||
|
@ -1250,7 +1252,7 @@ function showPermissionsPopupWindow(forCalling: boolean, forCamera: boolean) {
|
|||
parent: mainWindow,
|
||||
};
|
||||
|
||||
permissionsPopupWindow = createBrowserWindow(options);
|
||||
permissionsPopupWindow = new BrowserWindow(options);
|
||||
|
||||
handleCommonWindowEvents(permissionsPopupWindow);
|
||||
|
||||
|
@ -1392,6 +1394,8 @@ function getAppLocale(): string {
|
|||
// Some APIs can only be used after this event occurs.
|
||||
let ready = false;
|
||||
app.on('ready', async () => {
|
||||
updateDefaultSession(session.defaultSession);
|
||||
|
||||
const [userDataPath, crashDumpsPath] = await Promise.all([
|
||||
realpath(app.getPath('userData')),
|
||||
realpath(app.getPath('crashDumps')),
|
||||
|
@ -1496,7 +1500,7 @@ app.on('ready', async () => {
|
|||
'sql.initialize is taking more than three seconds; showing loading dialog'
|
||||
);
|
||||
|
||||
loadingWindow = createBrowserWindow({
|
||||
loadingWindow = new BrowserWindow({
|
||||
show: false,
|
||||
width: 300,
|
||||
height: 265,
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
// Copyright 2022 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import type { Session } from 'electron';
|
||||
|
||||
const SPELL_CHECKER_DICTIONARY_DOWNLOAD_URL = `https://updates.signal.org/desktop/hunspell_dictionaries/${process.versions.electron}/`;
|
||||
|
||||
export function updateDefaultSession(session: Session): void {
|
||||
session.setSpellCheckerDictionaryDownloadURL(
|
||||
SPELL_CHECKER_DICTIONARY_DOWNLOAD_URL
|
||||
);
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
// Copyright 2022 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import * as sinon from 'sinon';
|
||||
import { session } from 'electron';
|
||||
import { v4 as uuid } from 'uuid';
|
||||
|
||||
import { updateDefaultSession } from '../../../app/updateDefaultSession';
|
||||
|
||||
describe('updateDefaultSession', () => {
|
||||
let sandbox: sinon.SinonSandbox;
|
||||
|
||||
beforeEach(() => {
|
||||
sandbox = sinon.createSandbox();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
sandbox.restore();
|
||||
});
|
||||
|
||||
it('sets the spellcheck URL', () => {
|
||||
const sesh = session.fromPartition(uuid());
|
||||
const stub = sandbox.stub(sesh, 'setSpellCheckerDictionaryDownloadURL');
|
||||
|
||||
updateDefaultSession(sesh);
|
||||
|
||||
sinon.assert.calledOnce(stub);
|
||||
sinon.assert.calledWith(
|
||||
stub,
|
||||
`https://updates.signal.org/desktop/hunspell_dictionaries/${process.versions.electron}/`
|
||||
);
|
||||
});
|
||||
});
|
|
@ -1,14 +0,0 @@
|
|||
// Copyright 2021 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import { assert } from 'chai';
|
||||
import { BrowserWindow } from 'electron';
|
||||
|
||||
import { createBrowserWindow } from '../../util/createBrowserWindow';
|
||||
|
||||
describe('createBrowserWindow', () => {
|
||||
it('returns a BrowserWindow', () => {
|
||||
const result = createBrowserWindow({ show: false });
|
||||
assert.instanceOf(result, BrowserWindow);
|
||||
});
|
||||
});
|
|
@ -1,25 +0,0 @@
|
|||
// Copyright 2021 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
// This is the one place that *should* be able to import `BrowserWindow`.
|
||||
// eslint-disable-next-line @typescript-eslint/no-restricted-imports
|
||||
import { BrowserWindow } from 'electron';
|
||||
import type { BrowserWindowConstructorOptions } from 'electron';
|
||||
|
||||
const SPELL_CHECKER_DICTIONARY_DOWNLOAD_URL = `https://updates.signal.org/desktop/hunspell_dictionaries/${process.versions.electron}/`;
|
||||
|
||||
/**
|
||||
* A wrapper around `new BrowserWindow` that updates the spell checker download URL. This
|
||||
* function should be used instead of `new BrowserWindow`.
|
||||
*/
|
||||
export function createBrowserWindow(
|
||||
options: BrowserWindowConstructorOptions
|
||||
): BrowserWindow {
|
||||
const result = new BrowserWindow(options);
|
||||
|
||||
result.webContents.session.setSpellCheckerDictionaryDownloadURL(
|
||||
SPELL_CHECKER_DICTIONARY_DOWNLOAD_URL
|
||||
);
|
||||
|
||||
return result;
|
||||
}
|
Loading…
Reference in New Issue