Fix eslint errors
This commit is contained in:
303
src/main.js
303
src/main.js
@@ -12,32 +12,34 @@ const {
|
||||
session
|
||||
} = require('electron');
|
||||
|
||||
const AutoLaunch = require('auto-launch');
|
||||
|
||||
process.on('uncaughtException', (error) => {
|
||||
console.error(error);
|
||||
});
|
||||
|
||||
if (process.platform === 'win32') {
|
||||
var cmd = process.argv[1];
|
||||
var AutoLaunch = require('auto-launch');
|
||||
var appLauncher = new AutoLaunch({
|
||||
name: 'Mattermost',
|
||||
isHidden: true
|
||||
});
|
||||
if (cmd === '--squirrel-uninstall') {
|
||||
// If we're uninstalling, make sure we also delete our auto launch registry key
|
||||
appLauncher.isEnabled().then(function(enabled) {
|
||||
if (enabled)
|
||||
appLauncher.disable();
|
||||
});
|
||||
}
|
||||
else if (cmd === '--squirrel-install' || cmd === '--squirrel-updated') {
|
||||
// If we're updating and already have an registry entry for auto launch, make sure to update the path
|
||||
appLauncher.isEnabled().then(function(enabled) {
|
||||
appLauncher.isEnabled().then((enabled) => {
|
||||
if (enabled) {
|
||||
return appLauncher.disable().then(function() {
|
||||
appLauncher.disable();
|
||||
}
|
||||
});
|
||||
} else if (cmd === '--squirrel-install' || cmd === '--squirrel-updated') {
|
||||
// If we're updating and already have an registry entry for auto launch, make sure to update the path
|
||||
appLauncher.isEnabled().then((enabled) => {
|
||||
if (enabled) {
|
||||
return appLauncher.disable().then(() => {
|
||||
return appLauncher.enable();
|
||||
});
|
||||
}
|
||||
return true;
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -46,21 +48,27 @@ app.setAppUserModelId('com.squirrel.mattermost.Mattermost'); // Use explicit App
|
||||
require('electron-squirrel-startup');
|
||||
|
||||
const fs = require('fs');
|
||||
const os = require('os');
|
||||
const path = require('path');
|
||||
|
||||
var settings = require('./common/settings');
|
||||
const osVersion = require('./common/osVersion');
|
||||
var certificateStore = require('./main/certificateStore').load(path.resolve(app.getPath('userData'), 'certificate.json'));
|
||||
var appMenu = require('./main/menus/app');
|
||||
const appMenu = require('./main/menus/app');
|
||||
const trayMenu = require('./main/menus/tray');
|
||||
const allowProtocolDialog = require('./main/allowProtocolDialog');
|
||||
|
||||
var argv = require('yargs')
|
||||
.parse(process.argv.slice(1));
|
||||
// Keep a global reference of the window object, if you don't, the window will
|
||||
// be closed automatically when the JavaScript object is garbage collected.
|
||||
var mainWindow = null;
|
||||
|
||||
var client = null;
|
||||
var argv = require('yargs').parse(process.argv.slice(1));
|
||||
|
||||
const electronConnect = argv.livereload ? require('electron-connect') : null;
|
||||
var client;
|
||||
if (argv.livereload) {
|
||||
client = require('electron-connect').client.create();
|
||||
client.on('reload', function() {
|
||||
client = electronConnect.client.create();
|
||||
client.on('reload', () => {
|
||||
mainWindow.reload();
|
||||
});
|
||||
}
|
||||
@@ -73,56 +81,53 @@ if (argv.hidden) {
|
||||
// TODO: We should document this if that hasn't been done already
|
||||
if (argv['config-file']) {
|
||||
global['config-file'] = argv['config-file'];
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
global['config-file'] = app.getPath('userData') + '/config.json';
|
||||
}
|
||||
|
||||
var config = {};
|
||||
try {
|
||||
var configFile = global['config-file'];
|
||||
const configFile = global['config-file'];
|
||||
config = settings.readFileSync(configFile);
|
||||
if (config.version != settings.version || wasUpdated()) {
|
||||
if (config.version !== settings.version || wasUpdated()) {
|
||||
clearAppCache();
|
||||
config = settings.upgrade(config, app.getVersion());
|
||||
settings.writeFileSync(configFile, config);
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
} catch (e) {
|
||||
config = settings.loadDefault();
|
||||
console.log('Failed to read or upgrade config.json', e);
|
||||
}
|
||||
|
||||
ipcMain.on('update-config', () => {
|
||||
const configFile = global['config-file'];
|
||||
config = settings.readFileSync(configFile);
|
||||
});
|
||||
|
||||
// Only for OS X
|
||||
const switchMenuIconImages = function(icons, isDarkMode) {
|
||||
function switchMenuIconImages(icons, isDarkMode) {
|
||||
if (isDarkMode) {
|
||||
icons.normal = icons.clicked.normal;
|
||||
icons.unread = icons.clicked.unread;
|
||||
icons.mention = icons.clicked.mention;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
icons.normal = icons.light.normal;
|
||||
icons.unread = icons.light.unread;
|
||||
icons.mention = icons.light.mention;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// Keep a global reference of the window object, if you don't, the window will
|
||||
// be closed automatically when the JavaScript object is garbage collected.
|
||||
var mainWindow = null;
|
||||
var trayIcon = null;
|
||||
const trayImages = function() {
|
||||
const trayImages = (() => {
|
||||
switch (process.platform) {
|
||||
case 'win32':
|
||||
return {
|
||||
normal: nativeImage.createFromPath(path.resolve(__dirname, 'resources/windows/tray.ico')),
|
||||
unread: nativeImage.createFromPath(path.resolve(__dirname, 'resources/windows/tray_unread.ico')),
|
||||
mention: nativeImage.createFromPath(path.resolve(__dirname, 'resources/windows/tray_mention.ico'))
|
||||
};
|
||||
case 'darwin':
|
||||
case 'win32':
|
||||
return {
|
||||
normal: nativeImage.createFromPath(path.resolve(__dirname, 'resources/windows/tray.ico')),
|
||||
unread: nativeImage.createFromPath(path.resolve(__dirname, 'resources/windows/tray_unread.ico')),
|
||||
mention: nativeImage.createFromPath(path.resolve(__dirname, 'resources/windows/tray_mention.ico'))
|
||||
};
|
||||
case 'darwin':
|
||||
{
|
||||
const icons = {
|
||||
light: {
|
||||
normal: nativeImage.createFromPath(path.resolve(__dirname, 'resources/osx/MenuIcon.png')),
|
||||
@@ -137,27 +142,31 @@ const trayImages = function() {
|
||||
};
|
||||
switchMenuIconImages(icons, systemPreferences.isDarkMode());
|
||||
return icons;
|
||||
case 'linux':
|
||||
var resourcesDir = 'resources/linux/' + (config.trayIconTheme || 'light') + '/';
|
||||
return {
|
||||
normal: nativeImage.createFromPath(path.resolve(__dirname, resourcesDir + 'MenuIconTemplate.png')),
|
||||
unread: nativeImage.createFromPath(path.resolve(__dirname, resourcesDir + 'MenuIconUnreadTemplate.png')),
|
||||
mention: nativeImage.createFromPath(path.resolve(__dirname, resourcesDir + 'MenuIconMentionTemplate.png'))
|
||||
};
|
||||
default:
|
||||
return {};
|
||||
}
|
||||
case 'linux':
|
||||
var resourcesDir = 'resources/linux/' + (config.trayIconTheme || 'light') + '/';
|
||||
return {
|
||||
normal: nativeImage.createFromPath(path.resolve(__dirname, resourcesDir + 'MenuIconTemplate.png')),
|
||||
unread: nativeImage.createFromPath(path.resolve(__dirname, resourcesDir + 'MenuIconUnreadTemplate.png')),
|
||||
mention: nativeImage.createFromPath(path.resolve(__dirname, resourcesDir + 'MenuIconMentionTemplate.png'))
|
||||
};
|
||||
default:
|
||||
return {};
|
||||
}
|
||||
}();
|
||||
})();
|
||||
var willAppQuit = false;
|
||||
|
||||
// If there is already an instance, activate the window in the existing instace and quit this one
|
||||
if (app.makeSingleInstance((commandLine, workingDirectory) => {
|
||||
// Someone tried to run a second instance, we should focus our window.
|
||||
if (mainWindow) {
|
||||
if (mainWindow.isMinimized()) mainWindow.restore();
|
||||
else mainWindow.show();
|
||||
if (app.makeSingleInstance((/*commandLine, workingDirectory*/) => {
|
||||
// Someone tried to run a second instance, we should focus our window.
|
||||
if (mainWindow) {
|
||||
if (mainWindow.isMinimized()) {
|
||||
mainWindow.restore();
|
||||
} else {
|
||||
mainWindow.show();
|
||||
}
|
||||
})) {
|
||||
}
|
||||
})) {
|
||||
app.quit();
|
||||
}
|
||||
|
||||
@@ -172,25 +181,24 @@ function shouldShowTrayIcon() {
|
||||
}
|
||||
|
||||
function wasUpdated() {
|
||||
return config.lastMattermostVersion != app.getVersion();
|
||||
return config.lastMattermostVersion !== app.getVersion();
|
||||
}
|
||||
|
||||
function clearAppCache() {
|
||||
//Wait for mainWindow
|
||||
if (!mainWindow) {
|
||||
setTimeout(clearAppCache, 100);
|
||||
}
|
||||
else {
|
||||
if (mainWindow) {
|
||||
console.log('Clear cache after update');
|
||||
mainWindow.webContents.session.clearCache(function() {
|
||||
mainWindow.webContents.session.clearCache(() => {
|
||||
//Restart after cache clear
|
||||
mainWindow.reload();
|
||||
});
|
||||
} else {
|
||||
//Wait for mainWindow
|
||||
setTimeout(clearAppCache, 100);
|
||||
}
|
||||
}
|
||||
|
||||
// Quit when all windows are closed.
|
||||
app.on('window-all-closed', function() {
|
||||
app.on('window-all-closed', () => {
|
||||
// On OS X it is common for applications and their menu bar
|
||||
// to stay active until the user quits explicitly with Cmd + Q
|
||||
if (process.platform !== 'darwin') {
|
||||
@@ -199,7 +207,7 @@ app.on('window-all-closed', function() {
|
||||
});
|
||||
|
||||
// For win32, auto-hide menu bar.
|
||||
app.on('browser-window-created', function(event, window) {
|
||||
app.on('browser-window-created', (event, window) => {
|
||||
if (process.platform === 'win32' || process.platform === 'linux') {
|
||||
if (config.hideMenuBar) {
|
||||
window.setAutoHideMenuBar(true);
|
||||
@@ -209,11 +217,11 @@ app.on('browser-window-created', function(event, window) {
|
||||
});
|
||||
|
||||
// For OSX, show hidden mainWindow when clicking dock icon.
|
||||
app.on('activate', function(event) {
|
||||
app.on('activate', () => {
|
||||
mainWindow.show();
|
||||
});
|
||||
|
||||
app.on('before-quit', function() {
|
||||
app.on('before-quit', () => {
|
||||
// Make sure tray icon gets removed if the user exits via CTRL-Q
|
||||
if (process.platform === 'win32') {
|
||||
trayIcon.destroy();
|
||||
@@ -221,12 +229,11 @@ app.on('before-quit', function() {
|
||||
willAppQuit = true;
|
||||
});
|
||||
|
||||
app.on('certificate-error', function(event, webContents, url, error, certificate, callback) {
|
||||
app.on('certificate-error', (event, webContents, url, error, certificate, callback) => {
|
||||
if (certificateStore.isTrusted(url, certificate)) {
|
||||
event.preventDefault();
|
||||
callback(true);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
var detail = `URL: ${url}\nError: ${error}`;
|
||||
if (certificateStore.isExisting(url)) {
|
||||
detail = `Certificate is different from previous one.\n\n` + detail;
|
||||
@@ -235,14 +242,14 @@ app.on('certificate-error', function(event, webContents, url, error, certificate
|
||||
dialog.showMessageBox(mainWindow, {
|
||||
title: 'Certificate error',
|
||||
message: `Do you trust certificate from "${certificate.issuerName}"?`,
|
||||
detail: detail,
|
||||
detail,
|
||||
type: 'warning',
|
||||
buttons: [
|
||||
'Yes',
|
||||
'No'
|
||||
],
|
||||
cancelId: 1
|
||||
}, function(response) {
|
||||
}, (response) => {
|
||||
if (response === 0) {
|
||||
certificateStore.add(url, certificate);
|
||||
certificateStore.save();
|
||||
@@ -255,14 +262,14 @@ app.on('certificate-error', function(event, webContents, url, error, certificate
|
||||
|
||||
const loginCallbackMap = new Map();
|
||||
|
||||
ipcMain.on('login-credentials', function(event, request, user, password) {
|
||||
ipcMain.on('login-credentials', (event, request, user, password) => {
|
||||
const callback = loginCallbackMap.get(JSON.stringify(request));
|
||||
if (callback != null) {
|
||||
callback(user, password);
|
||||
}
|
||||
});
|
||||
|
||||
app.on('login', function(event, webContents, request, authInfo, callback) {
|
||||
app.on('login', (event, webContents, request, authInfo, callback) => {
|
||||
event.preventDefault();
|
||||
loginCallbackMap.set(JSON.stringify(request), callback);
|
||||
mainWindow.webContents.send('login-request', request, authInfo);
|
||||
@@ -272,8 +279,8 @@ allowProtocolDialog.init(mainWindow);
|
||||
|
||||
// This method will be called when Electron has finished
|
||||
// initialization and is ready to create browser windows.
|
||||
app.on('ready', function() {
|
||||
ipcMain.on('notified', function(event, arg) {
|
||||
app.on('ready', () => {
|
||||
ipcMain.on('notified', () => {
|
||||
if (process.platform === 'win32' || process.platform === 'linux') {
|
||||
if (config.notifications.flashWindow === 2) {
|
||||
mainWindow.flashFrame(true);
|
||||
@@ -281,7 +288,7 @@ app.on('ready', function() {
|
||||
}
|
||||
});
|
||||
|
||||
ipcMain.on('update-title', function(event, arg) {
|
||||
ipcMain.on('update-title', (event, arg) => {
|
||||
mainWindow.setTitle(arg.title);
|
||||
});
|
||||
|
||||
@@ -290,30 +297,27 @@ app.on('ready', function() {
|
||||
trayIcon = new Tray(trayImages.normal);
|
||||
if (process.platform === 'darwin') {
|
||||
trayIcon.setPressedImage(trayImages.clicked.normal);
|
||||
systemPreferences.subscribeNotification('AppleInterfaceThemeChangedNotification', (event, userInfo) => {
|
||||
systemPreferences.subscribeNotification('AppleInterfaceThemeChangedNotification', () => {
|
||||
switchMenuIconImages(trayImages, systemPreferences.isDarkMode());
|
||||
trayIcon.setImage(trayImages.normal);
|
||||
});
|
||||
}
|
||||
|
||||
trayIcon.setToolTip(app.getName());
|
||||
trayIcon.on('click', function() {
|
||||
trayIcon.on('click', () => {
|
||||
if (!mainWindow.isVisible() || mainWindow.isMinimized()) {
|
||||
if (mainWindow.isMinimized()) {
|
||||
mainWindow.restore();
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
mainWindow.show();
|
||||
}
|
||||
mainWindow.focus();
|
||||
if (process.platform === 'darwin') {
|
||||
app.dock.show();
|
||||
}
|
||||
}
|
||||
else if ((process.platform === 'win32') && config.toggleWindowOnTrayIconClick) {
|
||||
} else if ((process.platform === 'win32') && config.toggleWindowOnTrayIconClick) {
|
||||
mainWindow.minimize();
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
mainWindow.focus();
|
||||
}
|
||||
});
|
||||
@@ -321,10 +325,13 @@ app.on('ready', function() {
|
||||
trayIcon.on('right-click', () => {
|
||||
trayIcon.popUpContextMenu();
|
||||
});
|
||||
trayIcon.on('balloon-click', function() {
|
||||
trayIcon.on('balloon-click', () => {
|
||||
if (process.platform === 'win32' || process.platform === 'darwin') {
|
||||
if (mainWindow.isMinimized()) mainWindow.restore();
|
||||
else mainWindow.show();
|
||||
if (mainWindow.isMinimized()) {
|
||||
mainWindow.restore();
|
||||
} else {
|
||||
mainWindow.show();
|
||||
}
|
||||
}
|
||||
|
||||
if (process.platform === 'darwin') {
|
||||
@@ -333,7 +340,7 @@ app.on('ready', function() {
|
||||
|
||||
mainWindow.focus();
|
||||
});
|
||||
ipcMain.on('notified', function(event, arg) {
|
||||
ipcMain.on('notified', (event, arg) => {
|
||||
if (process.platform === 'win32') {
|
||||
// On Windows 8.1 and Windows 8, a shortcut with a Application User Model ID must be installed to the Start screen.
|
||||
// In current version, use tray balloon for notification
|
||||
@@ -349,7 +356,7 @@ app.on('ready', function() {
|
||||
|
||||
// Set overlay icon from dataURL
|
||||
// Set trayicon to show "dot"
|
||||
ipcMain.on('update-unread', function(event, arg) {
|
||||
ipcMain.on('update-unread', (event, arg) => {
|
||||
if (process.platform === 'win32') {
|
||||
const overlay = arg.overlayDataURL ? nativeImage.createFromDataURL(arg.overlayDataURL) : null;
|
||||
mainWindow.setOverlayIcon(overlay, arg.description);
|
||||
@@ -361,15 +368,13 @@ app.on('ready', function() {
|
||||
trayIcon.setPressedImage(trayImages.clicked.mention);
|
||||
}
|
||||
trayIcon.setToolTip(arg.mentionCount + ' unread mentions');
|
||||
}
|
||||
else if (arg.unreadCount > 0) {
|
||||
} else if (arg.unreadCount > 0) {
|
||||
trayIcon.setImage(trayImages.unread);
|
||||
if (process.platform === 'darwin') {
|
||||
trayIcon.setPressedImage(trayImages.clicked.unread);
|
||||
}
|
||||
trayIcon.setToolTip(arg.unreadCount + ' unread channels');
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
trayIcon.setImage(trayImages.normal);
|
||||
if (process.platform === 'darwin') {
|
||||
trayIcon.setPressedImage(trayImages.clicked.normal);
|
||||
@@ -380,33 +385,31 @@ app.on('ready', function() {
|
||||
}
|
||||
|
||||
// Create the browser window.
|
||||
var bounds_info_path = path.resolve(app.getPath("userData"), "bounds-info.json");
|
||||
var window_options;
|
||||
var boundsInfoPath = path.resolve(app.getPath('userData'), 'bounds-info.json');
|
||||
var windowOptions;
|
||||
try {
|
||||
window_options = JSON.parse(fs.readFileSync(bounds_info_path, 'utf-8'));
|
||||
}
|
||||
catch (e) {
|
||||
windowOptions = JSON.parse(fs.readFileSync(boundsInfoPath, 'utf-8'));
|
||||
} catch (e) {
|
||||
// follow Electron's defaults
|
||||
window_options = {};
|
||||
windowOptions = {};
|
||||
}
|
||||
if (process.platform === 'linux') {
|
||||
window_options.icon = path.resolve(__dirname, 'resources/appicon.png');
|
||||
windowOptions.icon = path.resolve(__dirname, 'resources/appicon.png');
|
||||
}
|
||||
window_options.title = app.getName();
|
||||
mainWindow = new BrowserWindow(window_options);
|
||||
windowOptions.title = app.getName();
|
||||
mainWindow = new BrowserWindow(windowOptions);
|
||||
|
||||
if (process.platform === 'darwin') {
|
||||
session.defaultSession.on('will-download', (event, item, webContents) => {
|
||||
session.defaultSession.on('will-download', (event, item) => {
|
||||
var filename = item.getFilename();
|
||||
var savePath = dialog.showSaveDialog({
|
||||
title: filename,
|
||||
defaultPath: require('os').homedir() + '/Downloads/' + filename
|
||||
defaultPath: os.homedir() + '/Downloads/' + filename
|
||||
});
|
||||
|
||||
if (savePath) {
|
||||
item.setSavePath(savePath);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
item.cancel();
|
||||
}
|
||||
});
|
||||
@@ -423,12 +426,11 @@ app.on('ready', function() {
|
||||
mainWindow.setFullScreenable(true); // fullscreenable option has no effect.
|
||||
if (hideOnStartup) {
|
||||
mainWindow.minimize();
|
||||
}
|
||||
else {
|
||||
if (window_options.maximized) {
|
||||
} else {
|
||||
if (windowOptions.maximized) {
|
||||
mainWindow.maximize();
|
||||
}
|
||||
if (window_options.fullscreen) {
|
||||
if (windowOptions.fullscreen) {
|
||||
mainWindow.setFullScreen(true);
|
||||
}
|
||||
}
|
||||
@@ -437,20 +439,22 @@ app.on('ready', function() {
|
||||
mainWindow.loadURL('file://' + __dirname + '/browser/index.html');
|
||||
|
||||
// Set application menu
|
||||
ipcMain.on('update-menu', (event, config) => {
|
||||
var app_menu = appMenu.createMenu(mainWindow, config);
|
||||
Menu.setApplicationMenu(app_menu);
|
||||
ipcMain.on('update-menu', (event, configData) => {
|
||||
var aMenu = appMenu.createMenu(mainWindow, config);
|
||||
Menu.setApplicationMenu(aMenu);
|
||||
|
||||
// set up context menu for tray icon
|
||||
if (shouldShowTrayIcon()) {
|
||||
const tray_menu = require('./main/menus/tray').createMenu(mainWindow, config);
|
||||
trayIcon.setContextMenu(tray_menu);
|
||||
const tMenu = trayMenu.createMenu(mainWindow, configData);
|
||||
trayIcon.setContextMenu(tMenu);
|
||||
if (process.platform === 'darwin' || process.platform === 'linux') {
|
||||
// store the information, if the tray was initialized, for checking in the settings, if the application
|
||||
// was restarted after setting "Show icon on menu bar"
|
||||
if (trayIcon)
|
||||
if (trayIcon) {
|
||||
mainWindow.trayWasVisible = true;
|
||||
else
|
||||
} else {
|
||||
mainWindow.trayWasVisible = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -459,47 +463,44 @@ app.on('ready', function() {
|
||||
// Open the DevTools.
|
||||
// mainWindow.openDevTools();
|
||||
|
||||
var saveWindowState = function(file, window) {
|
||||
var window_state = window.getBounds();
|
||||
window_state.maximized = window.isMaximized();
|
||||
window_state.fullscreen = window.isFullScreen();
|
||||
function saveWindowState(file, window) {
|
||||
var windowState = window.getBounds();
|
||||
windowState.maximized = window.isMaximized();
|
||||
windowState.fullscreen = window.isFullScreen();
|
||||
try {
|
||||
fs.writeFileSync(bounds_info_path, JSON.stringify(window_state));
|
||||
}
|
||||
catch (e) {
|
||||
fs.writeFileSync(boundsInfoPath, JSON.stringify(windowState));
|
||||
} catch (e) {
|
||||
// [Linux] error happens only when the window state is changed before the config dir is creatied.
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
mainWindow.on('close', function(event) {
|
||||
mainWindow.on('close', (event) => {
|
||||
if (willAppQuit) { // when [Ctrl|Cmd]+Q
|
||||
saveWindowState(bounds_info_path, mainWindow);
|
||||
}
|
||||
else { // Minimize or hide the window for close button.
|
||||
saveWindowState(boundsInfoPath, mainWindow);
|
||||
} else { // Minimize or hide the window for close button.
|
||||
event.preventDefault();
|
||||
const hide_window = (window) => {
|
||||
function hideWindow(window) {
|
||||
window.hide();
|
||||
window.blur(); // To move focus to the next top-level window in Windows
|
||||
};
|
||||
}
|
||||
switch (process.platform) {
|
||||
case 'win32':
|
||||
hide_window(mainWindow);
|
||||
break;
|
||||
case 'linux':
|
||||
if (config.minimizeToTray) {
|
||||
hide_window(mainWindow);
|
||||
}
|
||||
else {
|
||||
mainWindow.minimize();
|
||||
}
|
||||
break;
|
||||
case 'darwin':
|
||||
hide_window(mainWindow);
|
||||
if (config.minimizeToTray) {
|
||||
app.dock.hide();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
case 'win32':
|
||||
hideWindow(mainWindow);
|
||||
break;
|
||||
case 'linux':
|
||||
if (config.minimizeToTray) {
|
||||
hideWindow(mainWindow);
|
||||
} else {
|
||||
mainWindow.minimize();
|
||||
}
|
||||
break;
|
||||
case 'darwin':
|
||||
hideWindow(mainWindow);
|
||||
if (config.minimizeToTray) {
|
||||
app.dock.hide();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -509,12 +510,12 @@ app.on('ready', function() {
|
||||
// because main process is killed in such situations.
|
||||
// 'blur' event was effective in order to avoid this.
|
||||
// Ideally, app should detect that OS is shutting down.
|
||||
mainWindow.on('blur', function() {
|
||||
saveWindowState(bounds_info_path, mainWindow);
|
||||
mainWindow.on('blur', () => {
|
||||
saveWindowState(boundsInfoPath, mainWindow);
|
||||
});
|
||||
|
||||
// Emitted when the window is closed.
|
||||
mainWindow.on('closed', function() {
|
||||
mainWindow.on('closed', () => {
|
||||
// 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.
|
||||
@@ -523,7 +524,7 @@ app.on('ready', function() {
|
||||
|
||||
// Deny drag&drop navigation in mainWindow.
|
||||
// Drag&drop is allowed in webview of index.html.
|
||||
mainWindow.webContents.on('will-navigate', function(event, url) {
|
||||
mainWindow.webContents.on('will-navigate', (event, url) => {
|
||||
var dirname = __dirname;
|
||||
if (process.platform === 'win32') {
|
||||
dirname = '/' + dirname.replace(/\\/g, '/');
|
||||
|
Reference in New Issue
Block a user