Use Signal's spellcheck dictionary files
Co-authored-by: Evan Hahn <69474926+EvanHahn-Signal@users.noreply.github.com>
This commit is contained in:
parent
269d3d28d4
commit
2eab52dd0d
15
.eslintrc.js
15
.eslintrc.js
|
@ -117,6 +117,21 @@ const typescriptRules = {
|
||||||
|
|
||||||
'@typescript-eslint/array-type': ['error', { default: 'generic' }],
|
'@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
|
// Overrides recommended by typescript-eslint
|
||||||
// https://github.com/typescript-eslint/typescript-eslint/releases/tag/v4.0.0
|
// https://github.com/typescript-eslint/typescript-eslint/releases/tag/v4.0.0
|
||||||
'@typescript-eslint/no-redeclare': 'error',
|
'@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 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,
|
||||||
dialog,
|
dialog,
|
||||||
ipcMain as ipc,
|
ipcMain as ipc,
|
||||||
|
@ -72,6 +72,7 @@ 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 } from '../ts/util/version';
|
import { isProduction } from '../ts/util/version';
|
||||||
import {
|
import {
|
||||||
isSgnlHref,
|
isSgnlHref,
|
||||||
|
@ -530,7 +531,7 @@ async function createWindow() {
|
||||||
);
|
);
|
||||||
|
|
||||||
// Create the browser window.
|
// Create the browser window.
|
||||||
mainWindow = new BrowserWindow(windowOptions);
|
mainWindow = createBrowserWindow(windowOptions);
|
||||||
if (settingsChannel) {
|
if (settingsChannel) {
|
||||||
settingsChannel.setMainWindow(mainWindow);
|
settingsChannel.setMainWindow(mainWindow);
|
||||||
}
|
}
|
||||||
|
@ -968,7 +969,7 @@ function showScreenShareWindow(sourceName: string) {
|
||||||
y: 24,
|
y: 24,
|
||||||
};
|
};
|
||||||
|
|
||||||
screenShareWindow = new BrowserWindow(options);
|
screenShareWindow = createBrowserWindow(options);
|
||||||
|
|
||||||
handleCommonWindowEvents(screenShareWindow);
|
handleCommonWindowEvents(screenShareWindow);
|
||||||
|
|
||||||
|
@ -1014,7 +1015,7 @@ function showAbout() {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
aboutWindow = new BrowserWindow(options);
|
aboutWindow = createBrowserWindow(options);
|
||||||
|
|
||||||
handleCommonWindowEvents(aboutWindow);
|
handleCommonWindowEvents(aboutWindow);
|
||||||
|
|
||||||
|
@ -1057,7 +1058,7 @@ function showSettingsWindow() {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
settingsWindow = new BrowserWindow(options);
|
settingsWindow = createBrowserWindow(options);
|
||||||
|
|
||||||
handleCommonWindowEvents(settingsWindow);
|
handleCommonWindowEvents(settingsWindow);
|
||||||
|
|
||||||
|
@ -1128,7 +1129,7 @@ async function showStickerCreator() {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
stickerCreatorWindow = new BrowserWindow(options);
|
stickerCreatorWindow = createBrowserWindow(options);
|
||||||
setupSpellChecker(stickerCreatorWindow, getLocale().messages);
|
setupSpellChecker(stickerCreatorWindow, getLocale().messages);
|
||||||
|
|
||||||
handleCommonWindowEvents(stickerCreatorWindow);
|
handleCommonWindowEvents(stickerCreatorWindow);
|
||||||
|
@ -1188,7 +1189,7 @@ async function showDebugLogWindow() {
|
||||||
parent: mainWindow,
|
parent: mainWindow,
|
||||||
};
|
};
|
||||||
|
|
||||||
debugLogWindow = new BrowserWindow(options);
|
debugLogWindow = createBrowserWindow(options);
|
||||||
|
|
||||||
handleCommonWindowEvents(debugLogWindow);
|
handleCommonWindowEvents(debugLogWindow);
|
||||||
|
|
||||||
|
@ -1245,7 +1246,7 @@ function showPermissionsPopupWindow(forCalling: boolean, forCamera: boolean) {
|
||||||
parent: mainWindow,
|
parent: mainWindow,
|
||||||
};
|
};
|
||||||
|
|
||||||
permissionsPopupWindow = new BrowserWindow(options);
|
permissionsPopupWindow = createBrowserWindow(options);
|
||||||
|
|
||||||
handleCommonWindowEvents(permissionsPopupWindow);
|
handleCommonWindowEvents(permissionsPopupWindow);
|
||||||
|
|
||||||
|
@ -1482,7 +1483,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 = new BrowserWindow({
|
loadingWindow = createBrowserWindow({
|
||||||
show: false,
|
show: false,
|
||||||
width: 300,
|
width: 300,
|
||||||
height: 265,
|
height: 265,
|
||||||
|
|
|
@ -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',
|
||||||
|
},
|
||||||
|
};
|
|
@ -0,0 +1 @@
|
||||||
|
!.eslintrc.js
|
|
@ -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);
|
||||||
|
});
|
||||||
|
});
|
|
@ -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 New Issue