@@ -35,7 +35,7 @@ const options = {
35
35
// here you can add a tray menu, title, tooltip, event handler, etc
36
36
};
37
37
38
- const tray = TrayIcon .new (options);
38
+ const tray = await TrayIcon .new (options);
39
39
```
40
40
41
41
See [ ` TrayIconOptions ` ] for more information on the customization options.
@@ -62,16 +62,35 @@ See [`TrayIconBuilder`] for more information on customization options.
62
62
63
63
### Change the Tray Icon
64
64
65
- { /* TODO: add a way to do this easily from JS too */ }
65
+ When creating the tray you can use the application icon as the tray icon:
66
66
67
- When creating the tray icon from Rust code, you can set the application icon as the tray icon:
67
+ <Tabs >
68
+ <TabItem label = " JavaScript" >
69
+
70
+ ``` javascript
71
+ import { TrayIcon } from ' @tauri-apps/api/tray' ;
72
+ import { defaultWindowIcon } from ' @tauri-apps/api/app' ;
73
+
74
+ const options = {
75
+ icon: await defaultWindowIcon (),
76
+ };
77
+
78
+ const tray = await TrayIcon .new (options);
79
+ ```
80
+
81
+ </TabItem >
82
+
83
+ <TabItem label = " Rust" >
68
84
69
85
``` rust
70
86
let tray = TrayIconBuilder :: new ()
71
87
. icon (app . default_window_icon (). unwrap (). clone ())
72
88
. build (app )? ;
73
89
```
74
90
91
+ </TabItem >
92
+ </Tabs >
93
+
75
94
### Add a Menu
76
95
77
96
To attach a menu that is displayed when the tray is clicked, you can use the ` menu ` option.
@@ -106,7 +125,7 @@ const options = {
106
125
menuOnLeftClick: true ,
107
126
};
108
127
109
- const tray = TrayIcon .new (options);
128
+ const tray = await TrayIcon .new (options);
110
129
```
111
130
112
131
</TabItem >
@@ -244,7 +263,7 @@ const options = {
244
263
},
245
264
};
246
265
247
- const tray = TrayIcon .new (options);
266
+ const tray = await TrayIcon .new (options);
248
267
```
249
268
250
269
See [ ` TrayIconEvent ` ] [ js TrayIconEvent ] for more information on the event payload.
0 commit comments