2015-07-05 06:08:13 +00:00
|
|
|
/**
|
|
|
|
* Created by JiaHao on 4/7/15.
|
|
|
|
*/
|
|
|
|
|
|
|
|
var fs = require('fs');
|
2016-01-19 03:28:04 +00:00
|
|
|
var electron = require('electron');
|
|
|
|
|
|
|
|
var app = electron.app;
|
|
|
|
var BrowserWindow = electron.BrowserWindow;
|
|
|
|
var ipc = electron.ipcMain;
|
2015-07-05 06:08:13 +00:00
|
|
|
|
2016-01-19 03:45:17 +00:00
|
|
|
const APP_ARGS_FILE_PATH = __dirname + '/nativefier.json';
|
2015-07-05 06:08:13 +00:00
|
|
|
require('crash-reporter').start();
|
|
|
|
|
|
|
|
var mainWindow = null;
|
|
|
|
|
2015-07-06 02:31:09 +00:00
|
|
|
var appArgs = JSON.parse(fs.readFileSync(APP_ARGS_FILE_PATH, 'utf8'));
|
|
|
|
|
2015-07-05 06:08:13 +00:00
|
|
|
app.on('window-all-closed', function() {
|
|
|
|
if (process.platform != 'darwin') {
|
|
|
|
app.quit();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
app.on('ready', function() {
|
|
|
|
mainWindow = new BrowserWindow(
|
|
|
|
{
|
2015-07-06 02:31:09 +00:00
|
|
|
width: appArgs.width || 1280,
|
|
|
|
height: appArgs.height || 800,
|
2015-07-05 06:08:13 +00:00
|
|
|
'web-preferences': {
|
|
|
|
javascript: true,
|
|
|
|
plugins: true,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
2016-01-19 03:30:42 +00:00
|
|
|
|
2016-01-19 10:24:24 +00:00
|
|
|
// uncomment to show dev tools for the main window
|
|
|
|
//mainWindow.openDevTools();
|
2016-01-19 03:42:52 +00:00
|
|
|
|
2016-01-19 10:06:20 +00:00
|
|
|
mainWindow.loadUrl('file://' + __dirname + '/index.html');
|
2015-07-05 06:08:13 +00:00
|
|
|
|
2016-01-19 03:30:42 +00:00
|
|
|
mainWindow.webContents.on('did-finish-load', function() {
|
2015-07-06 02:31:09 +00:00
|
|
|
mainWindow.webContents.send('params', JSON.stringify(appArgs));
|
2015-07-05 06:08:13 +00:00
|
|
|
});
|
|
|
|
|
2015-07-06 01:38:04 +00:00
|
|
|
// if the window is focused, clear the badge
|
|
|
|
mainWindow.on('focus', function () {
|
2015-08-06 03:34:32 +00:00
|
|
|
if (process.platform === 'darwin') {
|
|
|
|
app.dock.setBadge('');
|
|
|
|
}
|
2015-07-06 01:38:04 +00:00
|
|
|
});
|
2015-07-05 06:08:13 +00:00
|
|
|
|
|
|
|
mainWindow.on('closed', function() {
|
|
|
|
mainWindow = null;
|
2015-07-06 01:38:04 +00:00
|
|
|
});
|
|
|
|
});
|
2015-07-05 06:08:13 +00:00
|
|
|
|
2015-07-06 01:38:04 +00:00
|
|
|
// listen for a notification message
|
|
|
|
ipc.on('notification-message', function(event, arg) {
|
|
|
|
if (arg === 'TITLE_CHANGED') {
|
2015-08-06 03:34:32 +00:00
|
|
|
if (process.platform === 'darwin' && !mainWindow.isFocused()) {
|
2015-07-06 01:38:04 +00:00
|
|
|
app.dock.setBadge('●');
|
|
|
|
}
|
|
|
|
}
|
2015-07-06 03:46:08 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
app.on('window-all-closed', function() {
|
|
|
|
app.quit();
|
2015-08-06 03:34:32 +00:00
|
|
|
});
|