mirror of
https://github.com/tiddly-gittly/TidGi-Desktop.git
synced 2025-12-06 02:30:47 -08:00
Upgrade to electron@8 (#165)
This commit is contained in:
parent
1799b45ae5
commit
123249a15d
34 changed files with 2090 additions and 2492 deletions
17
package.json
17
package.json
|
|
@ -30,14 +30,13 @@
|
|||
"electron-context-menu": "0.16.0",
|
||||
"electron-is-dev": "1.1.0",
|
||||
"electron-settings": "3.2.0",
|
||||
"electron-spellchecker": "2.2.1",
|
||||
"electron-updater": "4.2.5",
|
||||
"electron-window-state": "5.0.3",
|
||||
"follow-redirects": "1.10.0",
|
||||
"fs-extra": "8.1.0",
|
||||
"fs-extra": "9.0.0",
|
||||
"is-url": "1.2.4",
|
||||
"jimp": "0.9.6",
|
||||
"menubar": "7.2.0",
|
||||
"menubar": "8.0.1",
|
||||
"node-fetch": "2.6.0",
|
||||
"proxy-agent": "3.1.1",
|
||||
"semver": "7.1.3",
|
||||
|
|
@ -50,29 +49,29 @@
|
|||
"@material-ui/icons": "4.9.1",
|
||||
"@material-ui/pickers": "3.2.10",
|
||||
"algoliasearch": "4.1.0",
|
||||
"babel-eslint": "10.0.3",
|
||||
"babel-eslint": "10.1.0",
|
||||
"babel-preset-env": "1.7.0",
|
||||
"babel-preset-react": "6.24.1",
|
||||
"blueimp-md5": "2.12.0",
|
||||
"classnames": "2.2.6",
|
||||
"concurrently": "5.1.0",
|
||||
"cross-env": "7.0.2",
|
||||
"date-fns": "2.10.0",
|
||||
"electron": "6.1.9",
|
||||
"date-fns": "2.11.0",
|
||||
"electron": "8.1.1",
|
||||
"electron-builder": "22.4.1",
|
||||
"electron-notarize": "0.2.1",
|
||||
"eslint": "6.8.0",
|
||||
"eslint-config-airbnb": "18.0.1",
|
||||
"eslint-config-airbnb": "18.1.0",
|
||||
"eslint-plugin-import": "2.20.1",
|
||||
"eslint-plugin-jsx-a11y": "6.2.3",
|
||||
"eslint-plugin-react": "7.18.3",
|
||||
"eslint-plugin-react": "7.19.0",
|
||||
"eslint-plugin-react-hooks": "1.7.0",
|
||||
"lodash.camelcase": "4.3.0",
|
||||
"prop-types": "15.7.2",
|
||||
"react": "16.13.1",
|
||||
"react-dom": "16.13.1",
|
||||
"react-redux": "7.2.0",
|
||||
"react-scripts": "3.4.0",
|
||||
"react-scripts": "3.4.1",
|
||||
"react-sortable-hoc": "1.11.0",
|
||||
"redux": "4.0.5",
|
||||
"redux-thunk": "2.3.0",
|
||||
|
|
|
|||
|
|
@ -1,13 +0,0 @@
|
|||
diff --git a/node_modules/electron-spellchecker/src/context-menu-builder.js b/node_modules/electron-spellchecker/src/context-menu-builder.js
|
||||
index afded5f..6d647af 100644
|
||||
--- a/node_modules/electron-spellchecker/src/context-menu-builder.js
|
||||
+++ b/node_modules/electron-spellchecker/src/context-menu-builder.js
|
||||
@@ -8,7 +8,7 @@ let d = require('debug')('electron-spellchecker:context-menu-builder');
|
||||
const contextMenuStringTable = {
|
||||
copyMail: () => `Copy Email Address`,
|
||||
copyLinkUrl: () => `Copy Link`,
|
||||
- openLinkUrl: () => `Open Link`,
|
||||
+ openLinkUrl: () => `Open Link in Browser`,
|
||||
copyImageUrl: () => `Copy Image URL`,
|
||||
copyImage: () => `Copy Image`,
|
||||
addToDictionary: () => `Add to Dictionary`,
|
||||
|
|
@ -1,8 +1,9 @@
|
|||
// eslint-disable-next-line import/no-extraneous-dependencies
|
||||
const {
|
||||
app,
|
||||
protocol,
|
||||
ipcMain,
|
||||
nativeTheme,
|
||||
protocol,
|
||||
session,
|
||||
} = require('electron');
|
||||
const { autoUpdater } = require('electron-updater');
|
||||
|
|
@ -14,15 +15,19 @@ const mainWindow = require('./windows/main');
|
|||
const openUrlWithWindow = require('./windows/open-url-with');
|
||||
|
||||
const createMenu = require('./libs/create-menu');
|
||||
const extractHostname = require('./libs/extract-hostname');
|
||||
const sendToAllWindows = require('./libs/send-to-all-windows');
|
||||
const { addView } = require('./libs/views');
|
||||
const { getPreferences } = require('./libs/preferences');
|
||||
const { getWorkspaces, setWorkspace } = require('./libs/workspaces');
|
||||
const extractHostname = require('./libs/extract-hostname');
|
||||
|
||||
const MAILTO_URLS = require('./constants/mailto-urls');
|
||||
|
||||
require('./libs/updater');
|
||||
|
||||
// see https://github.com/electron/electron/issues/18397
|
||||
app.allowRendererProcessReuse = true;
|
||||
|
||||
const gotTheLock = app.requestSingleInstanceLock();
|
||||
|
||||
app.on('second-instance', () => {
|
||||
|
|
@ -73,6 +78,10 @@ if (!gotTheLock) {
|
|||
.then(() => {
|
||||
createMenu();
|
||||
|
||||
nativeTheme.addListener('updated', () => {
|
||||
sendToAllWindows('native-theme-updated');
|
||||
});
|
||||
|
||||
const workspaceObjects = getWorkspaces();
|
||||
|
||||
Object.keys(workspaceObjects).forEach((id) => {
|
||||
|
|
|
|||
437
public/libs/context-menu-builder.js
Normal file
437
public/libs/context-menu-builder.js
Normal file
|
|
@ -0,0 +1,437 @@
|
|||
/* eslint-disable class-methods-use-this */
|
||||
/* eslint-disable no-param-reassign */
|
||||
/* global Image */
|
||||
// Ported from
|
||||
// https://github.com/electron-userland/electron-spellchecker/blob/master/src/context-menu-builder.js
|
||||
|
||||
const {
|
||||
clipboard,
|
||||
nativeImage,
|
||||
remote,
|
||||
shell,
|
||||
} = require('electron');
|
||||
|
||||
const { Menu, MenuItem } = remote;
|
||||
|
||||
/**
|
||||
* Truncates a string to a max length of 25. Will split on a word boundary and
|
||||
* add an ellipsis.
|
||||
*
|
||||
* @param {String} string The string to truncate
|
||||
* @return {String} The truncated string
|
||||
*/
|
||||
const truncateString = (string) => {
|
||||
const match = string.match(/^.{0,25}[\S]*/);
|
||||
const { length } = match[0];
|
||||
let result = match[0].replace(/\s$/, '');
|
||||
if (length < string.length) result += '…';
|
||||
return result;
|
||||
};
|
||||
|
||||
const matchesWord = (string) => {
|
||||
const regex = /[\u0041-\u005A\u0061-\u007A\u00AA\u00B5\u00BA\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0370-\u0374\u0376\u0377\u037A-\u037D\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u048A-\u0527\u0531-\u0556\u0559\u0561-\u0587\u05D0-\u05EA\u05F0-\u05F2\u0620-\u064A\u066E\u066F\u0671-\u06D3\u06D5\u06E5\u06E6\u06EE\u06EF\u06FA-\u06FC\u06FF\u0710\u0712-\u072F\u074D-\u07A5\u07B1\u07CA-\u07EA\u07F4\u07F5\u07FA\u0800-\u0815\u081A\u0824\u0828\u0840-\u0858\u08A0\u08A2-\u08AC\u0904-\u0939\u093D\u0950\u0958-\u0961\u0971-\u0977\u0979-\u097F\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BD\u09CE\u09DC\u09DD\u09DF-\u09E1\u09F0\u09F1\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A59-\u0A5C\u0A5E\u0A72-\u0A74\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABD\u0AD0\u0AE0\u0AE1\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3D\u0B5C\u0B5D\u0B5F-\u0B61\u0B71\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BD0\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C33\u0C35-\u0C39\u0C3D\u0C58\u0C59\u0C60\u0C61\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBD\u0CDE\u0CE0\u0CE1\u0CF1\u0CF2\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D\u0D4E\u0D60\u0D61\u0D7A-\u0D7F\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0E01-\u0E30\u0E32\u0E33\u0E40-\u0E46\u0E81\u0E82\u0E84\u0E87\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3\u0EA5\u0EA7\u0EAA\u0EAB\u0EAD-\u0EB0\u0EB2\u0EB3\u0EBD\u0EC0-\u0EC4\u0EC6\u0EDC-\u0EDF\u0F00\u0F40-\u0F47\u0F49-\u0F6C\u0F88-\u0F8C\u1000-\u102A\u103F\u1050-\u1055\u105A-\u105D\u1061\u1065\u1066\u106E-\u1070\u1075-\u1081\u108E\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u1380-\u138F\u13A0-\u13F4\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u1700-\u170C\u170E-\u1711\u1720-\u1731\u1740-\u1751\u1760-\u176C\u176E-\u1770\u1780-\u17B3\u17D7\u17DC\u1820-\u1877\u1880-\u18A8\u18AA\u18B0-\u18F5\u1900-\u191C\u1950-\u196D\u1970-\u1974\u1980-\u19AB\u19C1-\u19C7\u1A00-\u1A16\u1A20-\u1A54\u1AA7\u1B05-\u1B33\u1B45-\u1B4B\u1B83-\u1BA0\u1BAE\u1BAF\u1BBA-\u1BE5\u1C00-\u1C23\u1C4D-\u1C4F\u1C5A-\u1C7D\u1CE9-\u1CEC\u1CEE-\u1CF1\u1CF5\u1CF6\u1D00-\u1DBF\u1E00-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u2071\u207F\u2090-\u209C\u2102\u2107\u210A-\u2113\u2115\u2119-\u211D\u2124\u2126\u2128\u212A-\u212D\u212F-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2183\u2184\u2C00-\u2C2E\u2C30-\u2C5E\u2C60-\u2CE4\u2CEB-\u2CEE\u2CF2\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D80-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u2E2F\u3005\u3006\u3031-\u3035\u303B\u303C\u3041-\u3096\u309D-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312D\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FCC\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA61F\uA62A\uA62B\uA640-\uA66E\uA67F-\uA697\uA6A0-\uA6E5\uA717-\uA71F\uA722-\uA788\uA78B-\uA78E\uA790-\uA793\uA7A0-\uA7AA\uA7F8-\uA801\uA803-\uA805\uA807-\uA80A\uA80C-\uA822\uA840-\uA873\uA882-\uA8B3\uA8F2-\uA8F7\uA8FB\uA90A-\uA925\uA930-\uA946\uA960-\uA97C\uA984-\uA9B2\uA9CF\uAA00-\uAA28\uAA40-\uAA42\uAA44-\uAA4B\uAA60-\uAA76\uAA7A\uAA80-\uAAAF\uAAB1\uAAB5\uAAB6\uAAB9-\uAABD\uAAC0\uAAC2\uAADB-\uAADD\uAAE0-\uAAEA\uAAF2-\uAAF4\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uABC0-\uABE2\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D\uFB1F-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE70-\uFE74\uFE76-\uFEFC\uFF21-\uFF3A\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC]+/g;
|
||||
|
||||
return string.match(regex);
|
||||
};
|
||||
|
||||
const contextMenuStringTable = {
|
||||
copyMail: () => 'Copy Email Address',
|
||||
copyLinkUrl: () => 'Copy Link',
|
||||
openLinkUrl: () => 'Open Link',
|
||||
copyImageUrl: () => 'Copy Image URL',
|
||||
copyImage: () => 'Copy Image',
|
||||
addToDictionary: () => 'Add to Dictionary',
|
||||
lookUpDefinition: ({ word }) => `Look Up "${word}"`,
|
||||
searchGoogle: () => 'Search with Google',
|
||||
cut: () => 'Cut',
|
||||
copy: () => 'Copy',
|
||||
paste: () => 'Paste',
|
||||
inspectElement: () => 'Inspect Element',
|
||||
};
|
||||
|
||||
/**
|
||||
* ContextMenuBuilder creates context menus based on the content clicked - this
|
||||
* information is derived from
|
||||
* https://github.com/electron/electron/blob/master/docs/api/web-contents.md#event-context-menu,
|
||||
* which we use to generate the menu. We also use the spell-check information to
|
||||
* generate suggestions.
|
||||
*/
|
||||
module.exports = class ContextMenuBuilder {
|
||||
/**
|
||||
* Creates an instance of ContextMenuBuilder
|
||||
*
|
||||
* @param {BrowserWindow|WebView} windowOrWebView The hosting window/WebView
|
||||
* @param {Boolean} debugMode If true, display the "Inspect Element" menu item.
|
||||
* @param {function} processMenu If passed, this method will be passed the menu to change
|
||||
* it prior to display. Signature: (menu, info) => menu
|
||||
*/
|
||||
constructor(windowOrWebView = null, debugMode = false, processMenu = (m) => m) {
|
||||
this.debugMode = debugMode;
|
||||
this.processMenu = processMenu;
|
||||
this.menu = null;
|
||||
this.stringTable = { ...contextMenuStringTable };
|
||||
|
||||
windowOrWebView = windowOrWebView || remote.getCurrentWebContents();
|
||||
|
||||
const ctorName = Object.getPrototypeOf(windowOrWebView).constructor.name;
|
||||
if (ctorName === 'WebContents') {
|
||||
this.getWebContents = () => windowOrWebView;
|
||||
} else {
|
||||
// NB: We do this because at the time a WebView is created, it doesn't
|
||||
// have a WebContents, we need to defer the call to getWebContents
|
||||
this.getWebContents = 'webContents' in windowOrWebView
|
||||
? () => windowOrWebView.webContents
|
||||
: () => windowOrWebView.getWebContents();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Override the default logger for this class. You probably want to use
|
||||
* {{setGlobalLogger}} instead
|
||||
*
|
||||
* @param {Function} fn The function which will operate like console.log
|
||||
*/
|
||||
static setLogger(fn) {
|
||||
// eslint-disable-next-line no-undef
|
||||
d = fn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify alternate string formatter for each context menu.
|
||||
* String table consist of string formatter as function instead per each context menu item,
|
||||
* allows to change string in runtime. All formatters are simply typeof () => string, except
|
||||
* lookUpDefinition provides word, ({word}) => string.
|
||||
*
|
||||
* @param {Object} stringTable The object contains string foramtter function for context menu.
|
||||
* It is allowed to specify only certain menu string as necessary, which will makes other string
|
||||
* fall backs to default.
|
||||
*
|
||||
*/
|
||||
setAlternateStringFormatter(stringTable) {
|
||||
this.stringTable = Object.assign(this.stringTable, stringTable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows a popup menu given the information returned from the context-menu
|
||||
* event. This is probably the only method you need to call in this class.
|
||||
*
|
||||
* @param {Object} contextInfo The object returned from the 'context-menu'
|
||||
* Electron event.
|
||||
*
|
||||
* @return {Promise} Completion
|
||||
*/
|
||||
async showPopupMenu(contextInfo) {
|
||||
const menu = await this.buildMenuForElement(contextInfo);
|
||||
if (!menu) return;
|
||||
menu.popup({});
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a context menu specific to the given info that _would_ be shown
|
||||
* immediately by {{showPopupMenu}}. Use this to add your own menu items to
|
||||
* the list but use most of the default behavior.
|
||||
*
|
||||
* @return {Promise<Menu>} The newly created `Menu`
|
||||
*/
|
||||
async buildMenuForElement(info) {
|
||||
// d(`Got context menu event with args: ${JSON.stringify(info)}`);
|
||||
|
||||
if (info.linkURL && info.linkURL.length > 0) {
|
||||
return this.buildMenuForLink(info);
|
||||
}
|
||||
|
||||
if (info.hasImageContents && info.srcURL && info.srcURL.length > 1) {
|
||||
return this.buildMenuForImage(info);
|
||||
}
|
||||
|
||||
if (info.isEditable || (info.inputFieldType && info.inputFieldType !== 'none')) {
|
||||
return this.buildMenuForTextInput(info);
|
||||
}
|
||||
|
||||
return this.buildMenuForText(info);
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a menu applicable to a text input field.
|
||||
*
|
||||
* @return {Menu} The `Menu`
|
||||
*/
|
||||
async buildMenuForTextInput(menuInfo) {
|
||||
const menu = new Menu();
|
||||
|
||||
await this.addSpellingItems(menu, menuInfo);
|
||||
this.addSearchItems(menu, menuInfo);
|
||||
|
||||
this.addCut(menu, menuInfo);
|
||||
this.addCopy(menu, menuInfo);
|
||||
this.addPaste(menu, menuInfo);
|
||||
this.addInspectElement(menu, menuInfo);
|
||||
this.processMenu(menu, menuInfo);
|
||||
|
||||
return menu;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a menu applicable to a link element.
|
||||
*
|
||||
* @return {Menu} The `Menu`
|
||||
*/
|
||||
buildMenuForLink(menuInfo) {
|
||||
const menu = new Menu();
|
||||
const isEmailAddress = menuInfo.linkURL.startsWith('mailto:');
|
||||
|
||||
const copyLink = new MenuItem({
|
||||
label: isEmailAddress ? this.stringTable.copyMail() : this.stringTable.copyLinkUrl(),
|
||||
click: () => {
|
||||
// Omit the mailto: portion of the link; we just want the address
|
||||
clipboard.writeText(isEmailAddress
|
||||
? menuInfo.linkText : menuInfo.linkURL);
|
||||
},
|
||||
});
|
||||
|
||||
const openLink = new MenuItem({
|
||||
label: this.stringTable.openLinkUrl(),
|
||||
click: () => {
|
||||
// d(`Navigating to: ${menuInfo.linkURL}`);
|
||||
shell.openExternal(menuInfo.linkURL);
|
||||
},
|
||||
});
|
||||
|
||||
menu.append(copyLink);
|
||||
menu.append(openLink);
|
||||
|
||||
if (this.isSrcUrlValid(menuInfo)) {
|
||||
this.addSeparator(menu);
|
||||
this.addImageItems(menu, menuInfo);
|
||||
}
|
||||
|
||||
this.addInspectElement(menu, menuInfo);
|
||||
this.processMenu(menu, menuInfo);
|
||||
|
||||
return menu;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a menu applicable to a text field.
|
||||
*
|
||||
* @return {Menu} The `Menu`
|
||||
*/
|
||||
buildMenuForText(menuInfo) {
|
||||
const menu = new Menu();
|
||||
|
||||
this.addSearchItems(menu, menuInfo);
|
||||
this.addCopy(menu, menuInfo);
|
||||
this.addInspectElement(menu, menuInfo);
|
||||
this.processMenu(menu, menuInfo);
|
||||
|
||||
return menu;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a menu applicable to an image.
|
||||
*
|
||||
* @return {Menu} The `Menu`
|
||||
*/
|
||||
buildMenuForImage(menuInfo) {
|
||||
const menu = new Menu();
|
||||
|
||||
if (this.isSrcUrlValid(menuInfo)) {
|
||||
this.addImageItems(menu, menuInfo);
|
||||
}
|
||||
this.addInspectElement(menu, menuInfo);
|
||||
this.processMenu(menu, menuInfo);
|
||||
|
||||
return menu;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the current text selection contains a single misspelled word and
|
||||
* if so, adds suggested spellings as individual menu items.
|
||||
*/
|
||||
async addSpellingItems(menu, menuInfo) {
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
const target = this.getWebContents();
|
||||
if (!menuInfo.misspelledWord || menuInfo.misspelledWord.length < 1) {
|
||||
return menu;
|
||||
}
|
||||
|
||||
// Ensure that we have valid corrections for that word
|
||||
const corrections = menuInfo.dictionarySuggestions;
|
||||
|
||||
if (corrections && corrections.length) {
|
||||
corrections.forEach((correction) => {
|
||||
const item = new MenuItem({
|
||||
label: correction,
|
||||
click: () => target.replaceMisspelling(correction),
|
||||
});
|
||||
|
||||
menu.append(item);
|
||||
});
|
||||
|
||||
this.addSeparator(menu);
|
||||
}
|
||||
|
||||
return menu;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds search-related menu items.
|
||||
*/
|
||||
addSearchItems(menu, menuInfo) {
|
||||
if (!menuInfo.selectionText || menuInfo.selectionText.length < 1) {
|
||||
return menu;
|
||||
}
|
||||
|
||||
const match = matchesWord(menuInfo.selectionText);
|
||||
if (!match || match.length === 0) {
|
||||
return menu;
|
||||
}
|
||||
|
||||
if (process.platform === 'darwin') {
|
||||
const target = this.getWebContents();
|
||||
|
||||
const lookUpDefinition = new MenuItem({
|
||||
label: this.stringTable.lookUpDefinition({ word: truncateString(menuInfo.selectionText) }),
|
||||
click: () => target.showDefinitionForSelection(),
|
||||
});
|
||||
|
||||
menu.append(lookUpDefinition);
|
||||
}
|
||||
|
||||
const search = new MenuItem({
|
||||
label: this.stringTable.searchGoogle(),
|
||||
click: () => {
|
||||
const url = `https://www.google.com/#q=${encodeURIComponent(menuInfo.selectionText)}`;
|
||||
|
||||
// d(`Searching Google using ${url}`);
|
||||
shell.openExternal(url);
|
||||
},
|
||||
});
|
||||
|
||||
menu.append(search);
|
||||
this.addSeparator(menu);
|
||||
|
||||
return menu;
|
||||
}
|
||||
|
||||
isSrcUrlValid(menuInfo) {
|
||||
return menuInfo.srcURL && menuInfo.srcURL.length > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds "Copy Image" and "Copy Image URL" items when `src` is valid.
|
||||
*/
|
||||
addImageItems(menu, menuInfo) {
|
||||
const copyImage = new MenuItem({
|
||||
label: this.stringTable.copyImage(),
|
||||
click: () => this.convertImageToBase64(menuInfo.srcURL,
|
||||
(dataURL) => clipboard.writeImage(nativeImage.createFromDataURL(dataURL))),
|
||||
});
|
||||
|
||||
menu.append(copyImage);
|
||||
|
||||
const copyImageUrl = new MenuItem({
|
||||
label: this.stringTable.copyImageUrl(),
|
||||
click: () => clipboard.writeText(menuInfo.srcURL),
|
||||
});
|
||||
|
||||
menu.append(copyImageUrl);
|
||||
return menu;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the Cut menu item
|
||||
*/
|
||||
addCut(menu, menuInfo) {
|
||||
const target = this.getWebContents();
|
||||
menu.append(new MenuItem({
|
||||
label: this.stringTable.cut(),
|
||||
accelerator: 'CommandOrControl+X',
|
||||
enabled: menuInfo.editFlags.canCut,
|
||||
click: () => target.cut(),
|
||||
}));
|
||||
|
||||
return menu;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the Copy menu item.
|
||||
*/
|
||||
addCopy(menu, menuInfo) {
|
||||
const target = this.getWebContents();
|
||||
menu.append(new MenuItem({
|
||||
label: this.stringTable.copy(),
|
||||
accelerator: 'CommandOrControl+C',
|
||||
enabled: menuInfo.editFlags.canCopy,
|
||||
click: () => target.copy(),
|
||||
}));
|
||||
|
||||
return menu;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the Paste menu item.
|
||||
*/
|
||||
addPaste(menu, menuInfo) {
|
||||
const target = this.getWebContents();
|
||||
menu.append(new MenuItem({
|
||||
label: this.stringTable.paste(),
|
||||
accelerator: 'CommandOrControl+V',
|
||||
enabled: menuInfo.editFlags.canPaste,
|
||||
click: () => target.paste(),
|
||||
}));
|
||||
|
||||
return menu;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a separator item.
|
||||
*/
|
||||
addSeparator(menu) {
|
||||
menu.append(new MenuItem({ type: 'separator' }));
|
||||
return menu;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the "Inspect Element" menu item.
|
||||
*/
|
||||
addInspectElement(menu, menuInfo, needsSeparator = true) {
|
||||
const target = this.getWebContents();
|
||||
if (!this.debugMode) return menu;
|
||||
if (needsSeparator) this.addSeparator(menu);
|
||||
|
||||
const inspect = new MenuItem({
|
||||
label: this.stringTable.inspectElement(),
|
||||
click: () => target.inspectElement(menuInfo.x, menuInfo.y),
|
||||
});
|
||||
|
||||
menu.append(inspect);
|
||||
return menu;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts an image to a base-64 encoded string.
|
||||
*
|
||||
* @param {String} url The image URL
|
||||
* @param {Function} callback A callback that will be invoked with the result
|
||||
* @param {String} outputFormat The image format to use, defaults to 'image/png'
|
||||
*/
|
||||
convertImageToBase64(url, callback, outputFormat = 'image/png') {
|
||||
let canvas = document.createElement('CANVAS');
|
||||
const ctx = canvas.getContext('2d');
|
||||
const img = new Image();
|
||||
img.crossOrigin = 'Anonymous';
|
||||
|
||||
img.onload = () => {
|
||||
canvas.height = img.height;
|
||||
canvas.width = img.width;
|
||||
ctx.drawImage(img, 0, 0);
|
||||
|
||||
const dataURL = canvas.toDataURL(outputFormat);
|
||||
canvas = null;
|
||||
callback(dataURL);
|
||||
};
|
||||
|
||||
img.src = url;
|
||||
}
|
||||
};
|
||||
|
|
@ -128,7 +128,7 @@ function createMenu() {
|
|||
|
||||
if (win != null && win.getBrowserView() != null) {
|
||||
const contents = win.getBrowserView().webContents;
|
||||
contents.setZoomFactor(1);
|
||||
contents.zoomFactor = 1;
|
||||
}
|
||||
},
|
||||
enabled: hasWorkspaces,
|
||||
|
|
@ -141,9 +141,7 @@ function createMenu() {
|
|||
|
||||
if (win != null && win.getBrowserView() != null) {
|
||||
const contents = win.getBrowserView().webContents;
|
||||
contents.getZoomFactor((zoomFactor) => {
|
||||
contents.setZoomFactor(zoomFactor + 0.1);
|
||||
});
|
||||
contents.zoomFactor += 0.1;
|
||||
}
|
||||
},
|
||||
enabled: hasWorkspaces,
|
||||
|
|
@ -156,9 +154,7 @@ function createMenu() {
|
|||
|
||||
if (win != null && win.getBrowserView() != null) {
|
||||
const contents = win.getBrowserView().webContents;
|
||||
contents.getZoomFactor((zoomFactor) => {
|
||||
contents.setZoomFactor(zoomFactor - 0.1);
|
||||
});
|
||||
contents.zoomFactor += 0.1;
|
||||
}
|
||||
},
|
||||
enabled: hasWorkspaces,
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ const {
|
|||
setViewsNotificationsPref,
|
||||
} = require('./views');
|
||||
|
||||
let pauseNotificationsInfo;
|
||||
let pauseNotificationsInfo = null;
|
||||
|
||||
const getCurrentScheduledDateTime = () => {
|
||||
const pauseNotificationsBySchedule = getPreference('pauseNotificationsBySchedule');
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ const path = require('path');
|
|||
const settings = require('electron-settings');
|
||||
const { app, ipcMain } = require('electron');
|
||||
|
||||
const sendToAllWindows = require('../libs/send-to-all-windows');
|
||||
const sendToAllWindows = require('./send-to-all-windows');
|
||||
|
||||
// scope
|
||||
const v = '2018.2';
|
||||
|
|
@ -108,18 +108,17 @@ const defaultPreferences = {
|
|||
rememberLastPageVisited: false,
|
||||
shareWorkspaceBrowsingData: false,
|
||||
sidebar: true,
|
||||
spellChecker: true,
|
||||
spellCheckerLanguages: null,
|
||||
spellcheck: true,
|
||||
spellcheckLanguages: ['en-US'],
|
||||
swipeToNavigate: true,
|
||||
theme: process.platform === 'darwin' ? 'automatic' : 'light',
|
||||
titleBar: false,
|
||||
unreadCountBadge: true,
|
||||
};
|
||||
|
||||
const getPreferences = () => {
|
||||
// cannot init at launch as app.getLocale() is undefined before app.on('ready')
|
||||
if (defaultPreferences.spellCheckerLanguages == null) {
|
||||
defaultPreferences.spellCheckerLanguages = getDefaultSpellCheckerLanguages();
|
||||
if (defaultPreferences.spellcheckLanguages == null) {
|
||||
defaultPreferences.spellcheckLanguages = getDefaultSpellCheckerLanguages();
|
||||
}
|
||||
return { ...defaultPreferences, ...settings.get(`preferences.${v}`) };
|
||||
};
|
||||
|
|
@ -129,8 +128,8 @@ const getPreference = (name) => {
|
|||
return settings.get(`preferences.${v}.${name}`);
|
||||
}
|
||||
// cannot init at launch as app.getLocale() is undefined before app.on('ready')
|
||||
if (name === 'spellCheckerLanguages' && defaultPreferences.spellCheckerLanguages == null) {
|
||||
defaultPreferences.spellCheckerLanguages = getDefaultSpellCheckerLanguages();
|
||||
if (name === 'spellcheckLanguages' && defaultPreferences.spellcheckLanguages == null) {
|
||||
defaultPreferences.spellcheckLanguages = getDefaultSpellCheckerLanguages();
|
||||
}
|
||||
return defaultPreferences[name];
|
||||
};
|
||||
|
|
|
|||
|
|
@ -87,13 +87,15 @@ const addView = (browserWindow, workspace) => {
|
|||
const {
|
||||
blockAds,
|
||||
customUserAgent,
|
||||
rememberLastPageVisited,
|
||||
shareWorkspaceBrowsingData,
|
||||
unreadCountBadge,
|
||||
proxyBypassRules,
|
||||
proxyPacScript,
|
||||
proxyRules,
|
||||
proxyType,
|
||||
rememberLastPageVisited,
|
||||
shareWorkspaceBrowsingData,
|
||||
spellcheck,
|
||||
spellcheckLanguages,
|
||||
unreadCountBadge,
|
||||
} = getPreferences();
|
||||
|
||||
// configure session, proxy & ad blocker
|
||||
|
|
@ -122,9 +124,12 @@ const addView = (browserWindow, workspace) => {
|
|||
blocker.enableBlockingInSession(ses);
|
||||
});
|
||||
}
|
||||
// spellchecker
|
||||
ses.setSpellCheckerLanguages(spellcheckLanguages);
|
||||
|
||||
const view = new BrowserView({
|
||||
webPreferences: {
|
||||
spellcheck,
|
||||
nativeWindowOpen: true,
|
||||
nodeIntegration: false,
|
||||
contextIsolation: true,
|
||||
|
|
@ -135,18 +140,18 @@ const addView = (browserWindow, workspace) => {
|
|||
|
||||
let adjustUserAgentByUrl = () => false;
|
||||
if (customUserAgent) {
|
||||
view.webContents.setUserAgent(customUserAgent);
|
||||
view.webContents.userAgent = customUserAgent;
|
||||
} else {
|
||||
// Hide Electron from UA to improve compatibility
|
||||
// https://github.com/quanglam2807/webcatalog/issues/182
|
||||
const uaStr = view.webContents.getUserAgent();
|
||||
const uaStr = view.webContents.userAgent;
|
||||
const commonUaStr = uaStr
|
||||
// Fix WhatsApp requires Google Chrome 49+ bug
|
||||
.replace(` ${app.getName()}/${app.getVersion()}`, '')
|
||||
.replace(` ${app.name}/${app.getVersion()}`, '')
|
||||
// Hide Electron from UA to improve compatibility
|
||||
// https://github.com/quanglam2807/webcatalog/issues/182
|
||||
.replace(` Electron/${process.versions.electron}`, '');
|
||||
view.webContents.setUserAgent(customUserAgent || commonUaStr);
|
||||
view.webContents.userAgent = customUserAgent || commonUaStr;
|
||||
|
||||
// fix Google prevents signing in because of security concerns
|
||||
// https://github.com/quanglam2807/webcatalog/issues/455
|
||||
|
|
@ -156,14 +161,14 @@ const addView = (browserWindow, workspace) => {
|
|||
if (customUserAgent) return false;
|
||||
|
||||
const navigatedDomain = extractDomain(url);
|
||||
const currentUaStr = view.webContents.getUserAgent();
|
||||
const currentUaStr = view.webContents.userAgent;
|
||||
if (navigatedDomain === 'accounts.google.com') {
|
||||
if (currentUaStr !== fakedEdgeUaStr) {
|
||||
view.webContents.setUserAgent(fakedEdgeUaStr);
|
||||
view.webContents.userAgent = fakedEdgeUaStr;
|
||||
return true;
|
||||
}
|
||||
} else if (currentUaStr !== commonUaStr) {
|
||||
view.webContents.setUserAgent(commonUaStr);
|
||||
view.webContents.userAgent = commonUaStr;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
@ -351,7 +356,8 @@ const addView = (browserWindow, workspace) => {
|
|||
if (!askForDownloadPath) {
|
||||
const finalFilePath = path.join(downloadPath, item.getFilename());
|
||||
if (!fsExtra.existsSync(finalFilePath)) {
|
||||
item.setSavePath(finalFilePath);
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
item.savePath = finalFilePath;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
@ -368,7 +374,8 @@ const addView = (browserWindow, workspace) => {
|
|||
if (!askForDownloadPath) {
|
||||
const finalFilePath = path.join(downloadPath, item.getFilename());
|
||||
if (!fsExtra.existsSync(finalFilePath)) {
|
||||
item.setSavePath(finalFilePath);
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
item.savePath = finalFilePath;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
@ -391,7 +398,7 @@ const addView = (browserWindow, workspace) => {
|
|||
count += c;
|
||||
});
|
||||
|
||||
app.setBadgeCount(count);
|
||||
app.badgeCount = count;
|
||||
|
||||
if (process.platform === 'win32') {
|
||||
if (count > 0) {
|
||||
|
|
@ -418,7 +425,7 @@ const addView = (browserWindow, workspace) => {
|
|||
|
||||
// Handle audio & notification preferences
|
||||
if (shouldMuteAudio !== undefined) {
|
||||
view.webContents.setAudioMuted(shouldMuteAudio);
|
||||
view.webContents.audioMuted = shouldMuteAudio;
|
||||
}
|
||||
view.webContents.once('did-stop-loading', () => {
|
||||
view.webContents.send('should-pause-notifications-changed', workspace.disableNotifications || shouldPauseNotifications);
|
||||
|
|
@ -503,7 +510,7 @@ const setViewsAudioPref = (_shouldMuteAudio) => {
|
|||
const view = views[id];
|
||||
if (view != null) {
|
||||
const workspace = getWorkspace(id);
|
||||
view.webContents.setAudioMuted(workspace.disableAudio || shouldMuteAudio);
|
||||
view.webContents.audioMuted = workspace.disableAudio || shouldMuteAudio;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ const isUrl = require('is-url');
|
|||
const download = require('download');
|
||||
const tmp = require('tmp');
|
||||
|
||||
const sendToAllWindows = require('../libs/send-to-all-windows');
|
||||
const sendToAllWindows = require('./send-to-all-windows');
|
||||
|
||||
const v = '14';
|
||||
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ const {
|
|||
app,
|
||||
dialog,
|
||||
ipcMain,
|
||||
nativeTheme,
|
||||
shell,
|
||||
} = require('electron');
|
||||
const { autoUpdater } = require('electron-updater');
|
||||
|
|
@ -62,6 +63,7 @@ const mainWindow = require('../windows/main');
|
|||
const notificationsWindow = require('../windows/notifications');
|
||||
const preferencesWindow = require('../windows/preferences');
|
||||
const proxyWindow = require('../windows/proxy');
|
||||
const spellcheckLanguagesWindow = require('../windows/spellcheck-languages');
|
||||
|
||||
const loadListeners = () => {
|
||||
ipcMain.on('request-open-in-browser', (e, url) => {
|
||||
|
|
@ -171,6 +173,10 @@ const loadListeners = () => {
|
|||
proxyWindow.show();
|
||||
});
|
||||
|
||||
ipcMain.on('request-show-spellcheck-languages-window', () => {
|
||||
spellcheckLanguagesWindow.show();
|
||||
});
|
||||
|
||||
ipcMain.on('request-show-require-restart-dialog', () => {
|
||||
dialog.showMessageBox({
|
||||
type: 'question',
|
||||
|
|
@ -406,6 +412,19 @@ const loadListeners = () => {
|
|||
sendToAllWindows(id, null);
|
||||
});
|
||||
});
|
||||
|
||||
// Native Theme
|
||||
ipcMain.on('get-should-use-dark-colors', (e) => {
|
||||
e.returnValue = nativeTheme.shouldUseDarkColors;
|
||||
});
|
||||
|
||||
ipcMain.on('get-theme-source', (e) => {
|
||||
e.returnValue = nativeTheme.themeSource;
|
||||
});
|
||||
|
||||
ipcMain.on('request-set-theme-source', (e, val) => {
|
||||
nativeTheme.themeSource = val;
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = loadListeners;
|
||||
|
|
|
|||
8
public/preload/spellcheck-languages.js
Normal file
8
public/preload/spellcheck-languages.js
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
window.mode = 'spellcheck-languages';
|
||||
|
||||
const { remote } = require('electron');
|
||||
const contextMenu = require('electron-context-menu');
|
||||
|
||||
contextMenu({
|
||||
window: remote.getCurrentWindow(),
|
||||
});
|
||||
|
|
@ -4,11 +4,7 @@ const {
|
|||
webFrame,
|
||||
} = require('electron');
|
||||
|
||||
const {
|
||||
SpellCheckHandler,
|
||||
ContextMenuListener,
|
||||
ContextMenuBuilder,
|
||||
} = require('electron-spellchecker');
|
||||
const ContextMenuBuilder = require('../libs/context-menu-builder');
|
||||
|
||||
const { MenuItem } = remote;
|
||||
|
||||
|
|
@ -38,23 +34,12 @@ window.onload = () => {
|
|||
}
|
||||
}
|
||||
|
||||
const spellChecker = ipcRenderer.sendSync('get-preference', 'spellChecker');
|
||||
const spellCheckerLanguages = ipcRenderer.sendSync('get-preference', 'spellCheckerLanguages');
|
||||
|
||||
if (spellChecker) {
|
||||
window.spellCheckHandler = new SpellCheckHandler();
|
||||
setTimeout(() => window.spellCheckHandler.attachToInput(), 1000);
|
||||
window.spellCheckHandler.switchLanguage(spellCheckerLanguages[0]);
|
||||
}
|
||||
|
||||
window.contextMenuBuilder = new ContextMenuBuilder(
|
||||
spellChecker ? window.spellCheckHandler : null,
|
||||
null,
|
||||
true,
|
||||
);
|
||||
|
||||
|
||||
window.contextMenuListener = new ContextMenuListener((info) => {
|
||||
remote.getCurrentWebContents().on('context-menu', (e, info) => {
|
||||
window.contextMenuBuilder.buildMenuForElement(info)
|
||||
.then((menu) => {
|
||||
if (info.linkURL && info.linkURL.length > 0) {
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ const create = () => {
|
|||
|
||||
win = new BrowserWindow({
|
||||
width: 400,
|
||||
height: 590,
|
||||
height: 550,
|
||||
resizable: false,
|
||||
maximizable: false,
|
||||
minimizable: false,
|
||||
|
|
|
|||
51
public/windows/spellcheck-languages.js
Normal file
51
public/windows/spellcheck-languages.js
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
const { BrowserWindow } = require('electron');
|
||||
const path = require('path');
|
||||
|
||||
const { REACT_PATH } = require('../constants/paths');
|
||||
const { getPreference } = require('../libs/preferences');
|
||||
|
||||
const mainWindow = require('./main');
|
||||
|
||||
let win;
|
||||
|
||||
const get = () => win;
|
||||
|
||||
const create = () => {
|
||||
const attachToMenubar = getPreference('attachToMenubar');
|
||||
|
||||
win = new BrowserWindow({
|
||||
width: 400,
|
||||
height: 590,
|
||||
resizable: false,
|
||||
maximizable: false,
|
||||
minimizable: false,
|
||||
fullscreenable: false,
|
||||
autoHideMenuBar: true,
|
||||
webPreferences: {
|
||||
nodeIntegration: true,
|
||||
webSecurity: false,
|
||||
preload: path.join(__dirname, '..', 'preload', 'spellcheck-languages.js'),
|
||||
},
|
||||
parent: attachToMenubar ? null : mainWindow.get(),
|
||||
});
|
||||
|
||||
win.loadURL(REACT_PATH);
|
||||
|
||||
win.on('closed', () => {
|
||||
win = null;
|
||||
});
|
||||
};
|
||||
|
||||
const show = () => {
|
||||
if (win == null) {
|
||||
create();
|
||||
} else {
|
||||
win.show();
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
get,
|
||||
create,
|
||||
show,
|
||||
};
|
||||
|
|
@ -12,8 +12,7 @@ import DateFnsUtils from '@date-io/date-fns';
|
|||
|
||||
import connectComponent from '../helpers/connect-component';
|
||||
|
||||
import { updateIsDarkMode, updateIsFullScreen } from '../state/general/actions';
|
||||
import { getShouldUseDarkMode } from '../state/general/utils';
|
||||
import { updateIsFullScreen } from '../state/general/actions';
|
||||
|
||||
class AppWrapper extends React.Component {
|
||||
constructor(props) {
|
||||
|
|
@ -21,33 +20,18 @@ class AppWrapper extends React.Component {
|
|||
|
||||
this.handleEnterFullScreen = this.handleEnterFullScreen.bind(this);
|
||||
this.handleLeaveFullScreen = this.handleLeaveFullScreen.bind(this);
|
||||
this.handleChangeTheme = this.handleChangeTheme.bind(this);
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
const { remote } = window.require('electron');
|
||||
remote.getCurrentWindow().on('enter-full-screen', this.handleEnterFullScreen);
|
||||
remote.getCurrentWindow().on('leave-full-screen', this.handleLeaveFullScreen);
|
||||
|
||||
if (window.process.platform === 'darwin') {
|
||||
this.appleInterfaceThemeChangedNotificationId = remote.systemPreferences
|
||||
.subscribeNotification(
|
||||
'AppleInterfaceThemeChangedNotification',
|
||||
this.handleChangeTheme,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
const { remote } = window.require('electron');
|
||||
remote.getCurrentWindow().removeListener('enter-full-screen', this.handleEnterFullScreen);
|
||||
remote.getCurrentWindow().removeListener('leave-full-screen', this.handleLeaveFullScreen);
|
||||
|
||||
if (window.process.platform === 'darwin') {
|
||||
remote.systemPreferences.unsubscribeNotification(
|
||||
this.appleInterfaceThemeChangedNotificationId,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
handleEnterFullScreen() {
|
||||
|
|
@ -60,21 +44,15 @@ class AppWrapper extends React.Component {
|
|||
onUpdateIsFullScreen(false);
|
||||
}
|
||||
|
||||
handleChangeTheme() {
|
||||
const { onUpdateIsDarkMode } = this.props;
|
||||
const { remote } = window.require('electron');
|
||||
onUpdateIsDarkMode(remote.systemPreferences.isDarkMode());
|
||||
}
|
||||
|
||||
render() {
|
||||
const { children, shouldUseDarkMode } = this.props;
|
||||
const { children, shouldUseDarkColors } = this.props;
|
||||
|
||||
const themeObj = {
|
||||
typography: {
|
||||
fontSize: 13.5,
|
||||
},
|
||||
palette: {
|
||||
type: shouldUseDarkMode ? 'dark' : 'light',
|
||||
type: shouldUseDarkColors ? 'dark' : 'light',
|
||||
primary: {
|
||||
light: blue[300],
|
||||
main: blue[600],
|
||||
|
|
@ -93,7 +71,7 @@ class AppWrapper extends React.Component {
|
|||
},
|
||||
};
|
||||
|
||||
if (!shouldUseDarkMode) {
|
||||
if (!shouldUseDarkColors) {
|
||||
themeObj.background = {
|
||||
primary: grey[200],
|
||||
};
|
||||
|
|
@ -117,17 +95,15 @@ AppWrapper.propTypes = {
|
|||
PropTypes.element,
|
||||
PropTypes.string,
|
||||
]).isRequired,
|
||||
shouldUseDarkMode: PropTypes.bool.isRequired,
|
||||
onUpdateIsDarkMode: PropTypes.func.isRequired,
|
||||
shouldUseDarkColors: PropTypes.bool.isRequired,
|
||||
onUpdateIsFullScreen: PropTypes.func.isRequired,
|
||||
};
|
||||
|
||||
const mapStateToProps = (state) => ({
|
||||
shouldUseDarkMode: getShouldUseDarkMode(state),
|
||||
shouldUseDarkColors: state.general.shouldUseDarkColors,
|
||||
});
|
||||
|
||||
const actionCreators = {
|
||||
updateIsDarkMode,
|
||||
updateIsFullScreen,
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -19,7 +19,6 @@ import connectComponent from '../../helpers/connect-component';
|
|||
import { requestOpenInBrowser } from '../../senders';
|
||||
|
||||
import { getHits, updateMode } from '../../state/dialog-add-workspace/actions';
|
||||
import { getShouldUseDarkMode } from '../../state/general/utils';
|
||||
|
||||
import AppCard from './app-card';
|
||||
import SubmitAppCard from './submit-app-card';
|
||||
|
|
@ -105,7 +104,7 @@ class AddWorkspace extends React.Component {
|
|||
mode,
|
||||
onGetHits,
|
||||
onUpdateMode,
|
||||
shouldUseDarkMode,
|
||||
shouldUseDarkColors,
|
||||
} = this.props;
|
||||
|
||||
const renderContent = () => {
|
||||
|
|
@ -181,7 +180,7 @@ class AddWorkspace extends React.Component {
|
|||
className={classes.searchByAlgoliaContainer}
|
||||
>
|
||||
<img
|
||||
src={shouldUseDarkMode ? searchByAlgoliaDarkSvg : searchByAlgoliaLightSvg}
|
||||
src={shouldUseDarkColors ? searchByAlgoliaDarkSvg : searchByAlgoliaLightSvg}
|
||||
alt="Search by Algolia"
|
||||
className={classes.searchByAlgolia}
|
||||
/>
|
||||
|
|
@ -260,7 +259,7 @@ AddWorkspace.propTypes = {
|
|||
mode: PropTypes.string.isRequired,
|
||||
onGetHits: PropTypes.func.isRequired,
|
||||
onUpdateMode: PropTypes.func.isRequired,
|
||||
shouldUseDarkMode: PropTypes.bool.isRequired,
|
||||
shouldUseDarkColors: PropTypes.bool.isRequired,
|
||||
};
|
||||
|
||||
const mapStateToProps = (state) => ({
|
||||
|
|
@ -269,7 +268,7 @@ const mapStateToProps = (state) => ({
|
|||
hits: state.dialogAddWorkspace.hits,
|
||||
isGetting: state.dialogAddWorkspace.isGetting,
|
||||
mode: state.dialogAddWorkspace.mode,
|
||||
shouldUseDarkMode: getShouldUseDarkMode(state),
|
||||
shouldUseDarkColors: state.general.shouldUseDarkColors,
|
||||
});
|
||||
|
||||
const actionCreators = {
|
||||
|
|
|
|||
|
|
@ -36,9 +36,6 @@ const styles = (theme) => ({
|
|||
hidden: {
|
||||
display: 'none',
|
||||
},
|
||||
root: {
|
||||
padding: 0,
|
||||
},
|
||||
pausingHeader: {
|
||||
background: `url(${nightBackgroundPng})`,
|
||||
height: 210,
|
||||
|
|
@ -93,10 +90,18 @@ const DialogPauseNotifications = (props) => {
|
|||
name: '4 hours',
|
||||
calcDate: () => addHours(new Date(), 4),
|
||||
},
|
||||
{
|
||||
name: '6 hours',
|
||||
calcDate: () => addHours(new Date(), 6),
|
||||
},
|
||||
{
|
||||
name: '8 hours',
|
||||
calcDate: () => addHours(new Date(), 8),
|
||||
},
|
||||
{
|
||||
name: '10 hours',
|
||||
calcDate: () => addHours(new Date(), 8),
|
||||
},
|
||||
{
|
||||
name: '12 hours',
|
||||
calcDate: () => addHours(new Date(), 12),
|
||||
|
|
@ -125,8 +130,8 @@ const DialogPauseNotifications = (props) => {
|
|||
if (shouldPauseNotifications) {
|
||||
return (
|
||||
<List
|
||||
component="nav"
|
||||
className={classes.root}
|
||||
dense
|
||||
disablePadding
|
||||
>
|
||||
<ListItem classes={{ root: classes.pausingHeader }}>
|
||||
<ListItemText
|
||||
|
|
@ -200,9 +205,9 @@ const DialogPauseNotifications = (props) => {
|
|||
|
||||
return (
|
||||
<List
|
||||
component="nav"
|
||||
dense
|
||||
disablePadding
|
||||
subheader={<ListSubheader component="div">Pause notifications</ListSubheader>}
|
||||
className={classes.root}
|
||||
>
|
||||
{quickShortcuts.map((shortcut) => (
|
||||
<ListItem
|
||||
|
|
|
|||
|
|
@ -35,6 +35,8 @@ import StatedMenu from '../shared/stated-menu';
|
|||
|
||||
import { updateIsDefaultMailClient, updateIsDefaultWebBrowser } from '../../state/general/actions';
|
||||
|
||||
import hunspellLanguagesMap from '../../constants/hunspell-languages';
|
||||
|
||||
import webcatalogLogo from '../../images/webcatalog-logo.svg';
|
||||
import translatiumLogo from '../../images/translatium-logo.svg';
|
||||
import singleboxLogo from '../../images/singlebox-logo.svg';
|
||||
|
|
@ -48,6 +50,7 @@ import {
|
|||
requestResetPreferences,
|
||||
requestSetPreference,
|
||||
requestSetSystemPreference,
|
||||
requestSetThemeSource,
|
||||
requestShowAboutWindow,
|
||||
requestShowCodeInjectionWindow,
|
||||
requestShowCustomUserAgentWindow,
|
||||
|
|
@ -55,6 +58,7 @@ import {
|
|||
requestShowNotificationsWindow,
|
||||
requestShowProxyWindow,
|
||||
requestShowRequireRestartDialog,
|
||||
requestShowSpellcheckLanguagesWindow,
|
||||
} from '../../senders';
|
||||
|
||||
const styles = (theme) => ({
|
||||
|
|
@ -108,57 +112,6 @@ const getOpenAtLoginString = (openAtLogin) => {
|
|||
return 'No';
|
||||
};
|
||||
|
||||
// language code extracted from https://github.com/electron/electron/releases/download/v8.0.0-beta.3/hunspell_dictionaries.zip
|
||||
// languages name from http://www.lingoes.net/en/translator/langcode.htm & Chrome preferences
|
||||
// sorted by name
|
||||
const hunspellLanguagesMap = {
|
||||
'af-ZA': 'Afrikaans',
|
||||
sq: 'Albanian - shqip',
|
||||
hy: 'Armenian - հայերեն',
|
||||
'bg-BG': 'Bulgarian - български',
|
||||
'ca-ES': 'Catalan - català',
|
||||
'hr-HR': 'Croatian - hrvatski',
|
||||
'cs-CZ': 'Czech - čeština',
|
||||
'da-DK': 'Danish - dansk',
|
||||
'nl-NL': 'Dutch - Nederlands',
|
||||
'en-AU': 'English (Australia)',
|
||||
'en-CA': 'English (Canada)',
|
||||
'en-GB': 'English (United Kingdom)',
|
||||
'en-US': 'English (United States)',
|
||||
'et-EE': 'Estonian - eesti',
|
||||
'fo-FO': 'Faroese - føroyskt',
|
||||
'fr-FR': 'French - français',
|
||||
'de-DE': 'German - Deutsch',
|
||||
'el-GR': 'Greek - Ελληνικά',
|
||||
'he-IL': 'Hebrew - עברית',
|
||||
'hi-IN': 'Hindi - हिन्दी',
|
||||
'hu-HU': 'Hungarian - magyar',
|
||||
'id-ID': 'Indonesian - Indonesia',
|
||||
'it-IT': 'Italian - italiano',
|
||||
ko: 'Korean - 한국어',
|
||||
'lv-LV': 'Latvian - latviešu',
|
||||
'lt-LT': 'Lithuanian - lietuvių',
|
||||
'nb-NO': 'Norwegian Bokmål - norsk bokmål',
|
||||
'fa-IR': 'Persian - فارسی',
|
||||
'pl-PL': 'Polish - polski',
|
||||
'pt-BR': 'Portuguese (Brazil) - português (Brasil)',
|
||||
'pt-PT': 'Portuguese (Portugal) - português (Portugal)',
|
||||
'ro-RO': 'Romanian - română',
|
||||
'ru-RU': 'Russian - русский',
|
||||
sr: 'Serbian - српски',
|
||||
sh: 'Serbo-Croatian - srpskohrvatski',
|
||||
'sk-SK': 'Slovak - slovenčina',
|
||||
'sl-SI': 'Slovenian - slovenščina',
|
||||
'es-ES': 'Spanish - español',
|
||||
'sv-SE': 'Swedish - svenska',
|
||||
'tg-TG': 'Tajik - тоҷикӣ',
|
||||
'ta-IN': 'Tamil - தமிழ்',
|
||||
'tr-TR': 'Turkish - Türkçe',
|
||||
'uk-UA': 'Ukrainian - українська',
|
||||
'vi-VN': 'Vietnamese - Tiếng Việt',
|
||||
'cy-GB': 'Welsh - Cymraeg',
|
||||
};
|
||||
|
||||
const formatBytes = (bytes, decimals = 2) => {
|
||||
if (bytes === 0) return '0 Bytes';
|
||||
|
||||
|
|
@ -218,10 +171,10 @@ const Preferences = ({
|
|||
rememberLastPageVisited,
|
||||
shareWorkspaceBrowsingData,
|
||||
sidebar,
|
||||
spellChecker,
|
||||
spellCheckerLanguages,
|
||||
spellcheck,
|
||||
spellcheckLanguages,
|
||||
swipeToNavigate,
|
||||
theme,
|
||||
themeSource,
|
||||
titleBar,
|
||||
unreadCountBadge,
|
||||
updaterInfo,
|
||||
|
|
@ -332,14 +285,14 @@ const Preferences = ({
|
|||
id="theme"
|
||||
buttonElement={(
|
||||
<ListItem button>
|
||||
<ListItemText primary="Theme" secondary={getThemeString(theme)} />
|
||||
<ListItemText primary="Theme" secondary={getThemeString(themeSource)} />
|
||||
<ChevronRightIcon color="action" />
|
||||
</ListItem>
|
||||
)}
|
||||
>
|
||||
<MenuItem dense onClick={() => requestSetPreference('theme', 'automatic')}>System default</MenuItem>
|
||||
<MenuItem dense onClick={() => requestSetPreference('theme', 'light')}>Light</MenuItem>
|
||||
<MenuItem dense onClick={() => requestSetPreference('theme', 'dark')}>Dark</MenuItem>
|
||||
<MenuItem dense onClick={() => requestSetThemeSource('system')}>System default</MenuItem>
|
||||
<MenuItem dense onClick={() => requestSetThemeSource('light')}>Light</MenuItem>
|
||||
<MenuItem dense onClick={() => requestSetThemeSource('dark')}>Dark</MenuItem>
|
||||
</StatedMenu>
|
||||
<Divider />
|
||||
<ListItem>
|
||||
|
|
@ -578,40 +531,26 @@ const Preferences = ({
|
|||
<Switch
|
||||
edge="end"
|
||||
color="primary"
|
||||
checked={spellChecker}
|
||||
checked={spellcheck}
|
||||
onChange={(e) => {
|
||||
requestSetPreference('spellChecker', e.target.checked);
|
||||
requestSetPreference('spellcheck', e.target.checked);
|
||||
requestShowRequireRestartDialog();
|
||||
}}
|
||||
/>
|
||||
</ListItemSecondaryAction>
|
||||
</ListItem>
|
||||
<Divider />
|
||||
<StatedMenu
|
||||
id="spellcheckerLanguages"
|
||||
buttonElement={(
|
||||
<ListItem button>
|
||||
{window.process.platform === 'darwin' && (
|
||||
<>
|
||||
<Divider />
|
||||
<ListItem button onClick={requestShowSpellcheckLanguagesWindow}>
|
||||
<ListItemText
|
||||
primary="Spell checking language"
|
||||
secondary={spellCheckerLanguages.map((code) => hunspellLanguagesMap[code]).join(' | ')}
|
||||
primary="Preferred spell checking languages"
|
||||
secondary={spellcheckLanguages.map((code) => hunspellLanguagesMap[code]).join(' | ')}
|
||||
/>
|
||||
<ChevronRightIcon color="action" />
|
||||
</ListItem>
|
||||
)}
|
||||
>
|
||||
{Object.keys(hunspellLanguagesMap).map((code) => (
|
||||
<MenuItem
|
||||
dense
|
||||
key={code}
|
||||
onClick={() => {
|
||||
requestSetPreference('spellCheckerLanguages', [code]);
|
||||
requestShowRequireRestartDialog();
|
||||
}}
|
||||
>
|
||||
{hunspellLanguagesMap[code]}
|
||||
</MenuItem>
|
||||
))}
|
||||
</StatedMenu>
|
||||
</>
|
||||
)}
|
||||
</List>
|
||||
</Paper>
|
||||
|
||||
|
|
@ -981,10 +920,10 @@ Preferences.propTypes = {
|
|||
rememberLastPageVisited: PropTypes.bool.isRequired,
|
||||
shareWorkspaceBrowsingData: PropTypes.bool.isRequired,
|
||||
sidebar: PropTypes.bool.isRequired,
|
||||
spellChecker: PropTypes.bool.isRequired,
|
||||
spellCheckerLanguages: PropTypes.arrayOf(PropTypes.string).isRequired,
|
||||
spellcheck: PropTypes.bool.isRequired,
|
||||
spellcheckLanguages: PropTypes.arrayOf(PropTypes.string).isRequired,
|
||||
swipeToNavigate: PropTypes.bool.isRequired,
|
||||
theme: PropTypes.string.isRequired,
|
||||
themeSource: PropTypes.string.isRequired,
|
||||
titleBar: PropTypes.bool.isRequired,
|
||||
unreadCountBadge: PropTypes.bool.isRequired,
|
||||
updaterInfo: PropTypes.object,
|
||||
|
|
@ -1014,10 +953,9 @@ const mapStateToProps = (state) => ({
|
|||
rememberLastPageVisited: state.preferences.rememberLastPageVisited,
|
||||
shareWorkspaceBrowsingData: state.preferences.shareWorkspaceBrowsingData,
|
||||
sidebar: state.preferences.sidebar,
|
||||
spellChecker: state.preferences.spellChecker,
|
||||
spellCheckerLanguages: state.preferences.spellCheckerLanguages,
|
||||
spellcheck: state.preferences.spellcheck,
|
||||
spellcheckLanguages: state.preferences.spellcheckLanguages,
|
||||
swipeToNavigate: state.preferences.swipeToNavigate,
|
||||
theme: state.preferences.theme,
|
||||
titleBar: state.preferences.titleBar,
|
||||
unreadCountBadge: state.preferences.unreadCountBadge,
|
||||
updaterInfo: state.updater.info,
|
||||
|
|
|
|||
122
src/components/dialog-spellcheck-languages/index.js
Normal file
122
src/components/dialog-spellcheck-languages/index.js
Normal file
|
|
@ -0,0 +1,122 @@
|
|||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
|
||||
import Button from '@material-ui/core/Button';
|
||||
import Checkbox from '@material-ui/core/Checkbox';
|
||||
import List from '@material-ui/core/List';
|
||||
import ListItem from '@material-ui/core/ListItem';
|
||||
import ListItemIcon from '@material-ui/core/ListItemIcon';
|
||||
import ListItemText from '@material-ui/core/ListItemText';
|
||||
|
||||
import connectComponent from '../../helpers/connect-component';
|
||||
|
||||
import hunspellLanguagesMap from '../../constants/hunspell-languages';
|
||||
|
||||
import {
|
||||
addLanguage,
|
||||
removeLanguage,
|
||||
save,
|
||||
} from '../../state/dialog-spellcheck-languages/actions';
|
||||
|
||||
const styles = (theme) => ({
|
||||
root: {
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
height: '100vh',
|
||||
},
|
||||
top: {
|
||||
flex: 1,
|
||||
overflow: 'auto',
|
||||
},
|
||||
bottom: {
|
||||
display: 'fixed',
|
||||
zIndex: 10,
|
||||
bottom: 0,
|
||||
left: 0,
|
||||
padding: theme.spacing(1),
|
||||
},
|
||||
button: {
|
||||
float: 'right',
|
||||
marginLeft: theme.spacing(1),
|
||||
},
|
||||
});
|
||||
|
||||
const DialogSpellcheckLanguages = (props) => {
|
||||
const {
|
||||
classes,
|
||||
spellcheckLanguages,
|
||||
onSave,
|
||||
onAddLanguage,
|
||||
onRemoveLanguage,
|
||||
} = props;
|
||||
|
||||
return (
|
||||
<div className={classes.root}>
|
||||
<List
|
||||
disablePadding
|
||||
dense
|
||||
className={classes.top}
|
||||
>
|
||||
{Object.keys(hunspellLanguagesMap).map((code) => (
|
||||
<ListItem
|
||||
dense
|
||||
key={code}
|
||||
button
|
||||
onClick={() => {
|
||||
if (spellcheckLanguages.includes(code)) {
|
||||
onRemoveLanguage(code);
|
||||
} else {
|
||||
onAddLanguage(code);
|
||||
}
|
||||
}}
|
||||
>
|
||||
<ListItemIcon>
|
||||
<Checkbox
|
||||
edge="start"
|
||||
checked={spellcheckLanguages.includes(code)}
|
||||
disabled={spellcheckLanguages.length < 2
|
||||
&& spellcheckLanguages.includes(code)}
|
||||
/>
|
||||
</ListItemIcon>
|
||||
<ListItemText primary={hunspellLanguagesMap[code]} />
|
||||
</ListItem>
|
||||
))}
|
||||
</List>
|
||||
<div className={classes.bottom}>
|
||||
<Button color="primary" variant="contained" disableElevation className={classes.button} onClick={onSave}>
|
||||
Save
|
||||
</Button>
|
||||
<Button variant="contained" disableElevation className={classes.button} onClick={() => window.require('electron').remote.getCurrentWindow().close()}>
|
||||
Cancel
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
DialogSpellcheckLanguages.defaultProps = {};
|
||||
|
||||
DialogSpellcheckLanguages.propTypes = {
|
||||
classes: PropTypes.object.isRequired,
|
||||
onAddLanguage: PropTypes.func.isRequired,
|
||||
onRemoveLanguage: PropTypes.func.isRequired,
|
||||
onSave: PropTypes.func.isRequired,
|
||||
spellcheckLanguages: PropTypes.arrayOf(PropTypes.string).isRequired,
|
||||
};
|
||||
|
||||
const mapStateToProps = (state) => ({
|
||||
spellcheckLanguages: state.dialogSpellcheckLanguages.form.spellcheckLanguages,
|
||||
});
|
||||
|
||||
const actionCreators = {
|
||||
save,
|
||||
addLanguage,
|
||||
removeLanguage,
|
||||
};
|
||||
|
||||
export default connectComponent(
|
||||
DialogSpellcheckLanguages,
|
||||
mapStateToProps,
|
||||
actionCreators,
|
||||
styles,
|
||||
);
|
||||
|
|
@ -42,7 +42,7 @@ const FakeTitleBar = (props) => {
|
|||
<div
|
||||
className={classnames(classes.root, window.mode === 'menubar' && classes.rootMenubar)}
|
||||
>
|
||||
{(window.mode === 'main' || window.mode === 'menubar') && title ? title : window.require('electron').getCurrentWindow().getTitle()}
|
||||
{(window.mode === 'main' || window.mode === 'menubar') && title ? title : window.require('electron').remote.getCurrentWindow().getTitle()}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ class StatedMenu extends React.Component {
|
|||
buttonElement,
|
||||
children,
|
||||
id,
|
||||
hasCheckbox,
|
||||
} = this.props;
|
||||
|
||||
const { anchorEl, open } = this.state;
|
||||
|
|
@ -46,9 +47,10 @@ class StatedMenu extends React.Component {
|
|||
open={open}
|
||||
onClose={this.handleRequestClose}
|
||||
anchorOrigin={{ vertical: 'top', horizontal: 'center' }}
|
||||
disableAutoFocusItem={hasCheckbox}
|
||||
>
|
||||
{React.Children.map(children, (child) => child && React.cloneElement(child, {
|
||||
onClick: () => {
|
||||
onClick: hasCheckbox ? null : () => {
|
||||
if (child.props.onClick) child.props.onClick();
|
||||
this.handleRequestClose();
|
||||
},
|
||||
|
|
@ -59,9 +61,14 @@ class StatedMenu extends React.Component {
|
|||
}
|
||||
}
|
||||
|
||||
StatedMenu.defaultProps = {
|
||||
hasCheckbox: false,
|
||||
};
|
||||
|
||||
StatedMenu.propTypes = {
|
||||
buttonElement: PropTypes.element.isRequired,
|
||||
children: PropTypes.node.isRequired,
|
||||
hasCheckbox: PropTypes.bool,
|
||||
id: PropTypes.string.isRequired,
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -21,7 +21,6 @@ export const UPDATE_ADDRESS_BAR_INFO = 'UPDATE_ADDRESS_BAR_INFO';
|
|||
export const UPDATE_CAN_GO_BACK = 'UPDATE_CAN_GO_BACK';
|
||||
export const UPDATE_CAN_GO_FORWARD = 'UPDATE_CAN_GO_FORWARD';
|
||||
export const UPDATE_DID_FAIL_LOAD = 'UPDATE_DID_FAIL_LOAD';
|
||||
export const UPDATE_IS_DARK_MODE = 'UPDATE_IS_DARK_MODE';
|
||||
export const UPDATE_IS_DEFAULT_MAIL_CLIENT = 'UPDATE_IS_DEFAULT_MAIL_CLIENT';
|
||||
export const UPDATE_IS_DEFAULT_WEB_BROWSER = 'UPDATE_IS_DEFAULT_WEB_BROWSER';
|
||||
export const UPDATE_IS_FULL_SCREEN = 'UPDATE_IS_FULL_SCREEN';
|
||||
|
|
@ -72,3 +71,11 @@ export const UPDATE_UPDATER = 'UPDATE_UPDATER';
|
|||
// Proxy
|
||||
export const DIALOG_PROXY_FORM_UPDATE = 'DIALOG_PROXY_FORM_UPDATE';
|
||||
export const DIALOG_PROXY_INIT = 'DIALOG_PROXY_INIT';
|
||||
|
||||
// Spell Check Languages
|
||||
export const DIALOG_SPELLCHECK_LANGUAGES_INIT = 'DIALOG_SPELLCHECK_LANGUAGES_INIT';
|
||||
export const DIALOG_SPELLCHECK_LANGUAGES_UPDATE_FORM = 'DIALOG_SPELLCHECK_LANGUAGES_UPDATE_FORM';
|
||||
|
||||
// Theme
|
||||
export const UPDATE_SHOULD_USE_DARK_COLORS = 'UPDATE_SHOULD_USE_DARK_COLORS';
|
||||
export const UPDATE_THEME_SOURCE = 'UPDATE_THEME_SOURCE';
|
||||
|
|
|
|||
60
src/constants/hunspell-languages.js
Normal file
60
src/constants/hunspell-languages.js
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
// language code extracted from session.availableSpellCheckerLanguages: string[]
|
||||
// languages name from http://www.lingoes.net/en/translator/langcode.htm & Chrome preferences
|
||||
// sorted by name
|
||||
|
||||
/* eslint-disable quote-props */
|
||||
const hunspellLanguagesMap = {
|
||||
'af': 'Afrikaans',
|
||||
'bg': 'Bulgarian - български',
|
||||
'ca': 'Catalan - català',
|
||||
'cs': 'Czech - čeština',
|
||||
'cy': 'Welsh - Cymraeg',
|
||||
'da': 'Danish - dansk',
|
||||
'de': 'German - Deutsch',
|
||||
'el': 'Greek - Ελληνικά',
|
||||
'en-AU': 'English (Australia)',
|
||||
'en-CA': 'English (Canada)',
|
||||
'en-GB': 'English (United Kingdom)',
|
||||
'en-US': 'English (United States)',
|
||||
'es': 'Spanish - español',
|
||||
'es-419': 'Spanish (Latin America) - español (América Latina)',
|
||||
'es-AR': 'Spanish (Argentina) - español (Argentina)',
|
||||
'es-ES': 'Spanish (Spain) - español (España)',
|
||||
'es-MX': 'Spanish (Mexico) - español (México)',
|
||||
'es-US': 'Spanish (United States) - español (Estados Unidos)',
|
||||
'et': 'Estonian - eesti',
|
||||
'fa': 'Persian - فارسی',
|
||||
'fo': 'Faroese - føroyskt',
|
||||
'fr': 'French - français',
|
||||
'he': 'Hebrew - עברית',
|
||||
'hi': 'Hindi - हिन्दी',
|
||||
'hr': 'Croatian - hrvatski',
|
||||
'hu': 'Hungarian - magyar',
|
||||
'hy': 'Armenian - հայերեն',
|
||||
'id': 'Indonesian - Indonesia',
|
||||
'it': 'Italian - italiano',
|
||||
'ko': 'Korean - 한국어',
|
||||
'lt': 'Lithuanian - lietuvių',
|
||||
'lv': 'Latvian - latviešu',
|
||||
'nb': 'Norwegian Bokmål - norsk bokmål',
|
||||
'nl': 'Dutch - Nederlands',
|
||||
'pl': 'Polish - polski',
|
||||
'pt-BR': 'Portuguese (Brazil) - português (Brasil)',
|
||||
'pt-PT': 'Portuguese (Portugal) - português (Portugal)',
|
||||
'ro': 'Romanian - română',
|
||||
'ru': 'Russian - русский',
|
||||
'sh': 'Serbo-Croatian - srpskohrvatski',
|
||||
'sk': 'Slovak - slovenčina',
|
||||
'sl': 'Slovenian - slovenščina',
|
||||
'sq': 'Albanian - shqip',
|
||||
'sr': 'Serbian - српски',
|
||||
'sv': 'Swedish - svenska',
|
||||
'ta': 'Tamil - தமிழ்',
|
||||
'tg': 'Tajik - тоҷикӣ',
|
||||
'tr': 'Turkish - Türkçe',
|
||||
'uk': 'Ukrainian - українська',
|
||||
'vi': 'Vietnamese - Tiếng Việt',
|
||||
};
|
||||
/* eslint-enable quote-props */
|
||||
|
||||
export default hunspellLanguagesMap;
|
||||
|
|
@ -11,6 +11,7 @@ import { init as initDialogCodeInjection } from './state/dialog-code-injection/a
|
|||
import { init as initDialogCustomUserAgent } from './state/dialog-custom-user-agent/actions';
|
||||
import { init as initDialogEditWorkspace } from './state/dialog-edit-workspace/actions';
|
||||
import { init as initDialogProxy } from './state/dialog-proxy/actions';
|
||||
import { init as initDialogSpellcheckLanguages } from './state/dialog-spellcheck-languages/actions';
|
||||
|
||||
import AppWrapper from './components/app-wrapper';
|
||||
|
||||
|
|
@ -29,6 +30,7 @@ const DialogNotifications = React.lazy(() => import('./components/dialog-notific
|
|||
const DialogOpenUrlWith = React.lazy(() => import('./components/dialog-open-url-with'));
|
||||
const DialogPreferences = React.lazy(() => import('./components/dialog-preferences'));
|
||||
const DialogProxy = React.lazy(() => import('./components/dialog-proxy'));
|
||||
const DialogSpellcheckLanguages = React.lazy(() => import('./components/dialog-spellcheck-languages'));
|
||||
const Main = React.lazy(() => import('./components/main'));
|
||||
|
||||
const App = () => {
|
||||
|
|
@ -46,6 +48,7 @@ const App = () => {
|
|||
case 'open-url-with': return <DialogOpenUrlWith />;
|
||||
case 'preferences': return <DialogPreferences />;
|
||||
case 'proxy': return <DialogProxy />;
|
||||
case 'spellcheck-languages': return <DialogSpellcheckLanguages />;
|
||||
default: return <Main />;
|
||||
}
|
||||
};
|
||||
|
|
@ -55,7 +58,6 @@ const runApp = () => {
|
|||
.then(() => {
|
||||
const { webFrame, remote } = window.require('electron');
|
||||
webFrame.setVisualZoomLevelLimits(1, 1);
|
||||
webFrame.setLayoutZoomLevelLimits(0, 0);
|
||||
if (window.mode === 'about') {
|
||||
document.title = 'About';
|
||||
} else if (window.mode === 'license-registration') {
|
||||
|
|
@ -98,6 +100,9 @@ const runApp = () => {
|
|||
} else if (window.mode === 'proxy') {
|
||||
store.dispatch(initDialogProxy());
|
||||
document.title = 'Proxy Settings';
|
||||
} else if (window.mode === 'spellcheck-languages') {
|
||||
store.dispatch(initDialogSpellcheckLanguages());
|
||||
document.title = 'Preferred Spell Checking Languages';
|
||||
} else {
|
||||
document.title = 'Singlebox';
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@ import { setPreference } from '../state/preferences/actions';
|
|||
import { setSystemPreference } from '../state/system-preferences/actions';
|
||||
import { setWorkspace } from '../state/workspaces/actions';
|
||||
import {
|
||||
updateShouldUseDarkColors,
|
||||
updateThemeSource,
|
||||
updateAddressBarInfo,
|
||||
updateCanGoBack,
|
||||
updateCanGoForward,
|
||||
|
|
@ -18,7 +20,11 @@ import {
|
|||
updatePauseNotificationsInfo,
|
||||
} from '../state/notifications/actions';
|
||||
import { updateUpdater } from '../state/updater/actions';
|
||||
import { requestFindInPage } from '../senders';
|
||||
import {
|
||||
getShouldUseDarkColors,
|
||||
getThemeSource,
|
||||
requestFindInPage,
|
||||
} from '../senders';
|
||||
|
||||
const loadListeners = (store) => {
|
||||
const { ipcRenderer } = window.require('electron');
|
||||
|
|
@ -90,6 +96,11 @@ const loadListeners = (store) => {
|
|||
ipcRenderer.on('update-updater', (e, updaterObj) => {
|
||||
store.dispatch(updateUpdater(updaterObj));
|
||||
});
|
||||
|
||||
ipcRenderer.on('native-theme-updated', () => {
|
||||
store.dispatch(updateThemeSource(getThemeSource()));
|
||||
store.dispatch(updateShouldUseDarkColors(getShouldUseDarkColors()));
|
||||
});
|
||||
};
|
||||
|
||||
export default loadListeners;
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ export const requestShowLicenseRegistrationWindow = () => ipcRenderer.send('requ
|
|||
export const requestShowNotificationsWindow = () => ipcRenderer.send('request-show-notifications-window');
|
||||
export const requestShowPreferencesWindow = (scrollTo) => ipcRenderer.send('request-show-preferences-window', scrollTo);
|
||||
export const requestShowProxyWindow = () => ipcRenderer.send('request-show-proxy-window');
|
||||
export const requestShowSpellcheckLanguagesWindow = () => ipcRenderer.send('request-show-spellcheck-languages-window');
|
||||
|
||||
// Notifications
|
||||
export const requestShowNotification = (opts) => ipcRenderer.send('request-show-notification', opts);
|
||||
|
|
@ -61,3 +62,8 @@ export const requestStopFindInPage = (close) => ipcRenderer.send('request-stop-f
|
|||
|
||||
// Auth
|
||||
export const requestValidateAuthIdentity = (windowId, username, password) => ipcRenderer.send('request-validate-auth-identity', windowId, username, password);
|
||||
|
||||
// Native Theme
|
||||
export const getShouldUseDarkColors = () => ipcRenderer.sendSync('get-should-use-dark-colors');
|
||||
export const getThemeSource = () => ipcRenderer.sendSync('get-theme-source');
|
||||
export const requestSetThemeSource = (val) => ipcRenderer.send('request-set-theme-source', val);
|
||||
|
|
|
|||
44
src/state/dialog-spellcheck-languages/actions.js
Normal file
44
src/state/dialog-spellcheck-languages/actions.js
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
|
||||
import {
|
||||
DIALOG_SPELLCHECK_LANGUAGES_INIT,
|
||||
DIALOG_SPELLCHECK_LANGUAGES_UPDATE_FORM,
|
||||
} from '../../constants/actions';
|
||||
import { requestSetPreference, requestShowRequireRestartDialog } from '../../senders';
|
||||
|
||||
export const init = () => ({
|
||||
type: DIALOG_SPELLCHECK_LANGUAGES_INIT,
|
||||
});
|
||||
|
||||
export const updateForm = (changes) => (dispatch) => dispatch({
|
||||
type: DIALOG_SPELLCHECK_LANGUAGES_UPDATE_FORM,
|
||||
changes,
|
||||
});
|
||||
|
||||
export const addLanguage = (code) => (dispatch, getState) => {
|
||||
const { spellcheckLanguages } = getState().dialogSpellcheckLanguages.form;
|
||||
if (!spellcheckLanguages.includes(code)) {
|
||||
dispatch(updateForm({
|
||||
spellcheckLanguages: [...spellcheckLanguages, code],
|
||||
}));
|
||||
}
|
||||
};
|
||||
|
||||
export const removeLanguage = (code) => (dispatch, getState) => {
|
||||
const { spellcheckLanguages } = getState().dialogSpellcheckLanguages.form;
|
||||
const filteredSpellCheckerLanguages = spellcheckLanguages
|
||||
.filter((lang) => lang !== code);
|
||||
dispatch(updateForm({
|
||||
spellcheckLanguages: filteredSpellCheckerLanguages,
|
||||
}));
|
||||
};
|
||||
|
||||
export const save = () => (dispatch, getState) => {
|
||||
const { form } = getState().dialogSpellcheckLanguages;
|
||||
const { remote } = window.require('electron');
|
||||
|
||||
requestSetPreference('spellcheckLanguages', form.spellcheckLanguages);
|
||||
|
||||
requestShowRequireRestartDialog();
|
||||
|
||||
remote.getCurrentWindow().close();
|
||||
};
|
||||
22
src/state/dialog-spellcheck-languages/reducers.js
Normal file
22
src/state/dialog-spellcheck-languages/reducers.js
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
import { combineReducers } from 'redux';
|
||||
|
||||
import {
|
||||
DIALOG_SPELLCHECK_LANGUAGES_INIT,
|
||||
DIALOG_SPELLCHECK_LANGUAGES_UPDATE_FORM,
|
||||
} from '../../constants/actions';
|
||||
|
||||
import { getPreference } from '../../senders';
|
||||
|
||||
const form = (state = {}, action) => {
|
||||
switch (action.type) {
|
||||
case DIALOG_SPELLCHECK_LANGUAGES_INIT: {
|
||||
return {
|
||||
spellcheckLanguages: getPreference('spellcheckLanguages'),
|
||||
};
|
||||
}
|
||||
case DIALOG_SPELLCHECK_LANGUAGES_UPDATE_FORM: return { ...state, ...action.changes };
|
||||
default: return state;
|
||||
}
|
||||
};
|
||||
|
||||
export default combineReducers({ form });
|
||||
|
|
@ -1,9 +1,10 @@
|
|||
import {
|
||||
UPDATE_SHOULD_USE_DARK_COLORS,
|
||||
UPDATE_THEME_SOURCE,
|
||||
UPDATE_ADDRESS_BAR_INFO,
|
||||
UPDATE_CAN_GO_BACK,
|
||||
UPDATE_CAN_GO_FORWARD,
|
||||
UPDATE_DID_FAIL_LOAD,
|
||||
UPDATE_IS_DARK_MODE,
|
||||
UPDATE_IS_DEFAULT_MAIL_CLIENT,
|
||||
UPDATE_IS_DEFAULT_WEB_BROWSER,
|
||||
UPDATE_IS_FULL_SCREEN,
|
||||
|
|
@ -11,6 +12,16 @@ import {
|
|||
UPDATE_TITLE,
|
||||
} from '../../constants/actions';
|
||||
|
||||
export const updateShouldUseDarkColors = (shouldUseDarkColors) => ({
|
||||
type: UPDATE_SHOULD_USE_DARK_COLORS,
|
||||
shouldUseDarkColors,
|
||||
});
|
||||
|
||||
export const updateThemeSource = (themeSource) => ({
|
||||
type: UPDATE_THEME_SOURCE,
|
||||
themeSource,
|
||||
});
|
||||
|
||||
export const updateCanGoBack = (canGoBack) => ({
|
||||
type: UPDATE_CAN_GO_BACK,
|
||||
canGoBack,
|
||||
|
|
@ -41,11 +52,6 @@ export const updateIsDefaultWebBrowser = (isDefaultWebBrowser) => ({
|
|||
isDefaultWebBrowser,
|
||||
});
|
||||
|
||||
export const updateIsDarkMode = (isDarkMode) => ({
|
||||
type: UPDATE_IS_DARK_MODE,
|
||||
isDarkMode,
|
||||
});
|
||||
|
||||
export const updateIsLoading = (isLoading) => ({
|
||||
type: UPDATE_IS_LOADING,
|
||||
isLoading,
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
import { combineReducers } from 'redux';
|
||||
|
||||
import {
|
||||
UPDATE_SHOULD_USE_DARK_COLORS,
|
||||
UPDATE_THEME_SOURCE,
|
||||
UPDATE_CAN_GO_BACK,
|
||||
UPDATE_CAN_GO_FORWARD,
|
||||
UPDATE_DID_FAIL_LOAD,
|
||||
UPDATE_IS_DARK_MODE,
|
||||
UPDATE_IS_DEFAULT_MAIL_CLIENT,
|
||||
UPDATE_IS_DEFAULT_WEB_BROWSER,
|
||||
UPDATE_IS_FULL_SCREEN,
|
||||
|
|
@ -13,6 +14,11 @@ import {
|
|||
UPDATE_TITLE,
|
||||
} from '../../constants/actions';
|
||||
|
||||
import {
|
||||
getThemeSource,
|
||||
getShouldUseDarkColors,
|
||||
} from '../../senders';
|
||||
|
||||
const { remote } = window.require('electron');
|
||||
|
||||
const canGoBack = (state = false, action) => {
|
||||
|
|
@ -71,17 +77,23 @@ const isDefaultWebBrowser = (state = remote.app.isDefaultProtocolClient('http'),
|
|||
}
|
||||
};
|
||||
|
||||
|
||||
const isDarkMode = (state = remote.systemPreferences.isDarkMode(), action) => {
|
||||
const isLoading = (state = true, action) => {
|
||||
switch (action.type) {
|
||||
case UPDATE_IS_DARK_MODE: return action.isDarkMode;
|
||||
case UPDATE_IS_LOADING: return action.isLoading;
|
||||
default: return state;
|
||||
}
|
||||
};
|
||||
|
||||
const isLoading = (state = true, action) => {
|
||||
const shouldUseDarkColors = (state = getShouldUseDarkColors(), action) => {
|
||||
switch (action.type) {
|
||||
case UPDATE_IS_LOADING: return action.isLoading;
|
||||
case UPDATE_SHOULD_USE_DARK_COLORS: return action.shouldUseDarkColors;
|
||||
default: return state;
|
||||
}
|
||||
};
|
||||
|
||||
const themeSource = (state = getThemeSource(), action) => {
|
||||
switch (action.type) {
|
||||
case UPDATE_THEME_SOURCE: return action.themeSource;
|
||||
default: return state;
|
||||
}
|
||||
};
|
||||
|
|
@ -99,10 +111,11 @@ export default combineReducers({
|
|||
canGoBack,
|
||||
canGoForward,
|
||||
didFailLoad,
|
||||
isDarkMode,
|
||||
isDefaultMailClient,
|
||||
isDefaultWebBrowser,
|
||||
isFullScreen,
|
||||
isLoading,
|
||||
shouldUseDarkColors,
|
||||
themeSource,
|
||||
title,
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,9 +0,0 @@
|
|||
export const getShouldUseDarkMode = (state) => {
|
||||
let shouldUseDarkMode;
|
||||
if (state.preferences.theme === 'automatic') {
|
||||
shouldUseDarkMode = state.general.isDarkMode;
|
||||
} else {
|
||||
shouldUseDarkMode = state.preferences.theme === 'dark';
|
||||
}
|
||||
return shouldUseDarkMode;
|
||||
};
|
||||
|
|
@ -13,6 +13,7 @@ import dialogEditWorkspace from './dialog-edit-workspace/reducers';
|
|||
import dialogGoToUrl from './dialog-go-to-url/reducers';
|
||||
import dialogLicenseRegistration from './dialog-license-registration/reducers';
|
||||
import dialogProxy from './dialog-proxy/reducers';
|
||||
import dialogSpellcheckLanguages from './dialog-spellcheck-languages/reducers';
|
||||
import findInPage from './find-in-page/reducers';
|
||||
import general from './general/reducers';
|
||||
import notifications from './notifications/reducers';
|
||||
|
|
@ -33,6 +34,7 @@ const rootReducer = combineReducers({
|
|||
dialogGoToUrl,
|
||||
dialogLicenseRegistration,
|
||||
dialogProxy,
|
||||
dialogSpellcheckLanguages,
|
||||
findInPage,
|
||||
general,
|
||||
notifications,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue