feat: document defaultWindowIcon JS API (#2857)

This commit is contained in:
Lucas Fernandes Nogueira
2024-10-13 17:20:31 -03:00
committed by GitHub
parent cd3054cca4
commit 44e2caf27f

View File

@@ -35,7 +35,7 @@ const options = {
// here you can add a tray menu, title, tooltip, event handler, etc
};
const tray = TrayIcon.new(options);
const tray = await TrayIcon.new(options);
```
See [`TrayIconOptions`] for more information on the customization options.
@@ -62,9 +62,25 @@ See [`TrayIconBuilder`] for more information on customization options.
### Change the Tray Icon
{/* TODO: add a way to do this easily from JS too */}
When creating the tray you can use the application icon as the tray icon:
When creating the tray icon from Rust code, you can set the application icon as the tray icon:
<Tabs>
<TabItem label="JavaScript">
```javascript
import { TrayIcon } from '@tauri-apps/api/tray';
import { defaultWindowIcon } from '@tauri-apps/api/app';
const options = {
icon: await defaultWindowIcon(),
};
const tray = await TrayIcon.new(options);
```
</TabItem>
<TabItem label="Rust">
```rust
let tray = TrayIconBuilder::new()
@@ -72,6 +88,9 @@ let tray = TrayIconBuilder::new()
.build(app)?;
```
</TabItem>
</Tabs>
### Add a Menu
To attach a menu that is displayed when the tray is clicked, you can use the `menu` option.
@@ -106,7 +125,7 @@ const options = {
menuOnLeftClick: true,
};
const tray = TrayIcon.new(options);
const tray = await TrayIcon.new(options);
```
</TabItem>
@@ -244,7 +263,7 @@ const options = {
},
};
const tray = TrayIcon.new(options);
const tray = await TrayIcon.new(options);
```
See [`TrayIconEvent`][js TrayIconEvent] for more information on the event payload.