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

Updates electron and associated dependencies to the latest #2102

Merged
merged 18 commits into from
Jun 18, 2020
Merged
Show file tree
Hide file tree
Changes from 16 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
6 changes: 1 addition & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ PUBLISH ?= onTag

# Main targets
.PHONY: start
start: rebuild-deps
start:
@NODE_ENV=$(NODE_ENV) DEV_SERVER=$(DEV_SERVER) npx electron .

.PHONY: dev
Expand Down Expand Up @@ -159,10 +159,6 @@ endif
.PHONY: config-release
config-release: config.json install

.PHONY: rebuild-deps
rebuild-deps:
@npx electron-rebuild -v $(ELECTRON_VERSION)

.PHONY: format
format:
@npx prettier --ignore-path .gitignore --write "**/*.{js,jsx,json,sass,ts,tsx}"
Expand Down
12 changes: 5 additions & 7 deletions desktop/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const createMenuTemplate = require('./menus');
const platform = require('./detect/platform');
const updater = require('./updater');
const { isDev } = require('./env');
const spellcheck = require('./spellchecker');

require('module').globalPaths.push(path.resolve(path.join(__dirname)));

Expand Down Expand Up @@ -46,11 +47,6 @@ module.exports = function main() {
defaultHeight: 768,
});

// Create the browser window.
const iconPath = path.join(
__dirname,
'../lib/icons/app-icon/icon_256x256.png'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this mean this icon is now unused, or is it being loaded somewhere else? I would like to remove it if possible (see #2158)

);
mainWindow = new BrowserWindow({
backgroundColor: '#fff',
x: mainWindowState.x,
Expand All @@ -59,11 +55,11 @@ module.exports = function main() {
height: mainWindowState.height,
minWidth: 370,
minHeight: 520,
icon: iconPath,
titleBarStyle: 'hidden',
show: false,
webPreferences: {
nodeIntegration: true,
contextIsolation: true,
nodeIntegration: false,
preload: path.join(__dirname, './preload.js'),
},
});
Expand All @@ -75,6 +71,8 @@ module.exports = function main() {
mainWindow.loadUrl(url);
}

spellcheck(mainWindow);

if (
'test' !== process.env.NODE_ENV &&
(isDev || process.argv.includes('--devtools'))
Expand Down
50 changes: 0 additions & 50 deletions desktop/context-menu/context-menu-builder.js

This file was deleted.

21 changes: 0 additions & 21 deletions desktop/context-menu/index.js

This file was deleted.

20 changes: 0 additions & 20 deletions desktop/context-menu/spellcheck-handler.js

This file was deleted.

22 changes: 21 additions & 1 deletion desktop/preload.js
Original file line number Diff line number Diff line change
@@ -1 +1,21 @@
require('./context-menu');
belcherj marked this conversation as resolved.
Show resolved Hide resolved
const { contextBridge, ipcRenderer } = require('electron');

contextBridge.exposeInMainWorld('electron', {
send: (channel, data) => {
// whitelist channels
let validChannels = ['appCommand', 'setAutoHideMenuBar', 'settingsUpdate'];
if (validChannels.includes(channel)) {
ipcRenderer.send(channel, data);
}
},
receive: (channel, func) => {
let validChannels = ['appCommand'];
if (validChannels.includes(channel)) {
// Deliberately strip event as it includes `sender`
ipcRenderer.on(channel, (event, ...args) => {
return func(...args);
});
}
},
isMac: process.platform === 'darwin',
});
63 changes: 63 additions & 0 deletions desktop/spellchecker/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
'use strict';

/**
* External dependencies
*/
const { Menu, MenuItem } = require('electron');

module.exports = function (mainWindow) {
mainWindow.webContents.on('context-menu', (event, params) => {
const menu = new Menu();

const copy = new MenuItem({ label: 'Copy', role: 'copy' });

if (!params.isEditable) {
// If text is not editable, only permit the `Copy` action
menu.append(copy);
} else {
// Add each spelling suggestion
for (const suggestion of params.dictionarySuggestions) {
menu.append(
new MenuItem({
label: suggestion,
click: () => mainWindow.webContents.replaceMisspelling(suggestion),
})
);
}

// Allow users to add the misspelled word to the dictionary
if (params.misspelledWord) {
menu.append(new MenuItem({ type: 'separator' }));
menu.append(
new MenuItem({
label: 'Add to Dictionary',
click: () =>
mainWindow.webContents.session.addWordToSpellCheckerDictionary(
params.misspelledWord
),
})
);
}

// If text is editable, permit the Select All, Cut, Copy and Paste actions
const cut = new MenuItem({ label: 'Cut', role: 'cut' });
const paste = new MenuItem({ label: 'Paste', role: 'paste' });
const selectAll = new MenuItem({
label: 'Select All',
role: 'selectAll',
});

const menuItems = [selectAll, cut, copy, paste];

if (params?.dictionarySuggestions?.length > 0) {
menu.append(new MenuItem({ type: 'separator' }));
}

for (const item of menuItems) {
menu.append(item);
}
}

menu.popup();
});
};
7 changes: 3 additions & 4 deletions electron-builder.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"productName": "Simplenote",
"appId": "com.automattic.simplenote",
"directories": {
"output": "release",
"buildResources": "resources"
"output": "./release",
"buildResources": "./resources"
},
"files": ["desktop", "dist", "shared"],
"mac": {
Expand Down Expand Up @@ -55,7 +55,6 @@
"deleteAppDataOnUninstall": true
},
"linux": {
"icon": "resources/images/",
"artifactName": "Simplenote-linux-${version}-${arch}.${ext}",
"target": [
{
Expand Down Expand Up @@ -84,7 +83,7 @@
"GenericName": "Note Taking Application",
"Type": "Application",
"Icon": "simplenote",
"StartupNotify": "true",
"StartupNotify": true,
"Categories": "Utility"
},
"vendor": "Automattic, Inc.",
Expand Down
Loading