Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add menu entry to toggle spell checking #4037

Merged
merged 1 commit into from
Jul 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions electron/src/interfaces/locale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export type i18nLanguageIdentifier =
| 'menuDelete'
| 'menuDownloadDebugLogs'
| 'menuEdit'
| 'menuEnableSpellChecking'
| 'menuFullScreen'
| 'menuHelp'
| 'menuHideApp'
Expand Down
30 changes: 17 additions & 13 deletions electron/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,9 @@ const initWindowStateKeeper = () => {
};

if (showInFullScreen !== 'not-set-in-v0') {
stateKeeperOptions.fullScreen = showInFullScreen;
stateKeeperOptions.maximize = showInFullScreen;
isFullScreen = showInFullScreen;
stateKeeperOptions.fullScreen = showInFullScreen as boolean;
stateKeeperOptions.maximize = showInFullScreen as boolean;
isFullScreen = showInFullScreen as boolean;
}

return WindowStateKeeper(stateKeeperOptions);
Expand Down Expand Up @@ -533,6 +533,8 @@ class ElectronWrapperInit {
}
};

const enableSpellChecking = settings.restore(SettingsType.ENABLE_SPELL_CHECKING, true);

app.on('web-contents-created', async (_webviewEvent: ElectronEvent, contents: WebContents) => {
if (proxyInfoArg?.origin && contents.session) {
this.logger.log('Applying proxy settings on a webview...');
Expand All @@ -551,7 +553,7 @@ class ElectronWrapperInit {
webPreferences.experimentalFeatures = true;
webPreferences.nodeIntegration = false;
webPreferences.preload = PRELOAD_RENDERER_JS;
webPreferences.spellcheck = true;
webPreferences.spellcheck = enableSpellChecking;
webPreferences.webSecurity = true;
});
break;
Expand Down Expand Up @@ -581,15 +583,17 @@ class ElectronWrapperInit {
});
}

