mirror of
https://github.com/tauri-apps/tauri.git
synced 2024-09-11 07:55:34 +03:00
Co-authored-by: Lucas Nogueira <lucas@tauri.studio>
This commit is contained in:
parent
f280dcfb7c
commit
84c4159754
5
.changes/core-app-montior.md
Normal file
5
.changes/core-app-montior.md
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
'tauri': 'minor:feat'
|
||||
---
|
||||
|
||||
Add `App::primary_monitor`, `App::available_monitors`, `AppHandle::primary_monitor`, and `AppHandle::available_monitors`
|
6
.changes/runtime-monitor.md
Normal file
6
.changes/runtime-monitor.md
Normal file
@ -0,0 +1,6 @@
|
||||
---
|
||||
"tauri-runtime": "minor:feat"
|
||||
"tauri-runtime-wry": "minor:feat"
|
||||
---
|
||||
|
||||
Added `primary_monitor` and `available_monitors` to `Runtime` and `RuntimeHandle`.
|
@ -1912,6 +1912,25 @@ impl<T: UserEvent> RuntimeHandle<T> for WryHandle<T> {
|
||||
self.context.main_thread.window_target.raw_display_handle()
|
||||
}
|
||||
|
||||
fn primary_monitor(&self) -> Option<Monitor> {
|
||||
self
|
||||
.context
|
||||
.main_thread
|
||||
.window_target
|
||||
.primary_monitor()
|
||||
.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()
|
||||
}
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
fn show(&self) -> tauri_runtime::Result<()> {
|
||||
send_user_message(
|
||||
@ -2090,6 +2109,25 @@ impl<T: UserEvent> Runtime<T> for Wry<T> {
|
||||
.push(Arc::new(Box::new(f)));
|
||||
}
|
||||
|
||||
fn primary_monitor(&self) -> Option<Monitor> {
|
||||
self
|
||||
.context
|
||||
.main_thread
|
||||
.window_target
|
||||
.primary_monitor()
|
||||
.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()
|
||||
}
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
fn set_activation_policy(&mut self, activation_policy: ActivationPolicy) {
|
||||
self
|
||||
|
@ -387,6 +387,9 @@ pub trait RuntimeHandle<T: UserEvent>: Debug + Clone + Send + Sync + Sized + 'st
|
||||
|
||||
fn raw_display_handle(&self) -> RawDisplayHandle;
|
||||
|
||||
fn primary_monitor(&self) -> Option<Monitor>;
|
||||
fn available_monitors(&self) -> Vec<Monitor>;
|
||||
|
||||
/// Shows the application, but does not automatically focus it.
|
||||
#[cfg(target_os = "macos")]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(target_os = "macos")))]
|
||||
@ -460,6 +463,9 @@ pub trait Runtime<T: UserEvent>: Debug + Sized + 'static {
|
||||
#[cfg_attr(doc_cfg, doc(cfg(feature = "system-tray")))]
|
||||
fn on_system_tray_event<F: Fn(TrayId, &SystemTrayEvent) + Send + 'static>(&mut self, f: F);
|
||||
|
||||
fn primary_monitor(&self) -> Option<Monitor>;
|
||||
fn available_monitors(&self) -> Vec<Monitor>;
|
||||
|
||||
/// Sets the activation policy for the application. It is set to `NSApplicationActivationPolicyRegular` by default.
|
||||
#[cfg(target_os = "macos")]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(target_os = "macos")))]
|
||||
|
@ -24,7 +24,7 @@ use crate::{
|
||||
utils::config::Config,
|
||||
utils::{assets::Assets, Env},
|
||||
Context, DeviceEventFilter, EventLoopMessage, Icon, Invoke, InvokeError, InvokeResponse, Manager,
|
||||
Runtime, Scopes, StateManager, Theme, Window,
|
||||
Monitor, Runtime, Scopes, StateManager, Theme, Window,
|
||||
};
|
||||
|
||||
#[cfg(feature = "protocol-asset")]
|
||||
@ -570,6 +570,35 @@ macro_rules! shared_app_impl {
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the primary monitor of the system.
|
||||
///
|
||||
/// Returns None if it can't identify any monitor as a primary one.
|
||||
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),
|
||||
_ => unreachable!()
|
||||
})
|
||||
}
|
||||
|
||||
/// Returns the list of all the monitors available on the system.
|
||||
pub fn available_monitors(&self) -> crate::Result<Vec<Monitor>> {
|
||||
Ok(match self.runtime() {
|
||||
RuntimeOrDispatch::Runtime(h) => h
|
||||
.available_monitors()
|
||||
.into_iter()
|
||||
.map(Into::into)
|
||||
.collect(),
|
||||
RuntimeOrDispatch::RuntimeHandle(h) => h
|
||||
.available_monitors()
|
||||
.into_iter()
|
||||
.map(Into::into)
|
||||
.collect(),
|
||||
_ => unreachable!()
|
||||
})
|
||||
}
|
||||
/// Returns the default window icon.
|
||||
pub fn default_window_icon(&self) -> Option<&Icon> {
|
||||
self.manager.inner.default_window_icon.as_ref()
|
||||
|
@ -154,6 +154,14 @@ impl<T: UserEvent> RuntimeHandle<T> for MockRuntimeHandle {
|
||||
return unimplemented!();
|
||||
}
|
||||
|
||||
fn primary_monitor(&self) -> Option<Monitor> {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
fn available_monitors(&self) -> Vec<Monitor> {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
/// Shows the application, but does not automatically focus it.
|
||||
#[cfg(target_os = "macos")]
|
||||
fn show(&self) -> Result<()> {
|
||||
@ -815,6 +823,14 @@ impl<T: UserEvent> Runtime<T> for MockRuntime {
|
||||
#[cfg_attr(doc_cfg, doc(cfg(feature = "system-tray")))]
|
||||
fn on_system_tray_event<F: Fn(TrayId, &SystemTrayEvent) + Send + 'static>(&mut self, f: F) {}
|
||||
|
||||
fn primary_monitor(&self) -> Option<Monitor> {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
fn available_monitors(&self) -> Vec<Monitor> {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(target_os = "macos")))]
|
||||
fn set_activation_policy(&mut self, activation_policy: tauri_runtime::ActivationPolicy) {}
|
||||
|
Loading…
Reference in New Issue
Block a user