Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
Bob620 committed Oct 31, 2020
2 parents 668ec99 + 2cd02a2 commit 6409a33
Show file tree
Hide file tree
Showing 27 changed files with 2,661 additions and 968 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

bin
dist
build
node_modules

assets/react
Expand Down
Binary file added assets/svg/atom-2-mac.ico
Binary file not shown.
6 changes: 6 additions & 0 deletions electron-builder.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"npmRebuild": false,
"mac": {
"minimumSystemVersion": "10.11"
}
}
1,530 changes: 897 additions & 633 deletions package-lock.json

Large diffs are not rendered by default.

34 changes: 17 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
{
"name": "probelab-reimager-app",
"productName": "Probelab ReImager",
"version": "1.4.0-stable",
"version": "1.6.1-dev",
"description": "Visual UI for Probelab ReImager using Electron",
"main": "./src/backend/main.js",
"scripts": {
"start": "electron .",
"build": "node build.js",
"build-prod": "node build.js production",
"rebuild": "electron-rebuild -f",
"test": "echo \"Error: no test specified\" && exit 1",
"compile": "npm run build-prod && node package.js && cd ./bin/unpackaged && npm install --production && npm run rebuild",
"package": "npm run compile && electron-packager ./bin/unpackaged --out ./bin --overwrite",
"win-package": "npm run compile && electron-packager ./bin/unpackaged --out ./bin --overwrite --platform=win32 --arch=x64",
"postpack": "electron-builder --pd \"./bin/Probelab ReImager-win32-x64\""
"build": "node util/build.js",
"build-prod": "node util/build.js production",
"build-el-capitan": "node util/elcapitain/download.js",
"compile": "node util/compile.js",
"clean": "node util/clean.js",
"distclean": "node util/clean.js distclean",
"test": "echo \"Error: no test specified\" && exit 1"
},
"browserify": {
"transform": [
Expand All @@ -32,7 +31,7 @@
]
},
"build": {
"icon": "./assets/svg/atom-2.ico",
"icon": "./assets/svg/atom-2-mac.ico",
"appId": "net.probelab.reimager",
"win": {
"target": [
Expand Down Expand Up @@ -75,7 +74,6 @@
"mac": {
"target": [
{
"sign": false,
"target": "dmg",
"arch": [
"x64"
Expand All @@ -98,13 +96,15 @@
"babel-preset-react": "^6.24.1",
"babelify": "^8.0.0",
"bakadux": "^1.1.0",
"bent": "^7.3.12",
"browserify": "^16.5.1",
"browserify-css": "^0.15.0",
"electron": "^9.1.2",
"electron-builder": "^22.8.0",
"electron-packager": "^15.0.0",
"electron-rebuild": "^1.11.0",
"electron": "10.1.5",
"electron-builder": "^22.9.1",
"electron-packager": "^15.1.0",
"electron-rebuild": "^2.3.2",
"envify": "^4.1.0",
"node-gyp": "^7.1.2",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-svg": "^11.0.32",
Expand All @@ -114,7 +114,7 @@
},
"dependencies": {
"canvas": "^2.5.0",
"sharp": "^0.25.4",
"thermo-reimager": "github:bob620/thermo-reimager"
"probelab-reimager": "github:bob620/probelab-reimager",
"sharp": "^0.25.4"
}
}
49 changes: 39 additions & 10 deletions src/backend/children/reimager/child.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
const { CanvasRoot, NodeCanvas } = require('thermo-reimager');
const {CanvasRoot, NodeCanvas} = require('probelab-reimager');

const ThermoWatcher = require('../thermowatcher.js');
const Communications = require('../../communications.js');
const Functions = require('./functions.js');

class Child {
constructor(canvas, comms=process) {
constructor(canvas, comms = process) {
this.data = {
watchedDirs: new Map(),
comms: new Communications(comms),
Expand All @@ -20,8 +20,9 @@ class Child {
this.data.comms.on('watchDir', this.watchDir.bind(this));
this.data.comms.on('writeImage', this.writeImage.bind(this));

canvas.init().then(() => {
this.data.comms.send('ready');
canvas.init().then(async () => {
await this.data.comms.send('ready');
this.data.log = this.data.comms.log;
});
}

Expand All @@ -30,18 +31,26 @@ class Child {
}

async getDir({uri}) {
return (await Functions.getDir(uri, this.data.canvas)).map(thermo => thermo.serialize());
this.data.log.info('Getting directory...');
const thermos = (await Functions.getDir(uri, this.data.canvas)).map(thermo => thermo.serialize());

this.data.log.info('Returning thermos from directory');
return thermos;
}

async getImages({uri, uuids={}}) {
async getImages({uri, uuids = {}}) {
this.data.log.info('Getting images...');
return (await Functions.getImages(uri, this.data.canvas)).map(thermo => {
const uuid = uuids[thermo.data.files.entry];
thermo.data.uuid = uuid ? uuid : thermo.data.uuid;
return thermo.serialize();
});
}

async processImage({uri, uuid, operations, settings}, returnThermo=false) {
async processImage({uri, uuid, operations, settings}, returnThermo = false) {
this.data.log.info(`Processing image (${uuid}) ${uri}`);
this.data.log.info(`operations: ${operations.map(e => e.command).join(', ')}`);

settings = Functions.sanitizeSettings(settings);

for (let i = 0; i < operations.length; i++) {
Expand All @@ -51,29 +60,44 @@ class Child {
}

const tempThermos = await Functions.getImages(uri.split('/').slice(0, -1).join('/') + '/', this.data.canvas);
if (tempThermos === undefined) throw {code: 0, message: 'No Thermo found'};
if (tempThermos === undefined) {
this.data.log.info(`Unable to find Thermo`);
throw {code: 0, message: 'No Thermo found'};
}

this.data.log.info(`${tempThermos.length} Thermos found`);
for (const thermo of tempThermos) {
if (thermo.data.files.entry === uri) {
thermo.data.uuid = uuid ? uuid : thermo.data.uuid;

for (const {command, args} of operations)
await thermo[command](...args, settings);
for (const {command, args} of operations) {
this.data.log.info(`Running ${command}(${args.join(', ')})`);
try {
await thermo[command](...args, settings);
} catch(err) {
this.data.log.error(err);
console.log(err);
throw {code: 0, message: 'RIP'};
}
}

if (returnThermo)
return thermo;

this.data.log.info(`Serializing thermo for transport...`);
return {
data: thermo.serialize(),
image: await thermo.toUrl(settings)
};
}
}

this.data.log.info(`Unable to find Thermo matching`);
throw {code: 0, message: 'No Thermo found'};
}

async unwatchDir({uri}) {
this.data.log.info('Unwatching directory');
const watcher = this.data.watchedDirs.get(uri);
if (watcher) {
watcher.unwatch();
Expand All @@ -83,6 +107,7 @@ class Child {

async watchDir({uri}) {
if (!this.data.watchedDirs.has(uri)) {
this.data.log.info('Watching directory');
const watcher = new ThermoWatcher(uri);

watcher.on('close', uri => {
Expand All @@ -96,6 +121,7 @@ class Child {
}

async writeImage({uri, uuid, operations, settings}) {
this.data.log.info('Processing image...');
const thermo = await this.processImage(
{
uri,
Expand All @@ -104,7 +130,10 @@ class Child {
},
true
);

this.data.log.info('Writing image...');
await thermo.write(Functions.sanitizeSettings(settings));
this.data.log.info('Image written');
}
}

Expand Down
54 changes: 23 additions & 31 deletions src/backend/children/reimager/functions.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const fs = require('fs');
const fsPromise = fs.promises;
const {PointShoot, ExtractedMap, constants, JeolImage, PFEImage, getPFEExpectedImages} = require('thermo-reimager');
const {PointShoot, ExtractedMap, constants, JeolImage, PFEImage, getPFEExpectedImages} = require('probelab-reimager');

const appConstants = require('../../../../constants.json');

Expand Down Expand Up @@ -86,40 +86,32 @@ const Functions = {
return settings;
},
getDir: async (dirUri, canvas) => {
try {
const directory = await fsPromise.readdir(dirUri, {withFileTypes: true});
const files = (await Functions.getImages(dirUri + '/', canvas)).filter(i => i);
return files.concat((await Promise.all(directory.map(dir => dir.isDirectory() ? Functions.getImages(dirUri + dir.name + '/', canvas) : []))).flat().filter(i => i));
} catch(err) {
return [];
}
const directory = await fsPromise.readdir(dirUri, {withFileTypes: true});
const files = (await Functions.getImages(dirUri + '/', canvas)).filter(i => i);
return files.concat((await Promise.all(directory.map(dir => dir.isDirectory() ? Functions.getImages(dirUri + dir.name + '/', canvas) : []))).flat().filter(i => i));
},
getImages: async (dirUri, canvas) => {
try {
const files = fs.readdirSync(dirUri, {withFileTypes: true}).filter(file => file.isFile());
let thermos = [];
let extraLayers = [];
const files = fs.readdirSync(dirUri, {withFileTypes: true}).filter(file => file.isFile());
let thermos = [];
let extraLayers = [];

return (await Promise.all(files.map(file => {
file.uri = dirUri + file.name;
if (file.name.endsWith(constants.extractedMap.fileFormats.LAYER)) {
extraLayers.push(file);
return Promise.all(thermos.map(thermo => thermo.addLayerFile(file.uri))).then(() => undefined);
} else {
const thermo = Functions.createThermo(file, canvas);
if (thermo) {
thermos.push(thermo[0]);
return new Promise(async resolve => {
for (const layer of extraLayers)
await thermo[0].addLayerFile(layer.uri);
resolve(thermo[1]);
});
}
return (await Promise.all(files.map(file => {
file.uri = dirUri + file.name;
if (file.name.endsWith(constants.extractedMap.fileFormats.LAYER)) {
extraLayers.push(file);
return Promise.all(thermos.map(thermo => thermo.addLayerFile(file.uri))).then(() => undefined);
} else {
const thermo = Functions.createThermo(file, canvas);
if (thermo) {
thermos.push(thermo[0]);
return new Promise(async resolve => {
for (const layer of extraLayers)
await thermo[0].addLayerFile(layer.uri);
resolve(thermo[1]);
});
}
}).flat())).filter(i => i);
} catch(err) {
return [];
}
}
}).flat())).filter(i => i);
},
createThermo: (file, canvas, uuid = undefined) => {
if (file.isFile()) {
Expand Down
Loading

0 comments on commit 6409a33

Please sign in to comment.