try {
const availableSpellCheckerLanguages = contents.session.availableSpellCheckerLanguages;
const foundLanguages = locale.supportedSpellCheckLanguages[currentLocale].filter(language =>
availableSpellCheckerLanguages.includes(language),
);
contents.session.setSpellCheckerLanguages(foundLanguages);
} catch (error) {
logger.error(error);
contents.session.setSpellCheckerLanguages([]);
if (enableSpellChecking) {
try {
const availableSpellCheckerLanguages = contents.session.availableSpellCheckerLanguages;
const foundLanguages = locale.supportedSpellCheckLanguages[currentLocale].filter(language =>
availableSpellCheckerLanguages.includes(language),
);
contents.session.setSpellCheckerLanguages(foundLanguages);
} catch (error) {
logger.error(error);
contents.session.setSpellCheckerLanguages([]);
}
}

contents.session.setCertificateVerifyProc(setCertificateVerifyProc);
Expand Down
29 changes: 26 additions & 3 deletions electron/src/menu/system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,13 @@ const signOutTemplate: MenuItemConstructorOptions = {
label: locale.getText('menuSignOut'),
};

const spellingTemplate: MenuItemConstructorOptions = {
checked: settings.restore(SettingsType.ENABLE_SPELL_CHECKING, true),
click: () => toggleSpellChecking(),
label: locale.getText('menuEnableSpellChecking'),
type: 'checkbox',
};

const conversationTemplate: MenuItemConstructorOptions = {
label: `&${locale.getText('menuConversation')}`,
submenu: [
Expand Down Expand Up @@ -299,6 +306,8 @@ const darwinTemplate: MenuItemConstructorOptions = {
role: 'unhide',
},
separatorTemplate,
spellingTemplate,
separatorTemplate,
signOutTemplate,
{
accelerator: 'Command+Q',
Expand All @@ -319,6 +328,8 @@ const win32Template: MenuItemConstructorOptions = {
localeTemplate,
toggleAutoLaunchTemplate,
separatorTemplate,
spellingTemplate,
separatorTemplate,
signOutTemplate,
{
accelerator: 'Alt+F4',
Expand All @@ -335,6 +346,8 @@ const linuxTemplate: MenuItemConstructorOptions = {
separatorTemplate,
localeTemplate,
separatorTemplate,
spellingTemplate,
separatorTemplate,
signOutTemplate,
{
accelerator: 'Ctrl+Q',
Expand All @@ -356,8 +369,7 @@ const processMenu = (template: Iterable<MenuItemConstructorOptions>, language: S
}
};

const changeLocale = async (language: SupportedI18nLanguage): Promise<void> => {
locale.setLocale(language);
const showRestartMessageBox = async () => {
const {response} = await dialog.showMessageBox({
buttons: [
locale.getText('restartLater'),
Expand All @@ -368,10 +380,15 @@ const changeLocale = async (language: SupportedI18nLanguage): Promise<void> => {
type: 'info',
});
if (response === 1) {
return EnvironmentUtil.platform.IS_MAC_OS ? lifecycle.quit() : lifecycle.relaunch();
await (EnvironmentUtil.platform.IS_MAC_OS ? lifecycle.quit() : lifecycle.relaunch());
}
};

const changeLocale = async (language: SupportedI18nLanguage): Promise<void> => {
locale.setLocale(language);
await showRestartMessageBox();
};

export const createMenu = (isFullScreen: boolean): Menu => {
const menuTemplate = [conversationTemplate, editTemplate, windowTemplate, helpTemplate];

Expand Down Expand Up @@ -463,6 +480,12 @@ export const toggleMenuBar = (): void => {
}
};

export const toggleSpellChecking = async (): Promise<void> => {
const enableSpellChecking = settings.restore(SettingsType.ENABLE_SPELL_CHECKING, true);
settings.save(SettingsType.ENABLE_SPELL_CHECKING, !enableSpellChecking);
await showRestartMessageBox();
};

export const registerGlobalShortcuts = (): void => {
if (!EnvironmentUtil.platform.IS_LINUX) {
const muteAccelerator = 'CmdOrCtrl+Alt+M';
Expand Down
1 change: 1 addition & 0 deletions electron/src/settings/SettingsType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
export enum SettingsType {
AUTO_LAUNCH = 'shouldAutoLaunch',
CUSTOM_WEBAPP_URL = 'customWebAppURL',
ENABLE_SPELL_CHECKING = 'enableSpellChecking',
ENV = 'env',
FULL_SCREEN = 'fullscreen',
LOCALE = 'locale',
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@
"typescript": "3.9.6",
"webpack": "4.43.0",
"webpack-cli": "3.3.12",
"wire-web-config-internal": "https://github.com/wireapp/wire-web-config-default#v0.24.85",
"wire-web-config-production": "https://github.com/wireapp/wire-web-config-wire#v0.24.86-0"
"wire-web-config-internal": "https://github.com/wireapp/wire-web-config-default#v0.25.1",
"wire-web-config-production": "https://github.com/wireapp/wire-web-config-wire#v0.25.2-0"
},
"homepage": "https://wire.com",
"husky": {
Expand Down
12 changes: 6 additions & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10990,16 +10990,16 @@ winreg@1.2.4:
resolved "https://registry.npmjs.org/winreg/-/winreg-1.2.4.tgz#ba065629b7a925130e15779108cf540990e98d1b"
integrity sha1-ugZWKbepJRMOFXeRCM9UCZDpjRs=

"wire-web-config-internal@https://github.com/wireapp/wire-web-config-default#v0.24.85":
version "0.24.85"
resolved "https://github.com/wireapp/wire-web-config-default#cfbab94fee1c051ec47a7360209341e5558e8301"
"wire-web-config-internal@https://github.com/wireapp/wire-web-config-default#v0.25.1":
version "0.25.1"
resolved "https://github.com/wireapp/wire-web-config-default#78eb5b4728e64d794bc316f5a8395f699a0b5193"
dependencies:
adm-zip "0.4.14"
sort-json "2.0.0"

"wire-web-config-production@https://github.com/wireapp/wire-web-config-wire#v0.24.86-0":
version "0.24.86-0"
resolved "https://github.com/wireapp/wire-web-config-wire#bb81e99e27e7aaa80eb55549709fff631daa459c"
"wire-web-config-production@https://github.com/wireapp/wire-web-config-wire#v0.25.2-0":
version "0.25.2-0"
resolved "https://github.com/wireapp/wire-web-config-wire#c8148412944e2211ac3e01ae896048ba69abc504"
dependencies:
adm-zip "0.4.14"
sort-json "2.0.0"
Expand Down