From fc54b557e2fdca7f65a7c7cc8c428035cb14a37c Mon Sep 17 00:00:00 2001 From: 1Euro7Cent Date: Thu, 16 May 2024 22:19:38 +0200 Subject: [PATCH] added sendDynInstructionLen added that on connection loss the gui tries to reconnect --- build.js | 2 +- classes/config/Config.js | 3 ++- classes/instructions/InstructionWriter.js | 17 ++++++++++++++++- gui.py | 7 +++++-- package.json | 6 +++--- 5 files changed, 27 insertions(+), 8 deletions(-) diff --git a/build.js b/build.js index 4f8e97e..cd9b014 100644 --- a/build.js +++ b/build.js @@ -92,7 +92,7 @@ for (let file of cleanupFiles) { } // auto change log generation -//* +/* try { execSync("github_changelog_generator --help") diff --git a/classes/config/Config.js b/classes/config/Config.js index 5735a34..e269c49 100644 --- a/classes/config/Config.js +++ b/classes/config/Config.js @@ -30,7 +30,8 @@ module.exports = class Config extends BaseConfig { height: -1, x: -1, y: -1 - } + }, + sendDynInstructionLen: false, // if true it will send instruction data length to gui every 100 instructions. otherwise every new color }, communication: { diff --git a/classes/instructions/InstructionWriter.js b/classes/instructions/InstructionWriter.js index 23a59bc..cd0c3bd 100644 --- a/classes/instructions/InstructionWriter.js +++ b/classes/instructions/InstructionWriter.js @@ -476,7 +476,9 @@ module.exports = class InstructionWriter { process.stdout.write(' ') let logText = `writing color ${color} ${colorCounter}/${colorCount} ${this.settings.dualColorMode && nextColor ? 'and ' + nextColor : ''}` console.timeLog("write", logText) - this.logger("Calculating...\n" + logText) + // this.logger("Calculating...\n" + logText) + this.logger("Calculating...\n" + logText + `(${instructions.length})`) + if (this.isAborting) return [] await sleep(5) // console.log("next color", nextColor) @@ -544,6 +546,7 @@ module.exports = class InstructionWriter { for (let y = 0; y < recolored.bitmap.height; y++) { + if (this.config.gui.sendDynInstructionLen) await sleep(1) // sleep to not block the event loop if (this.isAborting) return [] for (let x = 0; x < recolored.bitmap.width; x++) { let numb = recolored.getPixelColor(x, y) @@ -608,6 +611,8 @@ module.exports = class InstructionWriter { delay: this.settings.delay, moveDelay: this.settings.moveDelay }, hex == nextColor ? "right" : "left", "DRAW_LINE")) + if (this.config.gui.sendDynInstructionLen && instructions.length % 100 == 0) this.logger("Calculating...\n" + logText + `(${instructions.length})`) + } else { let pos = relativeToAbsolute(x, y, position, this.settings.distancing, 0, 0) @@ -617,6 +622,8 @@ module.exports = class InstructionWriter { delay: this.settings.delay, moveDelay: this.settings.moveDelay }, hex == nextColor ? "right" : "left", "DRAW_PIXEL")) + if (this.config.gui.sendDynInstructionLen && instructions.length % 100 == 0) this.logger("Calculating...\n" + logText + `(${instructions.length})`) + } x = fx @@ -660,6 +667,8 @@ module.exports = class InstructionWriter { delay: this.settings.delay, moveDelay: this.settings.moveDelay }, hex == nextColor ? "right" : "left", "DRAW_LINE")) + if (this.config.gui.sendDynInstructionLen && instructions.length % 100 == 0) this.logger("Calculating...\n" + logText + `(${instructions.length})`) + let pixString = `${x}-${x + (xPixels - 1)},${y}-${y}` this.debug?.drawnPixels.push(pixString) @@ -684,6 +693,8 @@ module.exports = class InstructionWriter { delay: this.settings.delay, moveDelay: this.settings.moveDelay }, hex == nextColor ? "right" : "left", "DRAW_LINE")) + if (this.config.gui.sendDynInstructionLen && instructions.length % 100 == 0) this.logger("Calculating...\n" + logText + `(${instructions.length})`) + // addLTodrawn(instructions, drawnPixels) let pixString = `${x}-${x},${y}-${y + (yPixels - 1)}` @@ -701,6 +712,8 @@ module.exports = class InstructionWriter { delay: this.settings.delay, moveDelay: this.settings.moveDelay }, hex == nextColor ? "right" : "left", "DRAW_PIXEL")) + if (this.config.gui.sendDynInstructionLen && instructions.length % 100 == 0) this.logger("Calculating...\n" + logText + `(${instructions.length})`) + this.debug?.customPixels.push(`${x},${y}`) } @@ -718,6 +731,8 @@ module.exports = class InstructionWriter { }, hex == nextColor ? "right" : "left", "DRAW_PIXEL") instructions.push(instruction) this.debug?.customPixels.push(`${x},${y}`) + if (this.config.gui.sendDynInstructionLen && instructions.length % 100 == 0) this.logger("Calculating...\n" + logText + `(${instructions.length})`) + } } } diff --git a/gui.py b/gui.py index d4c60bf..e817dea 100644 --- a/gui.py +++ b/gui.py @@ -403,8 +403,11 @@ def negativeColor(hex): sys.exit() if not communicationThread.is_alive(): - print("websocket thread died... exiting") - sys.exit() + print("websocket thread died... restarting session...") + communicationThread = threading.Thread(target=communication, args=(config,)) + communicationThread.daemon = True + communicationThread.start() + # sys.exit() if not keyboardThread.is_alive(): print("keyboard thread died... exiting") diff --git a/package.json b/package.json index 2954a5a..0cec5e3 100644 --- a/package.json +++ b/package.json @@ -1,10 +1,10 @@ { "name": "Drawbot", - "version": "3.17.1", + "version": "3.18.0", "description": "This moves the mouse to draw stuff", "main": "index.js", "scripts": { - "dev": "nodemon", + "dev": "start cmd /C python gui.py && nodemon", "build": "node build.js" }, "repository": { @@ -39,7 +39,7 @@ }, "nodemonConfig": { "events": { - "start": "start cmd /C python gui.py" + "start_": "start cmd /C python gui.py" }, "ignore": [ "/temp/*",