From c48d34d26bb7595e3dd0203966a6fc02eb0b9e14 Mon Sep 17 00:00:00 2001 From: BenDol Date: Fri, 24 Feb 2023 19:00:00 -0500 Subject: [PATCH] Add support for windowName (equals or contains) configuration. This is useful in cases where you're running multiple of the same window with different names (e.g. coding project idea's). Also ignore config.json and added config.json.dist to the tracking as the example config json file. --- .gitignore | 3 ++- config.json => config.json.dist | 6 ++++++ index.js | 25 +++++++++++++++++++++---- package.json | 2 +- 4 files changed, 30 insertions(+), 6 deletions(-) rename config.json => config.json.dist (58%) diff --git a/.gitignore b/.gitignore index 34234d7..86c35ac 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ node_modules/* package-lock.json slobs-stream-switcher-* -*.zip \ No newline at end of file +*.zip +config.json \ No newline at end of file diff --git a/config.json b/config.json.dist similarity index 58% rename from config.json rename to config.json.dist index 1c22553..6c144e7 100644 --- a/config.json +++ b/config.json.dist @@ -4,6 +4,12 @@ "scenes": [ { "windowClassName": "Code.exe", + "windowName": { "name": "ide - project1", "contains": true }, + "targetScene": "CodeScene" + }, + { + "windowClassName": "Code.exe", + "windowName": { "name": "ide - project2", "contains": true }, "targetScene": "CodeScene" }, { diff --git a/index.js b/index.js index e7dbdef..ccbd8b9 100644 --- a/index.js +++ b/index.js @@ -12,7 +12,7 @@ const currentDirectory = process.cwd().replace(/\\/g, '/'); let nextConfigRefreshTime = Date.now(); let pendingTransactions = []; -let lastWindow = ''; +let lastSceneIndex = -1; let paused = false; let oldSize = 0; @@ -22,6 +22,7 @@ let config = { scenes: [ { windowClassName: 'Code.exe', + windowName: { name: "Project Name", contains: true }, targetScene: `CodeScene` }, { @@ -122,21 +123,37 @@ function checkCurrentWindow() { } if (config.printWindowNames) { + printInfo(`DEBUG WINDOW NAME: ${currentWindow.windowName}`); printInfo(`DEBUG WINDOW CLASS NAME: ${currentWindow.windowClass}`); } - const configIndex = config.scenes.findIndex((option) => option.windowClassName === currentWindow.windowClass); + var comparator = (option) => { + var result = option.windowClassName === currentWindow.windowClass; + if (result && option.windowName !== undefined) { + if (typeof option.windowName === "string") + result = currentWindow.windowName === option.windowName; + else { + var windowName = option.windowName.name + result = option.windowName.contains + ? currentWindow.windowName.includes(windowName) + : currentWindow.windowName === windowName + } + } + return result; + } + + const configIndex = config.scenes.findIndex(comparator); if (configIndex <= -1) { return; } const sceneInfo = config.scenes[configIndex]; - if (lastWindow === currentWindow.windowClass) { + if (lastSceneIndex !== -1 && configIndex === lastSceneIndex) { return; } - lastWindow = currentWindow.windowClass; + lastSceneIndex = configIndex; pendingTransactions.push({ type: 'sceneRequest', sceneName: sceneInfo.targetScene }); sock.send( JSON.stringify({ diff --git a/package.json b/package.json index a38e8a0..4c902e4 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "author": "stuyk", "license": "ISC", "dependencies": { - "active-windows": "^0.1.12", + "active-windows": "^0.1.14", "chalk": "^4.1.0", "sockjs-client": "^1.4.0" },