2
2
mirror of https://github.com/Llewellynvdm/nativefier.git synced 2024-11-18 10:35:14 +00:00
nativefier/app/src/main.js

71 lines
1.9 KiB
JavaScript
Raw Normal View History

2015-07-05 06:08:13 +00:00
/**
* Created by JiaHao on 4/7/15.
*/
var fs = require('fs');
var path = require('path');
var electron = require('electron');
var createMainWindow = require('./components/mainWindow/mainWindow');
var createLoginWindow = require('./components/login/loginWindow');
var helpers = require('./helpers/helpers');
var app = electron.app;
2016-01-21 18:39:52 +00:00
var ipcMain = electron.ipcMain;
var isOSX = helpers.isOSX;
const APP_ARGS_FILE_PATH = path.join(__dirname, '..', 'nativefier.json');
2015-07-05 06:08:13 +00:00
var appArgs = JSON.parse(fs.readFileSync(APP_ARGS_FILE_PATH, 'utf8'));
var mainWindow;
// 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-23 18:02:23 +00:00
app.on('window-all-closed', function() {
if (!isOSX()) {
2015-07-05 06:08:13 +00:00
app.quit();
}
});
2016-01-23 18:02:23 +00:00
app.on('activate', function(event, hasVisibleWindows) {
if (isOSX()) {
// this is called when the dock is clicked
if (!hasVisibleWindows) {
mainWindow.show();
}
}
});
2016-01-23 18:02:23 +00:00
app.on('before-quit', function() {
// 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-23 18:02:23 +00:00
app.on('ready', function() {
mainWindow = createMainWindow(appArgs, app.quit, setDockBadge);
});
2015-07-05 06:08:13 +00:00
2016-01-21 18:39:52 +00:00
app.on('login', function(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', function(event, title, opts) {
if (!isOSX() || mainWindow.isFocused()) {
return;
}
setDockBadge('●');
});