From 169028705dc5b64f33a880d3b7bb845d44cf882f Mon Sep 17 00:00:00 2001 From: mrxiaozhuox Date: Mon, 31 Jan 2022 00:33:14 +0800 Subject: [PATCH 1/8] feat: add `DesktopContext` --- examples/borderless.rs | 21 +++++ packages/desktop/src/desktop_context.rs | 110 ++++-------------------- packages/desktop/src/lib.rs | 31 +++++++ 3 files changed, 71 insertions(+), 91 deletions(-) create mode 100644 examples/borderless.rs diff --git a/examples/borderless.rs b/examples/borderless.rs new file mode 100644 index 000000000..18bbbb80b --- /dev/null +++ b/examples/borderless.rs @@ -0,0 +1,21 @@ +use dioxus::prelude::*; +use dioxus_desktop::desktop_context::DesktopContext; + +fn main() { + dioxus::desktop::launch_cfg(app, |cfg| { + cfg.with_window(|w| { + w.with_title("BorderLess Demo") + .with_decorations(false) + }) + }); +} + +fn app (cx: Scope) -> Element { + let desktop = cx.consume_context::().unwrap(); + cx.render(rsx!( + div { + style: "background-color: black; height: 20px; width: 100%", + onmousedown: move |_| desktop.drag_window(), + } + )) +} \ No newline at end of file diff --git a/packages/desktop/src/desktop_context.rs b/packages/desktop/src/desktop_context.rs index 48c82f5a8..3a48879c0 100644 --- a/packages/desktop/src/desktop_context.rs +++ b/packages/desktop/src/desktop_context.rs @@ -1,100 +1,28 @@ -use std::cell::RefCell; +use wry::application::event_loop::EventLoopProxy; -use dioxus::prelude::Scope; -use dioxus_core as dioxus; -use dioxus_core::{Context, Element, LazyNodes, NodeFactory, Properties}; -use dioxus_core_macro::Props; +use crate::UserWindowEvent; -/* -This module provides a set of Dioxus components to easily manage windows, tabs, etc. +type ProxyType = EventLoopProxy; -Windows can be created anywhere in the tree, making them very flexible for things like modals, etc. - -*/ -pub struct DesktopContext {} +#[derive(Clone)] +pub struct DesktopContext { + proxy: ProxyType, +} impl DesktopContext { - fn add_window(&mut self) { - // + pub fn new(proxy: ProxyType) -> Self { + Self { proxy } } - fn close_window(&mut self) { - // + + pub fn drag_window(&self) { + let _ = self.proxy.send_event(UserWindowEvent::DragWindow); } -} -enum WindowHandlers { - Resized(Box), - Moved(Box), - CloseRequested(Box), - Destroyed(Box), - DroppedFile(Box), - HoveredFile(Box), - HoverFileCancelled(Box), - ReceivedTimeText(Box), - Focused(Box), -} + pub fn minimized(&self, minimized: bool) { + let _ = self.proxy.send_event(UserWindowEvent::Minimized(minimized)); + } -#[derive(Props)] -pub struct WebviewWindowProps<'a> { - onclose: &'a dyn FnMut(()), - - onopen: &'a dyn FnMut(()), - - /// focuse me - onfocused: &'a dyn FnMut(()), - - children: Element, -} - -/// A handle to a -/// -/// -/// -/// -/// -/// -/// -/// -/// -pub fn WebviewWindow(cx: Scope) -> Element { - let dtcx = cx.consume_state::>()?; - - cx.use_hook(|_| {}); - - // render the children directly - todo!() - // cx.render(LazyNodes::new(move |f: NodeFactory| { - // f.fragment_from_iter(cx.children()) - // })) -} - -pub struct WindowHandle {} - -/// Get a handle to the current window from inside a component -pub fn use_current_window(cx: Scope) -> Option { - todo!() -} - -#[test] -fn syntax_works() { - use dioxus_core as dioxus; - use dioxus_core::prelude::*; - use dioxus_core_macro::*; - use dioxus_hooks::*; - use dioxus_html as dioxus_elements; - - static App: Component = |cx| { - cx.render(rsx! { - // left window - WebviewWindow { - onclose: move |evt| {} - onopen: move |evt| {} - onfocused: move |evt| {} - - div { - - } - } - }) - }; -} + pub fn maximized(&self, maximized: bool) { + let _ = self.proxy.send_event(UserWindowEvent::Maximized(maximized)); + } +} \ No newline at end of file diff --git a/packages/desktop/src/lib.rs b/packages/desktop/src/lib.rs index 36b017077..b27ef7742 100644 --- a/packages/desktop/src/lib.rs +++ b/packages/desktop/src/lib.rs @@ -51,10 +51,12 @@ //! 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; +use desktop_context::DesktopContext; use dioxus_core::*; use std::{ collections::{HashMap, VecDeque}, @@ -282,6 +284,27 @@ pub fn launch_with_props( // 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(); + window.drag_window().unwrap(); + } + } + UserWindowEvent::Minimized(state) => { + // this loop just run once, because dioxus-desktop is unsupport multi-window. + for webview in desktop.webviews.values() { + let window = webview.window(); + window.set_minimized(state); + } + } + UserWindowEvent::Maximized(state) => { + // this loop just run once, because dioxus-desktop is unsupport multi-window. + for webview in desktop.webviews.values() { + let window = webview.window(); + window.set_maximized(state); + } + } } } Event::MainEventsCleared => {} @@ -296,6 +319,9 @@ pub fn launch_with_props( pub enum UserWindowEvent { Update, + DragWindow, + Minimized(bool), + Maximized(bool), } pub struct DesktopController { @@ -322,6 +348,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() @@ -333,6 +360,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 From 31a2f8f63abbbcc39c1ce23fb0d47d8e2e010f6f Mon Sep 17 00:00:00 2001 From: mrxiaozhuox Date: Mon, 31 Jan 2022 01:06:43 +0800 Subject: [PATCH 2/8] feat: add `DesktopContext` --- packages/desktop/src/desktop_context.rs | 31 +++++++++++++++++++++---- packages/desktop/src/lib.rs | 19 +++++++++++---- 2 files changed, 41 insertions(+), 9 deletions(-) diff --git a/packages/desktop/src/desktop_context.rs b/packages/desktop/src/desktop_context.rs index 3a48879c0..577e33c54 100644 --- a/packages/desktop/src/desktop_context.rs +++ b/packages/desktop/src/desktop_context.rs @@ -4,25 +4,48 @@ use crate::UserWindowEvent; type ProxyType = EventLoopProxy; +/// Desktop-Window handle api context +/// +/// you can use this context control some window event +/// +/// you can use `cx.consume_context::` to get this context +/// +/// ```rust +/// let desktop = cx.consume_context::().unwrap(); +/// ``` #[derive(Clone)] pub struct DesktopContext { proxy: ProxyType, } impl DesktopContext { + pub fn new(proxy: ProxyType) -> Self { Self { proxy } } + /// trigger the drag-window event + /// + /// Moves the window with the left mouse button until the button is released. + /// + /// you need use it in `onmousedown` event: + /// ```rust + /// onmousedown: move |_| { desktop.drag_window(); } + /// ``` pub fn drag_window(&self) { let _ = self.proxy.send_event(UserWindowEvent::DragWindow); } - pub fn minimized(&self, minimized: bool) { - let _ = self.proxy.send_event(UserWindowEvent::Minimized(minimized)); + pub fn minimize(&self, minimized: bool) { + let _ = self.proxy.send_event(UserWindowEvent::Minimize(minimized)); } - pub fn maximized(&self, maximized: bool) { - let _ = self.proxy.send_event(UserWindowEvent::Maximized(maximized)); + pub fn maximize(&self, maximized: bool) { + let _ = self.proxy.send_event(UserWindowEvent::Maximize(maximized)); } + + pub fn close(&self) { + let _ = self.proxy.send_event(UserWindowEvent::CloseWindow); + } + } \ No newline at end of file diff --git a/packages/desktop/src/lib.rs b/packages/desktop/src/lib.rs index b27ef7742..45314df34 100644 --- a/packages/desktop/src/lib.rs +++ b/packages/desktop/src/lib.rs @@ -288,20 +288,28 @@ pub fn launch_with_props( // this loop just run once, because dioxus-desktop is unsupport multi-window. for webview in desktop.webviews.values() { let window = webview.window(); - window.drag_window().unwrap(); + // start to drag the window. + // if the drag_window have any err. we don't do anything. + let _ = window.drag_window(); } } - UserWindowEvent::Minimized(state) => { + 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::Maximized(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); } } @@ -320,8 +328,9 @@ pub fn launch_with_props( pub enum UserWindowEvent { Update, DragWindow, - Minimized(bool), - Maximized(bool), + CloseWindow, + Minimize(bool), + Maximize(bool), } pub struct DesktopController { From a0ffe66a371744f5a38697f06e6fee89f2db2809 Mon Sep 17 00:00:00 2001 From: mrxiaozhuox Date: Mon, 31 Jan 2022 09:47:09 +0800 Subject: [PATCH 3/8] feat: add `borderless` example --- .gitignore | 1 + examples/borderless.rs | 47 +++++++++++++++++++------ packages/desktop/src/desktop_context.rs | 5 ++- 3 files changed, 42 insertions(+), 11 deletions(-) diff --git a/.gitignore b/.gitignore index 9534dc207..9df7e9f93 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ /target +/dist Cargo.lock .DS_Store diff --git a/examples/borderless.rs b/examples/borderless.rs index 18bbbb80b..7f85ff22d 100644 --- a/examples/borderless.rs +++ b/examples/borderless.rs @@ -1,21 +1,48 @@ -use dioxus::prelude::*; +use dioxus::{events::onmousedown, prelude::*}; use dioxus_desktop::desktop_context::DesktopContext; fn main() { dioxus::desktop::launch_cfg(app, |cfg| { - cfg.with_window(|w| { - w.with_title("BorderLess Demo") - .with_decorations(false) - }) + cfg.with_window(|w| w.with_title("BorderLess Demo").with_decorations(false)) }); } -fn app (cx: Scope) -> Element { +fn app(cx: Scope) -> Element { let desktop = cx.consume_context::().unwrap(); + + let drag = desktop.clone(); + let close = desktop.clone(); + let min = desktop.clone(); + cx.render(rsx!( - div { - style: "background-color: black; height: 20px; width: 100%", - onmousedown: move |_| desktop.drag_window(), + link { href:"https://unpkg.com/tailwindcss@^2/dist/tailwind.min.css", rel:"stylesheet" } + header { + class: "text-gray-400 bg-gray-900 body-font", + onmousedown: move |_| drag.drag_window(), + div { + class: "container mx-auto flex flex-wrap p-5 flex-col md:flex-row items-center", + a { class: "flex title-font font-medium items-center text-white mb-4 md:mb-0", + span { class: "ml-3 text-xl", "Dioxus"} + } + nav { class: "md:ml-auto flex flex-wrap items-center text-base justify-center", + // a { class: "mr-5 hover:text-white", "First Link"} + // a { class: "mr-5 hover:text-white", "Second Link"} + // a { class: "mr-5 hover:text-white", "Third Link"} + // a { class: "mr-5 hover:text-white", "Fourth Link"} + } + button { + class: "inline-flex items-center bg-gray-800 border-0 py-1 px-3 focus:outline-none hover:bg-gray-700 rounded text-base mt-4 md:mt-0", + onmousedown: |evt| evt.cancel_bubble(), + onclick: move |_| min.minimize(true), + "Minimize" + } + button { + class: "inline-flex items-center bg-gray-800 border-0 py-1 px-3 focus:outline-none hover:bg-gray-700 rounded text-base mt-4 md:mt-0", + onmousedown: |evt| evt.cancel_bubble(), + onclick: move |_| close.close(), + "Close" + } + } } )) -} \ No newline at end of file +} diff --git a/packages/desktop/src/desktop_context.rs b/packages/desktop/src/desktop_context.rs index 577e33c54..456dba1c1 100644 --- a/packages/desktop/src/desktop_context.rs +++ b/packages/desktop/src/desktop_context.rs @@ -20,7 +20,7 @@ pub struct DesktopContext { impl DesktopContext { - pub fn new(proxy: ProxyType) -> Self { + pub(crate) fn new(proxy: ProxyType) -> Self { Self { proxy } } @@ -36,14 +36,17 @@ impl DesktopContext { let _ = self.proxy.send_event(UserWindowEvent::DragWindow); } + /// set window minimize state pub fn minimize(&self, minimized: bool) { let _ = self.proxy.send_event(UserWindowEvent::Minimize(minimized)); } + /// set window maximize state pub fn maximize(&self, maximized: bool) { let _ = self.proxy.send_event(UserWindowEvent::Maximize(maximized)); } + /// close window pub fn close(&self) { let _ = self.proxy.send_event(UserWindowEvent::CloseWindow); } From e4eb982a367ed588b370e4a28e8cf2a94d0f4b24 Mon Sep 17 00:00:00 2001 From: mrxiaozhuox Date: Mon, 31 Jan 2022 10:11:58 +0800 Subject: [PATCH 4/8] fix: format code --- examples/borderless.rs | 14 ++++---------- packages/desktop/src/desktop_context.rs | 14 ++++++-------- 2 files changed, 10 insertions(+), 18 deletions(-) diff --git a/examples/borderless.rs b/examples/borderless.rs index 7f85ff22d..e6cd4eda1 100644 --- a/examples/borderless.rs +++ b/examples/borderless.rs @@ -1,4 +1,4 @@ -use dioxus::{events::onmousedown, prelude::*}; +use dioxus::prelude::*; use dioxus_desktop::desktop_context::DesktopContext; fn main() { @@ -12,11 +12,10 @@ fn app(cx: Scope) -> Element { let drag = desktop.clone(); let close = desktop.clone(); - let min = desktop.clone(); cx.render(rsx!( link { href:"https://unpkg.com/tailwindcss@^2/dist/tailwind.min.css", rel:"stylesheet" } - header { + header { class: "text-gray-400 bg-gray-900 body-font", onmousedown: move |_| drag.drag_window(), div { @@ -24,16 +23,11 @@ fn app(cx: Scope) -> Element { a { class: "flex title-font font-medium items-center text-white mb-4 md:mb-0", span { class: "ml-3 text-xl", "Dioxus"} } - nav { class: "md:ml-auto flex flex-wrap items-center text-base justify-center", - // a { class: "mr-5 hover:text-white", "First Link"} - // a { class: "mr-5 hover:text-white", "Second Link"} - // a { class: "mr-5 hover:text-white", "Third Link"} - // a { class: "mr-5 hover:text-white", "Fourth Link"} - } + nav { class: "md:ml-auto flex flex-wrap items-center text-base justify-center" } button { class: "inline-flex items-center bg-gray-800 border-0 py-1 px-3 focus:outline-none hover:bg-gray-700 rounded text-base mt-4 md:mt-0", onmousedown: |evt| evt.cancel_bubble(), - onclick: move |_| min.minimize(true), + onclick: move |_| desktop.minimize(true), "Minimize" } button { diff --git a/packages/desktop/src/desktop_context.rs b/packages/desktop/src/desktop_context.rs index 456dba1c1..0a1fa2b02 100644 --- a/packages/desktop/src/desktop_context.rs +++ b/packages/desktop/src/desktop_context.rs @@ -5,11 +5,11 @@ use crate::UserWindowEvent; type ProxyType = EventLoopProxy; /// Desktop-Window handle api context -/// +/// /// you can use this context control some window event -/// +/// /// you can use `cx.consume_context::` to get this context -/// +/// /// ```rust /// let desktop = cx.consume_context::().unwrap(); /// ``` @@ -19,15 +19,14 @@ pub struct DesktopContext { } impl DesktopContext { - pub(crate) fn new(proxy: ProxyType) -> Self { Self { proxy } } /// trigger the drag-window event - /// + /// /// Moves the window with the left mouse button until the button is released. - /// + /// /// you need use it in `onmousedown` event: /// ```rust /// onmousedown: move |_| { desktop.drag_window(); } @@ -50,5 +49,4 @@ impl DesktopContext { pub fn close(&self) { let _ = self.proxy.send_event(UserWindowEvent::CloseWindow); } - -} \ No newline at end of file +} From 366cf758870f6bc54c36acfecfbda261ed28bebf Mon Sep 17 00:00:00 2001 From: mrxiaozhuox Date: Mon, 31 Jan 2022 19:39:44 +0800 Subject: [PATCH 5/8] feat: add `use_desktop_context` hook --- examples/borderless.rs | 10 +++------- packages/desktop/src/desktop_context.rs | 10 ++++++++++ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/examples/borderless.rs b/examples/borderless.rs index e6cd4eda1..15756503e 100644 --- a/examples/borderless.rs +++ b/examples/borderless.rs @@ -1,5 +1,4 @@ use dioxus::prelude::*; -use dioxus_desktop::desktop_context::DesktopContext; fn main() { dioxus::desktop::launch_cfg(app, |cfg| { @@ -8,16 +7,13 @@ fn main() { } fn app(cx: Scope) -> Element { - let desktop = cx.consume_context::().unwrap(); - - let drag = desktop.clone(); - let close = desktop.clone(); + let desktop = dioxus::desktop::desktop_context::use_desktop_context(&cx); cx.render(rsx!( link { href:"https://unpkg.com/tailwindcss@^2/dist/tailwind.min.css", rel:"stylesheet" } header { class: "text-gray-400 bg-gray-900 body-font", - onmousedown: move |_| drag.drag_window(), + onmousedown: move |_| desktop.drag_window(), div { class: "container mx-auto flex flex-wrap p-5 flex-col md:flex-row items-center", a { class: "flex title-font font-medium items-center text-white mb-4 md:mb-0", @@ -33,7 +29,7 @@ fn app(cx: Scope) -> Element { button { class: "inline-flex items-center bg-gray-800 border-0 py-1 px-3 focus:outline-none hover:bg-gray-700 rounded text-base mt-4 md:mt-0", onmousedown: |evt| evt.cancel_bubble(), - onclick: move |_| close.close(), + onclick: move |_| desktop.close(), "Close" } } diff --git a/packages/desktop/src/desktop_context.rs b/packages/desktop/src/desktop_context.rs index 0a1fa2b02..0e2fbdddd 100644 --- a/packages/desktop/src/desktop_context.rs +++ b/packages/desktop/src/desktop_context.rs @@ -1,3 +1,6 @@ +use std::rc::Rc; + +use dioxus_core::ScopeState; use wry::application::event_loop::EventLoopProxy; use crate::UserWindowEvent; @@ -50,3 +53,10 @@ impl DesktopContext { let _ = self.proxy.send_event(UserWindowEvent::CloseWindow); } } + +/// use this function can get the `DesktopContext` context. +pub fn use_desktop_context(cx: &ScopeState) -> &Rc { + cx.use_hook(|_| cx.consume_context::()) + .as_ref() + .unwrap() +} From 7ca92be015090ff2f4c44d778f10e97edcf90a92 Mon Sep 17 00:00:00 2001 From: mrxiaozhuox Date: Mon, 31 Jan 2022 19:44:40 +0800 Subject: [PATCH 6/8] feat: add `focus` api --- packages/desktop/src/desktop_context.rs | 5 +++++ packages/desktop/src/lib.rs | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/packages/desktop/src/desktop_context.rs b/packages/desktop/src/desktop_context.rs index 0e2fbdddd..a41712904 100644 --- a/packages/desktop/src/desktop_context.rs +++ b/packages/desktop/src/desktop_context.rs @@ -52,6 +52,11 @@ impl DesktopContext { pub fn close(&self) { let _ = self.proxy.send_event(UserWindowEvent::CloseWindow); } + + /// set window to focus + pub fn focus(&self) { + let _ = self.proxy.send_event(UserWindowEvent::FocusWindow); + } } /// use this function can get the `DesktopContext` context. diff --git a/packages/desktop/src/lib.rs b/packages/desktop/src/lib.rs index 45314df34..eb76ce63d 100644 --- a/packages/desktop/src/lib.rs +++ b/packages/desktop/src/lib.rs @@ -313,6 +313,12 @@ pub fn launch_with_props( window.set_maximized(state); } } + UserWindowEvent::FocusWindow => { + for webview in desktop.webviews.values() { + let window = webview.window(); + window.set_focus(); + } + } } } Event::MainEventsCleared => {} @@ -329,6 +335,7 @@ pub enum UserWindowEvent { Update, DragWindow, CloseWindow, + FocusWindow, Minimize(bool), Maximize(bool), } From f1fe8f1d2a02b53919ef0d107fca0f85619b89fc Mon Sep 17 00:00:00 2001 From: mrxiaozhuox Date: Tue, 1 Feb 2022 08:39:31 +0800 Subject: [PATCH 7/8] fix: change hooks name --- examples/borderless.rs | 8 ++++---- packages/desktop/src/desktop_context.rs | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/examples/borderless.rs b/examples/borderless.rs index 15756503e..2a1c007f2 100644 --- a/examples/borderless.rs +++ b/examples/borderless.rs @@ -7,13 +7,13 @@ fn main() { } fn app(cx: Scope) -> Element { - let desktop = dioxus::desktop::desktop_context::use_desktop_context(&cx); + let window = dioxus::desktop::desktop_context::use_window(&cx); cx.render(rsx!( link { href:"https://unpkg.com/tailwindcss@^2/dist/tailwind.min.css", rel:"stylesheet" } header { class: "text-gray-400 bg-gray-900 body-font", - onmousedown: move |_| desktop.drag_window(), + onmousedown: move |_| window.drag(), div { class: "container mx-auto flex flex-wrap p-5 flex-col md:flex-row items-center", a { class: "flex title-font font-medium items-center text-white mb-4 md:mb-0", @@ -23,13 +23,13 @@ fn app(cx: Scope) -> Element { button { class: "inline-flex items-center bg-gray-800 border-0 py-1 px-3 focus:outline-none hover:bg-gray-700 rounded text-base mt-4 md:mt-0", onmousedown: |evt| evt.cancel_bubble(), - onclick: move |_| desktop.minimize(true), + onclick: move |_| window.minimize(true), "Minimize" } button { class: "inline-flex items-center bg-gray-800 border-0 py-1 px-3 focus:outline-none hover:bg-gray-700 rounded text-base mt-4 md:mt-0", onmousedown: |evt| evt.cancel_bubble(), - onclick: move |_| desktop.close(), + onclick: move |_| window.close(), "Close" } } diff --git a/packages/desktop/src/desktop_context.rs b/packages/desktop/src/desktop_context.rs index a41712904..9c0404477 100644 --- a/packages/desktop/src/desktop_context.rs +++ b/packages/desktop/src/desktop_context.rs @@ -34,7 +34,7 @@ impl DesktopContext { /// ```rust /// onmousedown: move |_| { desktop.drag_window(); } /// ``` - pub fn drag_window(&self) { + pub fn drag(&self) { let _ = self.proxy.send_event(UserWindowEvent::DragWindow); } @@ -60,7 +60,7 @@ impl DesktopContext { } /// use this function can get the `DesktopContext` context. -pub fn use_desktop_context(cx: &ScopeState) -> &Rc { +pub fn use_window(cx: &ScopeState) -> &Rc { cx.use_hook(|_| cx.consume_context::()) .as_ref() .unwrap() From bead03596942089862b63d83e6d7514ddada946a Mon Sep 17 00:00:00 2001 From: mrxiaozhuox Date: Tue, 1 Feb 2022 08:43:54 +0800 Subject: [PATCH 8/8] feat: export `use_window` --- examples/borderless.rs | 2 +- packages/desktop/src/lib.rs | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/borderless.rs b/examples/borderless.rs index 2a1c007f2..d52e9fb5a 100644 --- a/examples/borderless.rs +++ b/examples/borderless.rs @@ -7,7 +7,7 @@ fn main() { } fn app(cx: Scope) -> Element { - let window = dioxus::desktop::desktop_context::use_window(&cx); + let window = dioxus::desktop::use_window(&cx); cx.render(rsx!( link { href:"https://unpkg.com/tailwindcss@^2/dist/tailwind.min.css", rel:"stylesheet" } diff --git a/packages/desktop/src/lib.rs b/packages/desktop/src/lib.rs index eb76ce63d..524e42da4 100644 --- a/packages/desktop/src/lib.rs +++ b/packages/desktop/src/lib.rs @@ -56,6 +56,7 @@ pub mod escape; pub mod events; use cfg::DesktopConfig; +pub use desktop_context::use_window; use desktop_context::DesktopContext; use dioxus_core::*; use std::{