diff --git a/public_html/js/scann3r.js b/public_html/js/scann3r.js
index 0a1682c..b94b9f9 100644
--- a/public_html/js/scann3r.js
+++ b/public_html/js/scann3r.js
@@ -1,4 +1,4 @@
-console.log(location.hash);
+
var Scann3r = {
sio: null,
@@ -12,6 +12,7 @@ var Scann3r = {
this.gallery.init();
this.gallery.loadPage(0);
this.toasts = [];
+ this.sio.emit('ready');
},
showWebsocketError() {
@@ -67,10 +68,6 @@ var Scann3r = {
hideAfter: false,
loader: false,
sticky: true,
- afterShown: () => {
- console.log('yup', $(this));
-
- }
}
if (typeof this.toasts[data.id] != 'undefined') {
@@ -93,6 +90,10 @@ var Scann3r = {
});
this.sio.on('setSliderValue', (name, value) => {
+ if (! $('.slider[data-slider=' + name + ']').hasClass('ui-widget')) {
+ return; // not initialized yet
+ }
+
let key = (typeof value == 'object') ? 'values' : 'value';
$('.slider[data-slider=' + name + ']').slider(key, value);
});
@@ -352,11 +353,13 @@ var Scann3r = {
}
});
- console.log(data);
-
- t.find('.infolist').append(`
${data.rotorCount}x${data.turntableCount} Images`);
- t.find('.infolist').append(`${humanReadableFilesize(data.zipSize)}`);
- t.find('.infolist').append(`${data.range}`);
+ if (data.complete) {
+ t.find('.infolist').append(`${data.rotorCount}x${data.turntableCount} Images`);
+ t.find('.infolist').append(`${humanReadableFilesize(data.zipSize)}`);
+ t.find('.infolist').append(`${data.range}`);
+ } else {
+ t.find('.infolist').append('Aborted');
+ }
t.find('.t-cloud-up').click(() => {
diff --git a/src/index.js b/src/index.js
index 8664d55..d27f521 100644
--- a/src/index.js
+++ b/src/index.js
@@ -36,9 +36,10 @@ if (!fs.existsSync(configfile)) {
rotorStep: new Gpio(config.data.rotor.step, 'out'),
rotorDir: new Gpio(config.data.rotor.dir, 'out'),
rotorEnable: new Gpio(config.data.rotor.enable, 'out'),
- }
+ };
+
- registry.set('scanning', false);
+ registry.set('currentScan', null);
registry.set('config', config);
registry.set('redis', Redis.createClient(config.data.redis));
await config.loadDynamicValues();
diff --git a/src/lib/Config.js b/src/lib/Config.js
index 33f62d2..1520386 100644
--- a/src/lib/Config.js
+++ b/src/lib/Config.js
@@ -1,6 +1,5 @@
const _ = require('lodash');
const fs = require('fs');
-const log = require('../lib/Log.js').createLogger({name: 'Config'});
class Config {
@@ -19,7 +18,6 @@ class Config {
}
}
-
let file = JSON.parse(fs.readFileSync('./package.json').toString());
this.data.version = file.version;
}
diff --git a/src/lib/Log.js b/src/lib/Log.js
index 7c20b54..73a588d 100644
--- a/src/lib/Log.js
+++ b/src/lib/Log.js
@@ -14,4 +14,4 @@ module.exports = {
}
}
}
-}
\ No newline at end of file
+};
\ No newline at end of file
diff --git a/src/lib/Scan.js b/src/lib/Scan.js
index 403a77f..6bf0e0b 100644
--- a/src/lib/Scan.js
+++ b/src/lib/Scan.js
@@ -42,6 +42,8 @@ class Scan {
this.turntableCount = imagesPerRevision - 1;
this.cropValues = config.get('crop.values');
+
+ this.bAbort = false;
}
@@ -68,6 +70,7 @@ class Scan {
await this.deleteImages('cropped');
await this.deleteImages('original');
this.progress({photo: '', text: `Finished scanning project #${this.project.id}.`});
+ this.project.set('complete', 1);
} else {
this.progress({photo: '', text: `Scan failed #${this.project.id}.`});
}
@@ -76,14 +79,18 @@ class Scan {
}
checkAbort() {
- if (this.registry.get('abort')) {
- this.registry.set('abort', false);
+ if (this.bAbort) {
this.progress({photo: '', text: 'Scan aborted.'});
return true;
}
return false;
}
+ abort() {
+ this.progress({text: 'Aborting scan...'});
+ this.bAbort = true;
+ }
+
async next() {
if (this.checkAbort()) {
return false;
diff --git a/src/modules/Camera.js b/src/modules/Camera.js
index 96c49f4..dd379a0 100644
--- a/src/modules/Camera.js
+++ b/src/modules/Camera.js
@@ -93,7 +93,7 @@ class Camera {
}
async startPreview() {
- if (this.registry.get('scanning')) {
+ if (this.registry.get('currentScan') != null) {
return;
}
if (!this.refresh && !this.snapping) {
diff --git a/src/modules/WebSocket.js b/src/modules/WebSocket.js
index 4107d1a..6d482a9 100644
--- a/src/modules/WebSocket.js
+++ b/src/modules/WebSocket.js
@@ -100,21 +100,25 @@ class WebSocket {
this.io.on('connection', async (socket) => {
log.info(`Client connected from ${socket.handshake.address}`);
- if (this.registry.get('scanning')) {
- socket.emit('disableControls');
- }
- this.registry.get('camera').startPreview();
+ socket.on('ready', () => {
- for (let slider in this.sliderAction) {
- let options = this.config.get(slider);
- socket.emit('initSlider', slider, options);
- }
- console.log(this.config.get('version'));
- socket.emit('info', 'info-version', this.config.get('version'));
- socket.emit('imgArea', this.config.get('crop.values'));
- socket.emit('invert', this.config.get('rotor.invert'));
+ this.registry.get('camera').startPreview();
+
+ for (let slider in this.sliderAction) {
+ let options = this.config.get(slider);
+ socket.emit('initSlider', slider, options);
+ }
+
+ if (this.registry.get('currentScan') != null) {
+ socket.emit('disableControls');
+ }
+
+ socket.emit('info', 'info-version', this.config.get('version'));
+ socket.emit('imgArea', this.config.get('crop.values'));
+ socket.emit('invert', this.config.get('rotor.invert'));
+ });
socket.on('disconnect', () => {
log.info(`Client disconnected from ${socket.handshake.address}`);
@@ -150,23 +154,28 @@ class WebSocket {
});
socket.on('start', async () => {
- this.io.emit('disableControls');
- this.registry.set('abort', false);
- this.registry.set('scanning', true);
- let scan = new Scan(this.registry, this.io);
- scan.onProgress = (data) => {
- this.io.emit('progress', data);
- };
- let project = await scan.start();
- let projectData = await project.getAll();
- this.io.emit('newProject', projectData);
- this.io.emit('enableControls');
- this.registry.set('scanning', false);
+ if (this.registry.get('currentScan') == null) {
+ this.io.emit('disableControls');
+ let scan = new Scan(this.registry, this.io);
+ this.registry.set('currentScan', scan);
+ scan.onProgress = (data) => {
+ this.io.emit('progress', data);
+ };
+ let project = await scan.start();
+ let projectData = await project.getAll();
+ this.io.emit('newProject', projectData);
+ this.io.emit('enableControls');
+ this.registry.set('currentScan', null);
+ } else {
+
+ }
});
socket.on('abort', async () => {
- console.log('ABORT');
- this.registry.set('abort', true);
+ let scan = this.registry.get('currentScan');
+ if (scan !== null) {
+ scan.abort();
+ }
});
socket.on('delete', async (id, cb) => {