feat: add window api

This commit is contained in:
mrxiaozhuox committed 2022-02-10 13:47:45 +08:00
1 parent 6eaad850ee
commit f28fb7165a
2 files changed
+30 -5

No files matched your search

+12 -2
View File
@@ -58,11 +58,21 @@ impl DesktopContext {
let _ = self.proxy.send_event(UserWindowEvent::FocusWindow); let _ = self.proxy.send_event(UserWindowEvent::FocusWindow);
} }
/// set resizable state
pub fn resizable(&self, resizable: bool) {
let _ = self.proxy.send_event(UserWindowEvent::Resizable(resizable));
}
/// set window title /// set window title
pub fn title(&self, title: &str) { pub fn set_title(&self, title: &str) {
let _ = self let _ = self
.proxy .proxy
.send_event(UserWindowEvent::Title(String::from(title))); .send_event(UserWindowEvent::SetTitle(String::from(title)));
}
/// hide the menu
pub fn hide_menu(&self) {
let _ = self.proxy.send_event(UserWindowEvent::HideMenu);
} }
} }
+18 -3
View File
@@ -321,12 +321,25 @@ pub fn launch_with_props<P: 'static + Send>(
window.set_focus(); window.set_focus();
} }
} }
UserWindowEvent::Title(content) => {
UserWindowEvent::SetTitle(content) => {
for webview in desktop.webviews.values() { for webview in desktop.webviews.values() {
let window = webview.window(); let window = webview.window();
window.set_title(&content); window.set_title(&content);
} }
} }
UserWindowEvent::Resizable(state) => {
for webview in desktop.webviews.values() {
let window = webview.window();
window.set_resizable(state);
}
}
UserWindowEvent::HideMenu => {
for webview in desktop.webviews.values() {
let window = webview.window();
window.hide_menu();
}
}
} }
} }
Event::MainEventsCleared => {} Event::MainEventsCleared => {}
@@ -344,10 +357,12 @@ pub enum UserWindowEvent {
DragWindow, DragWindow,
CloseWindow, CloseWindow,
FocusWindow, FocusWindow,
Title(String),
Minimize(bool), Minimize(bool),
Maximize(bool), Maximize(bool),
Resizable(bool),
SetTitle(String),
HideMenu,
} }
pub struct DesktopController { pub struct DesktopController {