Manual merge from capper branch: all changes to display library.

This commit is contained in:
Matt McWilliams 2023-08-06 14:36:31 -04:00
parent 8b235bb6b0
commit 176643f148
10 changed files with 37 additions and 25 deletions

View File

@ -1,5 +1,5 @@
{ {
"version": "1.7.22", "version": "1.7.23",
"ext_port": 1111, "ext_port": 1111,
"profiles": { "profiles": {
"mcopy": { "mcopy": {

View File

@ -7,6 +7,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
const path_1 = require("path"); const path_1 = require("path");
const url_1 = require("url"); const url_1 = require("url");
const delay_1 = require("delay"); const delay_1 = require("delay");
const Log = require("log");
const { BrowserWindow } = require('electron'); const { BrowserWindow } = require('electron');
class WebView { class WebView {
constructor(platform, display) { constructor(platform, display) {
@ -31,6 +32,7 @@ class WebView {
pathname: pagePath, pathname: pagePath,
protocol: 'file:' protocol: 'file:'
}); });
this.init();
if (!display.primary) { if (!display.primary) {
prefs.x = display.x + 50; prefs.x = display.x + 50;
prefs.y = display.y + 50; prefs.y = display.y + 50;
@ -51,6 +53,9 @@ class WebView {
this.ipc = require('electron').ipcMain; this.ipc = require('electron').ipcMain;
this.ipc.on('display_load', this.onLoad.bind(this)); this.ipc.on('display_load', this.onLoad.bind(this));
} }
async init() {
this.log = await Log({ label: 'devices' });
}
async open() { async open() {
this.digitalWindow.show(); this.digitalWindow.show();
this.showing = true; this.showing = true;
@ -64,14 +69,14 @@ class WebView {
async show(src) { async show(src) {
const normalSrc = path_1.normalize(path_1.join(src)); const normalSrc = path_1.normalize(path_1.join(src));
if (!this.digitalWindow) { if (!this.digitalWindow) {
console.warn(`Cannot show "${src}" because window does not exist`); this.log.warn(`Cannot show "${src}" because window does not exist`);
return false; return false;
} }
try { try {
this.digitalWindow.webContents.send('display', { src: normalSrc }); this.digitalWindow.webContents.send('display', { src: normalSrc });
} }
catch (err) { catch (err) {
console.error(err); this.log.error(err);
} }
this.showing = true; this.showing = true;
return new Promise(function (resolve) { return new Promise(function (resolve) {
@ -86,7 +91,7 @@ class WebView {
} }
async focus() { async focus() {
if (!this.digitalWindow) { if (!this.digitalWindow) {
console.warn(`Cannot show focus screen because window does not exist`); this.log.warn(`Cannot show focus screen because window does not exist`);
return false; return false;
} }
await delay_1.delay(500); await delay_1.delay(500);
@ -94,12 +99,12 @@ class WebView {
this.digitalWindow.webContents.send('focus', { focus: true }); this.digitalWindow.webContents.send('focus', { focus: true });
} }
catch (err) { catch (err) {
console.error(err); this.log.error(err);
} }
} }
async field(ratio) { async field(ratio) {
if (!this.digitalWindow) { if (!this.digitalWindow) {
console.warn(`Cannot show field guide because window does not exist`); this.log.warn(`Cannot show field guide because window does not exist`);
return false; return false;
} }
await delay_1.delay(500); await delay_1.delay(500);
@ -107,12 +112,12 @@ class WebView {
this.digitalWindow.webContents.send('field', { field: true, ratio }); this.digitalWindow.webContents.send('field', { field: true, ratio });
} }
catch (err) { catch (err) {
console.error(err); this.log.error(err);
} }
} }
async meter() { async meter() {
if (!this.digitalWindow) { if (!this.digitalWindow) {
console.warn(`Cannot show meter screen because window does not exist`); this.log.warn(`Cannot show meter screen because window does not exist`);
return false; return false;
} }
await delay_1.delay(500); await delay_1.delay(500);
@ -120,7 +125,7 @@ class WebView {
this.digitalWindow.webContents.send('meter', { meter: true }); this.digitalWindow.webContents.send('meter', { meter: true });
} }
catch (err) { catch (err) {
console.error(err); this.log.error(err);
} }
} }
hide() { hide() {

File diff suppressed because one or more lines are too long

2
app/package-lock.json generated
View File

@ -1,6 +1,6 @@
{ {
"name": "mcopy-app", "name": "mcopy-app",
"version": "1.7.22", "version": "1.7.23",
"lockfileVersion": 2, "lockfileVersion": 2,
"requires": true, "requires": true,
"packages": { "packages": {

View File

@ -1,6 +1,6 @@
{ {
"name": "mcopy-app", "name": "mcopy-app",
"version": "1.7.22", "version": "1.7.23",
"description": "GUI for the mcopy small gauge film optical printer platform", "description": "GUI for the mcopy small gauge film optical printer platform",
"main": "main.js", "main": "main.js",
"scripts": { "scripts": {

View File

@ -1,5 +1,5 @@
{ {
"version": "1.7.22", "version": "1.7.23",
"ext_port": 1111, "ext_port": 1111,
"profiles": { "profiles": {
"mcopy": { "mcopy": {

4
package-lock.json generated
View File

@ -1,12 +1,12 @@
{ {
"name": "mcopy", "name": "mcopy",
"version": "1.7.22", "version": "1.7.23",
"lockfileVersion": 2, "lockfileVersion": 2,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "mcopy", "name": "mcopy",
"version": "1.7.22", "version": "1.7.23",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"arduino": "file:app/lib/arduino", "arduino": "file:app/lib/arduino",

View File

@ -1,6 +1,6 @@
{ {
"name": "mcopy", "name": "mcopy",
"version": "1.7.22", "version": "1.7.23",
"description": "Small gauge film optical printer platform", "description": "Small gauge film optical printer platform",
"main": "build.js", "main": "build.js",
"directories": { "directories": {

View File

@ -1,5 +1,5 @@
{ {
"version": "1.7.22", "version": "1.7.23",
"ext_port": 1111, "ext_port": 1111,
"profiles": { "profiles": {
"mcopy": { "mcopy": {

View File

@ -8,6 +8,7 @@
import { join as pathJoin, normalize as pathNormalize } from 'path'; import { join as pathJoin, normalize as pathNormalize } from 'path';
import { format as urlFormat } from 'url'; import { format as urlFormat } from 'url';
import { delay } from 'delay'; import { delay } from 'delay';
import Log = require('log');
const { BrowserWindow } = require('electron'); const { BrowserWindow } = require('electron');
@ -19,6 +20,7 @@ class WebView {
public display : any; public display : any;
private loadWait : any = {}; private loadWait : any = {};
private ipc : any; private ipc : any;
private log : any;
constructor (platform : string, display : any) { constructor (platform : string, display : any) {
const prefs : any = { const prefs : any = {
@ -39,6 +41,8 @@ class WebView {
pathname : pagePath, pathname : pagePath,
protocol : 'file:' protocol : 'file:'
}); });
this.init();
if (!display.primary) { if (!display.primary) {
prefs.x = display.x + 50; prefs.x = display.x + 50;
prefs.y = display.y + 50; prefs.y = display.y + 50;
@ -61,6 +65,9 @@ class WebView {
this.ipc.on('display_load', this.onLoad.bind(this)); this.ipc.on('display_load', this.onLoad.bind(this));
} }
async init () {
this.log = await Log({ label : 'devices' })
}
async open () { async open () {
this.digitalWindow.show(); this.digitalWindow.show();
this.showing = true; this.showing = true;
@ -74,13 +81,13 @@ class WebView {
async show (src : string) { async show (src : string) {
const normalSrc : string = pathNormalize(pathJoin(src)); const normalSrc : string = pathNormalize(pathJoin(src));
if (!this.digitalWindow) { if (!this.digitalWindow) {
console.warn(`Cannot show "${src}" because window does not exist`); this.log.warn(`Cannot show "${src}" because window does not exist`)
return false; return false;
} }
try { try {
this.digitalWindow.webContents.send('display', { src : normalSrc }); this.digitalWindow.webContents.send('display', { src : normalSrc });
} catch (err) { } catch (err) {
console.error(err); this.log.error(err);
} }
this.showing = true; this.showing = true;
@ -97,38 +104,38 @@ class WebView {
} }
async focus () { async focus () {
if (!this.digitalWindow) { if (!this.digitalWindow) {
console.warn(`Cannot show focus screen because window does not exist`); this.log.warn(`Cannot show focus screen because window does not exist`);
return false; return false;
} }
await delay(500); await delay(500);
try { try {
this.digitalWindow.webContents.send('focus', { focus : true }); this.digitalWindow.webContents.send('focus', { focus : true });
} catch (err) { } catch (err) {
console.error(err); this.log.error(err);
} }
} }
async field (ratio : number) { async field (ratio : number) {
if (!this.digitalWindow) { if (!this.digitalWindow) {
console.warn(`Cannot show field guide because window does not exist`); this.log.warn(`Cannot show field guide because window does not exist`);
return false; return false;
} }
await delay(500); await delay(500);
try { try {
this.digitalWindow.webContents.send('field', { field : true, ratio }); this.digitalWindow.webContents.send('field', { field : true, ratio });
} catch (err) { } catch (err) {
console.error(err); this.log.error(err);
} }
} }
async meter () { async meter () {
if (!this.digitalWindow) { if (!this.digitalWindow) {
console.warn(`Cannot show meter screen because window does not exist`); this.log.warn(`Cannot show meter screen because window does not exist`);
return false; return false;
} }
await delay(500); await delay(500);
try { try {
this.digitalWindow.webContents.send('meter', { meter : true }); this.digitalWindow.webContents.send('meter', { meter : true });
} catch (err) { } catch (err) {
console.error(err); this.log.error(err);
} }
} }
hide () { hide () {