Merge branch 'master' into feature/test-recorder
This commit is contained in:
commit
a052ce58b0
69 changed files with 1555 additions and 833 deletions
|
|
@ -1,11 +1,20 @@
|
|||
//! Access the native system.
|
||||
use crate::core::theme;
|
||||
use crate::futures::futures::channel::oneshot;
|
||||
use crate::futures::subscription::{self, Subscription};
|
||||
use crate::task::{self, Task};
|
||||
|
||||
/// An operation to be performed on the system.
|
||||
#[derive(Debug)]
|
||||
pub enum Action {
|
||||
/// Query system information and produce `T` with the result.
|
||||
QueryInformation(oneshot::Sender<Information>),
|
||||
/// Send available system information.
|
||||
GetInformation(oneshot::Sender<Information>),
|
||||
|
||||
/// Send the current system theme mode.
|
||||
GetTheme(oneshot::Sender<theme::Mode>),
|
||||
|
||||
/// Notify to the runtime that the system theme has changed.
|
||||
NotifyTheme(theme::Mode),
|
||||
}
|
||||
|
||||
/// Contains information about the system (e.g. system name, processor, memory, graphics adapter).
|
||||
|
|
@ -37,3 +46,29 @@ pub struct Information {
|
|||
/// Model information for the active graphics adapter
|
||||
pub graphics_adapter: String,
|
||||
}
|
||||
|
||||
/// Returns available system information.
|
||||
pub fn information() -> Task<Information> {
|
||||
task::oneshot(|channel| {
|
||||
crate::Action::System(Action::GetInformation(channel))
|
||||
})
|
||||
}
|
||||
|
||||
/// Returns the current system theme.
|
||||
pub fn theme() -> Task<theme::Mode> {
|
||||
task::oneshot(|sender| crate::Action::System(Action::GetTheme(sender)))
|
||||
}
|
||||
|
||||
/// Subscribes to system theme changes.
|
||||
pub fn theme_changes() -> Subscription<theme::Mode> {
|
||||
#[derive(Hash)]
|
||||
struct ThemeChanges;
|
||||
|
||||
subscription::filter_map(ThemeChanges, |event| {
|
||||
let subscription::Event::SystemThemeChanged(mode) = event else {
|
||||
return None;
|
||||
};
|
||||
|
||||
Some(mode)
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -266,12 +266,12 @@ pub fn close<T>(id: Id) -> Task<T> {
|
|||
}
|
||||
|
||||
/// Gets the window [`Id`] of the oldest window.
|
||||
pub fn get_oldest() -> Task<Option<Id>> {
|
||||
pub fn oldest() -> Task<Option<Id>> {
|
||||
task::oneshot(|channel| crate::Action::Window(Action::GetOldest(channel)))
|
||||
}
|
||||
|
||||
/// Gets the window [`Id`] of the latest window.
|
||||
pub fn get_latest() -> Task<Option<Id>> {
|
||||
pub fn latest() -> Task<Option<Id>> {
|
||||
task::oneshot(|channel| crate::Action::Window(Action::GetLatest(channel)))
|
||||
}
|
||||
|
||||
|
|
@ -315,14 +315,14 @@ pub fn set_resize_increments<T>(id: Id, increments: Option<Size>) -> Task<T> {
|
|||
}
|
||||
|
||||
/// Get the window's size in logical dimensions.
|
||||
pub fn get_size(id: Id) -> Task<Size> {
|
||||
pub fn size(id: Id) -> Task<Size> {
|
||||
task::oneshot(move |channel| {
|
||||
crate::Action::Window(Action::GetSize(id, channel))
|
||||
})
|
||||
}
|
||||
|
||||
/// Gets the maximized state of the window with the given [`Id`].
|
||||
pub fn get_maximized(id: Id) -> Task<bool> {
|
||||
pub fn is_maximized(id: Id) -> Task<bool> {
|
||||
task::oneshot(move |channel| {
|
||||
crate::Action::Window(Action::GetMaximized(id, channel))
|
||||
})
|
||||
|
|
@ -334,7 +334,7 @@ pub fn maximize<T>(id: Id, maximized: bool) -> Task<T> {
|
|||
}
|
||||
|
||||
/// Gets the minimized state of the window with the given [`Id`].
|
||||
pub fn get_minimized(id: Id) -> Task<Option<bool>> {
|
||||
pub fn is_minimized(id: Id) -> Task<Option<bool>> {
|
||||
task::oneshot(move |channel| {
|
||||
crate::Action::Window(Action::GetMinimized(id, channel))
|
||||
})
|
||||
|
|
@ -346,14 +346,14 @@ pub fn minimize<T>(id: Id, minimized: bool) -> Task<T> {
|
|||
}
|
||||
|
||||
/// Gets the position in logical coordinates of the window with the given [`Id`].
|
||||
pub fn get_position(id: Id) -> Task<Option<Point>> {
|
||||
pub fn position(id: Id) -> Task<Option<Point>> {
|
||||
task::oneshot(move |channel| {
|
||||
crate::Action::Window(Action::GetPosition(id, channel))
|
||||
})
|
||||
}
|
||||
|
||||
/// Gets the scale factor of the window with the given [`Id`].
|
||||
pub fn get_scale_factor(id: Id) -> Task<f32> {
|
||||
pub fn scale_factor(id: Id) -> Task<f32> {
|
||||
task::oneshot(move |channel| {
|
||||
crate::Action::Window(Action::GetScaleFactor(id, channel))
|
||||
})
|
||||
|
|
@ -365,7 +365,7 @@ pub fn move_to<T>(id: Id, position: Point) -> Task<T> {
|
|||
}
|
||||
|
||||
/// Gets the current [`Mode`] of the window.
|
||||
pub fn get_mode(id: Id) -> Task<Mode> {
|
||||
pub fn mode(id: Id) -> Task<Mode> {
|
||||
task::oneshot(move |channel| {
|
||||
crate::Action::Window(Action::GetMode(id, channel))
|
||||
})
|
||||
|
|
@ -426,7 +426,7 @@ pub fn show_system_menu<T>(id: Id) -> Task<T> {
|
|||
|
||||
/// Gets an identifier unique to the window, provided by the underlying windowing system. This is
|
||||
/// not to be confused with [`Id`].
|
||||
pub fn get_raw_id<Message>(id: Id) -> Task<u64> {
|
||||
pub fn raw_id<Message>(id: Id) -> Task<u64> {
|
||||
task::oneshot(|channel| {
|
||||
crate::Action::Window(Action::GetRawId(id, channel))
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue