Merge pull request #180 from mrxiaozhuox/borderless-frame

Add support for desktop context, borderless frames, minimize, maximize, and other window-related goodies through the imperative `use_window` hook.
This commit is contained in:
Jonathan Kelley authored and GitHub committed 2022-01-31 19:53:27 -05:00
commit 0c0f638c47
4 files changed
+143 -89

No files matched your search

+48
View File
@@ -51,10 +51,13 @@
//! Make sure to read the [Dioxus Guide](https://dioxuslabs.com/guide) if you already haven't!
pub mod cfg;
pub mod desktop_context;
pub mod escape;
pub mod events;
use cfg::DesktopConfig;
pub use desktop_context::use_window;
use desktop_context::DesktopContext;
use dioxus_core::*;
use std::{
collections::{HashMap, VecDeque},
@@ -283,6 +286,41 @@ pub fn launch_with_props<P: 'static + Send>(
//
match _evt {
UserWindowEvent::Update => desktop.try_load_ready_webviews(),
UserWindowEvent::DragWindow => {
// this loop just run once, because dioxus-desktop is unsupport multi-window.
for webview in desktop.webviews.values() {
let window = webview.window();
// start to drag the window.
// if the drag_window have any err. we don't do anything.
let _ = window.drag_window();
}
}
UserWindowEvent::CloseWindow => {
// close window
*control_flow = ControlFlow::Exit;
}
UserWindowEvent::Minimize(state) => {
// this loop just run once, because dioxus-desktop is unsupport multi-window.
for webview in desktop.webviews.values() {
let window = webview.window();
// change window minimized state.
window.set_minimized(state);
}
}
UserWindowEvent::Maximize(state) => {
// this loop just run once, because dioxus-desktop is unsupport multi-window.
for webview in desktop.webviews.values() {
let window = webview.window();
// change window maximized state.
window.set_maximized(state);
}
}
UserWindowEvent::FocusWindow => {
for webview in desktop.webviews.values() {
let window = webview.window();
window.set_focus();
}
}
}
}
Event::MainEventsCleared => {}
@@ -297,6 +335,11 @@ pub fn launch_with_props<P: 'static + Send>(
pub enum UserWindowEvent {
Update,
DragWindow,
CloseWindow,
FocusWindow,
Minimize(bool),
Maximize(bool),
}
pub struct DesktopController {
@@ -323,6 +366,7 @@ impl DesktopController {
let return_sender = sender.clone();
let proxy = evt.clone();
let desktop_context_proxy = proxy.clone();
std::thread::spawn(move || {
// We create the runtime as multithreaded, so you can still "spawn" onto multiple threads
let runtime = tokio::runtime::Builder::new_multi_thread()
@@ -334,6 +378,10 @@ impl DesktopController {
let mut dom =
VirtualDom::new_with_props_and_scheduler(root, props, (sender, receiver));
let window_context = DesktopContext::new(desktop_context_proxy);
dom.base_scope().provide_context(window_context);
let edits = dom.rebuild();
edit_queue