Nativefier/app/src/main.js

71 lines
1.9 KiB
JavaScript
Raw Normal View History

import 'source-map-support/register';
2016-01-29 15:04:41 +01:00
import fs from 'fs';
import path from 'path';
import electron from 'electron';
import createLoginWindow from './components/login/loginWindow';
import createMainWindow from './components/mainWindow/mainWindow';
import helpers from './helpers/helpers';
2016-01-29 15:04:41 +01:00
const {app, ipcMain} = electron;
const {isOSX} = helpers;
const APP_ARGS_FILE_PATH = path.join(__dirname, '..', 'nativefier.json');
2016-01-29 15:04:41 +01:00
const appArgs = JSON.parse(fs.readFileSync(APP_ARGS_FILE_PATH, 'utf8'));
2016-01-29 15:04:41 +01:00
let mainWindow;
if (appArgs.insecure) {
app.commandLine.appendSwitch('ignore-certificate-errors');
}
// do nothing for setDockBadge if not OSX
let setDockBadge = () => {};
2016-01-23 19:02:23 +01:00
if (isOSX()) {
setDockBadge = app.dock.setBadge;
}
2016-01-29 15:04:41 +01:00
app.on('window-all-closed', () => {
if (!isOSX()) {
2015-07-05 08:08:13 +02:00
app.quit();
}
});
2016-01-29 15:04:41 +01:00
app.on('activate', (event, hasVisibleWindows) => {
if (isOSX()) {
// this is called when the dock is clicked
if (!hasVisibleWindows) {
mainWindow.show();
}
}
});
2016-01-29 15:04:41 +01:00
app.on('before-quit', () => {
// not fired when the close button on the window is clicked
if (isOSX()) {
// need to force a quit as a workaround here to simulate the osx app hiding behaviour
// Somehow sokution at https://github.com/atom/electron/issues/444#issuecomment-76492576 does not work,
// e.prevent default appears to persist
// might cause issues in the future as before-quit and will-quit events are not called
app.exit(0);
}
});
2016-01-29 15:04:41 +01:00
app.on('ready', () => {
mainWindow = createMainWindow(appArgs, app.quit, setDockBadge);
});
2015-07-05 08:08:13 +02:00
2016-01-29 15:04:41 +01:00
app.on('login', (event, webContents, request, authInfo, callback) => {
// for http authentication
2016-01-21 19:39:52 +01:00
event.preventDefault();
createLoginWindow(callback);
2016-01-21 19:39:52 +01:00
});
2016-01-29 15:04:41 +01:00
ipcMain.on('notification', (event, title, opts) => {
if (!isOSX() || mainWindow.isFocused()) {
return;
}
setDockBadge('●');
});