feat: add window module

This commit is contained in:
Jonas Kruckenberg 2022-11-03 11:09:17 +01:00
parent 6a0e0a6e82
commit 6bd4dd0489
8 changed files with 1830 additions and 5 deletions

View file

@ -20,6 +20,9 @@ fn Header<G: Html>(cx: Scope) -> View<G> {
a(href="/communication") {
"Communication"
}
a(href="/window") {
"Window"
}
}
}
}

View file

@ -2,6 +2,7 @@ mod app;
mod clipboard;
mod communication;
mod welcome;
mod window;
use sycamore::view::View;
use sycamore_router::Route;
@ -15,6 +16,8 @@ pub enum Page {
Clipboard,
#[to("/communication")]
Communication,
#[to("/window")]
Window,
#[not_found]
NotFound
}
@ -24,6 +27,7 @@ pub fn switch<G: Html>(cx: Scope, route: &ReadSignal<Page>) -> View<G> {
Page::App => app::App(cx),
Page::Clipboard => clipboard::Clipboard(cx),
Page::Communication => communication::Communication(cx),
Page::Window => window::Window(cx),
Page::NotFound => welcome::Welcome(cx)
}
}

View file

@ -0,0 +1,63 @@
use sycamore::prelude::*;
use tauri_sys::window;
#[component]
pub fn Window<G: Html>(cx: Scope) -> View<G> {
let get_current = |_| {
let win = window::current_window();
log::debug!("{:?}", win);
};
let get_all = |_| {
let windows = window::all_windows();
log::debug!("{:?}", windows);
};
let get_current_monitor = |_| {
sycamore::futures::spawn_local(async move {
let monitor = window::current_monitor().await;
log::debug!("{:?}", monitor);
});
};
let get_primary_monitor = |_| {
sycamore::futures::spawn_local(async move {
let monitor = window::primary_monitor().await;
log::debug!("{:?}", monitor);
});
};
let get_all_monitors = |_| {
sycamore::futures::spawn_local(async move {
let monitors = window::available_monitors().await.collect::<Vec<_>>();
log::debug!("{:?}", monitors);
});
};
view! { cx,
div {
button(class="btn",id="get_name",on:click=get_current) {
"Get Current Window"
}
button(class="btn",id="get_version",on:click=get_all) {
"Get All Windows"
}
}
div {
button(class="btn",id="get_tauri_version",on:click=get_current_monitor) {
"Get Current Monitor"
}
button(class="btn",id="get_tauri_version",on:click=get_primary_monitor) {
"Get Primary Monitor"
}
button(class="btn",id="get_tauri_version",on:click=get_all_monitors) {
"Get All Monitors"
}
}
}
}