Merge branch 'master' into electron-144

This commit is contained in:
Vikas Shashidhar
2017-10-05 15:55:45 +05:30
committed by GitHub
13 changed files with 298 additions and 57 deletions
+52
View File
@@ -0,0 +1,52 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>About Symphony</title>
<style>
html, body {
margin: 0;
height: 100%;
font-family: sans-serif;
}
.name {
flex: 1;
font-size: 1.3em;
padding: 10px;
font-weight: bold;
}
.version-text {
flex: 1;
font-size: 1em;
color: #2f2f2f;
}
.copyright-text {
flex: 1;
padding: 10px;
font-size: 0.6em;
color: #7f7f7f;
}
.content {
text-align: center;
display: flex;
flex-direction: column;
padding-top: 20px
}
.logo {
margin: auto;
}
</style>
</head>
<body>
<div class="content">
<img class="logo" src="symphony-logo.png">
<span id="app-name" class="name">Symphony</span>
<span id="version" class="version-text"></span>
<span id="copyright" class="copyright-text"></span>
</div>
</body>
</html>
+83
View File
@@ -0,0 +1,83 @@
'use strict';
const electron = require('electron');
const BrowserWindow = electron.BrowserWindow;
const path = require('path');
const fs = require('fs');
const log = require('../log.js');
const logLevels = require('../enums/logLevels.js');
let aboutWindow;
let windowConfig = {
width: 350,
height: 260,
show: false,
modal: true,
autoHideMenuBar: true,
titleBarStyle: true,
resizable: false,
webPreferences: {
preload: path.join(__dirname, 'renderer.js'),
sandbox: true,
nodeIntegration: false
}
};
/**
* method to get the HTML template path
* @returns {string}
*/
function getTemplatePath() {
let templatePath = path.join(__dirname, 'about-app.html');
try {
fs.statSync(templatePath).isFile();
} catch (err) {
log.send(logLevels.ERROR, 'about-window: Could not find template ("' + templatePath + '").');
}
return 'file://' + templatePath;
}
/**
* Opens the about application window for a specific window
* @param {String} windowName - name of the window upon
* which this window should show
*/
function openAboutWindow(windowName) {
let allWindows = BrowserWindow.getAllWindows();
allWindows = allWindows.find((window) => { return window.winName === windowName });
// if we couldn't find any window matching the window name
// it will render as a new window
if (allWindows) {
windowConfig.parent = allWindows;
}
aboutWindow = new BrowserWindow(windowConfig);
aboutWindow.setVisibleOnAllWorkspaces(true);
aboutWindow.loadURL(getTemplatePath());
aboutWindow.once('ready-to-show', () => {
aboutWindow.show();
});
aboutWindow.on('close', () => {
destroyWindow();
});
aboutWindow.on('closed', () => {
destroyWindow();
});
}
/**
* Destroys a window
*/
function destroyWindow() {
aboutWindow = null;
}
module.exports = {
openAboutWindow: openAboutWindow
};
+21
View File
@@ -0,0 +1,21 @@
'use strict';
const { remote } = require('electron');
renderDom();
/**
* Method that renders application data
*/
function renderDom() {
document.addEventListener('DOMContentLoaded', function () {
const applicationName = remote.app.getName() || 'Symphony';
const version = remote.app.getVersion();
let appName = document.getElementById('app-name');
let versionText = document.getElementById('version');
let copyright = document.getElementById('copyright');
appName.innerHTML = applicationName;
versionText.innerHTML = version ? `Version ${version} (${version})` : null;
copyright.innerHTML = `Copyright &copy; ${new Date().getFullYear()} ${applicationName}`
});
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 5.1 KiB

+1
View File
@@ -110,6 +110,7 @@ function createDOM(arg) {
let h2FileName = document.createElement('h2');
h2FileName.classList.add('text-cutoff');
h2FileName.innerHTML = fileDisplayName;
h2FileName.title = fileDisplayName;
fileNameDiv.appendChild(h2FileName);
let fileProgressTitle = document.createElement('span');
+3
View File
@@ -3,6 +3,7 @@
// Third Party Dependencies
const electron = require('electron');
const app = electron.app;
const crashReporter = electron.crashReporter;
const nodeURL = require('url');
const squirrelStartup = require('electron-squirrel-startup');
const AutoLaunch = require('auto-launch');
@@ -31,6 +32,8 @@ require('./memoryMonitor.js');
const windowMgr = require('./windowMgr.js');
crashReporter.start({companyName: 'Symphony', submitURL: 'http://localhost:3000', uploadToServer: false, extra: {'process': 'main'}});
// only allow a single instance of app.
const shouldQuit = app.makeSingleInstance((argv) => {
// Someone tried to run a second instance, we should focus our window.
+22 -4
View File
@@ -7,6 +7,7 @@ const isMac = require('../utils/misc.js').isMac;
const log = require('../log.js');
const logLevels = require('../enums/logLevels.js');
const eventEmitter = require('../eventEmitter');
const aboutApp = require('../aboutApp');
let minimizeOnClose = false;
let launchOnStartup = false;
@@ -65,6 +66,13 @@ const template = [{
}
}
},
{
label: 'Open Crashes Directory',
click() {
const crashesDirectory = electron.crashReporter.getCrashesDirectory() + '/completed';
electron.shell.showItemInFolder(crashesDirectory);
}
},
{
type: 'separator'
},
@@ -97,10 +105,11 @@ const template = [{
},
{
role: 'help',
submenu: [{
label: 'Learn More',
click() { electron.shell.openExternal('https://www.symphony.com'); }
}]
submenu: [
{
label: 'Learn More',
click() { electron.shell.openExternal('https://www.symphony.com'); }
}]
}
];
@@ -238,6 +247,15 @@ function getTemplate(app) {
app.quit();
}
});
// This adds About Symphony under help menu for windows
template[3].submenu.push({
label: 'About Symphony',
click(focusedWindow) {
let windowName = focusedWindow ? focusedWindow.name : '';
aboutApp.openAboutWindow(windowName);
}
});
}
return template;
+34 -13
View File
@@ -11,7 +11,7 @@
// also to bring pieces of node.js:
// https://github.com/electron/electron/issues/2984
//
const { ipcRenderer, remote } = require('electron');
const { ipcRenderer, remote, crashReporter } = require('electron');
const throttle = require('../utils/throttle.js');
const apiEnums = require('../enums/api.js');
@@ -26,20 +26,27 @@ require('../downloadManager');
// so loading the spellchecker in try catch so that we don't
// block other method from loading
document.addEventListener('DOMContentLoaded', () => {
try {
/* eslint-disable global-require */
const SpellCheckerHelper = require('../spellChecker').SpellCheckHelper;
/* eslint-enable global-require */
// Method to initialize spell checker
const spellChecker = new SpellCheckerHelper();
spellChecker.initializeSpellChecker();
} catch (err) {
/* eslint-disable no-console */
console.error('unable to load the spell checker module, hence, skipping the spell check feature ' + err);
/* eslint-enable no-console */
}
//loadSpellChecker();
});
/**
* Loads up the spell checker module
*/
// function loadSpellChecker() {
// try {
// /* eslint-disable global-require */
// const SpellCheckerHelper = require('../spellChecker').SpellCheckHelper;
// /* eslint-enable global-require */
// // Method to initialize spell checker
// const spellChecker = new SpellCheckerHelper();
// spellChecker.initializeSpellChecker();
// } catch (err) {
// /* eslint-disable no-console */
// console.error('unable to load the spell checker module, hence, skipping the spell check feature ' + err);
// /* eslint-enable no-console */
// }
// }
// hold ref so doesn't get GC'ed
const local = {
ipcRenderer: ipcRenderer
@@ -53,6 +60,7 @@ const throttledSetBadgeCount = throttle(1000, function(count) {
});
});
crashReporter.start({companyName: 'Symphony', submitURL: 'http://localhost:3000', uploadToServer: false, extra: {'process': 'preload script / renderer'}});
createAPI();
// creates API exposed from electron.
@@ -109,6 +117,19 @@ function createAPI() {
*/
ScreenSnippet: remote.require('./screenSnippet/index.js').ScreenSnippet,
/**
* Provides API to crash the renderer process that calls this function
* Is only used for demos.
*/
crashRendererProcess: function () {
// For practical purposes, we don't allow
// this method to work in non-dev environments
if (!process.env.ELECTRON_DEV) {
return;
}
process.crash();
},
/**
* Brings window forward and gives focus.
* @param {String} windowName Name of window. Note: main window name is 'main'
+43 -2
View File
@@ -2,6 +2,7 @@
const electron = require('electron');
const app = electron.app;
const crashReporter = electron.crashReporter;
const BrowserWindow = electron.BrowserWindow;
const path = require('path');
const nodeURL = require('url');
@@ -16,7 +17,6 @@ const log = require('./log.js');
const logLevels = require('./enums/logLevels.js');
const notify = require('./notify/electron-notify.js');
const eventEmitter = require('./eventEmitter');
const throttle = require('./utils/throttle.js');
const { getConfigField, updateConfigField } = require('./config.js');
const { isMac, isNodeEnv } = require('./utils/misc');
@@ -81,7 +81,7 @@ function createMainWindow(initialUrl) {
// failed, use default bounds
doCreateMainWindow(initialUrl, null);
}
)
);
}
/**
@@ -93,6 +93,7 @@ function doCreateMainWindow(initialUrl, initialBounds) {
let url = initialUrl;
let key = getGuid();
crashReporter.start({companyName: 'Symphony', submitURL: 'http://localhost:3000', uploadToServer: false, extra: {'process': 'renderer / main window'}});
log.send(logLevels.INFO, 'creating main window url: ' + url);
let newWinOpts = {
@@ -180,6 +181,26 @@ function doCreateMainWindow(initialUrl, initialBounds) {
loadErrors.showLoadFailure(mainWindow, validatedURL, errorDesc, errorCode, retry, false);
});
// In case a renderer process crashes, provide an
// option for the user to either reload or close the window
mainWindow.webContents.on('crashed', function () {
const options = {
type: 'error',
title: 'Renderer Process Crashed',
message: 'Oops! Looks like we have had a crash. Please reload or close this window.',
buttons: ['Reload', 'Close']
};
electron.dialog.showMessageBox(options, function (index) {
if (index === 0) {
mainWindow.reload();
}
else {
mainWindow.close();
}
});
});
addWindowKey(key, mainWindow);
mainWindow.loadURL(url);
@@ -315,6 +336,8 @@ function doCreateMainWindow(initialUrl, initialBounds) {
if (browserWin) {
log.send(logLevels.INFO, 'loaded pop-out window url: ' + newWinParsedUrl);
crashReporter.start({companyName: 'Symphony', submitURL: 'http://localhost:3000', uploadToServer: false, extra: {'process': 'renderer / pop out window - winKey -> ' + newWinKey}});
browserWin.winName = frameName;
browserWin.setAlwaysOnTop(alwaysOnTop);
@@ -324,6 +347,24 @@ function doCreateMainWindow(initialUrl, initialBounds) {
browserWin.removeListener('resize', throttledBoundsChange);
});
browserWin.webContents.on('crashed', function () {
const options = {
type: 'error',
title: 'Renderer Process Crashed',
message: 'Oops! Looks like we have had a crash. Please reload or close this window.',
buttons: ['Reload', 'Close']
};
electron.dialog.showMessageBox(options, function (index) {
if (index === 0) {
mainWindow.reload();
}
else {
mainWindow.close();
}
});
});
addWindowKey(newWinKey, browserWin);
// throttle changes so we don't flood client.