@trayjs/trayjs 0.0.1 → 0.0.3
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 +25 -4
- package/package.json +7 -7
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];
|
|
@@ -42,11 +51,17 @@ function getBinaryPath() {
|
|
|
42
51
|
* @property {boolean} [enabled]
|
|
43
52
|
* @property {boolean} [checked]
|
|
44
53
|
* @property {boolean} [separator]
|
|
54
|
+
* @property {MenuItem[]} [items] - Nested submenu items
|
|
55
|
+
*/
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* @typedef {{ png: Buffer, ico: Buffer }} Icon
|
|
59
|
+
* PNG for macOS/Linux, ICO for Windows. Both are required.
|
|
45
60
|
*/
|
|
46
61
|
|
|
47
62
|
/**
|
|
48
63
|
* @typedef {object} TrayOptions
|
|
49
|
-
* @property {
|
|
64
|
+
* @property {Icon} [icon] - Tray icon ({ png, ico })
|
|
50
65
|
* @property {string} [tooltip]
|
|
51
66
|
* @property {() => MenuItem[] | Promise<MenuItem[]>} [onMenuRequested]
|
|
52
67
|
* @property {(id: string) => void} [onClicked]
|
|
@@ -108,14 +123,20 @@ export class Tray extends EventEmitter {
|
|
|
108
123
|
this.#send({ method: 'setMenu', params: { items } });
|
|
109
124
|
}
|
|
110
125
|
|
|
111
|
-
/** @param {
|
|
112
|
-
setIcon(
|
|
126
|
+
/** @param {Icon} icon */
|
|
127
|
+
setIcon(icon) {
|
|
128
|
+
const buf = resolveIcon(icon);
|
|
113
129
|
this.#send({
|
|
114
130
|
method: 'setIcon',
|
|
115
|
-
params: { base64:
|
|
131
|
+
params: { base64: buf.toString('base64') },
|
|
116
132
|
});
|
|
117
133
|
}
|
|
118
134
|
|
|
135
|
+
/** @param {MenuItem[]} items */
|
|
136
|
+
setMenu(items) {
|
|
137
|
+
this.#send({ method: 'setMenu', params: { items } });
|
|
138
|
+
}
|
|
139
|
+
|
|
119
140
|
/** @param {string} text */
|
|
120
141
|
setTooltip(text) {
|
|
121
142
|
this.#send({ method: 'setTooltip', params: { text } });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trayjs/trayjs",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": "./index.mjs",
|
|
@@ -8,11 +8,11 @@
|
|
|
8
8
|
"index.mjs"
|
|
9
9
|
],
|
|
10
10
|
"optionalDependencies": {
|
|
11
|
-
"@trayjs/linux-x64": "0.0.
|
|
12
|
-
"@trayjs/linux-arm64": "0.0.
|
|
13
|
-
"@trayjs/darwin-x64": "0.0.
|
|
14
|
-
"@trayjs/darwin-arm64": "0.0.
|
|
15
|
-
"@trayjs/win32-x64": "0.0.
|
|
16
|
-
"@trayjs/win32-arm64": "0.0.
|
|
11
|
+
"@trayjs/linux-x64": "0.0.3",
|
|
12
|
+
"@trayjs/linux-arm64": "0.0.3",
|
|
13
|
+
"@trayjs/darwin-x64": "0.0.3",
|
|
14
|
+
"@trayjs/darwin-arm64": "0.0.3",
|
|
15
|
+
"@trayjs/win32-x64": "0.0.3",
|
|
16
|
+
"@trayjs/win32-arm64": "0.0.3"
|
|
17
17
|
}
|
|
18
18
|
}
|