2019-03-22 01:18:13 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
import path = require('path');
|
|
|
|
import exec = require('exec');
|
|
|
|
import spawn = require('spawn');
|
|
|
|
import delay = require('delay');
|
|
|
|
|
|
|
|
const { BrowserWindow } = require('electron');
|
|
|
|
|
|
|
|
let wv : any;
|
|
|
|
let cp : any;
|
|
|
|
let system : any = {};
|
|
|
|
|
|
|
|
let TMPDIR : any;
|
|
|
|
|
|
|
|
class WebView {
|
2019-03-22 02:33:30 +00:00
|
|
|
private digitalWindow : any;
|
|
|
|
public opened : boolean : false;
|
|
|
|
public showing : boolean = false;
|
2019-03-22 01:18:13 +00:00
|
|
|
constructor() {
|
2019-03-22 02:33:30 +00:00
|
|
|
this.digitalWindow = new BrowserWindow({
|
2019-03-22 01:18:13 +00:00
|
|
|
webPreferences: {
|
|
|
|
nodeIntegration: true,
|
|
|
|
allowRunningInsecureContent: false,
|
|
|
|
'unsafe-eval' : false
|
|
|
|
},
|
|
|
|
width: 800,
|
|
|
|
height: 600,
|
|
|
|
minWidth : 800,
|
|
|
|
minHeight : 600//,
|
|
|
|
//icon: path.join(__dirname, '../../assets/icons/icon.png')
|
|
|
|
});
|
2019-03-22 02:33:30 +00:00
|
|
|
this.digitalWindow.loadURL('file://' + __dirname + '../../../display.html');
|
2019-03-22 01:18:13 +00:00
|
|
|
if (process.argv.indexOf('-d') !== -1 || process.argv.indexOf('--dev') !== -1) {
|
2019-03-22 02:33:30 +00:00
|
|
|
this.digitalWindow.webContents.openDevTools();
|
2019-03-22 01:18:13 +00:00
|
|
|
}
|
2019-03-22 02:33:30 +00:00
|
|
|
this.digitalWindow.on('closed', () => {
|
|
|
|
this.digitalWindow = null
|
2019-03-22 01:18:13 +00:00
|
|
|
});
|
2019-03-22 02:33:30 +00:00
|
|
|
this.digitalWindow.hide();
|
|
|
|
}
|
|
|
|
async open () {
|
|
|
|
this.digitalWindow.show();
|
|
|
|
this.showing = true;
|
|
|
|
this.opened = true;
|
|
|
|
}
|
|
|
|
async start () {
|
|
|
|
await this.open();
|
|
|
|
await this.fullScreen();
|
|
|
|
await delay(300);
|
2019-03-22 01:18:13 +00:00
|
|
|
}
|
|
|
|
async fullScreen () {
|
2019-03-22 02:33:30 +00:00
|
|
|
//this.digitalWindow.setFullScreen(true);
|
|
|
|
await this.digitalWindow.maximize();
|
2019-03-22 01:18:13 +00:00
|
|
|
}
|
2019-03-22 02:33:30 +00:00
|
|
|
setImage (src : string) {
|
|
|
|
try {
|
|
|
|
this.digitalWindow.webContents.send('display', { src });
|
|
|
|
} catch (err) {
|
|
|
|
console.error(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
setMeter () {
|
|
|
|
this.digitalWindow.webContents.send('display', { meter : true });
|
2019-03-22 01:18:13 +00:00
|
|
|
}
|
2019-03-22 02:33:30 +00:00
|
|
|
setGrid () {
|
|
|
|
this.digitalWindow.webContents.send('display', { grid : true });
|
2019-03-22 01:18:13 +00:00
|
|
|
}
|
2019-03-22 02:33:30 +00:00
|
|
|
hide () {
|
|
|
|
if (this.digitalWindow) {
|
|
|
|
this.digitalWindow.hide();
|
|
|
|
}
|
|
|
|
this.showing = false;
|
2019-03-22 01:18:13 +00:00
|
|
|
}
|
2019-03-22 02:33:30 +00:00
|
|
|
close () {
|
|
|
|
if (this.digitalWindow) {
|
|
|
|
this.digitalWindow.close();
|
|
|
|
this.digitalWindow = null;
|
|
|
|
|
2019-03-22 01:18:13 +00:00
|
|
|
}
|
2019-03-22 02:33:30 +00:00
|
|
|
this.showing = false;
|
|
|
|
this.opened = false;
|
2019-03-22 01:18:13 +00:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
async move () {
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function padded_frame (i : number) {
|
|
|
|
let len = (i + '').length;
|
|
|
|
let str = i + '';
|
|
|
|
for (let x = 0; x < 5 - len; x++) {
|
|
|
|
str = '0' + str;
|
|
|
|
}
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
async function display_eog (src : string) {
|
|
|
|
//timeout 3 eog --fullscreen ${src}
|
|
|
|
cp = spawn('eog', ['--fullscreen', src]);
|
2019-03-22 02:33:30 +00:00
|
|
|
await delay(200)
|
2019-03-22 01:18:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-03-22 02:33:30 +00:00
|
|
|
function display_wv (src : string) {
|
|
|
|
wv.setImage(src);
|
2019-03-22 01:18:13 +00:00
|
|
|
}
|
|
|
|
|
2019-03-22 02:33:30 +00:00
|
|
|
async function hide () {
|
2019-03-22 01:18:13 +00:00
|
|
|
if (system.platform !== 'nix') {
|
2019-03-22 02:33:30 +00:00
|
|
|
//wv.hide();
|
2019-03-22 01:18:13 +00:00
|
|
|
} else {
|
|
|
|
if (cp) cp.kill();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-22 02:33:30 +00:00
|
|
|
async function show (frame : number) {
|
|
|
|
let padded : string = padded_frame(frame);
|
|
|
|
let ext : string = 'tif';
|
|
|
|
let tmppath : string;
|
2019-03-22 01:18:13 +00:00
|
|
|
|
|
|
|
if (system.platform !== 'nix') {
|
|
|
|
ext = 'png';
|
|
|
|
}
|
|
|
|
|
|
|
|
tmppath = path.join(TMPDIR, `export-${padded}.${ext}`);
|
|
|
|
|
|
|
|
if (system.platform !== 'nix') {
|
2019-03-22 02:33:30 +00:00
|
|
|
await open()
|
2019-03-22 01:18:13 +00:00
|
|
|
display_wv(tmppath);
|
|
|
|
} else {
|
2019-03-22 02:33:30 +00:00
|
|
|
await display_eog(tmppath);
|
2019-03-22 01:18:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-22 02:33:30 +00:00
|
|
|
async function open () {
|
|
|
|
if (system.platform !== 'nix') {
|
|
|
|
if (!wv || !wv.opened) {
|
|
|
|
wv = new WebView();
|
|
|
|
await wv.start()
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
//
|
|
|
|
}
|
|
|
|
}
|
2019-03-22 01:18:13 +00:00
|
|
|
|
2019-03-22 02:33:30 +00:00
|
|
|
async function close () {
|
2019-03-22 01:18:13 +00:00
|
|
|
if (system.platform !== 'nix') {
|
2019-03-22 02:33:30 +00:00
|
|
|
wv.close()
|
2019-03-22 01:18:13 +00:00
|
|
|
} else {
|
2019-03-22 02:33:30 +00:00
|
|
|
if (cp) cp.kill();
|
2019-03-22 01:18:13 +00:00
|
|
|
}
|
2019-03-22 02:33:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = function (sys : any) {
|
|
|
|
system = sys;
|
|
|
|
TMPDIR = path.join(system.tmp, 'mcopy_digital');
|
2019-03-22 01:18:13 +00:00
|
|
|
|
|
|
|
return {
|
2019-03-22 02:33:30 +00:00
|
|
|
open,
|
|
|
|
show,
|
|
|
|
hide,
|
|
|
|
close
|
2019-03-22 01:18:13 +00:00
|
|
|
}
|
|
|
|
}
|