@trayjs/trayjs 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.mjs +19 -4
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -19,6 +19,15 @@ const PLATFORMS = {
|
|
|
19
19
|
|
|
20
20
|
const BIN_NAME = process.platform === 'win32' ? 'tray.exe' : 'tray';
|
|
21
21
|
|
|
22
|
+
/**
|
|
23
|
+
* Picks the right icon buffer for the current platform.
|
|
24
|
+
* @param {{ png: Buffer, ico: Buffer }} icon
|
|
25
|
+
* @returns {Buffer}
|
|
26
|
+
*/
|
|
27
|
+
function resolveIcon(icon) {
|
|
28
|
+
return process.platform === 'win32' ? icon.ico : icon.png;
|
|
29
|
+
}
|
|
30
|
+
|
|
22
31
|
function getBinaryPath() {
|
|
23
32
|
const key = `${process.platform}-${process.arch}`;
|
|
24
33
|
const pkg = PLATFORMS[key];
|
|
@@ -44,9 +53,14 @@ function getBinaryPath() {
|
|
|
44
53
|
* @property {boolean} [separator]
|
|
45
54
|
*/
|
|
46
55
|
|
|
56
|
+
/**
|
|
57
|
+
* @typedef {{ png: Buffer, ico: Buffer }} Icon
|
|
58
|
+
* PNG for macOS/Linux, ICO for Windows. Both are required.
|
|
59
|
+
*/
|
|
60
|
+
|
|
47
61
|
/**
|
|
48
62
|
* @typedef {object} TrayOptions
|
|
49
|
-
* @property {
|
|
63
|
+
* @property {Icon} [icon] - Tray icon ({ png, ico })
|
|
50
64
|
* @property {string} [tooltip]
|
|
51
65
|
* @property {() => MenuItem[] | Promise<MenuItem[]>} [onMenuRequested]
|
|
52
66
|
* @property {(id: string) => void} [onClicked]
|
|
@@ -108,11 +122,12 @@ export class Tray extends EventEmitter {
|
|
|
108
122
|
this.#send({ method: 'setMenu', params: { items } });
|
|
109
123
|
}
|
|
110
124
|
|
|
111
|
-
/** @param {
|
|
112
|
-
setIcon(
|
|
125
|
+
/** @param {Icon} icon */
|
|
126
|
+
setIcon(icon) {
|
|
127
|
+
const buf = resolveIcon(icon);
|
|
113
128
|
this.#send({
|
|
114
129
|
method: 'setIcon',
|
|
115
|
-
params: { base64:
|
|
130
|
+
params: { base64: buf.toString('base64') },
|
|
116
131
|
});
|
|
117
132
|
}
|
|
118
133
|
|