2016-01-24 13:20:29 +00:00
|
|
|
import 'source-map-support/register';
|
2016-01-29 14:04:41 +00: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-02-23 08:46:14 +00:00
|
|
|
import inferFlash from './helpers/inferFlash';
|
2016-01-24 13:20:29 +00:00
|
|
|
|
2016-01-29 14:04:41 +00:00
|
|
|
const {app, ipcMain} = electron;
|
|
|
|
const {isOSX} = helpers;
|
2016-01-19 11:53:10 +00:00
|
|
|
|
2016-01-22 11:57:39 +00:00
|
|
|
const APP_ARGS_FILE_PATH = path.join(__dirname, '..', 'nativefier.json');
|
2016-01-29 14:04:41 +00:00
|
|
|
const appArgs = JSON.parse(fs.readFileSync(APP_ARGS_FILE_PATH, 'utf8'));
|
2015-07-06 02:31:09 +00:00
|
|
|
|
2016-01-29 14:04:41 +00:00
|
|
|
let mainWindow;
|
2016-01-23 02:09:47 +00:00
|
|
|
|
2016-02-23 08:46:14 +00:00
|
|
|
if (appArgs.flashPluginDir) {
|
|
|
|
app.commandLine.appendSwitch('ppapi-flash-path', appArgs.flashPluginDir);
|
|
|
|
} else {
|
|
|
|
const flashPath = inferFlash();
|
|
|
|
app.commandLine.appendSwitch('ppapi-flash-path', flashPath);
|
|
|
|
}
|
|
|
|
|
2016-02-23 13:31:47 +00:00
|
|
|
if (appArgs.ignoreCertificate) {
|
2016-01-25 15:42:28 +00:00
|
|
|
app.commandLine.appendSwitch('ignore-certificate-errors');
|
|
|
|
}
|
|
|
|
|
2016-01-23 07:12:53 +00:00
|
|
|
// do nothing for setDockBadge if not OSX
|
|
|
|
let setDockBadge = () => {};
|
2016-01-23 18:02:23 +00:00
|
|
|
|
2016-01-23 07:12:53 +00:00
|
|
|
if (isOSX()) {
|
|
|
|
setDockBadge = app.dock.setBadge;
|
|
|
|
}
|
|
|
|
|
2016-01-29 14:04:41 +00:00
|
|
|
app.on('window-all-closed', () => {
|
2016-01-21 04:25:33 +00:00
|
|
|
if (!isOSX()) {
|
2015-07-05 06:08:13 +00:00
|
|
|
app.quit();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-01-29 14:04:41 +00:00
|
|
|
app.on('activate', (event, hasVisibleWindows) => {
|
2016-01-21 04:25:33 +00:00
|
|
|
if (isOSX()) {
|
|
|
|
// this is called when the dock is clicked
|
|
|
|
if (!hasVisibleWindows) {
|
|
|
|
mainWindow.show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-01-29 14:04:41 +00:00
|
|
|
app.on('before-quit', () => {
|
2016-01-21 04:25:33 +00:00
|
|
|
// 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 14:04:41 +00:00
|
|
|
app.on('ready', () => {
|
2016-01-23 07:12:53 +00:00
|
|
|
mainWindow = createMainWindow(appArgs, app.quit, setDockBadge);
|
2015-07-06 01:38:04 +00:00
|
|
|
});
|
2015-07-05 06:08:13 +00:00
|
|
|
|
2016-01-29 14:04:41 +00:00
|
|
|
app.on('login', (event, webContents, request, authInfo, callback) => {
|
2016-01-23 02:09:47 +00:00
|
|
|
// for http authentication
|
2016-01-21 18:39:52 +00:00
|
|
|
event.preventDefault();
|
2016-01-23 02:09:47 +00:00
|
|
|
createLoginWindow(callback);
|
2016-01-21 18:39:52 +00:00
|
|
|
});
|
|
|
|
|
2016-01-29 14:04:41 +00:00
|
|
|
ipcMain.on('notification', (event, title, opts) => {
|
2016-01-23 05:43:33 +00:00
|
|
|
if (!isOSX() || mainWindow.isFocused()) {
|
|
|
|
return;
|
|
|
|
}
|
2016-01-23 07:12:53 +00:00
|
|
|
setDockBadge('●');
|
2016-01-23 05:43:33 +00:00
|
|
|
});
|