From ac6d79d43ba51146690b596aabe1cbc0f47f5ddf Mon Sep 17 00:00:00 2001 From: Eistee Date: Fri, 10 Apr 2026 22:14:28 +0200 Subject: [PATCH] fix: improve script restart behavior Prevents duplicate 'Stopping script' logs by early-returning when script is not running. Restricts restart handling to the owning instance only. Co-Authored-By: Claude Opus 4.6 (1M context) --- README.md | 2 ++ build/main.js | 9 ++++++--- src/main.ts | 12 +++++++++--- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 5ff0ef264..627f7cb2a 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,8 @@ Executes Javascript, Typescript Scripts. ### **WORK IN PROGRESS** --> ### WORK IN PROGRESS +* (Eistee82) Fix: prevent duplicate 'Stopping script' log when script is not running +* (Eistee82) Fix: only restart scripts on the instance that owns them * (Eistee82) Added OID display mode toggle for Blockly editor: 4 display modes (Name, Name path, State ID, Full ID) with toolbar dropdown, context menu, optional object icons, and translations in 11 languages * Per-provider test buttons in adapter config (OpenAI, Anthropic, Gemini, DeepSeek, Custom API) * Optional API key field for custom base URL providers (e.g. Ollama without auth) diff --git a/build/main.js b/build/main.js index 3c30c3764..6baef72cc 100644 --- a/build/main.js +++ b/build/main.js @@ -578,9 +578,9 @@ class JavaScript extends adapter_core_1.Adapter { await this.loadScriptById(id); } } - else { - // if (obj.common.source !== formerObj.common.source) { - // Source changed => restart the script + else if (obj.common.engine === `system.adapter.${this.namespace}` || + formerObj.common.engine === `system.adapter.${this.namespace}`) { + // Source changed => restart the script (only on the relevant instance) this.stopCounters[id] = this.stopCounters[id] ? this.stopCounters[id] + 1 : 1; void this.stopScript(id).then(() => { // only start again after stop when "last" object change to prevent problems on @@ -2175,6 +2175,9 @@ class JavaScript extends adapter_core_1.Adapter { } } async stopScript(name) { + if (!this.scripts[name]) { + return false; + } this.log.info(`${name}: Stopping script`); await this.setState(`scriptEnabled.${name.substring(SCRIPT_CODE_MARKER.length)}`, false, true); if (this.messageBusHandlers[name]) { diff --git a/src/main.ts b/src/main.ts index ebc82e8f6..78b850b24 100644 --- a/src/main.ts +++ b/src/main.ts @@ -675,9 +675,11 @@ class JavaScript extends Adapter { // Start script await this.loadScriptById(id); } - } else { - // if (obj.common.source !== formerObj.common.source) { - // Source changed => restart the script + } else if ( + obj.common.engine === `system.adapter.${this.namespace}` || + formerObj.common.engine === `system.adapter.${this.namespace}` + ) { + // Source changed => restart the script (only on the relevant instance) this.stopCounters[id] = this.stopCounters[id] ? this.stopCounters[id] + 1 : 1; void this.stopScript(id).then(() => { // only start again after stop when "last" object change to prevent problems on @@ -2597,6 +2599,10 @@ class JavaScript extends Adapter { } async stopScript(name: string): Promise { + if (!this.scripts[name]) { + return false; + } + this.log.info(`${name}: Stopping script`); await this.setState(`scriptEnabled.${name.substring(SCRIPT_CODE_MARKER.length)}`, false, true);