Skip to content

Commit

Permalink
chore(deps): update wry to 0.14, tao to 0.7 (#3790)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog committed Mar 28, 2022
1 parent 8b807e0 commit 5fb7433
Show file tree
Hide file tree
Showing 6 changed files with 148 additions and 40 deletions.
7 changes: 7 additions & 0 deletions .changes/menuitem-about-refactor.md
@@ -0,0 +1,7 @@
---
"tauri": patch
"tauri-runtime-wry": minor
"tauri-runtime": minor
---

**Breaking change:** The `MenuItem::About` variant is now associated with a tuple value `(String, AboutMetadata)`.
6 changes: 6 additions & 0 deletions .changes/update-wry.md
@@ -0,0 +1,6 @@
---
"tauri": patch
"tauri-runtime-wry": minor
---

Update `wry` to `0.14` and `tao` to `0.7`.
4 changes: 2 additions & 2 deletions core/tauri-runtime-wry/Cargo.toml
Expand Up @@ -13,7 +13,7 @@ exclude = [ ".license_template", "CHANGELOG.md", "/target" ]
readme = "README.md"

[dependencies]
wry = { version = "0.13.3", default-features = false, features = [ "file-drop", "protocol" ] }
wry = { version = "0.14", default-features = false, features = [ "file-drop", "protocol" ] }
tauri-runtime = { version = "0.3.3", path = "../tauri-runtime" }
tauri-utils = { version = "1.0.0-rc.3", path = "../tauri-utils" }
uuid = { version = "0.8.2", features = [ "v4" ] }
Expand All @@ -31,7 +31,7 @@ gtk = { version = "0.15", features = [ "v3_20" ] }

[features]
dox = [ "wry/dox" ]
devtools = [ "wry/devtool", "tauri-runtime/devtools" ]
devtools = [ "wry/devtools", "tauri-runtime/devtools" ]
system-tray = [ "wry/tray", "tauri-runtime/system-tray" ]
macos-private-api = [
"wry/fullscreen",
Expand Down
89 changes: 54 additions & 35 deletions core/tauri-runtime-wry/src/lib.rs
Expand Up @@ -9,7 +9,7 @@ use tauri_runtime::{
Request as HttpRequest, RequestParts as HttpRequestParts, Response as HttpResponse,
ResponseParts as HttpResponseParts,
},
menu::{CustomMenuItem, Menu, MenuEntry, MenuHash, MenuId, MenuItem, MenuUpdate},
menu::{AboutMetadata, CustomMenuItem, Menu, MenuEntry, MenuHash, MenuId, MenuItem, MenuUpdate},
monitor::Monitor,
webview::{WebviewIpcHandler, WindowBuilder, WindowBuilderBase},
window::{
Expand Down Expand Up @@ -55,8 +55,9 @@ use wry::{
},
global_shortcut::{GlobalShortcut, ShortcutManager as WryShortcutManager},
menu::{
CustomMenuItem as WryCustomMenuItem, MenuBar, MenuId as WryMenuId, MenuItem as WryMenuItem,
MenuItemAttributes as WryMenuItemAttributes, MenuType,
AboutMetadata as WryAboutMetadata, CustomMenuItem as WryCustomMenuItem, MenuBar,
MenuId as WryMenuId, MenuItem as WryMenuItem, MenuItemAttributes as WryMenuItemAttributes,
MenuType,
},
monitor::MonitorHandle,
window::{Fullscreen, Icon as WryWindowIcon, UserAttentionType as WryUserAttentionType},
Expand Down Expand Up @@ -331,12 +332,31 @@ impl<'a> From<&'a CustomMenuItem> for MenuItemAttributesWrapper<'a> {
}
}

pub struct AboutMetadataWrapper(pub WryAboutMetadata);

impl From<AboutMetadata> for AboutMetadataWrapper {
fn from(metadata: AboutMetadata) -> Self {
Self(WryAboutMetadata {
version: metadata.version,
authors: metadata.authors,
comments: metadata.comments,
copyright: metadata.copyright,
license: metadata.license,
website: metadata.website,
website_label: metadata.website_label,
})
}
}

pub struct MenuItemWrapper(pub WryMenuItem);

impl From<MenuItem> for MenuItemWrapper {
fn from(item: MenuItem) -> Self {
match item {
MenuItem::About(v) => Self(WryMenuItem::About(v)),
MenuItem::About(name, metadata) => Self(WryMenuItem::About(
name,
AboutMetadataWrapper::from(metadata).0,
)),
MenuItem::Hide => Self(WryMenuItem::Hide),
MenuItem::Services => Self(WryMenuItem::Services),
MenuItem::HideOthers => Self(WryMenuItem::HideOthers),
Expand Down Expand Up @@ -1979,7 +1999,7 @@ fn handle_user_message<T: UserEvent>(
#[cfg(any(debug_assertions, feature = "devtools"))]
WindowMessage::OpenDevTools => {
if let WindowHandle::Webview(w) = &webview.inner {
w.devtool();
w.open_devtools();
}
}
// Getters
Expand Down Expand Up @@ -2731,7 +2751,7 @@ fn create_webview<T: UserEvent>(

#[cfg(any(debug_assertions, feature = "devtools"))]
{
webview_builder = webview_builder.with_dev_tool(true);
webview_builder = webview_builder.with_devtools(true);
}

let webview = webview_builder
Expand All @@ -2743,36 +2763,35 @@ fn create_webview<T: UserEvent>(

#[cfg(windows)]
{
if let Some(controller) = webview.controller() {
let proxy_ = proxy.clone();
let mut token = EventRegistrationToken::default();
unsafe {
controller.GotFocus(
FocusChangedEventHandler::create(Box::new(move |_, _| {
let _ = proxy_.send_event(Message::Webview(
window_id,
WebviewMessage::WebviewEvent(WebviewEvent::Focused(true)),
));
Ok(())
})),
&mut token,
)
}
.unwrap();
unsafe {
controller.LostFocus(
FocusChangedEventHandler::create(Box::new(move |_, _| {
let _ = proxy.send_event(Message::Webview(
window_id,
WebviewMessage::WebviewEvent(WebviewEvent::Focused(false)),
));
Ok(())
})),
&mut token,
)
}
.unwrap();
let controller = webview.controller();
let proxy_ = proxy.clone();
let mut token = EventRegistrationToken::default();
unsafe {
controller.GotFocus(
FocusChangedEventHandler::create(Box::new(move |_, _| {
let _ = proxy_.send_event(Message::Webview(
window_id,
WebviewMessage::WebviewEvent(WebviewEvent::Focused(true)),
));
Ok(())
})),
&mut token,
)
}
.unwrap();
unsafe {
controller.LostFocus(
FocusChangedEventHandler::create(Box::new(move |_, _| {
let _ = proxy.send_event(Message::Webview(
window_id,
WebviewMessage::WebviewEvent(WebviewEvent::Focused(false)),
));
Ok(())
})),
&mut token,
)
}
.unwrap();
}

Ok(WindowWrapper {
Expand Down
80 changes: 78 additions & 2 deletions core/tauri-runtime/src/menu.rs
Expand Up @@ -396,19 +396,95 @@ impl From<Submenu> for MenuEntry {
}
}

/// Application metadata for the [`MenuItem::About`] action.
///
/// ## Platform-specific
///
/// - **Windows / macOS / Android / iOS:** The metadata is ignored on these platforms.
#[derive(Debug, Clone, Default)]
#[non_exhaustive]
pub struct AboutMetadata {
/// The application name.
pub version: Option<String>,
/// The authors of the application.
pub authors: Option<Vec<String>>,
/// Application comments.
pub comments: Option<String>,
/// The copyright of the application.
pub copyright: Option<String>,
/// The license of the application.
pub license: Option<String>,
/// The application website.
pub website: Option<String>,
/// The website label.
pub website_label: Option<String>,
}

impl AboutMetadata {
/// Creates the default metadata for the [`MenuItem::About`] action, which is just empty.
pub fn new() -> Self {
Default::default()
}

/// Defines the application version.
pub fn version(mut self, version: String) -> Self {
self.version.replace(version);
self
}

/// Defines the application authors.
pub fn authors(mut self, authors: Vec<String>) -> Self {
self.authors.replace(authors);
self
}

/// Defines the application comments.
pub fn comments(mut self, comments: String) -> Self {
self.comments.replace(comments);
self
}

/// Defines the application copyright.
pub fn copyright(mut self, copyright: String) -> Self {
self.copyright.replace(copyright);
self
}

/// Defines the application license.
pub fn license(mut self, license: String) -> Self {
self.license.replace(license);
self
}

/// Defines the application version.
pub fn website(mut self, website: String) -> Self {
self.website.replace(website);
self
}

/// Defines the application version.
pub fn website_label(mut self, website_label: String) -> Self {
self.website_label.replace(website_label);
self
}
}

/// A menu item, bound to a pre-defined action or `Custom` emit an event. Note that status bar only
/// supports `Custom` menu item variants. And on the menu bar, some platforms might not support some
/// of the variants. Unsupported variant will be no-op on such platform.
#[derive(Debug, Clone)]
#[non_exhaustive]
pub enum MenuItem {
/// Shows a standard "About" item
/// Shows a standard "About" item.
///
/// The first value is the application name, and the second is its metadata.
///
/// ## Platform-specific
///
/// - **Windows / Android / iOS:** Unsupported
/// - **Linux:** The metadata is only applied on Linux
///
About(String),
About(String, AboutMetadata),

/// A standard "hide the app" menu item.
///
Expand Down
2 changes: 1 addition & 1 deletion core/tauri/src/lib.rs
Expand Up @@ -197,7 +197,7 @@ pub use {
pub use {
self::app::WindowMenuEvent,
self::event::{Event, EventHandler},
self::runtime::menu::{CustomMenuItem, Menu, MenuEntry, MenuItem, Submenu},
self::runtime::menu::{AboutMetadata, CustomMenuItem, Menu, MenuEntry, MenuItem, Submenu},
self::window::menu::MenuEvent,
};
pub use {
Expand Down

0 comments on commit 5fb7433

Please sign in to comment.