2019-03-22 01:18:13 +00:00
|
|
|
'use strict';
|
|
|
|
|
2019-06-14 15:29:52 +00:00
|
|
|
/**
|
|
|
|
* @module display
|
|
|
|
* Provides features for displaying a full screen display of images for the digital module.
|
|
|
|
**/
|
|
|
|
|
2019-03-22 01:18:13 +00:00
|
|
|
import spawn = require('spawn');
|
2019-06-15 15:06:57 +00:00
|
|
|
import { join as pathJoin } from 'path';
|
2019-06-09 01:43:14 +00:00
|
|
|
import { delay } from 'delay';
|
|
|
|
import { exec } from 'exec';
|
2019-03-22 01:18:13 +00:00
|
|
|
|
|
|
|
const { BrowserWindow } = require('electron');
|
|
|
|
|
2019-06-15 15:06:57 +00:00
|
|
|
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;
|
|
|
|
}
|
2019-03-22 01:18:13 +00:00
|
|
|
|
|
|
|
class WebView {
|
2019-03-22 02:33:30 +00:00
|
|
|
private digitalWindow : any;
|
2019-03-22 02:55:12 +00:00
|
|
|
public opened : boolean = false;
|
2019-03-22 02:33:30 +00:00
|
|
|
public showing : boolean = false;
|
2019-06-26 20:09:14 +00:00
|
|
|
private platform : string;
|
2019-06-27 00:08:49 +00:00
|
|
|
public display : any;
|
|
|
|
|
|
|
|
constructor (platform : string, display : any) {
|
|
|
|
const prefs : any = {
|
2019-03-22 01:18:13 +00:00
|
|
|
webPreferences: {
|
|
|
|
nodeIntegration: true,
|
2019-06-22 15:52:14 +00:00
|
|
|
allowRunningInsecureContent: false
|
2019-03-22 01:18:13 +00:00
|
|
|
},
|
|
|
|
width: 800,
|
|
|
|
height: 600,
|
|
|
|
minWidth : 800,
|
|
|
|
minHeight : 600//,
|
|
|
|
//icon: path.join(__dirname, '../../assets/icons/icon.png')
|
2019-06-27 00:08:49 +00:00
|
|
|
}
|
|
|
|
if (!display.primary) {
|
|
|
|
prefs.x = display.x + 50;
|
|
|
|
prefs.y = display.y + 50;
|
|
|
|
}
|
|
|
|
this.digitalWindow = new BrowserWindow(prefs);
|
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', () => {
|
2019-06-18 17:35:50 +00:00
|
|
|
this.digitalWindow = null;
|
|
|
|
this.close();
|
2019-03-22 01:18:13 +00:00
|
|
|
});
|
2019-06-26 20:09:14 +00:00
|
|
|
//this.digitalWindow.hide();
|
|
|
|
this.platform = platform;
|
2019-06-27 00:08:49 +00:00
|
|
|
this.display = display;
|
2019-03-22 02:33:30 +00:00
|
|
|
}
|
|
|
|
async open () {
|
|
|
|
this.digitalWindow.show();
|
|
|
|
this.showing = true;
|
|
|
|
this.opened = true;
|
2019-06-18 17:47:55 +00:00
|
|
|
await this.digitalWindow.setFullScreen(true);
|
2019-06-15 15:06:57 +00:00
|
|
|
await delay(300);
|
2019-06-26 20:09:14 +00:00
|
|
|
if (this.platform === 'osx') {
|
|
|
|
await delay(300); //give macs an extra 300ms to open fullscreen
|
|
|
|
}
|
2019-03-22 01:18:13 +00:00
|
|
|
}
|
2019-06-15 15:06:57 +00:00
|
|
|
async show (src : string) {
|
2019-06-18 17:35:50 +00:00
|
|
|
if (!this.digitalWindow) {
|
|
|
|
console.warn(`Cannot show "${src}" because window does not exist`);
|
|
|
|
return false;
|
|
|
|
}
|
2019-03-22 02:33:30 +00:00
|
|
|
try {
|
|
|
|
this.digitalWindow.webContents.send('display', { src });
|
|
|
|
} catch (err) {
|
2019-06-18 17:35:50 +00:00
|
|
|
console.error(err);
|
2019-03-22 02:33:30 +00:00
|
|
|
}
|
2019-06-15 15:06:57 +00:00
|
|
|
this.showing = true;
|
2019-06-25 16:13:15 +00:00
|
|
|
await delay(200);
|
2019-06-18 17:35:50 +00:00
|
|
|
return true;
|
2019-03-22 01:18:13 +00:00
|
|
|
}
|
2019-06-18 19:47:17 +00:00
|
|
|
async focus () {
|
|
|
|
if (!this.digitalWindow) {
|
|
|
|
console.warn(`Cannot show focus screen because window does not exist`);
|
|
|
|
return false;
|
|
|
|
}
|
2019-06-25 16:13:15 +00:00
|
|
|
await delay(500);
|
2019-06-18 19:47:17 +00:00
|
|
|
try {
|
|
|
|
this.digitalWindow.webContents.send('focus', { focus : true });
|
|
|
|
} catch (err) {
|
|
|
|
console.error(err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
async field () {
|
|
|
|
if (!this.digitalWindow) {
|
|
|
|
console.warn(`Cannot show field guide because window does not exist`);
|
|
|
|
return false;
|
|
|
|
}
|
2019-06-25 16:13:15 +00:00
|
|
|
await delay(500);
|
2019-06-18 19:47:17 +00:00
|
|
|
try {
|
|
|
|
this.digitalWindow.webContents.send('field', { field : true });
|
|
|
|
} catch (err) {
|
|
|
|
console.error(err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
async meter () {
|
|
|
|
if (!this.digitalWindow) {
|
|
|
|
console.warn(`Cannot show meter screen because window does not exist`);
|
|
|
|
return false;
|
|
|
|
}
|
2019-06-25 16:13:15 +00:00
|
|
|
await delay(500);
|
2019-06-18 19:47:17 +00:00
|
|
|
try {
|
|
|
|
this.digitalWindow.webContents.send('meter', { meter : true });
|
|
|
|
} catch (err) {
|
|
|
|
console.error(err);
|
|
|
|
}
|
|
|
|
}
|
2019-03-22 02:33:30 +00:00
|
|
|
hide () {
|
|
|
|
if (this.digitalWindow) {
|
|
|
|
this.digitalWindow.hide();
|
|
|
|
}
|
|
|
|
this.showing = false;
|
2019-06-18 17:35:50 +00:00
|
|
|
return true;
|
2019-03-22 01:18:13 +00:00
|
|
|
}
|
2019-03-22 02:33:30 +00:00
|
|
|
close () {
|
2019-06-15 15:06:57 +00:00
|
|
|
this.hide();
|
2019-03-22 02:33:30 +00:00
|
|
|
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.opened = false;
|
2019-06-18 17:35:50 +00:00
|
|
|
this.showing = false;
|
2019-03-22 01:18:13 +00:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-15 15:06:57 +00:00
|
|
|
class EOG {
|
|
|
|
private cp : any;
|
|
|
|
constructor () {
|
2019-03-22 01:18:13 +00:00
|
|
|
|
2019-06-15 15:06:57 +00:00
|
|
|
}
|
2019-03-22 01:18:13 +00:00
|
|
|
|
2019-06-15 15:06:57 +00:00
|
|
|
public open () {
|
|
|
|
this.hide();
|
2019-03-22 01:18:13 +00:00
|
|
|
}
|
|
|
|
|
2019-06-15 15:06:57 +00:00
|
|
|
public async show (src : string) {
|
|
|
|
//timeout 3 eog --fullscreen ${src}
|
|
|
|
this.cp = spawn('eog', ['--fullscreen', src]);
|
|
|
|
await delay(200)
|
|
|
|
return true
|
|
|
|
}
|
2019-03-22 01:18:13 +00:00
|
|
|
|
2019-06-15 15:06:57 +00:00
|
|
|
public hide () {
|
|
|
|
if (this.cp) {
|
|
|
|
this.cp.kill();
|
|
|
|
this.cp = null;
|
|
|
|
}
|
2019-03-22 01:18:13 +00:00
|
|
|
}
|
2019-06-15 15:06:57 +00:00
|
|
|
public close () {
|
|
|
|
this.hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class Display {
|
|
|
|
private platform : string;
|
2019-06-27 00:08:49 +00:00
|
|
|
private displays : any[];
|
|
|
|
private display : any;
|
2019-06-15 15:06:57 +00:00
|
|
|
private tmpdir : string;
|
|
|
|
private wv : WebView;
|
|
|
|
private eog : EOG;
|
|
|
|
|
|
|
|
constructor (sys : any) {
|
|
|
|
this.platform = sys.platform;
|
2019-06-27 00:08:49 +00:00
|
|
|
this.displays = sys.displays;
|
2019-06-15 15:06:57 +00:00
|
|
|
this.tmpdir = pathJoin(sys.tmp, 'mcopy_digital');
|
2019-06-27 00:08:49 +00:00
|
|
|
this.display = this.displays.find((display : any) => {
|
|
|
|
if (display.primary) return true;
|
|
|
|
})
|
2019-06-15 15:06:57 +00:00
|
|
|
}
|
|
|
|
public async open () {
|
2019-06-27 00:08:49 +00:00
|
|
|
if (this.wv && this.wv.display && this.wv.display.id !== this.display.id) {
|
|
|
|
this.wv.close();
|
|
|
|
}
|
|
|
|
if (!this.wv || !this.wv.opened) {
|
|
|
|
this.wv = new WebView(this.platform, this.display);
|
|
|
|
await this.wv.open();
|
|
|
|
}
|
2019-06-15 15:06:57 +00:00
|
|
|
}
|
|
|
|
public async show (frame : number) {
|
|
|
|
let padded : string = padded_frame(frame);
|
2019-06-27 00:08:49 +00:00
|
|
|
let ext : string = 'png';
|
2019-06-15 15:06:57 +00:00
|
|
|
let tmppath : string;
|
2019-03-22 01:18:13 +00:00
|
|
|
|
2019-06-15 15:06:57 +00:00
|
|
|
tmppath = pathJoin(this.tmpdir, `export-${padded}.${ext}`);
|
2019-03-22 01:18:13 +00:00
|
|
|
|
2019-06-27 00:08:49 +00:00
|
|
|
await this.wv.show(tmppath);
|
2019-03-22 02:33:30 +00:00
|
|
|
}
|
2019-06-18 19:47:17 +00:00
|
|
|
public async showPath (pathStr : string) {
|
|
|
|
return await this.wv.show(pathStr);
|
|
|
|
}
|
2019-06-15 15:06:57 +00:00
|
|
|
public hide () {
|
2019-06-27 00:08:49 +00:00
|
|
|
|
2019-06-15 15:06:57 +00:00
|
|
|
}
|
2019-06-27 00:08:49 +00:00
|
|
|
public async close () {
|
|
|
|
return await this.wv.close()
|
2019-03-22 01:18:13 +00:00
|
|
|
}
|
2019-06-18 19:47:17 +00:00
|
|
|
public async focus () {
|
|
|
|
return await this.wv.focus();
|
|
|
|
}
|
|
|
|
public async field () {
|
|
|
|
return await this.wv.field();
|
|
|
|
}
|
|
|
|
public async meter () {
|
|
|
|
return await this.wv.meter();
|
|
|
|
}
|
2019-06-27 00:08:49 +00:00
|
|
|
public change (id : any) {
|
|
|
|
this.display = this.displays.find((display : any) => {
|
|
|
|
if (display.id == id) return true;
|
|
|
|
});
|
|
|
|
}
|
2019-03-22 02:33:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = function (sys : any) {
|
2019-06-15 15:06:57 +00:00
|
|
|
return new Display(sys)
|
2019-03-22 01:18:13 +00:00
|
|
|
}
|