nexfep 0.5.5 → 0.6.1
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/README-CN.md +144 -78
- package/README.md +143 -77
- package/frontend/index.d.ts +19 -19
- package/package.json +14 -8
- package/src/Application.d.ts +7 -4
- package/src/Application.js +4 -3
- package/src/Icon.d.ts +19 -0
- package/src/Icon.js +36 -0
- package/src/Logger.d.ts +1 -0
- package/src/Logger.js +5 -14
- package/src/SingleInstance.d.ts +2 -2
- package/src/SingleInstance.js +2 -2
- package/src/Tray.d.ts +4 -3
- package/src/Tray.js +3 -3
- package/src/WindowManager.d.ts +18 -2
- package/src/WindowManager.js +68 -28
package/README.md
CHANGED
|
@@ -41,7 +41,10 @@ import { Application } from "nexfep";
|
|
|
41
41
|
|
|
42
42
|
const app = new Application();
|
|
43
43
|
|
|
44
|
-
const window = await app.windows.createWindow(
|
|
44
|
+
const window = await app.windows.createWindow({
|
|
45
|
+
visible: true,
|
|
46
|
+
decoration: false,
|
|
47
|
+
});
|
|
45
48
|
|
|
46
49
|
await window.loadHTML("<h1 nexfep-area-drag>Hello Nexfep!</h1>");
|
|
47
50
|
```
|
|
@@ -81,11 +84,37 @@ const app = new Application({ LogFilePath: "./app.log" });
|
|
|
81
84
|
- `createLocker(appName)` — Create an application instance lock to prevent multiple instances
|
|
82
85
|
- `exit()` — Exit the application
|
|
83
86
|
|
|
87
|
+
### Icon
|
|
88
|
+
|
|
89
|
+
`Icon` represents an image resource that can be used as a window icon, tray icon, etc.
|
|
90
|
+
|
|
91
|
+
```typescript
|
|
92
|
+
import { Icon } from "nexfep";
|
|
93
|
+
|
|
94
|
+
// Create from file path
|
|
95
|
+
const icon = Icon.from("./icon.png");
|
|
96
|
+
|
|
97
|
+
// Create from Buffer or Uint8Array
|
|
98
|
+
const icon = Icon.from(buffer);
|
|
99
|
+
const icon = Icon.from(uint8Array);
|
|
100
|
+
|
|
101
|
+
// Create from an object containing data/width/height
|
|
102
|
+
const icon = Icon.from({ data: buffer, width: 64, height: 64 });
|
|
103
|
+
const icon = Icon.from({ data: uint8Array, width: 64, height: 64 });
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
**Static Methods**
|
|
107
|
+
|
|
108
|
+
| Method | Parameters | Return Value | Description |
|
|
109
|
+
| ------------------ | ----------------------------------------------------------------------------------------- | ------------ | ------------------------ |
|
|
110
|
+
| `Icon.from(input)` | `string` \| `Buffer` \| `Uint8Array` \| `{ data: Uint8Array \| Buffer, width?, height? }` | `Icon` | Creates an icon instance |
|
|
111
|
+
|
|
84
112
|
### Logger
|
|
85
113
|
|
|
86
114
|
The logger supports both file output and colored console output. It can be accessed via `app.logger`.
|
|
87
115
|
|
|
88
116
|
```typescript
|
|
117
|
+
app.logger.clear();
|
|
89
118
|
app.logger.log("Hello World");
|
|
90
119
|
app.logger.error("An error occurred");
|
|
91
120
|
app.logger.warn("Warning message");
|
|
@@ -95,13 +124,14 @@ app.logger.debug("Debug message");
|
|
|
95
124
|
|
|
96
125
|
**Methods**
|
|
97
126
|
|
|
98
|
-
| Method | Description
|
|
99
|
-
| ---------------- |
|
|
100
|
-
| `
|
|
101
|
-
| `
|
|
102
|
-
| `
|
|
103
|
-
| `
|
|
104
|
-
| `
|
|
127
|
+
| Method | Description |
|
|
128
|
+
| ---------------- | ------------------------------------------------------------------------------ |
|
|
129
|
+
| `clear()` | Clear the log file (only takes effect when the `LogFilePath` parameter is set) |
|
|
130
|
+
| `log(message)` | Log a message |
|
|
131
|
+
| `error(message)` | Log an error message (red) |
|
|
132
|
+
| `warn(message)` | Log a warning message (yellow) |
|
|
133
|
+
| `info(message)` | Log an info message (blue) |
|
|
134
|
+
| `debug(message)` | Log a debug message (gray) |
|
|
105
135
|
|
|
106
136
|
Each method accepts either a string or an array of strings.
|
|
107
137
|
|
|
@@ -118,15 +148,22 @@ const locker = app.createLocker("my-app");
|
|
|
118
148
|
try {
|
|
119
149
|
// Try to acquire the lock
|
|
120
150
|
await locker.lock();
|
|
151
|
+
// You can also pass data to the other instance when acquiring the lock
|
|
152
|
+
// await locker.lock(process.argv[2]);
|
|
121
153
|
} catch {
|
|
122
154
|
// Instance already exists, exit the application
|
|
123
155
|
app.exit();
|
|
124
156
|
}
|
|
125
157
|
// Focus the current instance when other instances acquire the lock
|
|
126
|
-
locker.whenLost(() => {
|
|
158
|
+
locker.whenLost((data) => {
|
|
127
159
|
if (!win.isFocused()) {
|
|
128
160
|
win.focus();
|
|
129
161
|
}
|
|
162
|
+
// If the other instance passed data, you can use it to perform specific actions
|
|
163
|
+
// If no data was passed, data will be null
|
|
164
|
+
if (data) {
|
|
165
|
+
console.log("Other instance passed data:", data);
|
|
166
|
+
}
|
|
130
167
|
});
|
|
131
168
|
// Release the lock
|
|
132
169
|
locker.unlock();
|
|
@@ -134,7 +171,7 @@ locker.unlock();
|
|
|
134
171
|
|
|
135
172
|
**Methods**
|
|
136
173
|
|
|
137
|
-
- `lock()` — Try to acquire the lock
|
|
174
|
+
- `lock(data?)` — Try to acquire the lock
|
|
138
175
|
- `whenLost(callback)` — Register a callback to be called when other instances acquire the lock
|
|
139
176
|
- `unlock()` — Release the lock
|
|
140
177
|
|
|
@@ -143,16 +180,14 @@ locker.unlock();
|
|
|
143
180
|
Create and manage system tray icons with context menus via `app.createTray()`.
|
|
144
181
|
|
|
145
182
|
```typescript
|
|
146
|
-
import {
|
|
183
|
+
import { Icon } from "nexfep";
|
|
184
|
+
|
|
185
|
+
const icon = Icon.from("./icon.png");
|
|
147
186
|
|
|
148
187
|
const tray = app.createTray({
|
|
149
188
|
id: "my-tray",
|
|
150
189
|
tooltip: "My App",
|
|
151
|
-
icon:
|
|
152
|
-
data: readFileSync("./icon.png"),
|
|
153
|
-
width: 32,
|
|
154
|
-
height: 32,
|
|
155
|
-
},
|
|
190
|
+
icon: icon, // Icon instance
|
|
156
191
|
menuItems: [
|
|
157
192
|
{ id: "show", label: "Show Window" },
|
|
158
193
|
{ id: "quit", label: "Quit" },
|
|
@@ -160,29 +195,19 @@ const tray = app.createTray({
|
|
|
160
195
|
});
|
|
161
196
|
```
|
|
162
197
|
|
|
163
|
-
The `icon` field accepts a `TrayIconImage` object:
|
|
164
|
-
|
|
165
|
-
```typescript
|
|
166
|
-
interface TrayIconImage {
|
|
167
|
-
data: Buffer; // Image binary data
|
|
168
|
-
width?: number; // Optional width
|
|
169
|
-
height?: number; // Optional height
|
|
170
|
-
}
|
|
171
|
-
```
|
|
172
|
-
|
|
173
198
|
**Methods**
|
|
174
199
|
|
|
175
|
-
| Method
|
|
176
|
-
|
|
|
177
|
-
| `addMenuItem(item)`
|
|
178
|
-
| `removeMenuItem(id)`
|
|
179
|
-
| `setMenuItems(items)`
|
|
180
|
-
| `setIcon(icon
|
|
181
|
-
| `setTooltip(tooltip)`
|
|
182
|
-
| `on(event, callback)`
|
|
183
|
-
| `show()`
|
|
184
|
-
| `hide()`
|
|
185
|
-
| `destroy()`
|
|
200
|
+
| Method | Description |
|
|
201
|
+
| --------------------- | ------------------------------------------------ |
|
|
202
|
+
| `addMenuItem(item)` | Add a menu item |
|
|
203
|
+
| `removeMenuItem(id)` | Remove a menu item by ID |
|
|
204
|
+
| `setMenuItems(items)` | Replace all menu items |
|
|
205
|
+
| `setIcon(icon)` | Change the tray icon, accepts an `Icon` instance |
|
|
206
|
+
| `setTooltip(tooltip)` | Change the tooltip text |
|
|
207
|
+
| `on(event, callback)` | Listen for tray events (e.g. `'click'`) |
|
|
208
|
+
| `show()` | Show the tray icon |
|
|
209
|
+
| `hide()` | Hide the tray icon |
|
|
210
|
+
| `destroy()` | Destroy the tray icon |
|
|
186
211
|
|
|
187
212
|
```typescript
|
|
188
213
|
tray.on("click", () => {
|
|
@@ -197,13 +222,14 @@ tray.setTooltip("Nexfep App");
|
|
|
197
222
|
Send desktop notifications via `app.utils.notify()`.
|
|
198
223
|
|
|
199
224
|
```typescript
|
|
200
|
-
const notification = app.utils.notify("Title", "Notification body");
|
|
225
|
+
const notification = app.utils.notify("Title", { body: "Notification body" });
|
|
201
226
|
```
|
|
202
227
|
|
|
203
228
|
**Parameters**
|
|
204
229
|
|
|
205
230
|
- `title` — Notification title
|
|
206
|
-
- `
|
|
231
|
+
- `options` (optional) — Configuration object
|
|
232
|
+
- `body` — Notification body text
|
|
207
233
|
|
|
208
234
|
### Window Pool
|
|
209
235
|
|
|
@@ -216,13 +242,38 @@ const pool = app.windows;
|
|
|
216
242
|
### Window Creation
|
|
217
243
|
|
|
218
244
|
```typescript
|
|
219
|
-
|
|
245
|
+
// Use all defaults by omitting parameters
|
|
246
|
+
const win = await pool.createWindow();
|
|
247
|
+
|
|
248
|
+
// Pass partial parameters
|
|
249
|
+
const win = await pool.createWindow({
|
|
250
|
+
visible: true,
|
|
251
|
+
title: "My App",
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
// All parameters
|
|
255
|
+
const win = await pool.createWindow({
|
|
256
|
+
visible: true, // Whether to show immediately, default true
|
|
257
|
+
decoration: true, // Whether to use system decorations, default true
|
|
258
|
+
title: "My App", // Window title, default "Nexfep Window"
|
|
259
|
+
icon: iconInstance, // Window icon, Icon instance, optional
|
|
260
|
+
resizable: true, // Whether the window is resizable, default true
|
|
261
|
+
width: 800, // Window width, default 800
|
|
262
|
+
height: 600, // Window height, default 600
|
|
263
|
+
});
|
|
220
264
|
```
|
|
221
265
|
|
|
222
266
|
**Parameters**
|
|
223
267
|
|
|
224
|
-
|
|
225
|
-
|
|
268
|
+
| Option | Type | Default | Description |
|
|
269
|
+
| ------------ | --------- | ----------------- | ---------------------------------------------------------------------------------------------------------------- |
|
|
270
|
+
| `visible` | `boolean` | `true` | Whether to immediately show the window |
|
|
271
|
+
| `decoration` | `boolean` | `true` | Whether to use system window decorations. When `false`, the window has no border and requires a custom title bar |
|
|
272
|
+
| `title` | `string` | `"Nexfep Window"` | Window title |
|
|
273
|
+
| `icon` | `Icon` | none | Window icon |
|
|
274
|
+
| `resizable` | `boolean` | `true` | Whether the window is resizable |
|
|
275
|
+
| `width` | `number` | `800` | Window width in pixels |
|
|
276
|
+
| `height` | `number` | `600` | Window height in pixels |
|
|
226
277
|
|
|
227
278
|
### Window Operations
|
|
228
279
|
|
|
@@ -358,6 +409,12 @@ window.addEventListener("user-login", (event) => {
|
|
|
358
409
|
});
|
|
359
410
|
```
|
|
360
411
|
|
|
412
|
+
The main process can send events to all open windows via `pool.broadcast`, with parameters identical to those of `window.broadcast` in the page:
|
|
413
|
+
|
|
414
|
+
```typescript
|
|
415
|
+
pool.broadcast("user-login", { userId: 123 });
|
|
416
|
+
```
|
|
417
|
+
|
|
361
418
|
#### Tell
|
|
362
419
|
|
|
363
420
|
Send a message to a specific window by its ID via `window.tell`:
|
|
@@ -386,6 +443,12 @@ Each window's ID can be accessed via `window.id`:
|
|
|
386
443
|
console.log("This window ID:", window.id);
|
|
387
444
|
```
|
|
388
445
|
|
|
446
|
+
The main process can also send messages to this window through `win.tell`:
|
|
447
|
+
|
|
448
|
+
```typescript
|
|
449
|
+
win.tell("custom-message", { text: `Hello Window ${win.id}` });
|
|
450
|
+
```
|
|
451
|
+
|
|
389
452
|
### Custom Messages
|
|
390
453
|
|
|
391
454
|
#### Send Messages
|
|
@@ -584,44 +647,47 @@ Please do not include the outer `metadata` field, just the internal fields. Like
|
|
|
584
647
|
|
|
585
648
|
### WindowPool
|
|
586
649
|
|
|
587
|
-
| Method/Property
|
|
588
|
-
|
|
|
589
|
-
| `createWindow(
|
|
590
|
-
| `handle(event, callback)`
|
|
591
|
-
| `unhandle(event, callback)`
|
|
592
|
-
| `global`
|
|
593
|
-
| `closeWindow(window)`
|
|
594
|
-
| `onCustomMessage`
|
|
650
|
+
| Method/Property | Parameters | Return Value | Description |
|
|
651
|
+
| --------------------------- | ------------------------------------------------------ | ----------------- | ------------------------------------------------------ |
|
|
652
|
+
| `createWindow(options?)` | Optional parameters, see Window Creation section above | Promise\<Window> | Creates and returns a window |
|
|
653
|
+
| `handle(event, callback)` | `event`: string, `callback`: (data: any) => any | None | Listens for the specified event |
|
|
654
|
+
| `unhandle(event, callback)` | `event`: string, `callback`: (data: any) => any | None | Removes the specified event listener |
|
|
655
|
+
| `global` | / | Map\<string, any> | A global variable map |
|
|
656
|
+
| `closeWindow(window)` | `window`: Window | Promise\<void> | Closes the specified window and returns it to the pool |
|
|
657
|
+
| `onCustomMessage` | `(window: Window, data: string) => void` | None | Custom message callback |
|
|
595
658
|
|
|
596
659
|
### Window
|
|
597
660
|
|
|
598
|
-
| Method/Property
|
|
599
|
-
|
|
|
600
|
-
| `loadURL(url)`
|
|
601
|
-
| `loadHTML(html)`
|
|
602
|
-
| `show()`
|
|
603
|
-
| `hide()`
|
|
604
|
-
| `maximize()`
|
|
605
|
-
| `unMaximize()`
|
|
606
|
-
| `minimize()`
|
|
607
|
-
| `unMinimize()`
|
|
608
|
-
| `close()`
|
|
609
|
-
| `setTitle(title)`
|
|
610
|
-
| `setDecorated(isDecorated)`
|
|
611
|
-
| `
|
|
612
|
-
| `
|
|
613
|
-
| `
|
|
614
|
-
| `
|
|
615
|
-
| `
|
|
616
|
-
| `
|
|
617
|
-
| `
|
|
618
|
-
| `
|
|
619
|
-
| `
|
|
620
|
-
| `isFocused()`
|
|
621
|
-
| `
|
|
622
|
-
| `
|
|
623
|
-
| `
|
|
624
|
-
| `
|
|
661
|
+
| Method/Property | Parameters | Return Value | Description |
|
|
662
|
+
| --------------------------------------- | ----------------------------------------------------------------- | --------------------------------- | -------------------------------------------------------------------------------------------------- |
|
|
663
|
+
| `loadURL(url)` | `url`: string — URL to load | Promise\<void> | Loads the specified URL |
|
|
664
|
+
| `loadHTML(html)` | `html`: string — HTML string | Promise\<void> | Loads the specified HTML content |
|
|
665
|
+
| `show()` | None | void | Shows the window |
|
|
666
|
+
| `hide()` | None | void | Hides the window |
|
|
667
|
+
| `maximize()` | None | void | Maximizes the window |
|
|
668
|
+
| `unMaximize()` | None | void | Restores the window (cancels maximize) |
|
|
669
|
+
| `minimize()` | None | void | Minimizes the window |
|
|
670
|
+
| `unMinimize()` | None | void | Restores the window (cancels minimize) |
|
|
671
|
+
| `close()` | None | void | Closes the window and returns to pool |
|
|
672
|
+
| `setTitle(title)` | `title`: string | void | Sets the window title |
|
|
673
|
+
| `setDecorated(isDecorated)` | `isDecorated`: boolean | void | Sets whether the window has borders and title bar |
|
|
674
|
+
| `setResizable(resizable)` | `resizable`: boolean | void | Sets whether the window is resizable |
|
|
675
|
+
| `setLevel(level)` | `level`: `-1` \| `0` \| `1` | void | Sets window level: -1=bottom, 0=normal, 1=top |
|
|
676
|
+
| `setFullScreen(isFullScreen, options?)` | `isFullScreen`: `boolean`, `options?`: `{ borderless?: boolean }` | void | Sets fullscreen mode. `borderless: true` for borderless fullscreen, otherwise exclusive fullscreen |
|
|
677
|
+
| `setIcon(icon)` | `icon`: `Icon` | void | Sets the window icon |
|
|
678
|
+
| `setSize(width, height)` | `width`: number, `height`: number | void | Sets the window size in pixels |
|
|
679
|
+
| `getSize()` | None | { width: number, height: number } | Gets the window size in pixels |
|
|
680
|
+
| `setPosition(x, y)` | `x`: number, `y`: number | void | Sets the window position in pixels |
|
|
681
|
+
| `getPosition()` | None | { x: number, y: number } | Gets the window position in pixels |
|
|
682
|
+
| `focus()` | None | void | Focuses the window |
|
|
683
|
+
| `isFocused()` | None | boolean | Whether the window has focus |
|
|
684
|
+
| `isMaximized()` | None | boolean | Whether the window is maximized |
|
|
685
|
+
| `isMinimized()` | None | boolean | Whether the window is minimized |
|
|
686
|
+
| `toggleMaximize()` | None | void | Toggles the window maximized state |
|
|
687
|
+
| `toggleMinimize()` | None | void | Toggles the window minimized state |
|
|
688
|
+
| `openDevTools()` | None | void | Opens developer tools |
|
|
689
|
+
| `closeDevTools()` | None | void | Closes developer tools |
|
|
690
|
+
| `id` | None | number | Unique window identifier, auto-incrementing |
|
|
625
691
|
|
|
626
692
|
## Development
|
|
627
693
|
|
package/frontend/index.d.ts
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
export {}
|
|
1
|
+
export {};
|
|
2
2
|
|
|
3
3
|
declare global {
|
|
4
4
|
interface Window {
|
|
5
|
-
tell: (to: number, message: string, data?: any) => void
|
|
6
|
-
broadcast: (message: string, data?: any) => void
|
|
7
|
-
invoke: (event: string, data?: any) => Promise<any
|
|
8
|
-
close: () => void
|
|
9
|
-
minimize: () => void
|
|
10
|
-
unminimize: () => void
|
|
11
|
-
toggleMaximize: () => void
|
|
12
|
-
toggleMinimize: () => void
|
|
13
|
-
maximize: () => void
|
|
14
|
-
unmaximize: () => void
|
|
15
|
-
setTitle: (title: string) => void
|
|
16
|
-
openDevTools: () => void
|
|
17
|
-
closeDevTools: () => void
|
|
18
|
-
setGlobal: (name: string, value: any) => void
|
|
19
|
-
getGlobal: (name: string) => Promise<any
|
|
20
|
-
id: number
|
|
21
|
-
isNexfepLoadDone: boolean
|
|
5
|
+
tell: (to: number, message: string, data?: any) => void;
|
|
6
|
+
broadcast: (message: string, data?: any) => void;
|
|
7
|
+
invoke: (event: string, data?: any) => Promise<any>;
|
|
8
|
+
close: () => void;
|
|
9
|
+
minimize: () => void;
|
|
10
|
+
unminimize: () => void;
|
|
11
|
+
toggleMaximize: () => void;
|
|
12
|
+
toggleMinimize: () => void;
|
|
13
|
+
maximize: () => void;
|
|
14
|
+
unmaximize: () => void;
|
|
15
|
+
setTitle: (title: string) => void;
|
|
16
|
+
openDevTools: () => void;
|
|
17
|
+
closeDevTools: () => void;
|
|
18
|
+
setGlobal: (name: string, value: any) => void;
|
|
19
|
+
getGlobal: (name: string) => Promise<any>;
|
|
20
|
+
id: number;
|
|
21
|
+
isNexfepLoadDone: boolean;
|
|
22
22
|
}
|
|
23
|
-
}
|
|
23
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nexfep",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.1",
|
|
4
4
|
"description": "A desktop application framework based on @webviewjs/webview",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"@webviewjs/webview",
|
|
@@ -20,12 +20,6 @@
|
|
|
20
20
|
"bin": {
|
|
21
21
|
"nexfep": "cli/index.mjs"
|
|
22
22
|
},
|
|
23
|
-
"typesVersions": {
|
|
24
|
-
"*": {
|
|
25
|
-
".": ["./index.d.ts"],
|
|
26
|
-
"frontend": ["./frontend/index.d.ts"]
|
|
27
|
-
}
|
|
28
|
-
},
|
|
29
23
|
"files": [
|
|
30
24
|
"index.js",
|
|
31
25
|
"index.d.ts",
|
|
@@ -47,10 +41,22 @@
|
|
|
47
41
|
"src/Logger.d.ts",
|
|
48
42
|
"src/SingleInstance.js",
|
|
49
43
|
"src/SingleInstance.d.ts",
|
|
44
|
+
"src/Icon.js",
|
|
45
|
+
"src/Icon.d.ts",
|
|
50
46
|
"frontend/index.d.ts"
|
|
51
47
|
],
|
|
52
48
|
"type": "module",
|
|
53
49
|
"main": "./index.js",
|
|
50
|
+
"typesVersions": {
|
|
51
|
+
"*": {
|
|
52
|
+
".": [
|
|
53
|
+
"./index.d.ts"
|
|
54
|
+
],
|
|
55
|
+
"frontend": [
|
|
56
|
+
"./frontend/index.d.ts"
|
|
57
|
+
]
|
|
58
|
+
}
|
|
59
|
+
},
|
|
54
60
|
"scripts": {
|
|
55
61
|
"compile": "tsc",
|
|
56
62
|
"fmt": "oxfmt --check",
|
|
@@ -59,7 +65,7 @@
|
|
|
59
65
|
"lint:fix": "oxlint --fix"
|
|
60
66
|
},
|
|
61
67
|
"dependencies": {
|
|
62
|
-
"@nexfteam/single-instance": "
|
|
68
|
+
"@nexfteam/single-instance": "0.0.8",
|
|
63
69
|
"@webviewjs/webview": "0.4.1"
|
|
64
70
|
},
|
|
65
71
|
"devDependencies": {
|
package/src/Application.d.ts
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
import { Application as WebviewApplication,
|
|
1
|
+
import { Application as WebviewApplication, Notification } from "@webviewjs/webview";
|
|
2
2
|
import { WindowPool } from "./WindowManager.js";
|
|
3
3
|
import { Tray } from "./Tray.js";
|
|
4
4
|
import { Logger } from "./Logger.js";
|
|
5
5
|
import { Locker } from "./SingleInstance.js";
|
|
6
|
+
import { Icon } from "./Icon.js";
|
|
6
7
|
declare class __Utils {
|
|
7
8
|
app: WebviewApplication;
|
|
8
9
|
constructor(app: WebviewApplication);
|
|
9
|
-
notify(title: string,
|
|
10
|
+
notify(title: string, options?: {
|
|
11
|
+
body?: string;
|
|
12
|
+
}): Notification;
|
|
10
13
|
}
|
|
11
14
|
declare class Application {
|
|
12
15
|
app: WebviewApplication;
|
|
@@ -20,7 +23,7 @@ declare class Application {
|
|
|
20
23
|
createTray(options: {
|
|
21
24
|
id: string;
|
|
22
25
|
tooltip: string;
|
|
23
|
-
icon
|
|
26
|
+
icon?: Icon;
|
|
24
27
|
menuItems: Array<{
|
|
25
28
|
id: string;
|
|
26
29
|
label: string;
|
|
@@ -29,4 +32,4 @@ declare class Application {
|
|
|
29
32
|
createLocker(appName: string): Locker;
|
|
30
33
|
exit(): void;
|
|
31
34
|
}
|
|
32
|
-
export { Application };
|
|
35
|
+
export { Application, Icon };
|
package/src/Application.js
CHANGED
|
@@ -3,13 +3,14 @@ import { WindowPool } from "./WindowManager.js";
|
|
|
3
3
|
import { Tray } from "./Tray.js";
|
|
4
4
|
import { Logger } from "./Logger.js";
|
|
5
5
|
import { Locker } from "./SingleInstance.js";
|
|
6
|
+
import { Icon } from "./Icon.js";
|
|
6
7
|
class __Utils {
|
|
7
8
|
app;
|
|
8
9
|
constructor(app) {
|
|
9
10
|
this.app = app;
|
|
10
11
|
}
|
|
11
|
-
notify(title,
|
|
12
|
-
const notification = new Notification(title, { body });
|
|
12
|
+
notify(title, options) {
|
|
13
|
+
const notification = new Notification(title, { body: options?.body });
|
|
13
14
|
return notification;
|
|
14
15
|
}
|
|
15
16
|
}
|
|
@@ -39,4 +40,4 @@ class Application {
|
|
|
39
40
|
this.app.exit();
|
|
40
41
|
}
|
|
41
42
|
}
|
|
42
|
-
export { Application };
|
|
43
|
+
export { Application, Icon };
|
package/src/Icon.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { TrayIconImage } from "@webviewjs/webview";
|
|
2
|
+
declare class Icon {
|
|
3
|
+
data: Uint8Array;
|
|
4
|
+
width?: number;
|
|
5
|
+
height?: number;
|
|
6
|
+
constructor(data: Uint8Array, width?: number, height?: number);
|
|
7
|
+
static from(input: string | Buffer | Uint8Array | {
|
|
8
|
+
data: Uint8Array;
|
|
9
|
+
width?: number;
|
|
10
|
+
height?: number;
|
|
11
|
+
} | {
|
|
12
|
+
data: Buffer;
|
|
13
|
+
width?: number;
|
|
14
|
+
height?: number;
|
|
15
|
+
}): Icon;
|
|
16
|
+
toTrayIconImage(): TrayIconImage;
|
|
17
|
+
toBuffer(): Buffer;
|
|
18
|
+
}
|
|
19
|
+
export { Icon };
|
package/src/Icon.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
class Icon {
|
|
3
|
+
data;
|
|
4
|
+
width;
|
|
5
|
+
height;
|
|
6
|
+
constructor(data, width, height) {
|
|
7
|
+
this.data = data;
|
|
8
|
+
this.width = width;
|
|
9
|
+
this.height = height;
|
|
10
|
+
}
|
|
11
|
+
static from(input) {
|
|
12
|
+
if (typeof input === "string") {
|
|
13
|
+
return new Icon(new Uint8Array(fs.readFileSync(input)));
|
|
14
|
+
}
|
|
15
|
+
else if (input instanceof Uint8Array) {
|
|
16
|
+
return new Icon(input);
|
|
17
|
+
}
|
|
18
|
+
else if (input instanceof Buffer) {
|
|
19
|
+
return new Icon(new Uint8Array(input));
|
|
20
|
+
}
|
|
21
|
+
else if (typeof input === "object" && input.data instanceof Uint8Array) {
|
|
22
|
+
return new Icon(input.data, input.width, input.height);
|
|
23
|
+
}
|
|
24
|
+
else if (typeof input === "object" && input.data instanceof Buffer) {
|
|
25
|
+
return new Icon(new Uint8Array(input.data), input.width, input.height);
|
|
26
|
+
}
|
|
27
|
+
throw new Error("Unsupported input type");
|
|
28
|
+
}
|
|
29
|
+
toTrayIconImage() {
|
|
30
|
+
return { data: Buffer.from(this.data), width: this.width, height: this.height };
|
|
31
|
+
}
|
|
32
|
+
toBuffer() {
|
|
33
|
+
return Buffer.from(this.data);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
export { Icon };
|