Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changes/change-pr-15177.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"tauri": patch:deps
"tauri-bundler": patch:deps
---

Update Specta in lockfile and upgrade dependencies using the removed `doc_auto_cfg` attribute to fix errors building documentation
6 changes: 6 additions & 0 deletions .changes/changed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'tauri': 'minor:feat'
'@tauri-apps/api': 'minor:feat'
---

Add macos support for setting the icon and icon template state in the same step of the main thread, to prevent flickering.
5 changes: 5 additions & 0 deletions .changes/feat-async_runtime-track.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tauri": minor:feat
---

Enable track_caller attribute for async_runtime to provide better location information in logs and panics.
10 changes: 5 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/tauri/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ const PLUGINS: &[(&str, &[(&str, bool)])] = &[
("set_visible", true),
("set_temp_dir_path", true),
("set_icon_as_template", true),
("set_icon_with_as_template", true),
("set_show_menu_on_left_click", true),
],
),
Expand Down
27 changes: 27 additions & 0 deletions crates/tauri/permissions/tray/autogenerated/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Default permissions for the plugin, which enables all commands.
- `allow-set-visible`
- `allow-set-temp-dir-path`
- `allow-set-icon-as-template`
- `allow-set-icon-with-as-template`
- `allow-set-show-menu-on-left-click`

## Permission Table
Expand Down Expand Up @@ -158,6 +159,32 @@ Denies the set_icon_as_template command without any pre-configured scope.
<tr>
<td>

`core:tray:allow-set-icon-with-as-template`

</td>
<td>

Enables the set_icon_with_as_template command without any pre-configured scope.

</td>
</tr>

<tr>
<td>

`core:tray:deny-set-icon-with-as-template`

</td>
<td>

Denies the set_icon_with_as_template command without any pre-configured scope.

</td>
</tr>

<tr>
<td>

`core:tray:allow-set-menu`

</td>
Expand Down
2 changes: 1 addition & 1 deletion crates/tauri/scripts/bundle.global.js

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions crates/tauri/src/async_runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ impl GlobalRuntime {
}
}

#[track_caller]
fn spawn<F>(&self, task: F) -> JoinHandle<F::Output>
where
F: Future + Send + 'static,
Expand All @@ -54,6 +55,7 @@ impl GlobalRuntime {
}
}

#[track_caller]
pub fn spawn_blocking<F, R>(&self, func: F) -> JoinHandle<R>
where
F: FnOnce() -> R + Send + 'static,
Expand All @@ -66,6 +68,7 @@ impl GlobalRuntime {
}
}

#[track_caller]
fn block_on<F: Future>(&self, task: F) -> F::Output {
if let Some(r) = &self.runtime {
r.block_on(task)
Expand Down Expand Up @@ -95,6 +98,7 @@ impl Runtime {
}
}

#[track_caller]
/// Spawns a future onto the runtime.
pub fn spawn<F>(&self, task: F) -> JoinHandle<F::Output>
where
Expand All @@ -109,6 +113,7 @@ impl Runtime {
}
}

#[track_caller]
/// Runs the provided function on an executor dedicated to blocking operations.
pub fn spawn_blocking<F, R>(&self, func: F) -> JoinHandle<R>
where
Expand All @@ -120,6 +125,7 @@ impl Runtime {
}
}

#[track_caller]
/// Runs a future to completion on runtime.
pub fn block_on<F: Future>(&self, task: F) -> F::Output {
match self {
Expand Down Expand Up @@ -177,6 +183,7 @@ impl RuntimeHandle {
h
}

#[track_caller]
/// Runs the provided function on an executor dedicated to blocking operations.
pub fn spawn_blocking<F, R>(&self, func: F) -> JoinHandle<R>
where
Expand All @@ -188,6 +195,7 @@ impl RuntimeHandle {
}
}

#[track_caller]
/// Spawns a future onto the runtime.
pub fn spawn<F>(&self, task: F) -> JoinHandle<F::Output>
where
Expand All @@ -202,6 +210,7 @@ impl RuntimeHandle {
}
}

