2017-11-08 19:51:55 +02:00
|
|
|
const { _ } = require('lib/locale.js');
|
|
|
|
|
2017-11-05 02:17:48 +02:00
|
|
|
class Bridge {
|
|
|
|
|
|
|
|
constructor(electronWrapper) {
|
|
|
|
this.electronWrapper_ = electronWrapper;
|
|
|
|
}
|
|
|
|
|
2017-11-11 14:00:37 +02:00
|
|
|
electronApp() {
|
|
|
|
return this.electronWrapper_;
|
|
|
|
}
|
|
|
|
|
2017-11-05 02:17:48 +02:00
|
|
|
processArgv() {
|
|
|
|
return process.argv;
|
|
|
|
}
|
|
|
|
|
|
|
|
window() {
|
|
|
|
return this.electronWrapper_.window();
|
|
|
|
}
|
|
|
|
|
|
|
|
windowContentSize() {
|
|
|
|
if (!this.window()) return { width: 0, height: 0 };
|
|
|
|
const s = this.window().getContentSize();
|
|
|
|
return { width: s[0], height: s[1] };
|
|
|
|
}
|
|
|
|
|
2017-11-11 00:18:00 +02:00
|
|
|
showOpenDialog(options) {
|
|
|
|
const {dialog} = require('electron');
|
|
|
|
return dialog.showOpenDialog(options);
|
|
|
|
}
|
|
|
|
|
2017-11-06 20:35:04 +02:00
|
|
|
showMessageBox(options) {
|
|
|
|
const {dialog} = require('electron');
|
|
|
|
return dialog.showMessageBox(options);
|
|
|
|
}
|
|
|
|
|
2017-11-08 19:51:55 +02:00
|
|
|
showErrorMessageBox(message) {
|
|
|
|
return this.showMessageBox({
|
|
|
|
type: 'error',
|
|
|
|
message: message,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
showConfirmMessageBox(message) {
|
|
|
|
const result = this.showMessageBox({
|
|
|
|
type: 'question',
|
|
|
|
message: message,
|
|
|
|
buttons: [_('OK'), _('Cancel')],
|
|
|
|
});
|
|
|
|
return result === 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
get Menu() {
|
|
|
|
return require('electron').Menu;
|
|
|
|
}
|
|
|
|
|
|
|
|
get MenuItem() {
|
|
|
|
return require('electron').MenuItem;
|
|
|
|
}
|
|
|
|
|
2017-11-11 14:00:37 +02:00
|
|
|
openExternal(url) {
|
|
|
|
return require('electron').shell.openExternal(url)
|
|
|
|
}
|
|
|
|
|
2017-11-05 02:17:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
let bridge_ = null;
|
|
|
|
|
|
|
|
function initBridge(wrapper) {
|
|
|
|
if (bridge_) throw new Error('Bridge already initialized');
|
|
|
|
bridge_ = new Bridge(wrapper);
|
|
|
|
return bridge_;
|
|
|
|
}
|
|
|
|
|
|
|
|
function bridge() {
|
|
|
|
if (!bridge_) throw new Error('Bridge not initialized');
|
|
|
|
return bridge_;
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = { bridge, initBridge }
|