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" },