2
2
mirror of https://github.com/Llewellynvdm/nativefier.git synced 2024-05-29 03:00:48 +00:00
nativefier/app/src/main.js

66 lines
1.8 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;
app.on('window-all-closed', function () {
if (!isOSX()) {
2015-07-05 06:08:13 +00:00
app.quit();
}
});
app.on('activate', function (event, hasVisibleWindows) {
if (isOSX()) {
// this is called when the dock is clicked
if (!hasVisibleWindows) {
mainWindow.show();
}
}
});
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);
}
});
app.on('ready', function () {
mainWindow = createMainWindow(appArgs, app.quit, app.dock.setBadge);
});
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;
}
app.dock.setBadge('●');
});