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,
"profiles": {
"mcopy": {

View File

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

View File

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

View File

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

4
package-lock.json generated
View File

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

View File

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

View File

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

View File

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