2019-02-08 17:46:58 +00:00
|
|
|
'use strict';
|
2019-03-22 01:18:13 +00:00
|
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
2019-06-14 16:00:22 +00:00
|
|
|
/**
|
|
|
|
* @module display
|
|
|
|
* Provides features for displaying a full screen display of images for the digital module.
|
|
|
|
**/
|
2019-06-15 15:06:57 +00:00
|
|
|
const path_1 = require("path");
|
2020-07-27 02:26:34 +00:00
|
|
|
const url_1 = require("url");
|
2019-06-09 01:43:14 +00:00
|
|
|
const delay_1 = require("delay");
|
2023-08-06 18:36:31 +00:00
|
|
|
const Log = require("log");
|
2019-02-08 17:46:58 +00:00
|
|
|
const { BrowserWindow } = require('electron');
|
|
|
|
class WebView {
|
2019-06-27 00:08:49 +00:00
|
|
|
constructor(platform, display) {
|
2019-03-22 02:54:49 +00:00
|
|
|
this.opened = false;
|
2019-03-22 02:33:30 +00:00
|
|
|
this.showing = false;
|
2020-02-21 07:28:26 +00:00
|
|
|
this.loadWait = {};
|
2019-06-27 00:08:49 +00:00
|
|
|
const prefs = {
|
2019-03-22 01:18:13 +00:00
|
|
|
webPreferences: {
|
|
|
|
nodeIntegration: true,
|
2021-02-23 21:16:17 +00:00
|
|
|
allowRunningInsecureContent: false,
|
2023-02-25 17:16:47 +00:00
|
|
|
enableRemoteModule: true,
|
|
|
|
contextIsolation: 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
|
|
|
};
|
2020-07-27 02:26:34 +00:00
|
|
|
const pagePath = path_1.normalize(path_1.join(__dirname, '../../display.html'));
|
|
|
|
const pageUrl = url_1.format({
|
|
|
|
pathname: pagePath,
|
|
|
|
protocol: 'file:'
|
|
|
|
});
|
2023-08-06 18:36:31 +00:00
|
|
|
this.init();
|
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);
|
2023-02-25 17:33:18 +00:00
|
|
|
require('@electron/remote/main').enable(this.digitalWindow.webContents);
|
2020-07-27 02:26:34 +00:00
|
|
|
this.digitalWindow.loadURL(pageUrl);
|
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-06-18 17:35:50 +00:00
|
|
|
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;
|
2020-02-21 07:28:26 +00:00
|
|
|
this.ipc = require('electron').ipcMain;
|
|
|
|
this.ipc.on('display_load', this.onLoad.bind(this));
|
2019-03-22 02:33:30 +00:00
|
|
|
}
|
2023-08-06 18:36:31 +00:00
|
|
|
async init() {
|
|
|
|
this.log = await Log({ label: 'devices' });
|
|
|
|
}
|
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_1.delay(300);
|
2019-06-26 20:09:14 +00:00
|
|
|
if (this.platform === 'osx') {
|
|
|
|
await delay_1.delay(300); //give macs an extra 300ms to open fullscreen
|
|
|
|
}
|
2019-03-22 02:33:30 +00:00
|
|
|
}
|
2019-06-15 15:06:57 +00:00
|
|
|
async show(src) {
|
2020-07-27 02:26:34 +00:00
|
|
|
const normalSrc = path_1.normalize(path_1.join(src));
|
2019-06-18 17:35:50 +00:00
|
|
|
if (!this.digitalWindow) {
|
2023-08-06 18:36:31 +00:00
|
|
|
this.log.warn(`Cannot show "${src}" because window does not exist`);
|
2019-06-18 17:35:50 +00:00
|
|
|
return false;
|
|
|
|
}
|
2019-03-22 02:33:30 +00:00
|
|
|
try {
|
2020-07-27 02:26:34 +00:00
|
|
|
this.digitalWindow.webContents.send('display', { src: normalSrc });
|
2019-03-22 02:33:30 +00:00
|
|
|
}
|
|
|
|
catch (err) {
|
2023-08-06 18:36:31 +00:00
|
|
|
this.log.error(err);
|
2019-03-22 02:33:30 +00:00
|
|
|
}
|
2019-06-15 15:06:57 +00:00
|
|
|
this.showing = true;
|
2020-02-21 07:28:26 +00:00
|
|
|
return new Promise(function (resolve) {
|
|
|
|
this.loadWait[src] = resolve;
|
|
|
|
}.bind(this));
|
|
|
|
}
|
|
|
|
onLoad(evt, arg) {
|
2020-02-21 18:34:22 +00:00
|
|
|
if (this.loadWait[arg.src]) {
|
|
|
|
this.loadWait[arg.src]();
|
|
|
|
delete this.loadWait[arg.src];
|
|
|
|
}
|
2019-03-22 01:18:13 +00:00
|
|
|
}
|
2019-06-18 19:47:17 +00:00
|
|
|
async focus() {
|
|
|
|
if (!this.digitalWindow) {
|
2023-08-06 18:36:31 +00:00
|
|
|
this.log.warn(`Cannot show focus screen because window does not exist`);
|
2019-06-18 19:47:17 +00:00
|
|
|
return false;
|
|
|
|
}
|
2019-06-25 16:13:15 +00:00
|
|
|
await delay_1.delay(500);
|
2019-06-18 19:47:17 +00:00
|
|
|
try {
|
|
|
|
this.digitalWindow.webContents.send('focus', { focus: true });
|
|
|
|
}
|
|
|
|
catch (err) {
|
2023-08-06 18:36:31 +00:00
|
|
|
this.log.error(err);
|
2019-06-18 19:47:17 +00:00
|
|
|
}
|
|
|
|
}
|
2019-08-25 19:26:43 +00:00
|
|
|
async field(ratio) {
|
2019-06-18 19:47:17 +00:00
|
|
|
if (!this.digitalWindow) {
|
2023-08-06 18:36:31 +00:00
|
|
|
this.log.warn(`Cannot show field guide because window does not exist`);
|
2019-06-18 19:47:17 +00:00
|
|
|
return false;
|
|
|
|
}
|
2019-06-25 16:13:15 +00:00
|
|
|
await delay_1.delay(500);
|
2019-06-18 19:47:17 +00:00
|
|
|
try {
|
2019-08-25 19:26:43 +00:00
|
|
|
this.digitalWindow.webContents.send('field', { field: true, ratio });
|
2019-06-18 19:47:17 +00:00
|
|
|
}
|
|
|
|
catch (err) {
|
2023-08-06 18:36:31 +00:00
|
|
|
this.log.error(err);
|
2019-06-18 19:47:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
async meter() {
|
|
|
|
if (!this.digitalWindow) {
|
2023-08-06 18:36:31 +00:00
|
|
|
this.log.warn(`Cannot show meter screen because window does not exist`);
|
2019-06-18 19:47:17 +00:00
|
|
|
return false;
|
|
|
|
}
|
2019-06-25 16:13:15 +00:00
|
|
|
await delay_1.delay(500);
|
2019-06-18 19:47:17 +00:00
|
|
|
try {
|
|
|
|
this.digitalWindow.webContents.send('meter', { meter: true });
|
|
|
|
}
|
|
|
|
catch (err) {
|
2023-08-06 18:36:31 +00:00
|
|
|
this.log.error(err);
|
2019-06-18 19:47:17 +00:00
|
|
|
}
|
|
|
|
}
|
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-02-08 17:46:58 +00:00
|
|
|
}
|
2019-06-15 15:06:57 +00:00
|
|
|
class Display {
|
|
|
|
constructor(sys) {
|
|
|
|
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 = path_1.join(sys.tmp, 'mcopy_digital');
|
2019-06-27 00:08:49 +00:00
|
|
|
this.display = this.displays.find((display) => {
|
|
|
|
if (display.primary)
|
|
|
|
return true;
|
|
|
|
});
|
2019-06-15 15:06:57 +00:00
|
|
|
}
|
|
|
|
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();
|
|
|
|
}
|
2019-06-18 17:47:55 +00:00
|
|
|
if (!this.wv || !this.wv.opened) {
|
2019-06-27 00:08:49 +00:00
|
|
|
this.wv = new WebView(this.platform, this.display);
|
2019-06-18 17:47:55 +00:00
|
|
|
await this.wv.open();
|
2019-03-22 02:33:30 +00:00
|
|
|
}
|
|
|
|
}
|
2020-02-21 18:34:22 +00:00
|
|
|
async show(src) {
|
|
|
|
await this.wv.show(src);
|
2019-03-22 02:33:30 +00:00
|
|
|
}
|
2019-06-18 19:47:17 +00:00
|
|
|
async showPath(pathStr) {
|
|
|
|
return await this.wv.show(pathStr);
|
|
|
|
}
|
2019-06-15 15:06:57 +00:00
|
|
|
hide() {
|
2019-03-22 01:18:13 +00:00
|
|
|
}
|
2019-06-27 00:08:49 +00:00
|
|
|
async close() {
|
|
|
|
return await this.wv.close();
|
2019-03-22 01:18:13 +00:00
|
|
|
}
|
2019-06-18 19:47:17 +00:00
|
|
|
async focus() {
|
|
|
|
return await this.wv.focus();
|
|
|
|
}
|
2019-08-25 19:26:43 +00:00
|
|
|
async field(ratio) {
|
|
|
|
return await this.wv.field(ratio);
|
2019-06-18 19:47:17 +00:00
|
|
|
}
|
|
|
|
async meter() {
|
|
|
|
return await this.wv.meter();
|
|
|
|
}
|
2019-06-27 00:08:49 +00:00
|
|
|
change(id) {
|
|
|
|
this.display = this.displays.find((display) => {
|
|
|
|
if (display.id == id)
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
}
|
2019-03-22 02:33:30 +00:00
|
|
|
}
|
|
|
|
module.exports = function (sys) {
|
2019-06-15 15:06:57 +00:00
|
|
|
return new Display(sys);
|
2019-03-22 01:18:13 +00:00
|
|
|
};
|
|
|
|
//# sourceMappingURL=index.js.map
|