2017-09-26 05:40:53 -05:00
|
|
|
'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');
|
2017-10-30 08:06:45 -05:00
|
|
|
const buildNumber = require('../../package.json').buildNumber;
|
2018-04-11 08:13:59 -05:00
|
|
|
const { initCrashReporterMain, initCrashReporterRenderer } = require('../crashReporter.js');
|
2018-06-19 09:56:04 -05:00
|
|
|
const i18n = require('../translation/i18n');
|
2017-09-26 05:40:53 -05:00
|
|
|
|
|
|
|
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,
|
2018-07-20 05:53:08 -05:00
|
|
|
nodeIntegration: false,
|
|
|
|
devTools: false
|
2017-09-26 05:40:53 -05:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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) {
|
2017-10-06 06:17:55 -05:00
|
|
|
|
|
|
|
// This prevents creating multiple instances of the
|
|
|
|
// about window
|
|
|
|
if (aboutWindow) {
|
|
|
|
if (aboutWindow.isMinimized()) {
|
|
|
|
aboutWindow.restore();
|
|
|
|
}
|
|
|
|
aboutWindow.focus();
|
|
|
|
return;
|
|
|
|
}
|
2017-09-26 05:40:53 -05:00
|
|
|
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());
|
|
|
|
|
2017-10-11 10:28:32 -05:00
|
|
|
// sets the AlwaysOnTop property for the about window
|
|
|
|
// if the main window's AlwaysOnTop is true
|
|
|
|
let focusedWindow = BrowserWindow.getFocusedWindow();
|
|
|
|
if (focusedWindow && focusedWindow.isAlwaysOnTop()) {
|
|
|
|
aboutWindow.setAlwaysOnTop(true);
|
|
|
|
}
|
|
|
|
|
2017-09-26 05:40:53 -05:00
|
|
|
aboutWindow.once('ready-to-show', () => {
|
|
|
|
aboutWindow.show();
|
|
|
|
});
|
|
|
|
|
2017-10-30 03:55:33 -05:00
|
|
|
aboutWindow.webContents.on('did-finish-load', () => {
|
2018-04-11 08:13:59 -05:00
|
|
|
// initialize crash reporter
|
|
|
|
initCrashReporterMain({ process: 'about app window' });
|
|
|
|
initCrashReporterRenderer(aboutWindow, { process: 'render | about app window' });
|
2017-10-30 08:06:45 -05:00
|
|
|
aboutWindow.webContents.send('buildNumber', buildNumber || '0');
|
2017-10-30 03:55:33 -05:00
|
|
|
});
|
|
|
|
|
2018-04-11 08:13:59 -05:00
|
|
|
aboutWindow.webContents.on('crashed', function () {
|
|
|
|
const options = {
|
|
|
|
type: 'error',
|
2018-06-19 09:56:04 -05:00
|
|
|
title: i18n.getMessageFor('Renderer Process Crashed'),
|
|
|
|
message: i18n.getMessageFor('Oops! Looks like we have had a crash.'),
|
2018-04-11 08:13:59 -05:00
|
|
|
buttons: ['Close']
|
|
|
|
};
|
|
|
|
|
|
|
|
electron.dialog.showMessageBox(options, function () {
|
|
|
|
if (aboutWindow && !aboutWindow.isDestroyed()) {
|
|
|
|
aboutWindow.close();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-09-26 05:40:53 -05:00
|
|
|
aboutWindow.on('close', () => {
|
|
|
|
destroyWindow();
|
|
|
|
});
|
|
|
|
|
|
|
|
aboutWindow.on('closed', () => {
|
|
|
|
destroyWindow();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Destroys a window
|
|
|
|
*/
|
|
|
|
function destroyWindow() {
|
|
|
|
aboutWindow = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
openAboutWindow: openAboutWindow
|
|
|
|
};
|