2
2
mirror of https://github.com/Llewellynvdm/nativefier.git synced 2024-11-16 18:15:08 +00:00
nativefier/app/src/main.js

81 lines
2.2 KiB
JavaScript
Raw Normal View History

import 'source-map-support/register';
2016-01-29 14:04:41 +00:00
import fs from 'fs';
import path from 'path';
import {app, ipcMain} from 'electron';
2016-01-29 14:04:41 +00:00
import createLoginWindow from './components/login/loginWindow';
import createMainWindow from './components/mainWindow/mainWindow';
import helpers from './helpers/helpers';
import inferFlash from './helpers/inferFlash';
import electronDownload from 'electron-dl';
2016-01-29 14:04:41 +00:00
const {isOSX} = helpers;
electronDownload();
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'));
2016-01-29 14:04:41 +00:00
let mainWindow;
if (typeof appArgs.flashPluginDir === 'string') {
app.commandLine.appendSwitch('ppapi-flash-path', appArgs.flashPluginDir);
} else if (appArgs.flashPluginDir) {
const flashPath = inferFlash();
app.commandLine.appendSwitch('ppapi-flash-path', flashPath);
}
if (appArgs.ignoreCertificate) {
app.commandLine.appendSwitch('ignore-certificate-errors');
}
// do nothing for setDockBadge if not OSX
let setDockBadge = () => {};
2016-01-23 18:02:23 +00:00
if (isOSX()) {
setDockBadge = app.dock.setBadge;
}
2016-01-29 14:04:41 +00:00
app.on('window-all-closed', () => {
2016-04-25 22:09:01 +00:00
if (!isOSX() || appArgs.fastQuit) {
2015-07-05 06:08:13 +00:00
app.quit();
}
});
2016-01-29 14:04:41 +00:00
app.on('activate', (event, hasVisibleWindows) => {
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', () => {
// 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', () => {
mainWindow = createMainWindow(appArgs, app.quit, setDockBadge);
});
2015-07-05 06:08:13 +00:00
2016-01-29 14:04:41 +00:00
app.on('login', (event, webContents, request, authInfo, callback) => {
// for http authentication
2016-01-21 18:39:52 +00:00
event.preventDefault();
createLoginWindow(callback);
2016-01-21 18:39:52 +00:00
});
ipcMain.on('notification', () => {
if (!isOSX() || mainWindow.isFocused()) {
return;
}
setDockBadge('●');
});