Refactor display module into typescript

This commit is contained in:
mmcwilliams 2019-03-21 21:18:13 -04:00
parent d264429726
commit 0ff1b5ff7d
9 changed files with 476 additions and 112 deletions

View File

@ -1,34 +1,28 @@
'use strict';
const path = require('path');
Object.defineProperty(exports, "__esModule", { value: true });
const path = require("path");
const spawn = require("spawn");
const delay = require("delay");
const { BrowserWindow } = require('electron');
const exec = require('exec');
const spawn = require('spawn');
const delay = require('delay');
let wv;
let cp;
let system = {};
let digitalWindow;
let TMPDIR;
class WebView {
constructor() {
}
async open () {
async open() {
digitalWindow = new BrowserWindow({
webPreferences: {
nodeIntegration: true,
allowRunningInsecureContent: false,
'unsafe-eval' : false
'unsafe-eval': false
},
width: 800,
height: 600,
minWidth : 800,
minHeight : 600//,
minWidth: 800,
minHeight: 600 //,
//icon: path.join(__dirname, '../../assets/icons/icon.png')
});
digitalWindow.loadURL('file://' + __dirname + '../../../display.html');
@ -36,33 +30,31 @@ class WebView {
digitalWindow.webContents.openDevTools();
}
digitalWindow.on('closed', () => {
digitalWindow = null
digitalWindow = null;
});
}
async fullScreen () {
async fullScreen() {
return digitalWindow.setFullScreen(true);
}
async setImage (src) {
async setImage(src) {
return digitalWindow.webContents.send('display', { src });
}
async setMeter () {
return digitalWindow.webContents.send('display', { meter : true });
async setMeter() {
return digitalWindow.webContents.send('display', { meter: true });
}
async setGrid () {
return digitalWindow.webContents.send('display', { grid : true });
async setGrid() {
return digitalWindow.webContents.send('display', { grid: true });
}
async close () {
async close() {
if (digitalWindow) {
digitalWindow.close();
}
return true
return true;
}
async move () {
async move() {
}
}
function padded_frame (i) {
function padded_frame(i) {
let len = (i + '').length;
let str = i + '';
for (let x = 0; x < 5 - len; x++) {
@ -70,58 +62,52 @@ function padded_frame (i) {
}
return str;
}
async function display_eog (src) {
async function display_eog(src) {
//timeout 3 eog --fullscreen ${src}
cp = spawn('eog', ['--fullscreen', src]);
}
async function display_wv (src) {
async function display_wv(src) {
await wv.open();
await wv.fullScreen();
await delay(200);
await wv.setImage(src);
}
async function end () {
async function end() {
if (system.platform !== 'nix') {
await wv.close();
} else {
if (cp) cp.kill()
}
else {
if (cp)
cp.kill();
}
}
async function start (frame) {
async function start(frame) {
let padded = padded_frame(frame);
let ext = 'tif';
let tmppath;
if (system.platform !== 'nix') {
ext = 'png';
}
tmppath = path.join(TMPDIR, `export-${padded}.${ext}`);
if (system.platform !== 'nix') {
display_wv(tmppath);
} else {
}
else {
display_eog(tmppath);
}
}
module.exports = function (sys) {
system = sys;
TMPDIR = path.join(system.tmp, 'mcopy_digital');
if (system.platform !== 'nix') {
wv = new WebView();
} else {
}
else {
//child process
}
return {
start,
end
}
}
};
};
//# sourceMappingURL=index.js.map

View File

@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/display/index.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,6BAA8B;AAE9B,+BAAgC;AAChC,+BAAgC;AAEhC,MAAM,EAAE,aAAa,EAAE,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;AAE9C,IAAI,EAAQ,CAAC;AACb,IAAI,EAAQ,CAAC;AACb,IAAI,MAAM,GAAS,EAAE,CAAC;AACtB,IAAI,aAAmB,CAAC;AAExB,IAAI,MAAY,CAAC;AAEjB,MAAM,OAAO;IACZ;IAEA,CAAC;IACD,KAAK,CAAC,IAAI;QACT,aAAa,GAAG,IAAI,aAAa,CAAC;YACjC,cAAc,EAAE;gBACV,eAAe,EAAE,IAAI;gBACrB,2BAA2B,EAAE,KAAK;gBAClC,aAAa,EAAG,KAAK;aACvB;YACJ,KAAK,EAAE,GAAG;YACV,MAAM,EAAE,GAAG;YACX,QAAQ,EAAG,GAAG;YACd,SAAS,EAAG,GAAG,CAAA,GAAG;YAClB,2DAA2D;SAC3D,CAAC,CAAC;QACH,aAAa,CAAC,OAAO,CAAC,SAAS,GAAG,SAAS,GAAG,uBAAuB,CAAC,CAAC;QACvE,IAAI,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,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AAE,eAAe,CAAC,CAAC;IAEhD,IAAI,MAAM,CAAC,QAAQ,KAAK,KAAK,EAAE;QAC9B,EAAE,GAAG,IAAI,OAAO,EAAE,CAAC;KACnB;SAAM;QACN,eAAe;KACf;IAED,OAAO;QACN,KAAK;QACL,GAAG;KACH,CAAA;AACF,CAAC,CAAA"}

113
cli/lib/display/index.js Normal file
View File

@ -0,0 +1,113 @@
'use strict';
Object.defineProperty(exports, "__esModule", { value: true });
const path = require("path");
const spawn = require("spawn");
const delay = require("delay");
const { BrowserWindow } = require('electron');
let wv;
let cp;
let system = {};
let digitalWindow;
let TMPDIR;
class WebView {
constructor() {
}
async open() {
digitalWindow = new BrowserWindow({
webPreferences: {
nodeIntegration: true,
allowRunningInsecureContent: false,
'unsafe-eval': false
},
width: 800,
height: 600,
minWidth: 800,
minHeight: 600 //,
//icon: path.join(__dirname, '../../assets/icons/icon.png')
});
digitalWindow.loadURL('file://' + __dirname + '../../../display.html');
if (process.argv.indexOf('-d') !== -1 || process.argv.indexOf('--dev') !== -1) {
digitalWindow.webContents.openDevTools();
}
digitalWindow.on('closed', () => {
digitalWindow = null;
});
}
async fullScreen() {
return digitalWindow.setFullScreen(true);
}
async setImage(src) {
return digitalWindow.webContents.send('display', { src });
}
async setMeter() {
return digitalWindow.webContents.send('display', { meter: true });
}
async setGrid() {
return digitalWindow.webContents.send('display', { grid: true });
}
async close() {
if (digitalWindow) {
digitalWindow.close();
}
return true;
}
async move() {
}
}
function padded_frame(i) {
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) {
//timeout 3 eog --fullscreen ${src}
cp = spawn('eog', ['--fullscreen', src]);
}
async function display_wv(src) {
await wv.open();
await wv.fullScreen();
await delay(200);
await wv.setImage(src);
}
async function end() {
if (system.platform !== 'nix') {
await wv.close();
}
else {
if (cp)
cp.kill();
}
}
async function start(frame) {
let padded = padded_frame(frame);
let ext = 'tif';
let tmppath;
if (system.platform !== 'nix') {
ext = 'png';
}
tmppath = path.join(TMPDIR, `export-${padded}.${ext}`);
if (system.platform !== 'nix') {
display_wv(tmppath);
}
else {
display_eog(tmppath);
}
}
module.exports = function (sys) {
system = sys;
TMPDIR = path.join(system.tmp, 'mcopy_digital');
if (system.platform !== 'nix') {
wv = new WebView();
}
else {
//child process
}
return {
start,
end
};
};
//# sourceMappingURL=index.js.map

View File

@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/display/index.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,6BAA8B;AAE9B,+BAAgC;AAChC,+BAAgC;AAEhC,MAAM,EAAE,aAAa,EAAE,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;AAE9C,IAAI,EAAQ,CAAC;AACb,IAAI,EAAQ,CAAC;AACb,IAAI,MAAM,GAAS,EAAE,CAAC;AACtB,IAAI,aAAmB,CAAC;AAExB,IAAI,MAAY,CAAC;AAEjB,MAAM,OAAO;IACZ;IAEA,CAAC;IACD,KAAK,CAAC,IAAI;QACT,aAAa,GAAG,IAAI,aAAa,CAAC;YACjC,cAAc,EAAE;gBACV,eAAe,EAAE,IAAI;gBACrB,2BAA2B,EAAE,KAAK;gBAClC,aAAa,EAAG,KAAK;aACvB;YACJ,KAAK,EAAE,GAAG;YACV,MAAM,EAAE,GAAG;YACX,QAAQ,EAAG,GAAG;YACd,SAAS,EAAG,GAAG,CAAA,GAAG;YAClB,2DAA2D;SAC3D,CAAC,CAAC;QACH,aAAa,CAAC,OAAO,CAAC,SAAS,GAAG,SAAS,GAAG,uBAAuB,CAAC,CAAC;QACvE,IAAI,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE;YAC9E,aAAa,CAAC,WAAW,CAAC,YAAY,EAAE,CAAC;SACzC;QACD,aAAa,CAAC,E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;KACH,CAAA;AACF,CAAC,CAAA"}

View File

@ -0,0 +1,11 @@
{
"name": "display",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}

113
lib/display/index.js Normal file
View File

@ -0,0 +1,113 @@
'use strict';
Object.defineProperty(exports, "__esModule", { value: true });
const path = require("path");
const spawn = require("spawn");
const delay = require("delay");
const { BrowserWindow } = require('electron');
let wv;
let cp;
let system = {};
let digitalWindow;
let TMPDIR;
class WebView {
constructor() {
}
async open() {
digitalWindow = new BrowserWindow({
webPreferences: {
nodeIntegration: true,
allowRunningInsecureContent: false,
'unsafe-eval': false
},
width: 800,
height: 600,
minWidth: 800,
minHeight: 600 //,
//icon: path.join(__dirname, '../../assets/icons/icon.png')
});
digitalWindow.loadURL('file://' + __dirname + '../../../display.html');
if (process.argv.indexOf('-d') !== -1 || process.argv.indexOf('--dev') !== -1) {
digitalWindow.webContents.openDevTools();
}
digitalWindow.on('closed', () => {
digitalWindow = null;
});
}
async fullScreen() {
return digitalWindow.setFullScreen(true);
}
async setImage(src) {
return digitalWindow.webContents.send('display', { src });
}
async setMeter() {
return digitalWindow.webContents.send('display', { meter: true });
}
async setGrid() {
return digitalWindow.webContents.send('display', { grid: true });
}
async close() {
if (digitalWindow) {
digitalWindow.close();
}
return true;
}
async move() {
}
}
function padded_frame(i) {
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) {
//timeout 3 eog --fullscreen ${src}
cp = spawn('eog', ['--fullscreen', src]);
}
async function display_wv(src) {
await wv.open();
await wv.fullScreen();
await delay(200);
await wv.setImage(src);
}
async function end() {
if (system.platform !== 'nix') {
await wv.close();
}
else {
if (cp)
cp.kill();
}
}
async function start(frame) {
let padded = padded_frame(frame);
let ext = 'tif';
let tmppath;
if (system.platform !== 'nix') {
ext = 'png';
}
tmppath = path.join(TMPDIR, `export-${padded}.${ext}`);
if (system.platform !== 'nix') {
display_wv(tmppath);
}
else {
display_eog(tmppath);
}
}
module.exports = function (sys) {
system = sys;
TMPDIR = path.join(system.tmp, 'mcopy_digital');
if (system.platform !== 'nix') {
wv = new WebView();
}
else {
//child process
}
return {
start,
end
};
};
//# sourceMappingURL=index.js.map

1
lib/display/index.js.map Normal file
View File

@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/display/index.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,6BAA8B;AAE9B,+BAAgC;AAChC,+BAAgC;AAEhC,MAAM,EAAE,aAAa,EAAE,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;AAE9C,IAAI,EAAQ,CAAC;AACb,IAAI,EAAQ,CAAC;AACb,IAAI,MAAM,GAAS,EAAE,CAAC;AACtB,IAAI,aAAmB,CAAC;AAExB,IAAI,MAAY,CAAC;AAEjB,MAAM,OAAO;IACZ;IAEA,CAAC;IACD,KAAK,CAAC,IAAI;QACT,aAAa,GAAG,IAAI,aAAa,CAAC;YACjC,cAAc,EAAE;gBACV,eAAe,EAAE,IAAI;gBACrB,2BAA2B,EAAE,KAAK;gBAClC,aAAa,EAAG,KAAK;aACvB;YACJ,KAAK,EAAE,GAAG;YACV,MAAM,EAAE,GAAG;YACX,QAAQ,EAAG,GAAG;YACd,SAAS,EAAG,GAAG,CAAA,GAAG;YAClB,2DAA2D;SAC3D,CAAC,CAAC;QACH,aAAa,CAAC,OAAO,CAAC,SAAS,GAAG,SAAS,GAAG,uBAAuB,CAAC,CAAC;QACvE,IAAI,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE;YAC9E,aAAa,CAAC,WAAW,CAAC,YAAY,EAAE,CAAC;SACzC;QACD,aAAa,CAAC,EAAE,CAAC,QAAQ,EAAE,GAAG,EAAE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ib/display/package.json Normal file
View File

@ -0,0 +1,11 @@
{
"name": "display",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}

127
src/display/index.ts Normal file
View File

@ -0,0 +1,127 @@
'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 digitalWindow : any;
let TMPDIR : any;
class WebView {
constructor() {
}
async open () {
digitalWindow = new BrowserWindow({
webPreferences: {
nodeIntegration: true,
allowRunningInsecureContent: false,
'unsafe-eval' : false
},
width: 800,
height: 600,
minWidth : 800,
minHeight : 600//,
//icon: path.join(__dirname, '../../assets/icons/icon.png')
});
digitalWindow.loadURL('file://' + __dirname + '../../../display.html');
if (process.argv.indexOf('-d') !== -1 || process.argv.indexOf('--dev') !== -1) {
digitalWindow.webContents.openDevTools();
}
digitalWindow.on('closed', () => {
digitalWindow = null
});
}
async fullScreen () {
return digitalWindow.setFullScreen(true);
}
async setImage (src : string) {
return digitalWindow.webContents.send('display', { src });
}
async setMeter () {
return digitalWindow.webContents.send('display', { meter : true });
}
async setGrid () {
return digitalWindow.webContents.send('display', { grid : true });
}
async close () {
if (digitalWindow) {
digitalWindow.close();
}
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]);
}
async function display_wv (src : string) {
await wv.open();
await wv.fullScreen();
await delay(200);
await wv.setImage(src);
}
async function end () {
if (system.platform !== 'nix') {
await wv.close();
} else {
if (cp) cp.kill();
}
}
async function start (frame : number) {
let padded = padded_frame(frame);
let ext = 'tif';
let tmppath;
if (system.platform !== 'nix') {
ext = 'png';
}
tmppath = path.join(TMPDIR, `export-${padded}.${ext}`);
if (system.platform !== 'nix') {
display_wv(tmppath);
} else {
display_eog(tmppath);
}
}
module.exports = function (sys : any) {
system = sys;
TMPDIR = path.join(system.tmp, 'mcopy_digital');
if (system.platform !== 'nix') {
wv = new WebView();
} else {
//child process
}
return {
start,
end
}
}