#[track_caller]
/// Runs a future to completion on runtime.
pub fn block_on<F: Future>(&self, task: F) -> F::Output {
match self {
Expand Down Expand Up @@ -258,12 +267,14 @@ pub fn handle() -> RuntimeHandle {
runtime.handle()
}

#[track_caller]
/// Runs a future to completion on runtime.
pub fn block_on<F: Future>(task: F) -> F::Output {
let runtime = RUNTIME.get_or_init(default_runtime);
runtime.block_on(task)
}

#[track_caller]
/// Spawns a future onto the runtime.
pub fn spawn<F>(task: F) -> JoinHandle<F::Output>
where
Expand All @@ -274,6 +285,7 @@ where
runtime.spawn(task)
}

#[track_caller]
/// Runs the provided function on an executor dedicated to blocking operations.
pub fn spawn_blocking<F, R>(func: F) -> JoinHandle<R>
where
Expand All @@ -284,6 +296,7 @@ where
runtime.spawn_blocking(func)
}

#[track_caller]
#[allow(dead_code)]
pub(crate) fn safe_block_on<F>(task: F) -> F::Output
where
Expand Down
32 changes: 32 additions & 0 deletions crates/tauri/src/tray/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,38 @@ impl<R: Runtime> TrayIcon<R> {
Ok(())
}

/// Sets the tray icon and template status atomically. **macOS only**.
///
/// On macOS, calling `set_icon` followed by `set_icon_as_template` causes a visible
/// flicker as the icon is rendered twice. This method sets both atomically to prevent that.
///
/// ## Platform-specific:
///
/// - **Linux / Windows:** Falls back to calling `set_icon`.
pub fn set_icon_with_as_template(
&self,
icon: Option<Image<'_>>,
#[allow(unused)] is_template: bool,
) -> crate::Result<()> {
#[cfg(target_os = "macos")]
{
let tray_icon = match icon {
Some(i) => Some(i.try_into()?),
None => None,
};
run_item_main_thread!(self, |self_: Self| {
self_
.inner
.set_icon_with_as_template(tray_icon, is_template)
})??;
}
#[cfg(not(target_os = "macos"))]
{
self.set_icon(icon)?;
}
Ok(())
}

/// Disable or enable showing the tray menu on left click.
///
///
Expand Down
19 changes: 19 additions & 0 deletions crates/tauri/src/tray/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,24 @@ fn set_icon_as_template<R: Runtime>(
tray.set_icon_as_template(as_template)
}

#[command(root = "crate")]
fn set_icon_with_as_template<R: Runtime>(
app: AppHandle<R>,
webview: Webview<R>,
rid: ResourceId,
icon: Option<JsImage>,
as_template: bool,
) -> crate::Result<()> {
let resources_table = app.resources_table();
let tray = resources_table.get::<TrayIcon<R>>(rid)?;
let webview_resources_table = webview.resources_table();
let icon = match icon {
Some(i) => Some(i.into_img(&webview_resources_table)?.as_ref().clone()),
None => None,
};
tray.set_icon_with_as_template(icon, as_template)
}

#[command(root = "crate")]
fn set_show_menu_on_left_click<R: Runtime>(
app: AppHandle<R>,
Expand All @@ -228,6 +246,7 @@ pub(crate) fn init<R: Runtime>() -> TauriPlugin<R> {
set_visible,
set_temp_dir_path,
set_icon_as_template,
set_icon_with_as_template,
set_show_menu_on_left_click,
])
.build()
Expand Down
25 changes: 25 additions & 0 deletions packages/api/src/tray.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,31 @@ export class TrayIcon extends Resource {
})
}

/**
* Sets a new tray icon and template status atomically. **macOS only**.
*
* Note that you may need the `image-ico` or `image-png` Cargo features to use this API.
* To enable it, change your Cargo.toml file:
* ```toml
* [dependencies]
* tauri = { version = "...", features = ["...", "image-png"] }
* ```
*/
async setIconWithAsTemplate(
icon: string | Image | Uint8Array | ArrayBuffer | number[] | null,
asTemplate: boolean
): Promise<void> {
let trayIcon = null
if (icon) {
trayIcon = transformImage(icon)
}
return invoke('plugin:tray|set_icon_with_as_template', {
rid: this.rid,
icon: trayIcon,
asTemplate
})
}

/**
* Disable or enable showing the tray menu on left click.
*
Expand Down
Loading