Nativefier/app/main.js

66 lines
1.6 KiB
JavaScript
Raw Normal View History

2015-07-05 08:08:13 +02:00
/**
* Created by JiaHao on 4/7/15.
*/
var app = require('app');
var fs = require('fs');
var BrowserWindow = require('browser-window');
var ipc = require('ipc');
2015-07-05 08:08:13 +02:00
const APP_ARGS_FILE_PATH = __dirname + '/targetUrl.txt';
require('crash-reporter').start();
var mainWindow = null;
app.on('window-all-closed', function() {
if (process.platform != 'darwin') {
app.quit();
}
});
app.on('ready', function() {
mainWindow = new BrowserWindow(
{
width: 1280,
height: 800,
'web-preferences': {
javascript: true,
plugins: true,
}
}
);
mainWindow.loadUrl('file://' + __dirname + '/index.html');
//mainWindow.openDevTools();
2015-07-05 08:08:13 +02:00
mainWindow.webContents.on('did-finish-load', function() {
fs.readFile(APP_ARGS_FILE_PATH, 'utf8', function (error, data) {
2015-07-05 08:08:13 +02:00
if (error) {
console.error('Error reading app config file: ' + error);
2015-07-05 08:08:13 +02:00
} else {
console.log(data);
2015-07-05 08:08:13 +02:00
mainWindow.webContents.send('params', data);
2015-07-05 08:08:13 +02:00
}
})
});
// if the window is focused, clear the badge
mainWindow.on('focus', function () {
app.dock.setBadge('');
});
2015-07-05 08:08:13 +02:00
mainWindow.on('closed', function() {
mainWindow = null;
});
});
2015-07-05 08:08:13 +02:00
// listen for a notification message
ipc.on('notification-message', function(event, arg) {
console.log(arg); // prints "ping"
if (arg === 'TITLE_CHANGED') {
if (!mainWindow.isFocused()) {
app.dock.setBadge('●');
}
}
});