mirror of
https://github.com/finos/SymphonyElectron.git
synced 2024-12-27 01:11:13 -06:00
add linting (#27)
This commit is contained in:
parent
40e6b173af
commit
71387c1dce
6
.eslintignore
Normal file
6
.eslintignore
Normal file
@ -0,0 +1,6 @@
|
||||
build
|
||||
config
|
||||
coverage
|
||||
dist
|
||||
installer
|
||||
node_modules
|
30
.eslintrc
Normal file
30
.eslintrc
Normal file
@ -0,0 +1,30 @@
|
||||
{
|
||||
"extends": [
|
||||
"airbnb-base/rules/best-practices",
|
||||
"airbnb-base/rules/errors",
|
||||
"airbnb-base/rules/node",
|
||||
"airbnb-base/rules/strict",
|
||||
"airbnb-base/rules/variables"
|
||||
],
|
||||
"rules": {
|
||||
"comma-dangle": 0,
|
||||
"vars-on-top": 0,
|
||||
"one-var": 0,
|
||||
"indent": [ 2, 4, {
|
||||
"SwitchCase": 1
|
||||
} ],
|
||||
"space-in-parens": 0,
|
||||
"func-names" : 0,
|
||||
"eol-last": 0,
|
||||
"no-use-before-define": 0,
|
||||
"strict": 0
|
||||
},
|
||||
"env": {
|
||||
"browser": true,
|
||||
"node": true,
|
||||
"es6": true
|
||||
},
|
||||
"globals": {
|
||||
"SYM_API": true
|
||||
}
|
||||
}
|
@ -21,8 +21,8 @@ electron.app.on('certificate-error', function(event, webContents, url, error,
|
||||
return;
|
||||
}
|
||||
|
||||
let browserWin = electron.BrowserWindow.fromWebContents(webContents);
|
||||
var buttonId = electron.dialog.showMessageBox(browserWin, {
|
||||
const browserWin = electron.BrowserWindow.fromWebContents(webContents);
|
||||
const buttonId = electron.dialog.showMessageBox(browserWin, {
|
||||
type: 'warning',
|
||||
buttons: [ 'Allow', 'Deny', 'Ignore All' ],
|
||||
defaultId: 1,
|
||||
|
@ -34,7 +34,7 @@ function getConfig() {
|
||||
configPath = path.join(execPath, isMac ? '..' : '', configFile);
|
||||
}
|
||||
|
||||
fs.readFile(configPath, 'utf8', function (err, data) {
|
||||
fs.readFile(configPath, 'utf8', function(err, data) {
|
||||
if (err) {
|
||||
reject('cannot open config file: ' + configPath + ', error: ' + err);
|
||||
} else {
|
||||
@ -42,7 +42,7 @@ function getConfig() {
|
||||
// data is the contents of the text file we just read
|
||||
let config = JSON.parse(data);
|
||||
resolve(config);
|
||||
} catch(e) {
|
||||
} catch (e) {
|
||||
reject('can not parse config file data: ' + data + ', error: ' + err);
|
||||
}
|
||||
}
|
||||
|
@ -3,11 +3,13 @@
|
||||
const electron = require('electron');
|
||||
const app = electron.app;
|
||||
const nodeURL = require('url');
|
||||
const squirrelStartup = require('electron-squirrel-startup');
|
||||
|
||||
const getConfig = require('./getConfig.js');
|
||||
const { isMac } = require('./utils.js');
|
||||
|
||||
// exit early for squirrel installer
|
||||
if (require('electron-squirrel-startup')) {
|
||||
if (squirrelStartup) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -45,7 +47,7 @@ function getUrlAndOpenMainWindow() {
|
||||
});
|
||||
}
|
||||
|
||||
app.on('window-all-closed', function () {
|
||||
app.on('window-all-closed', function() {
|
||||
// On OS X it is common for applications and their menu bar
|
||||
// to stay active until the user quits explicitly with Cmd + Q
|
||||
if (!isMac) {
|
||||
@ -53,7 +55,7 @@ app.on('window-all-closed', function () {
|
||||
}
|
||||
});
|
||||
|
||||
app.on('activate', function () {
|
||||
app.on('activate', function() {
|
||||
if (windowMgr.isMainWindow(null)) {
|
||||
getUrlAndOpenMainWindow();
|
||||
} else {
|
||||
|
@ -5,7 +5,6 @@
|
||||
* from the renderer process.
|
||||
*/
|
||||
const electron = require('electron');
|
||||
const path = require('path');
|
||||
|
||||
const windowMgr = require('./windowMgr.js');
|
||||
const log = require('./log.js');
|
||||
@ -18,8 +17,8 @@ const log = require('./log.js');
|
||||
function isValidWindow(event) {
|
||||
if (event && event.sender) {
|
||||
// validate that event sender is from window we created
|
||||
let browserWin = electron.BrowserWindow.fromWebContents(event.sender);
|
||||
let winKey = event.sender.browserWindowOptions &&
|
||||
const browserWin = electron.BrowserWindow.fromWebContents(event.sender);
|
||||
const winKey = event.sender.browserWindowOptions &&
|
||||
event.sender.browserWindowOptions.webPreferences &&
|
||||
event.sender.browserWindowOptions.webPreferences.winKey;
|
||||
|
||||
@ -43,14 +42,14 @@ function isCmdAllowed(event, cmd) {
|
||||
// validate that event sender is from window we created
|
||||
let browserWin = electron.BrowserWindow.fromWebContents(event.sender);
|
||||
|
||||
if (windowMgr.isMainWindow(browserWin)) {
|
||||
if (!windowMgr.isMainWindow(browserWin)) {
|
||||
// allow all commands for main window
|
||||
return true;
|
||||
} else {
|
||||
// allow only certain cmds for child windows
|
||||
// e.g., open cmd not allowed for child windows
|
||||
return (cmdBlackList.indexOf(cmd) === -1)
|
||||
}
|
||||
|
||||
// allow only certain cmds for child windows
|
||||
// e.g., open cmd not allowed for child windows
|
||||
return (cmdBlackList.indexOf(cmd) === -1)
|
||||
}
|
||||
|
||||
return false;
|
||||
@ -62,12 +61,16 @@ function isCmdAllowed(event, cmd) {
|
||||
*/
|
||||
electron.ipcMain.on('symphony-api', (event, arg) => {
|
||||
if (!isValidWindow(event)) {
|
||||
/* eslint-disable no-console */
|
||||
console.log('invalid window try to perform action, ignoring action.');
|
||||
/* eslint-enable no-console */
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isCmdAllowed(event, arg && arg.cmd)) {
|
||||
/* eslint-disable no-console */
|
||||
console.log('cmd not allowed for this window: ' + arg.cmd);
|
||||
/* eslint-enable no-console */
|
||||
return;
|
||||
}
|
||||
|
||||
@ -91,6 +94,5 @@ electron.ipcMain.on('symphony-api', (event, arg) => {
|
||||
let width = arg.width || 1024;
|
||||
let height = arg.height || 768;
|
||||
windowMgr.createChildWindow(arg.url, title, width, height);
|
||||
return;
|
||||
}
|
||||
});
|
||||
|
@ -1,6 +1,5 @@
|
||||
'use strict';
|
||||
|
||||
const electron = require('electron');
|
||||
const log = require('./log.js');
|
||||
const logLevels = require('./enums/logLevels.js')
|
||||
|
||||
|
@ -1,177 +1,161 @@
|
||||
'use strict';
|
||||
|
||||
const electron = require('electron');
|
||||
|
||||
const template = [
|
||||
{
|
||||
label: 'Edit',
|
||||
submenu: [
|
||||
{
|
||||
role: 'undo'
|
||||
},
|
||||
{
|
||||
role: 'redo'
|
||||
},
|
||||
{
|
||||
type: 'separator'
|
||||
},
|
||||
{
|
||||
role: 'cut'
|
||||
},
|
||||
{
|
||||
role: 'copy'
|
||||
},
|
||||
{
|
||||
role: 'paste'
|
||||
},
|
||||
{
|
||||
role: 'pasteandmatchstyle'
|
||||
},
|
||||
{
|
||||
role: 'delete'
|
||||
},
|
||||
{
|
||||
role: 'selectall'
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
label: 'View',
|
||||
submenu: [
|
||||
{
|
||||
label: 'Reload',
|
||||
accelerator: 'CmdOrCtrl+R',
|
||||
click (item, focusedWindow) {
|
||||
if (focusedWindow) {
|
||||
focusedWindow.reload();
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
label: 'Toggle Developer Tools',
|
||||
accelerator: process.platform === 'darwin' ? 'Alt+Command+I' : 'Ctrl+Shift+I',
|
||||
click (item, focusedWindow) {
|
||||
if (focusedWindow) {
|
||||
focusedWindow.webContents.toggleDevTools();
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'separator'
|
||||
},
|
||||
{
|
||||
role: 'resetzoom'
|
||||
},
|
||||
{
|
||||
role: 'zoomin'
|
||||
},
|
||||
{
|
||||
role: 'zoomout'
|
||||
},
|
||||
{
|
||||
type: 'separator'
|
||||
},
|
||||
{
|
||||
role: 'togglefullscreen'
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
role: 'window',
|
||||
submenu: [
|
||||
{
|
||||
role: 'minimize'
|
||||
},
|
||||
{
|
||||
role: 'close'
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
role: 'help',
|
||||
submenu: [
|
||||
{
|
||||
label: 'Learn More',
|
||||
click () { require('electron').shell.openExternal('https://www.symphony.com') }
|
||||
}
|
||||
]
|
||||
}
|
||||
{
|
||||
label: 'Edit',
|
||||
submenu: [
|
||||
{ role: 'undo' },
|
||||
{ role: 'redo' },
|
||||
{ type: 'separator' },
|
||||
{ role: 'cut' },
|
||||
{ role: 'copy' },
|
||||
{ role: 'paste' },
|
||||
{ role: 'pasteandmatchstyle' },
|
||||
{ role: 'delete' },
|
||||
{ role: 'selectall' }
|
||||
]
|
||||
},
|
||||
{
|
||||
label: 'View',
|
||||
submenu: [
|
||||
{
|
||||
label: 'Reload',
|
||||
accelerator: 'CmdOrCtrl+R',
|
||||
click (item, focusedWindow) {
|
||||
if (focusedWindow) {
|
||||
focusedWindow.reload();
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
label: 'Toggle Developer Tools',
|
||||
accelerator: process.platform === 'darwin' ? 'Alt+Command+I' : 'Ctrl+Shift+I',
|
||||
click (item, focusedWindow) {
|
||||
if (focusedWindow) {
|
||||
focusedWindow.webContents.toggleDevTools();
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'separator'
|
||||
},
|
||||
{
|
||||
role: 'resetzoom'
|
||||
},
|
||||
{
|
||||
role: 'zoomin'
|
||||
},
|
||||
{
|
||||
role: 'zoomout'
|
||||
},
|
||||
{
|
||||
type: 'separator'
|
||||
},
|
||||
{
|
||||
role: 'togglefullscreen'
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
role: 'window',
|
||||
submenu: [
|
||||
{
|
||||
role: 'minimize'
|
||||
},
|
||||
{
|
||||
role: 'close'
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
role: 'help',
|
||||
submenu: [
|
||||
{
|
||||
label: 'Learn More',
|
||||
click () { electron.shell.openExternal('https://www.symphony.com') }
|
||||
}
|
||||
]
|
||||
}
|
||||
];
|
||||
|
||||
function getTemplate(app) {
|
||||
if (process.platform === 'darwin' && template[0].label !== app.getName()) {
|
||||
template.unshift({
|
||||
label: app.getName(),
|
||||
submenu: [
|
||||
{
|
||||
role: 'about'
|
||||
},
|
||||
{
|
||||
type: 'separator'
|
||||
},
|
||||
{
|
||||
role: 'services',
|
||||
submenu: []
|
||||
},
|
||||
{
|
||||
type: 'separator'
|
||||
},
|
||||
{
|
||||
role: 'hide'
|
||||
},
|
||||
{
|
||||
role: 'hideothers'
|
||||
},
|
||||
{
|
||||
role: 'unhide'
|
||||
},
|
||||
{
|
||||
type: 'separator'
|
||||
},
|
||||
{
|
||||
role: 'quit'
|
||||
}
|
||||
]
|
||||
});
|
||||
template.unshift({
|
||||
label: app.getName(),
|
||||
submenu: [
|
||||
{
|
||||
role: 'about'
|
||||
},
|
||||
{
|
||||
type: 'separator'
|
||||
},
|
||||
{
|
||||
role: 'services',
|
||||
submenu: []
|
||||
},
|
||||
{
|
||||
type: 'separator'
|
||||
},
|
||||
{
|
||||
role: 'hide'
|
||||
},
|
||||
{
|
||||
role: 'hideothers'
|
||||
},
|
||||
{
|
||||
role: 'unhide'
|
||||
},
|
||||
{
|
||||
type: 'separator'
|
||||
},
|
||||
{
|
||||
role: 'quit'
|
||||
}
|
||||
]
|
||||
});
|
||||
// Edit menu.
|
||||
template[1].submenu.push(
|
||||
{
|
||||
type: 'separator'
|
||||
},
|
||||
{
|
||||
label: 'Speech',
|
||||
submenu: [
|
||||
template[1].submenu.push(
|
||||
{
|
||||
role: 'startspeaking'
|
||||
type: 'separator'
|
||||
},
|
||||
{
|
||||
role: 'stopspeaking'
|
||||
label: 'Speech',
|
||||
submenu: [
|
||||
{
|
||||
role: 'startspeaking'
|
||||
},
|
||||
{
|
||||
role: 'stopspeaking'
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
)
|
||||
// Window menu.
|
||||
template[3].submenu = [
|
||||
{
|
||||
label: 'Close',
|
||||
accelerator: 'CmdOrCtrl+W',
|
||||
role: 'close'
|
||||
},
|
||||
{
|
||||
label: 'Minimize',
|
||||
accelerator: 'CmdOrCtrl+M',
|
||||
role: 'minimize'
|
||||
},
|
||||
{
|
||||
label: 'Zoom',
|
||||
role: 'zoom'
|
||||
},
|
||||
{
|
||||
type: 'separator'
|
||||
},
|
||||
{
|
||||
label: 'Bring All to Front',
|
||||
role: 'front'
|
||||
}
|
||||
]
|
||||
template[3].submenu = [
|
||||
{
|
||||
label: 'Close',
|
||||
accelerator: 'CmdOrCtrl+W',
|
||||
role: 'close'
|
||||
},
|
||||
{
|
||||
label: 'Minimize',
|
||||
accelerator: 'CmdOrCtrl+M',
|
||||
role: 'minimize'
|
||||
},
|
||||
{
|
||||
label: 'Zoom',
|
||||
role: 'zoom'
|
||||
},
|
||||
{
|
||||
type: 'separator'
|
||||
},
|
||||
{
|
||||
label: 'Bring All to Front',
|
||||
role: 'front'
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
return template;
|
||||
|
@ -25,7 +25,8 @@ const api = 'symphony-api';
|
||||
// Note: certain cmds are only allowed on some windows, this is checked by
|
||||
// main process.
|
||||
window.SYM_API = {
|
||||
version: '1.0.0', // api version
|
||||
// api version
|
||||
version: '1.0.0',
|
||||
|
||||
// only allowed by main window - enforced by main process.
|
||||
openWindow: function(url) {
|
||||
@ -60,7 +61,6 @@ window.SYM_API = {
|
||||
|
||||
// listen for log message from main process
|
||||
local.ipcRenderer.on('log', (event, arg) => {
|
||||
console.log('got msg:' + arg)
|
||||
if (local.logger && arg && arg.level && arg.msg) {
|
||||
local.logger({
|
||||
logLevel: arg.level,
|
||||
@ -72,7 +72,7 @@ local.ipcRenderer.on('log', (event, arg) => {
|
||||
function updateOnlineStatus() {
|
||||
local.ipcRenderer.send(api, {
|
||||
cmd: 'isOnline',
|
||||
isOnline: navigator.onLine
|
||||
isOnline: window.navigator.onLine
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
const isDevEnv = process.env.ELECTRON_DEV ?
|
||||
process.env.ELECTRON_DEV.trim().toLowerCase() === "true" : false;
|
||||
process.env.ELECTRON_DEV.trim().toLowerCase() === 'true' : false;
|
||||
|
||||
const isMac = (process.platform === 'darwin');
|
||||
|
||||
@ -12,11 +12,11 @@ const isMac = (process.platform === 'darwin');
|
||||
* @return {String} guid value in string
|
||||
*/
|
||||
function getGuid() {
|
||||
var guid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g,
|
||||
const guid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g,
|
||||
function(c) {
|
||||
var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8);
|
||||
var r = Math.random() * 16 | 0, v = c === 'x' ? r : (r & 0x3 | 0x8);
|
||||
return v.toString(16);
|
||||
});
|
||||
});
|
||||
return guid;
|
||||
}
|
||||
|
||||
|
@ -22,14 +22,14 @@ let isOnline = true;
|
||||
const preloadScript = path.join(__dirname, '/RendererPreload.js');
|
||||
|
||||
function addWindowKey(key, browserWin) {
|
||||
windows[key] = browserWin;
|
||||
windows[ key ] = browserWin;
|
||||
}
|
||||
|
||||
function removeWindowKey(key) {
|
||||
delete windows[key];
|
||||
delete windows[ key ];
|
||||
}
|
||||
|
||||
function createMainWindow (url) {
|
||||
function createMainWindow(url) {
|
||||
let key = getGuid();
|
||||
|
||||
mainWindow = new electron.BrowserWindow({
|
||||
@ -45,10 +45,13 @@ function createMainWindow (url) {
|
||||
});
|
||||
|
||||
function retry() {
|
||||
if (isOnline) {
|
||||
mainWindow.webContents && mainWindow.webContents.reload();
|
||||
} else {
|
||||
if (!isOnline) {
|
||||
loadErrors.showNetworkConnectivityError(mainWindow, url, retry);
|
||||
return;
|
||||
}
|
||||
|
||||
if (mainWindow.webContents) {
|
||||
mainWindow.webContents.reload();
|
||||
}
|
||||
}
|
||||
|
||||
@ -63,7 +66,7 @@ function createMainWindow (url) {
|
||||
});
|
||||
|
||||
mainWindow.webContents.on('did-fail-load', function(event, errorCode,
|
||||
errorDesc, validatedURL, isMainFrame) {
|
||||
errorDesc) {
|
||||
loadErrors.showLoadFailure(mainWindow, url, errorDesc, errorCode, retry);
|
||||
});
|
||||
|
||||
@ -75,7 +78,7 @@ function createMainWindow (url) {
|
||||
|
||||
mainWindow.on('close', function(e) {
|
||||
if (willQuitApp) {
|
||||
mainWindow = null;
|
||||
destroyMainWindow();
|
||||
return;
|
||||
}
|
||||
// mac should hide window when hitting x close
|
||||
@ -85,19 +88,23 @@ function createMainWindow (url) {
|
||||
}
|
||||
});
|
||||
|
||||
mainWindow.on('closed', function () {
|
||||
function destroyMainWindow() {
|
||||
removeWindowKey(key);
|
||||
mainWindow.removeAllEventListeners();
|
||||
// Dereference the window object, usually you would store windows
|
||||
// in an array if your app supports multi windows, this is the time
|
||||
// when you should delete the corresponding element.
|
||||
mainWindow = null;
|
||||
});
|
||||
if (mainWindow) {
|
||||
mainWindow.removeAllListeners();
|
||||
if (mainWindow.webContents) {
|
||||
mainWindow.webContents.removeAllListeners();
|
||||
}
|
||||
mainWindow = null;
|
||||
}
|
||||
}
|
||||
|
||||
mainWindow.on('closed', destroyMainWindow);
|
||||
|
||||
// open external links in default browser - window.open
|
||||
mainWindow.webContents.on('new-window', function(event, url) {
|
||||
mainWindow.webContents.on('new-window', function(event, newWinUrl) {
|
||||
event.preventDefault();
|
||||
electron.shell.openExternal(url);
|
||||
electron.shell.openExternal(newWinUrl);
|
||||
});
|
||||
}
|
||||
|
||||
@ -115,7 +122,7 @@ function isMainWindow(win) {
|
||||
|
||||
function hasWindow(win, winKey) {
|
||||
if (win instanceof electron.BrowserWindow) {
|
||||
let browserWin = windows[winKey];
|
||||
let browserWin = windows[ winKey ];
|
||||
return browserWin && win === browserWin;
|
||||
}
|
||||
|
||||
@ -141,8 +148,13 @@ function createChildWindow(url, title, width, height) {
|
||||
childWindow.loadURL(url);
|
||||
|
||||
childWindow.on('closed', function() {
|
||||
childWindow.removeAllEventListeners();
|
||||
removeWindowKey(winKey);
|
||||
if (childWindow) {
|
||||
childWindow.removeAllListeners();
|
||||
if (childWindow.webContents) {
|
||||
childWindow.webContents.removeAllListeners();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
23
package.json
23
package.json
@ -9,15 +9,19 @@
|
||||
"dev:mac": "ELECTRON_DEV=true npm run start",
|
||||
"dev:win": "SET ELECTRON_DEV=true && npm run start",
|
||||
"start": "electron .",
|
||||
"dist-mac": "build --mac",
|
||||
"dist-win": "build --win --x64",
|
||||
"dist-win-x86": "build --win --ia32",
|
||||
"unpacked-win": "build --win --x64 --dir",
|
||||
"unpacked-win-x86": "build --win --ia32 --dir",
|
||||
"test": "jest --coverage"
|
||||
"dist-mac": "npm run test && npm run lint && build --mac",
|
||||
"dist-win": "npm run test && npm run lint && build --win --x64",
|
||||
"dist-win-x86": "npm run test && npm run lint && build --win --ia32",
|
||||
"unpacked-win": "npm run test && npm run lint && build --win --x64 --dir",
|
||||
"unpacked-win-x86": "npm run test && npm run lint && build --win --ia32 --dir",
|
||||
"test": "jest --coverage",
|
||||
"lint": "eslint js/**"
|
||||
},
|
||||
"build": {
|
||||
"files": [ "!installer/*", "!tests/*" ],
|
||||
"files": [
|
||||
"!installer/*",
|
||||
"!tests/*"
|
||||
],
|
||||
"extraFiles": "config/Symphony.config",
|
||||
"appId": "symphony-electron-desktop",
|
||||
"mac": {
|
||||
@ -59,6 +63,11 @@
|
||||
"electron-builder": "^13.9.0",
|
||||
"electron-builder-squirrel-windows": "^12.3.0",
|
||||
"electron-packager": "^8.5.2",
|
||||
"eslint": "^3.16.1",
|
||||
"eslint-config-airbnb": "^14.1.0",
|
||||
"eslint-plugin-import": "^2.2.0",
|
||||
"eslint-plugin-jsx-a11y": "^4.0.0",
|
||||
"eslint-plugin-react": "^6.10.0",
|
||||
"jest": "^19.0.2"
|
||||
},
|
||||
"dependencies": {
|
||||
|
Loading…
Reference in New Issue
Block a user