ordigi/app/modules/toolbar-ui.js

112 lines
3.2 KiB
JavaScript
Raw Permalink Normal View History

2015-11-19 06:00:09 +01:00
var exports = module.exports = {};
var menubar = require('menubar'),
menu = require('menu'),
tray = require('tray'),
config = require('./config.js'),
2015-11-19 06:00:09 +01:00
loadUrl = null;
2016-01-27 20:38:08 +01:00
var os = require('os')
2015-11-19 06:00:09 +01:00
2016-01-27 20:38:08 +01:00
var s_dir = __dirname.substr(0,__dirname.lastIndexOf(os.platform() == 'win32' ? '\\' : '/')) +
(os.platform() == 'win32' ? '\\html' : '/html');
2015-11-19 06:00:09 +01:00
exports.app = app = menubar(
{
preloadWindow: true,
2016-01-27 20:38:08 +01:00
dir: s_dir,
2015-11-19 06:00:09 +01:00
index: 'index.html',
pages: {
'blank': 'blank.html',
'config': 'config.html',
2015-11-19 06:00:09 +01:00
'location': 'location.html'
},
width: 400,
height: 500,
2016-01-27 16:27:12 +01:00
'window-position': 'trayCenter',
2016-01-27 20:38:08 +01:00
'frame': os.platform() == 'win32' ? true : false,
'always-on-top': os.platform() == 'win32' ? true : false
2015-11-19 06:00:09 +01:00
}
);
exports.ready = function() {
console.log('app is ready');
2015-11-19 06:00:09 +01:00
var template = [{
label: "Application",
submenu: [
{ label: "Quit", accelerator: "Command+Q", click: function() { app.quit(); }}
]}, {
label: "Edit",
submenu: [
{ label: "Undo", accelerator: "CmdOrCtrl+Z", selector: "undo:" },
{ label: "Redo", accelerator: "Shift+CmdOrCtrl+Z", selector: "redo:" },
{ label: "Cut", accelerator: "CmdOrCtrl+X", selector: "cut:" },
{ label: "Copy", accelerator: "CmdOrCtrl+C", selector: "copy:" },
{ label: "Paste", accelerator: "CmdOrCtrl+V", selector: "paste:" },
{ label: "Select All", accelerator: "CmdOrCtrl+A", selector: "selectAll:" }
]}
];
menu.setApplicationMenu(menu.buildFromTemplate(template));
this.tray.setToolTip('Drag and drop files here');
console.log(app.getOption('dir'));
this.tray.setImage(app.getOption('dir') + '/img/logo@18x22xbw.png');
this.tray.on('clicked', function clicked () {
console.log('tray-clicked')
});
this.tray.on('drop-files', function dropFiles (ev, files) {
loadUrl = app.getOption('pages')['location'];
app.showWindow();
//app.window.openDevTools();
app.window.webContents.on('did-finish-load', function() {
app.window.webContents.send('files', files);
app.window.webContents.send('preview', files);
});
});
};
2016-01-27 16:27:12 +01:00
exports.onDropFiles = function(event, args) {
var files = args;
loadUrl = app.getOption('pages')['location'];
app.showWindow();
app.window.webContents.on('did-finish-load', function() {
app.window.webContents.send('files', files);
app.window.webContents.send('preview', files);
});
};
2015-11-19 06:00:09 +01:00
exports.createWindow = function() {
console.log('create-window')
};
exports.afterCreateWindow = function() {
console.log('after-create-window')
};
exports.show = function() {
if(!config.hasConfig()) {
loadUrl = this.getOption('pages')['config'];
} else if(loadUrl === null) {
2015-11-19 06:00:09 +01:00
loadUrl = this.getOption('index');
}
2015-11-19 06:00:09 +01:00
this.window.loadUrl('file://' + this.getOption('dir') + '/' + loadUrl);
loadUrl = null;
2016-01-27 20:38:08 +01:00
//app.window.openDevTools();
2015-11-19 06:00:09 +01:00
};
exports.afterShow = function() {
console.log('after-show');
};
exports.hide = function() {
console.log('hide');
};
exports.afterHide = function() {
console.log('after-hide')
this.window.loadUrl('file://' + this.getOption('dir') + '/' + this.getOption('pages')['blank']);
};