Simplify spellcheck download URL, disable spellcheck in most windows
This commit is contained in:
parent
ab9d33cf1a
commit
1c43e7501c
6 changed files with 61 additions and 57 deletions
|
@ -122,12 +122,6 @@ const typescriptRules = {
|
||||||
'error',
|
'error',
|
||||||
{
|
{
|
||||||
paths: [
|
paths: [
|
||||||
{
|
|
||||||
name: 'electron',
|
|
||||||
importNames: ['BrowserWindow'],
|
|
||||||
message: 'Please use createBrowserWindow',
|
|
||||||
allowTypeImports: true,
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
name: 'chai',
|
name: 'chai',
|
||||||
importNames: ['expect', 'should', 'Should'],
|
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
|
// SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
import { join, normalize } from 'path';
|
import { join, normalize } from 'path';
|
||||||
|
@ -11,19 +11,20 @@ import normalizePath from 'normalize-path';
|
||||||
import fastGlob from 'fast-glob';
|
import fastGlob from 'fast-glob';
|
||||||
import PQueue from 'p-queue';
|
import PQueue from 'p-queue';
|
||||||
import { get, pick, isNumber, isBoolean, some, debounce, noop } from 'lodash';
|
import { get, pick, isNumber, isBoolean, some, debounce, noop } from 'lodash';
|
||||||
import type { BrowserWindow } from 'electron';
|
|
||||||
import {
|
import {
|
||||||
app,
|
app,
|
||||||
|
BrowserWindow,
|
||||||
clipboard,
|
clipboard,
|
||||||
|
desktopCapturer,
|
||||||
dialog,
|
dialog,
|
||||||
ipcMain as ipc,
|
ipcMain as ipc,
|
||||||
Menu,
|
Menu,
|
||||||
powerSaveBlocker,
|
powerSaveBlocker,
|
||||||
protocol as electronProtocol,
|
protocol as electronProtocol,
|
||||||
screen,
|
screen,
|
||||||
|
session,
|
||||||
shell,
|
shell,
|
||||||
systemPreferences,
|
systemPreferences,
|
||||||
desktopCapturer,
|
|
||||||
} from 'electron';
|
} from 'electron';
|
||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
|
|
||||||
|
@ -55,6 +56,7 @@ import * as attachments from './attachments';
|
||||||
import * as attachmentChannel from './attachment_channel';
|
import * as attachmentChannel from './attachment_channel';
|
||||||
import * as bounce from '../ts/services/bounce';
|
import * as bounce from '../ts/services/bounce';
|
||||||
import * as updater from '../ts/updater/index';
|
import * as updater from '../ts/updater/index';
|
||||||
|
import { updateDefaultSession } from './updateDefaultSession';
|
||||||
import { PreventDisplaySleepService } from './PreventDisplaySleepService';
|
import { PreventDisplaySleepService } from './PreventDisplaySleepService';
|
||||||
import { SystemTrayService } from './SystemTrayService';
|
import { SystemTrayService } from './SystemTrayService';
|
||||||
import { SystemTraySettingCache } from './SystemTraySettingCache';
|
import { SystemTraySettingCache } from './SystemTraySettingCache';
|
||||||
|
@ -72,7 +74,6 @@ import type { MenuOptionsType } from './menu';
|
||||||
import { createTemplate } from './menu';
|
import { createTemplate } from './menu';
|
||||||
import { installFileHandler, installWebHandler } from './protocol_filter';
|
import { installFileHandler, installWebHandler } from './protocol_filter';
|
||||||
import * as OS from '../ts/OS';
|
import * as OS from '../ts/OS';
|
||||||
import { createBrowserWindow } from '../ts/util/createBrowserWindow';
|
|
||||||
import { isProduction, isAlpha } from '../ts/util/version';
|
import { isProduction, isAlpha } from '../ts/util/version';
|
||||||
import {
|
import {
|
||||||
isSgnlHref,
|
isSgnlHref,
|
||||||
|
@ -137,6 +138,7 @@ const defaultWebPrefs = {
|
||||||
process.argv.some(arg => arg === '--enable-dev-tools') ||
|
process.argv.some(arg => arg === '--enable-dev-tools') ||
|
||||||
getEnvironment() !== Environment.Production ||
|
getEnvironment() !== Environment.Production ||
|
||||||
!isProduction(app.getVersion()),
|
!isProduction(app.getVersion()),
|
||||||
|
spellcheck: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
function showWindow() {
|
function showWindow() {
|
||||||
|
@ -529,7 +531,7 @@ async function createWindow() {
|
||||||
);
|
);
|
||||||
|
|
||||||
// Create the browser window.
|
// Create the browser window.
|
||||||
mainWindow = createBrowserWindow(windowOptions);
|
mainWindow = new BrowserWindow(windowOptions);
|
||||||
if (settingsChannel) {
|
if (settingsChannel) {
|
||||||
settingsChannel.setMainWindow(mainWindow);
|
settingsChannel.setMainWindow(mainWindow);
|
||||||
}
|
}
|
||||||
|
@ -965,7 +967,7 @@ function showScreenShareWindow(sourceName: string) {
|
||||||
y: 24,
|
y: 24,
|
||||||
};
|
};
|
||||||
|
|
||||||
screenShareWindow = createBrowserWindow(options);
|
screenShareWindow = new BrowserWindow(options);
|
||||||
|
|
||||||
handleCommonWindowEvents(screenShareWindow);
|
handleCommonWindowEvents(screenShareWindow);
|
||||||
|
|
||||||
|
@ -1011,7 +1013,7 @@ function showAbout() {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
aboutWindow = createBrowserWindow(options);
|
aboutWindow = new BrowserWindow(options);
|
||||||
|
|
||||||
handleCommonWindowEvents(aboutWindow);
|
handleCommonWindowEvents(aboutWindow);
|
||||||
|
|
||||||
|
@ -1054,7 +1056,7 @@ function showSettingsWindow() {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
settingsWindow = createBrowserWindow(options);
|
settingsWindow = new BrowserWindow(options);
|
||||||
|
|
||||||
handleCommonWindowEvents(settingsWindow);
|
handleCommonWindowEvents(settingsWindow);
|
||||||
|
|
||||||
|
@ -1125,7 +1127,7 @@ async function showStickerCreator() {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
stickerCreatorWindow = createBrowserWindow(options);
|
stickerCreatorWindow = new BrowserWindow(options);
|
||||||
setupSpellChecker(stickerCreatorWindow, getLocale());
|
setupSpellChecker(stickerCreatorWindow, getLocale());
|
||||||
|
|
||||||
handleCommonWindowEvents(stickerCreatorWindow);
|
handleCommonWindowEvents(stickerCreatorWindow);
|
||||||
|
@ -1190,7 +1192,7 @@ async function showDebugLogWindow() {
|
||||||
fullscreenable: !OS.isMacOS(),
|
fullscreenable: !OS.isMacOS(),
|
||||||
};
|
};
|
||||||
|
|
||||||
debugLogWindow = createBrowserWindow(options);
|
debugLogWindow = new BrowserWindow(options);
|
||||||
|
|
||||||
handleCommonWindowEvents(debugLogWindow);
|
handleCommonWindowEvents(debugLogWindow);
|
||||||
|
|
||||||
|
@ -1250,7 +1252,7 @@ function showPermissionsPopupWindow(forCalling: boolean, forCamera: boolean) {
|
||||||
parent: mainWindow,
|
parent: mainWindow,
|
||||||
};
|
};
|
||||||
|
|
||||||
permissionsPopupWindow = createBrowserWindow(options);
|
permissionsPopupWindow = new BrowserWindow(options);
|
||||||
|
|
||||||
handleCommonWindowEvents(permissionsPopupWindow);
|
handleCommonWindowEvents(permissionsPopupWindow);
|
||||||
|
|
||||||
|
@ -1392,6 +1394,8 @@ function getAppLocale(): string {
|
||||||
// Some APIs can only be used after this event occurs.
|
// Some APIs can only be used after this event occurs.
|
||||||
let ready = false;
|
let ready = false;
|
||||||
app.on('ready', async () => {
|
app.on('ready', async () => {
|
||||||
|
updateDefaultSession(session.defaultSession);
|
||||||
|
|
||||||
const [userDataPath, crashDumpsPath] = await Promise.all([
|
const [userDataPath, crashDumpsPath] = await Promise.all([
|
||||||
realpath(app.getPath('userData')),
|
realpath(app.getPath('userData')),
|
||||||
realpath(app.getPath('crashDumps')),
|
realpath(app.getPath('crashDumps')),
|
||||||
|
@ -1496,7 +1500,7 @@ app.on('ready', async () => {
|
||||||
'sql.initialize is taking more than three seconds; showing loading dialog'
|
'sql.initialize is taking more than three seconds; showing loading dialog'
|
||||||
);
|
);
|
||||||
|
|
||||||
loadingWindow = createBrowserWindow({
|
loadingWindow = new BrowserWindow({
|
||||||
show: false,
|
show: false,
|
||||||
width: 300,
|
width: 300,
|
||||||
height: 265,
|
height: 265,
|
||||||
|
|
12
app/updateDefaultSession.ts
Normal file
12
app/updateDefaultSession.ts
Normal file
|
@ -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
|
||||||
|
);
|
||||||
|
}
|
33
ts/test-node/app/updateDefaultSession_test.ts
Normal file
33
ts/test-node/app/updateDefaultSession_test.ts
Normal file
|
@ -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…
Add table
Add a link
Reference in a new issue