Skip to content

Commit

Permalink
Using asfw for Window Pin By Name, fixing issue #7
Browse files Browse the repository at this point in the history
  • Loading branch information
xurei committed Sep 13, 2020
1 parent 037f3bd commit 3d554d1
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 20 deletions.
17 changes: 12 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"@babel/runtime": "^7.9.6",
"@babel/runtime-corejs3": "^7.9.6",
"active-win": "^6.1.0",
"asfw": "git+https://github.com/xurei/node-asfw.git#48dcdf931aef2459584bc880f84dcf5eef10dd50",
"asfw": "git+https://github.com/xurei/node-asfw.git#337a3b513e82c5cb12146a4343c2dbb6c2582f07",
"core-js": "^3.6.5",
"debug": "^4.1.1",
"electron-json-storage": "^4.1.8",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ module.exports = {
command()
.catch(e => {
NotificationService.notify({
'title': 'Window Pinner',
'title': 'Window Pin',
'message': `Cannot bring window to foreground: ${e}`,
});
});
Expand Down
39 changes: 26 additions & 13 deletions src/hyperkeys-extensions/window-pin-by-name/action-show-window.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const exec = require('child_process').exec;
const path = require('path');
const debug = require('debug')(`hyperkeys-${path.basename(__dirname)}`);
const NotificationService = require('hyperkeys-api').NotificationService;
const platform = require('hyperkeys-api').platform;

module.exports = {
Expand All @@ -9,23 +10,35 @@ module.exports = {
return {
execute: () => {
if (action.config.name && action.config.name !== '') {
let command = '';
let command;
if (platform.isLinux) {
command = `${__dirname}/../../natives/linux/wmctrl -a "${action.config.name}"`;
command = () => new Promise((resolve, reject) => {
exec(`${__dirname}/../../natives/linux/wmctrl -a "${action.config.name}"`, function callback(error, stdout, stderr) {
if (!error) {
resolve();
}
else {
reject(error);
}
});
});
}
else if (platform.isWin) {
command = `"${__dirname}\\..\\..\\natives\\win32\\nircmd\\nircmdc.exe" win activate ititle "${action.config.name}"`;
const asfw = require('asfw').SetForegroundWindowByName;
command = () => new Promise((resolve, reject) => {
asfw(action.config.name);
resolve();
});

//command = `"${__dirname}\\..\\..\\natives\\win32\\nircmd\\nircmdc.exe" win activate ititle "${action.config.name}"`;
}

debug(command);
debug('Switching to', action.config.name);
exec(command, function callback(error, stdout, stderr){
if (error === null) {
/* nothing */
}
else {
//TODO error management
}

command()
.catch(e => {
NotificationService.notify({
'title': 'Window Pin By Name',
'message': `Cannot bring window to foreground: ${e}`,
});
});
}
else {
Expand Down

0 comments on commit 3d554d1

Please sign in to comment.