Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
node_modules/*
package-lock.json
slobs-stream-switcher-*
*.zip
*.zip
config.json
6 changes: 6 additions & 0 deletions config.json → config.json.dist
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
{
Expand Down
25 changes: 21 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -22,6 +22,7 @@ let config = {
scenes: [
{
windowClassName: 'Code.exe',
windowName: { name: "Project Name", contains: true },
targetScene: `CodeScene`
},
{
Expand Down Expand Up @@ -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({
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down