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/android-target-sdk-37.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"tauri-cli": patch:enhance
"@tauri-apps/cli": patch:enhance
---

Update template to use `targetSdk = 37`
6 changes: 6 additions & 0 deletions .changes/fix-monitor-queries-off-thread.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'tauri': 'patch:bug'
'tauri-runtime-wry': 'patch:bug'
---

Query monitor information (`primary_monitor`, `monitor_from_point`, `available_monitors`) on the main thread from the app-level runtime handle instead of touching the event loop's window target directly.
6 changes: 6 additions & 0 deletions .changes/runtime-handle-monitor-fns.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'tauri-runtime': 'minor:breaking'
'tauri-runtime-wry': 'minor:breaking'
---

Changed `RuntimeHandle::primary_monitor`, `RuntimeHandle::monitor_from_point`, `RuntimeHandle::available_monitors` to return `Result`s
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ val tauriProperties = Properties().apply {
}

android {
compileSdk = 36
compileSdk = 37
namespace = "{{app.identifier}}"
defaultConfig {
manifestPlaceholders["usesCleartextTraffic"] = "false"
applicationId = "{{app.identifier}}"
minSdk = {{android.min-sdk-version}}
targetSdk = 36
targetSdk = 37
versionCode = tauriProperties.getProperty("tauri.android.versionCode", "1").toInt()
versionName = tauriProperties.getProperty("tauri.android.versionName", "1.0")
}
Expand Down
57 changes: 35 additions & 22 deletions crates/tauri-runtime-wry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1478,6 +1478,9 @@ pub enum WebviewMessage {

pub enum EventLoopWindowTargetMessage {
CursorPosition(Sender<Result<PhysicalPosition<f64>>>),
PrimaryMonitor(Sender<Option<MonitorHandle>>),
MonitorFromPoint(Sender<Option<MonitorHandle>>, (f64, f64)),
AvailableMonitors(Sender<Vec<MonitorHandle>>),
SetTheme(Option<Theme>),
SetDeviceEventFilter(DeviceEventFilter),
}
Expand Down Expand Up @@ -2735,32 +2738,31 @@ impl<T: UserEvent> RuntimeHandle<T> for WryHandle<T> {
self.context.main_thread.window_target.display_handle()
}

fn primary_monitor(&self) -> Option<Monitor> {
self
.context
.main_thread
.window_target
.primary_monitor()
.map(|m| MonitorHandleWrapper(m).into())
fn primary_monitor(&self) -> Result<Option<Monitor>> {
Ok(
event_loop_window_getter!(self, EventLoopWindowTargetMessage::PrimaryMonitor)?
.map(|m| MonitorHandleWrapper(m).into()),
)
}

fn monitor_from_point(&self, x: f64, y: f64) -> Option<Monitor> {
self
.context
.main_thread
.window_target
.monitor_from_point(x, y)
.map(|m| MonitorHandleWrapper(m).into())
fn monitor_from_point(&self, x: f64, y: f64) -> Result<Option<Monitor>> {
let (tx, rx) = channel();
send_user_message(
&self.context,
Message::EventLoopWindowTarget(EventLoopWindowTargetMessage::MonitorFromPoint(tx, (x, y))),
)?;
Ok(rx.recv().unwrap().map(|m| MonitorHandleWrapper(m).into()))
}

fn available_monitors(&self) -> Vec<Monitor> {
self
.context
.main_thread
.window_target
.available_monitors()
.map(|m| MonitorHandleWrapper(m).into())
.collect()
fn available_monitors(&self) -> Result<Vec<Monitor>> {
event_loop_window_getter!(self, EventLoopWindowTargetMessage::AvailableMonitors).map(
|monitors| {
monitors
.into_iter()
.map(|m| MonitorHandleWrapper(m).into())
.collect()
},
)
}

fn cursor_position(&self) -> Result<PhysicalPosition<f64>> {
Expand Down Expand Up @@ -4084,6 +4086,17 @@ fn handle_user_message<T: UserEvent>(
.map_err(|_| Error::FailedToSendMessage);
sender.send(pos).unwrap();
}
EventLoopWindowTargetMessage::PrimaryMonitor(sender) => {
sender.send(event_loop.primary_monitor()).unwrap();
}
EventLoopWindowTargetMessage::MonitorFromPoint(sender, (x, y)) => {
sender.send(event_loop.monitor_from_point(x, y)).unwrap();
}
EventLoopWindowTargetMessage::AvailableMonitors(sender) => {
sender
.send(event_loop.available_monitors().collect())
.unwrap();
}
EventLoopWindowTargetMessage::SetTheme(theme) => {
event_loop.set_theme(to_tao_theme(theme));
}
Expand Down
6 changes: 3 additions & 3 deletions crates/tauri-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,13 +315,13 @@ pub trait RuntimeHandle<T: UserEvent>: Debug + Clone + Send + Sync + Sized + 'st
/// Returns the primary monitor of the system.
///
/// Returns None if it can't identify any monitor as a primary one.
fn primary_monitor(&self) -> Option<Monitor>;
fn primary_monitor(&self) -> Result<Option<Monitor>>;

/// Returns the monitor that contains the given point.
fn monitor_from_point(&self, x: f64, y: f64) -> Option<Monitor>;
fn monitor_from_point(&self, x: f64, y: f64) -> Result<Option<Monitor>>;

/// Returns the list of all the monitors available on the system.
fn available_monitors(&self) -> Vec<Monitor>;
fn available_monitors(&self) -> Result<Vec<Monitor>>;

/// Get the cursor position relative to the top-left hand corner of the desktop.
fn cursor_position(&self) -> Result<PhysicalPosition<f64>>;
Expand Down
12 changes: 7 additions & 5 deletions crates/tauri/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -870,7 +870,7 @@ macro_rules! shared_app_impl {
pub fn primary_monitor(&self) -> crate::Result<Option<Monitor>> {
Ok(match self.runtime() {
RuntimeOrDispatch::Runtime(h) => h.primary_monitor().map(Into::into),
RuntimeOrDispatch::RuntimeHandle(h) => h.primary_monitor().map(Into::into),
RuntimeOrDispatch::RuntimeHandle(h) => h.primary_monitor()?.map(Into::into),
_ => unreachable!(),
})
}
Expand All @@ -879,7 +879,7 @@ macro_rules! shared_app_impl {
pub fn monitor_from_point(&self, x: f64, y: f64) -> crate::Result<Option<Monitor>> {
Ok(match self.runtime() {
RuntimeOrDispatch::Runtime(h) => h.monitor_from_point(x, y).map(Into::into),
RuntimeOrDispatch::RuntimeHandle(h) => h.monitor_from_point(x, y).map(Into::into),
RuntimeOrDispatch::RuntimeHandle(h) => h.monitor_from_point(x, y)?.map(Into::into),
_ => unreachable!(),
})
}
Expand All @@ -890,9 +890,11 @@ macro_rules! shared_app_impl {
RuntimeOrDispatch::Runtime(h) => {
h.available_monitors().into_iter().map(Into::into).collect()
}
RuntimeOrDispatch::RuntimeHandle(h) => {
h.available_monitors().into_iter().map(Into::into).collect()
}
RuntimeOrDispatch::RuntimeHandle(h) => h
.available_monitors()?
.into_iter()
.map(Into::into)
.collect(),
_ => unreachable!(),
})
}
Expand Down
6 changes: 3 additions & 3 deletions crates/tauri/src/test/mock_runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,15 +249,15 @@ impl<T: UserEvent> RuntimeHandle<T> for MockRuntimeHandle {
unimplemented!();
}

fn primary_monitor(&self) -> Option<Monitor> {
fn primary_monitor(&self) -> Result<Option<Monitor>> {
unimplemented!()
}

fn monitor_from_point(&self, x: f64, y: f64) -> Option<Monitor> {
fn monitor_from_point(&self, x: f64, y: f64) -> Result<Option<Monitor>> {
unimplemented!()
}

fn available_monitors(&self) -> Vec<Monitor> {
fn available_monitors(&self) -> Result<Vec<Monitor>> {
unimplemented!()
}

Expand Down
Loading