Merge branch 'master' into electron-17

* master:
  Electron-172 - Fixes the pop-out issue
  electron-173: added dependencies to the advanced installer
  electron-173: enabled spell checker
  Electron-142 - Changed the symphony logo
  Electron-142 - Moved inline styles to style tag
  Updated window title
  Electron-142 - Made changes as per review
  Electron-142 - Made changes as per review
  Updated comment
  Change title to reflect new file display name as per Electron-144
  Adds a count to the file name in the download manager if the user downloads a file with the same name.
  Electron-142 - Added a new menu item to show application version details
  Add tooltip to display full filename in download manager.
This commit is contained in:
Vishwas Shashidhar
2017-10-06 14:04:03 +05:30
10 changed files with 256 additions and 20 deletions

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
js/aboutApp/index.js Normal file
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
js/aboutApp/renderer.js Normal file
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

View File

@@ -56,9 +56,10 @@ function showInFinder(id) {
function createDOM(arg) {
if (arg && arg._id) {
let fileDisplayName = getFileDisplayName(arg.fileName);
let downloadItemKey = arg._id;
local.downloadItems.push(arg);
let downloadItemKey = arg._id;
let ul = document.getElementById('download-main');
if (ul) {
@@ -108,7 +109,8 @@ function createDOM(arg) {
let h2FileName = document.createElement('h2');
h2FileName.classList.add('text-cutoff');
h2FileName.innerHTML = arg.fileName;
h2FileName.innerHTML = fileDisplayName;
h2FileName.title = fileDisplayName;
fileNameDiv.appendChild(h2FileName);
let fileProgressTitle = document.createElement('span');
@@ -194,4 +196,33 @@ function initiate() {
});
}
}
}
/**
* Return a file display name for the download item
*/
function getFileDisplayName(fileName) {
let fileList = local.downloadItems;
let fileNameCount = 0;
let fileDisplayName = fileName;
/* Check if a file with the same name exists
* (akin to the user downloading a file with the same name again)
* in the download bar
*/
for (let i = 0; i < fileList.length; i++) {
if (fileName === fileList[i].fileName) {
fileNameCount++;
}
}
/* If it exists, add a count to the name like how Chrome does */
if (fileNameCount) {
let extLastIndex = fileDisplayName.lastIndexOf('.');
let fileCount = ' (' + fileNameCount + ')';
fileDisplayName = fileDisplayName.slice(0, extLastIndex) + fileCount + fileDisplayName.slice(extLastIndex);
}
return fileDisplayName;
}

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;
@@ -246,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;

View File

@@ -26,26 +26,26 @@ require('../downloadManager');
// so loading the spellchecker in try catch so that we don't
// block other method from loading
document.addEventListener('DOMContentLoaded', () => {
//loadSpellChecker();
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 */
// }
// }
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 = {

View File

@@ -395,6 +395,11 @@ function doCreateMainWindow(initialUrl, initialBounds) {
addWindowKey(newWinKey, browserWin);
// Method that sends bound changes as soon
// as a new window is created
// issue https://perzoinc.atlassian.net/browse/ELECTRON-172
sendChildWinBoundsChange(browserWin);
// throttle changes so we don't flood client.
let throttledBoundsChange = throttle(1000,
sendChildWinBoundsChange.bind(null, browserWin));