-
Notifications
You must be signed in to change notification settings - Fork 221
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #281 from Kyusung4698/develop
## 0.5.22 (2020-03-08)
- Loading branch information
Showing
48 changed files
with
2,432 additions
and
2,516 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"name": "Debug Main Process", | ||
"type": "node", | ||
"request": "launch", | ||
"cwd": "${workspaceFolder}", | ||
"runtimeExecutable": "${workspaceFolder}/node_modules/.bin/electron", | ||
"windows": { | ||
"runtimeExecutable": "${workspaceFolder}/node_modules/.bin/electron.cmd" | ||
}, | ||
"args" : ["."], | ||
"outputCapture": "std" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
import activeWin from 'active-win'; | ||
import iohook from 'iohook'; | ||
import { Subject, Subscription } from 'rxjs'; | ||
import { throttleTime } from 'rxjs/operators'; | ||
|
||
interface KeyboardEvent { | ||
ctrlKey: boolean; | ||
altKey: boolean; | ||
shiftKey: boolean; | ||
keycode: number; | ||
} | ||
|
||
interface WheelEvent { | ||
rotation: number; | ||
ctrlKey: boolean; | ||
} | ||
|
||
let active = false; | ||
let activeChangeFn: (active: boolean) => void; | ||
let wheelChangeFn: (event: WheelEvent) => void; | ||
|
||
const activeCheck$ = new Subject<void>(); | ||
let activeCheckSubscription: Subscription; | ||
|
||
function onKeydown(event: KeyboardEvent): void { | ||
activeCheck$.next(); | ||
} | ||
|
||
function onKeyup(event: KeyboardEvent): void { | ||
activeCheck$.next(); | ||
} | ||
|
||
function onMousewheel(event: WheelEvent): void { | ||
activeCheck$.next(); | ||
|
||
if (active) { | ||
if (wheelChangeFn) { | ||
wheelChangeFn(event); | ||
} | ||
} | ||
} | ||
|
||
function onMouseclick(event: WheelEvent): void { | ||
activeCheck$.next(); | ||
} | ||
|
||
function checkActive(): void { | ||
let old = active; | ||
|
||
const win = activeWin.sync(); | ||
const path = win?.owner?.path | ||
if (path) { | ||
active = path.endsWith('PathOfExile_x64_KG.exe') || path.endsWith('PathOfExile_KG.exe') | ||
|| path.endsWith('PathOfExile_x64Steam.exe') || path.endsWith('PathOfExileSteam.exe') | ||
|| path.endsWith('PathOfExile_x64.exe') || path.endsWith('PathOfExile.exe'); | ||
} | ||
|
||
if (old !== active) { | ||
if (activeChangeFn) { | ||
activeChangeFn(active); | ||
} | ||
} | ||
} | ||
|
||
export function getActive(): boolean { | ||
return active; | ||
} | ||
|
||
export function on(event: 'change', callback: (active: boolean) => void): void; | ||
export function on(event: 'wheel', callback: (event: WheelEvent) => void): void; | ||
|
||
export function on(event: string, callback: any) { | ||
switch (event) { | ||
case 'change': | ||
activeChangeFn = callback; | ||
activeChangeFn(active); | ||
break; | ||
case 'wheel': | ||
wheelChangeFn = callback; | ||
break; | ||
} | ||
} | ||
|
||
export function off(event: 'change' | 'wheel') { | ||
switch (event) { | ||
case 'change': | ||
activeChangeFn = undefined; | ||
break; | ||
case 'wheel': | ||
wheelChangeFn = undefined; | ||
break; | ||
} | ||
} | ||
|
||
export function register(): void { | ||
iohook.start(); | ||
|
||
activeCheckSubscription = activeCheck$.pipe( | ||
throttleTime(500, undefined, { | ||
trailing: true, | ||
leading: false | ||
}) | ||
).subscribe(() => { | ||
checkActive(); | ||
}); | ||
|
||
iohook.on('keydown', onKeydown); | ||
iohook.on('keyup', onKeyup); | ||
iohook.on('mousewheel', onMousewheel); | ||
iohook.on('mouseup', onMouseclick); | ||
} | ||
|
||
export function unregister(): void { | ||
iohook.off('keydown', onKeydown); | ||
iohook.off('keyup', onKeyup); | ||
iohook.off('mousewheel', onMousewheel); | ||
iohook.off('mouseup', onMouseclick); | ||
|
||
if (activeCheckSubscription) { | ||
activeCheckSubscription.unsubscribe(); | ||
} | ||
|
||
iohook.stop(); | ||
} |
Oops, something went wrong.