Skip to content

Commit 068f75b

Browse files
committed
feat: add getIcon method
Closes #22
1 parent 61a360f commit 068f75b

File tree

5 files changed

+30
-2
lines changed

5 files changed

+30
-2
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,3 +170,9 @@ Returns [`Window`](#class-window)
170170

171171
- `win` [Window](#class-window) | number | null
172172
- pass null to unset window owner.
173+
174+
#### win.getIcon(size: number) `Windows` `macOS`
175+
176+
- `size` number - can be only `16`, `32`, `64`, `256`. By default it's `64`.
177+
178+
Returns a png Buffer

example.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ console.log("[info]: Visible Windows List");
2222
windowManager.getWindows().forEach(window => {
2323
if (window.isVisible()) {
2424
console.log(window.getInfo());
25+
console.log(window.getIcon());
2526
window.bringToTop();
2627
}
2728
});

package-lock.json

Lines changed: 16 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@
3535
"typescript": "3.7.3"
3636
},
3737
"dependencies": {
38+
"extract-file-icon": "^0.3.2",
3839
"node-addon-api": "2.0.0",
3940
"node-gyp": "6.0.1"
4041
}
41-
}
42+
}

src/classes/window.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { platform } from "os";
22
import { windowManager } from "..";
3+
import extractFileIcon from 'extract-file-icon';
34

45
let addon: any;
56

@@ -166,6 +167,10 @@ export class Window {
166167
return this.getInfo().opacity;
167168
}
168169

170+
getIcon(size: 16 | 32 | 64 | 256 = 64) {
171+
return extractFileIcon(this.path, size);
172+
}
173+
169174
setOwner(window: Window | null | number) {
170175
if (!addon || platform() !== "win32") return;
171176

0 commit comments

Comments
 (0)