Use Signal's spellcheck dictionary files
This commit is contained in:
parent
fa9c523d39
commit
3fa911598b
6 changed files with 73 additions and 9 deletions
15
.eslintrc.js
15
.eslintrc.js
|
@ -117,6 +117,21 @@ const typescriptRules = {
|
|||
|
||||
'@typescript-eslint/array-type': ['error', { default: 'generic' }],
|
||||
|
||||
'no-restricted-imports': 'off',
|
||||
'@typescript-eslint/no-restricted-imports': [
|
||||
'error',
|
||||
{
|
||||
paths: [
|
||||
{
|
||||
name: 'electron',
|
||||
importNames: ['BrowserWindow'],
|
||||
message: 'Please use createBrowserWindow',
|
||||
allowTypeImports: true,
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
|
||||
// Overrides recommended by typescript-eslint
|
||||
// https://github.com/typescript-eslint/typescript-eslint/releases/tag/v4.0.0
|
||||
'@typescript-eslint/no-redeclare': 'error',
|
||||
|
|
19
app/main.ts
19
app/main.ts
|
@ -12,9 +12,9 @@ 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,
|
||||
dialog,
|
||||
ipcMain as ipc,
|
||||
|
@ -72,6 +72,7 @@ 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 } from '../ts/util/version';
|
||||
import {
|
||||
isSgnlHref,
|
||||
|
@ -530,7 +531,7 @@ async function createWindow() {
|
|||
);
|
||||
|
||||
// Create the browser window.
|
||||
mainWindow = new BrowserWindow(windowOptions);
|
||||
mainWindow = createBrowserWindow(windowOptions);
|
||||
if (settingsChannel) {
|
||||
settingsChannel.setMainWindow(mainWindow);
|
||||
}
|
||||
|
@ -968,7 +969,7 @@ function showScreenShareWindow(sourceName: string) {
|
|||
y: 24,
|
||||
};
|
||||
|
||||
screenShareWindow = new BrowserWindow(options);
|
||||
screenShareWindow = createBrowserWindow(options);
|
||||
|
||||
handleCommonWindowEvents(screenShareWindow);
|
||||
|
||||
|
@ -1014,7 +1015,7 @@ function showAbout() {
|
|||
},
|
||||
};
|
||||
|
||||
aboutWindow = new BrowserWindow(options);
|
||||
aboutWindow = createBrowserWindow(options);
|
||||
|
||||
handleCommonWindowEvents(aboutWindow);
|
||||
|
||||
|
@ -1057,7 +1058,7 @@ function showSettingsWindow() {
|
|||
},
|
||||
};
|
||||
|
||||
settingsWindow = new BrowserWindow(options);
|
||||
settingsWindow = createBrowserWindow(options);
|
||||
|
||||
handleCommonWindowEvents(settingsWindow);
|
||||
|
||||
|
@ -1128,7 +1129,7 @@ async function showStickerCreator() {
|
|||
},
|
||||
};
|
||||
|
||||
stickerCreatorWindow = new BrowserWindow(options);
|
||||
stickerCreatorWindow = createBrowserWindow(options);
|
||||
setupSpellChecker(stickerCreatorWindow, getLocale().messages);
|
||||
|
||||
handleCommonWindowEvents(stickerCreatorWindow);
|
||||
|
@ -1188,7 +1189,7 @@ async function showDebugLogWindow() {
|
|||
parent: mainWindow,
|
||||
};
|
||||
|
||||
debugLogWindow = new BrowserWindow(options);
|
||||
debugLogWindow = createBrowserWindow(options);
|
||||
|
||||
handleCommonWindowEvents(debugLogWindow);
|
||||
|
||||
|
@ -1245,7 +1246,7 @@ function showPermissionsPopupWindow(forCalling: boolean, forCamera: boolean) {
|
|||
parent: mainWindow,
|
||||
};
|
||||
|
||||
permissionsPopupWindow = new BrowserWindow(options);
|
||||
permissionsPopupWindow = createBrowserWindow(options);
|
||||
|
||||
handleCommonWindowEvents(permissionsPopupWindow);
|
||||
|
||||
|
@ -1482,7 +1483,7 @@ app.on('ready', async () => {
|
|||
'sql.initialize is taking more than three seconds; showing loading dialog'
|
||||
);
|
||||
|
||||
loadingWindow = new BrowserWindow({
|
||||
loadingWindow = createBrowserWindow({
|
||||
show: false,
|
||||
width: 300,
|
||||
height: 265,
|
||||
|
|
8
ts/test-node/.eslintrc.js
Normal file
8
ts/test-node/.eslintrc.js
Normal file
|
@ -0,0 +1,8 @@
|
|||
// Copyright 2021 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
module.exports = {
|
||||
rules: {
|
||||
'@typescript-eslint/no-restricted-imports': 'off',
|
||||
},
|
||||
};
|
1
ts/test-node/.gitignore
vendored
Normal file
1
ts/test-node/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
!.eslintrc.js
|
14
ts/test-node/util/createBrowserWindow_test.ts
Normal file
14
ts/test-node/util/createBrowserWindow_test.ts
Normal file
|
@ -0,0 +1,14 @@
|
|||
// 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);
|
||||
});
|
||||
});
|
25
ts/util/createBrowserWindow.ts
Normal file
25
ts/util/createBrowserWindow.ts
Normal file
|
@ -0,0 +1,25 @@
|
|||
// 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 a new issue