Comparing version 1.0.5 to 1.0.6
@@ -12,2 +12,4 @@ const { spawn, execFile, exec } = require("child_process"); | ||
const randSuffix = ()=>("_"+Math.ceil(Math.random()*999999999).toString()+Math.ceil(Math.random()*999999999).toString()).substr(0,20); | ||
function awaitDelay(delay) { | ||
@@ -30,2 +32,3 @@ return new Promise((resolve)=>{ | ||
{ | ||
startTimeout: 700, | ||
x: 0, | ||
@@ -52,2 +55,8 @@ y: 0, | ||
for(let k in settings.wins) { | ||
const w = settings.wins[k]; | ||
w.name = k; | ||
w.title = w.name+randSuffix() | ||
} | ||
try { | ||
@@ -64,21 +73,21 @@ let personal_settings = JSON5.parse(fs.readFileSync("my_wins_personal.json")); | ||
for (let name in settings.wins) { | ||
if (!wins.filter((w) => w.title === name).length) exec(`start cmd.exe @cmd /k "title ${name}"`); | ||
else delete settings.wins[name]; | ||
for(let k in settings.wins) { | ||
const w = settings.wins[k]; | ||
const {name, title} = w; | ||
exec(`start cmd.exe @cmd /k "title ${title}"`); | ||
} | ||
await awaitDelay(1000); | ||
await awaitDelay(settings.startTimeout || 700); | ||
wins = keysender.getAllWindows(); | ||
let y = settings.y; | ||
for (let name in settings.wins) { | ||
const win = settings.wins[name]; | ||
let win_info_candidates = wins.filter((w) => w.title === name); | ||
if(!win_info_candidates.length) | ||
win_info_candidates = wins.filter((w) => w.title.endsWith(name)); // In case of "Administrator: " prefix in windows. Prefix is localized so I can't just use constant here! | ||
for(let k in settings.wins) { | ||
const w = settings.wins[k]; | ||
const {name, title} = w; | ||
let win_info_candidates = wins.filter(c => c.title.includes(title)); | ||
const win_info = win_info_candidates[0]; | ||
if (!win_info) console.warn(`CODE00000000 Couldn't find window ${name}`); | ||
if (!win_info) console.warn(`CODE00000000 Couldn't find window ${title}`); | ||
else if (win_info_candidates.length > 1) | ||
console.warn(`CODE00000000 There are ${win_info_candidates.length} windows with name '${name}'. Only one window expected!`); | ||
console.warn(`CODE00000000 There are ${win_info_candidates.length} windows with title '${title}'. Only one window expected!`); | ||
else { | ||
@@ -89,4 +98,5 @@ const win = new keysender.Hardware(win_info.handle); | ||
win.workwindow.setForeground(); | ||
if(!win.no_run) { | ||
win.keyboard.printText(win.cmd); | ||
if(!w.no_run) { | ||
win.keyboard.printText(w.cmd); | ||
win.keyboard.sendKey(13); | ||
@@ -98,6 +108,6 @@ } | ||
await awaitDelay(1000); | ||
await awaitDelay(100); | ||
console.log(`my_wins finished successfully!`); | ||
process.exit(0); | ||
} | ||
}; | ||
{ | ||
"name": "my_wins", | ||
"version": "1.0.5", | ||
"version": "1.0.6", | ||
"description": "Automates starting and laying out your console windows for tsc, babel, tests, verdaccio, etc...", | ||
@@ -5,0 +5,0 @@ "keywords": "automation cmd keysender windows autostart autorun", |
11799
104