diff --git a/.changes/011.md b/.changes/011.md new file mode 100644 index 000000000..9f8be81e7 --- /dev/null +++ b/.changes/011.md @@ -0,0 +1,5 @@ +--- +"wry": patch +--- + +Update tao to 0.11 diff --git a/Cargo.toml b/Cargo.toml index acf80acfe..43621021d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -40,7 +40,7 @@ serde = { version = "1.0", features = [ "derive" ] } serde_json = "1.0" thiserror = "1.0" url = "2.2" -tao = { version = "0.10", default-features = false, features = [ "serde" ] } +tao = { version = "0.11", default-features = false, features = [ "serde" ] } http = "0.2.7" [dev-dependencies] diff --git a/examples/README.md b/examples/README.md index 104d87845..e5bff2a59 100644 --- a/examples/README.md +++ b/examples/README.md @@ -12,6 +12,4 @@ Run the `cargo run --example ` to see how each example works. - `menu_bar`: uses a custom menu for the application in macOS and the Window and Linux/Windows. - `multi_window`: create the window dynamically even after the application is running. - `stream_range`: read the incoming header from the custom protocol and return part of the data. [RFC7233](https://httpwg.org/specs/rfc7233.html#header.range) -- `system_tray_no_menu`: open window on tray icon left click. -- `system_tray`: sample tray application with different behaviours. - `transparent`: transparent example that also show how to create a valid data URI. diff --git a/examples/icon.ico b/examples/icon.ico deleted file mode 100644 index 2a02a5347..000000000 Binary files a/examples/icon.ico and /dev/null differ diff --git a/examples/icon.png b/examples/icon.png deleted file mode 100644 index fb9287640..000000000 Binary files a/examples/icon.png and /dev/null differ diff --git a/examples/icon_blue.ico b/examples/icon_blue.ico deleted file mode 100644 index b39902404..000000000 Binary files a/examples/icon_blue.ico and /dev/null differ diff --git a/examples/icon_dark.png b/examples/icon_dark.png deleted file mode 100644 index 8161347ea..000000000 Binary files a/examples/icon_dark.png and /dev/null differ diff --git a/examples/system_tray.rs b/examples/system_tray.rs deleted file mode 100644 index ee44b8290..000000000 --- a/examples/system_tray.rs +++ /dev/null @@ -1,230 +0,0 @@ -// Copyright 2019-2021 Tauri Programme within The Commons Conservancy -// SPDX-License-Identifier: Apache-2.0 -// SPDX-License-Identifier: MIT - -#[cfg(any(target_os = "macos", target_os = "windows", target_os = "linux"))] -#[cfg(feature = "tray")] -fn main() -> wry::Result<()> { - use std::collections::HashMap; - #[cfg(target_os = "linux")] - use std::path::Path; - #[cfg(target_os = "macos")] - use wry::application::platform::macos::{ - ActivationPolicy, CustomMenuItemExtMacOS, EventLoopExtMacOS, NativeImage, - }; - #[cfg(target_os = "linux")] - use wry::application::platform::unix::WindowBuilderExtUnix; - #[cfg(target_os = "windows")] - use wry::application::platform::windows::WindowBuilderExtWindows; - use wry::{ - application::{ - accelerator::{Accelerator, SysMods}, - event::{Event, StartCause, WindowEvent}, - event_loop::{ControlFlow, EventLoop}, - global_shortcut::ShortcutManager, - keyboard::KeyCode, - menu::{ContextMenu, MenuItemAttributes, MenuType}, - system_tray::SystemTrayBuilder, - window::{WindowBuilder, WindowId}, - }, - http::ResponseBuilder, - webview::{WebView, WebViewBuilder}, - }; - - let index_html = r#" - - - - - - - - -

Welcome to WRY!

- - - "#; - - // Build our event loop - #[cfg(target_os = "macos")] - let mut event_loop = EventLoop::new(); - - #[cfg(not(target_os = "macos"))] - let event_loop = EventLoop::new(); - - // launch macos app without menu and without dock icon - // should be set at launch - #[cfg(target_os = "macos")] - event_loop.set_activation_policy(ActivationPolicy::Accessory); - - let mut webviews: HashMap = HashMap::new(); - - // Create global shortcut - let mut shortcut_manager = ShortcutManager::new(&event_loop); - // SysMods::CmdShift; Command + Shift on macOS, Ctrl + Shift on windows/linux - let my_accelerator = Accelerator::new(SysMods::CmdShift, KeyCode::Digit0); - let global_shortcut = shortcut_manager.register(my_accelerator.clone()).unwrap(); - - // Create sample menu item - let mut tray_menu = ContextMenu::new(); - let open_new_window = tray_menu.add_item(MenuItemAttributes::new("Open new window")); - // custom quit who take care to clean windows tray icon - let quit_item = tray_menu.add_item(MenuItemAttributes::new("Quit")); - - // set NativeImage for `Open new window` - #[cfg(target_os = "macos")] - open_new_window - .clone() - .set_native_image(NativeImage::StatusAvailable); - - // Windows require Vec ICO file - #[cfg(target_os = "windows")] - let icon = include_bytes!("icon.ico").to_vec(); - // macOS require Vec PNG file - #[cfg(target_os = "macos")] - let icon = include_bytes!("icon.png").to_vec(); - // Linux require Pathbuf to PNG file - #[cfg(target_os = "linux")] - let icon = Path::new(env!("CARGO_MANIFEST_DIR")).join("examples/icon.png"); - - // Windows require Vec ICO file - #[cfg(target_os = "windows")] - let new_icon = include_bytes!("icon_blue.ico").to_vec(); - // macOS require Vec PNG file - #[cfg(target_os = "macos")] - let new_icon = include_bytes!("icon_dark.png").to_vec(); - // Linux require Pathbuf to PNG file - #[cfg(target_os = "linux")] - let new_icon = Path::new(env!("CARGO_MANIFEST_DIR")).join("examples/icon_dark.png"); - - let mut system_tray = SystemTrayBuilder::new(icon.clone(), Some(tray_menu)) - .build(&event_loop) - .unwrap(); - - // launch WRY process - event_loop.run(move |event, event_loop, control_flow| { - *control_flow = ControlFlow::Wait; - - let mut create_window_or_focus = || { - // if we already have one webview, let's focus instead of opening - if !webviews.is_empty() { - for window in webviews.values() { - window.window().set_focus(); - } - return; - } - - // disable our global shortcut - shortcut_manager - .unregister(global_shortcut.clone()) - .unwrap(); - - // create our new window / webview instance - #[cfg(any(target_os = "windows", target_os = "linux"))] - let window_builder = WindowBuilder::new().with_skip_taskbar(true); - #[cfg(target_os = "macos")] - let window_builder = WindowBuilder::new(); - - let window = window_builder.build(event_loop).unwrap(); - - let id = window.id(); - - let webview = WebViewBuilder::new(window) - .unwrap() - .with_custom_protocol("wry.dev".into(), move |_request| { - ResponseBuilder::new() - .mimetype("text/html") - .body(index_html.as_bytes().into()) - }) - .with_url("wry.dev://") - .unwrap() - .build() - .unwrap(); - - webviews.insert(id, webview); - - // make sure open_new_window is mutable - let mut open_new_window = open_new_window.clone(); - // disable button - open_new_window.set_enabled(false); - // change title (text) - open_new_window.set_title("Window already open"); - // set checked - open_new_window.set_selected(true); - // update tray i con - system_tray.set_icon(new_icon.clone()); - // add macOS Native red dot - #[cfg(target_os = "macos")] - open_new_window.set_native_image(NativeImage::StatusUnavailable); - }; - - match event { - Event::NewEvents(StartCause::Init) => println!("Wry has started!"), - Event::WindowEvent { - event: WindowEvent::CloseRequested, - window_id, - .. - } => { - println!("Window {:?} has received the signal to close", window_id); - let mut open_new_window = open_new_window.clone(); - // Remove window from our hashmap - webviews.remove(&window_id); - // Modify our button's state - open_new_window.set_enabled(true); - // Reset text - open_new_window.set_title("Open new window"); - // Set selected - open_new_window.set_selected(false); - // Change tray icon - system_tray.set_icon(icon.clone()); - // re-active our global shortcut - shortcut_manager.register(my_accelerator.clone()).unwrap(); - // macOS have native image available that we can use in our menu-items - #[cfg(target_os = "macos")] - open_new_window.set_native_image(NativeImage::StatusAvailable); - } - // on Windows, habitually, we show the Window with left click - // and the menu is shown on right click - #[cfg(target_os = "windows")] - Event::TrayEvent { - event: tao::event::TrayEvent::LeftClick, - .. - } => create_window_or_focus(), - // Catch menu events - Event::MenuEvent { - menu_id, - // specify only context menu's - origin: MenuType::ContextMenu, - .. - } => { - // Click on Open new window or focus item - if menu_id == open_new_window.clone().id() { - create_window_or_focus(); - } - // click on `quit` item - if menu_id == quit_item.clone().id() { - // tell our app to close at the end of the loop. - *control_flow = ControlFlow::Exit; - } - println!("Clicked on {:?}", menu_id); - } - // catch global shortcut event and open window - Event::GlobalShortcutEvent(hotkey_id) if hotkey_id == my_accelerator.clone().id() => { - create_window_or_focus() - } - _ => (), - } - }); -} - -#[cfg(target_os = "ios")] -fn main() { - println!("This platform doesn't support system_tray."); -} - -// Tray feature flag disabled but can be available. -#[cfg(any(target_os = "windows", target_os = "linux", target_os = "macos"))] -#[cfg(not(feature = "tray"))] -fn main() { - println!("This platform doesn't have the `tray` feature enabled."); -} diff --git a/examples/system_tray_no_menu.rs b/examples/system_tray_no_menu.rs deleted file mode 100644 index 97d36c535..000000000 --- a/examples/system_tray_no_menu.rs +++ /dev/null @@ -1,198 +0,0 @@ -// Copyright 2019-2021 Tauri Programme within The Commons Conservancy -// SPDX-License-Identifier: Apache-2.0 -// SPDX-License-Identifier: MIT - -#[cfg(any(target_os = "macos", target_os = "windows", target_os = "linux"))] -#[cfg(feature = "tray")] -fn main() -> wry::Result<()> { - use std::collections::HashMap; - #[cfg(target_os = "linux")] - use std::path::Path; - #[cfg(target_os = "linux")] - use tao::menu::{ContextMenu, MenuItemAttributes}; - #[cfg(target_os = "macos")] - use wry::application::platform::macos::{ActivationPolicy, EventLoopExtMacOS}; - #[cfg(target_os = "linux")] - use wry::application::platform::unix::WindowBuilderExtUnix; - #[cfg(target_os = "windows")] - use wry::application::platform::windows::WindowBuilderExtWindows; - use wry::{ - application::{ - dpi::{LogicalSize, PhysicalPosition}, - event::{Event, Rectangle, StartCause, WindowEvent}, - event_loop::{ControlFlow, EventLoop}, - menu::MenuId, - system_tray::SystemTrayBuilder, - window::{WindowBuilder, WindowId}, - }, - http::ResponseBuilder, - webview::{WebView, WebViewBuilder}, - }; - - let index_html = r#" - - - - - - - - -

Welcome to WRY!

- - - "#; - - // Build our event loop - #[cfg(target_os = "macos")] - let mut event_loop = EventLoop::new(); - - #[cfg(not(target_os = "macos"))] - let event_loop = EventLoop::new(); - - // launch macos app without menu and without dock icon - // should be set at launch - #[cfg(target_os = "macos")] - event_loop.set_activation_policy(ActivationPolicy::Accessory); - - let mut webviews: HashMap = HashMap::new(); - - // Windows require Vec ICO file - #[cfg(target_os = "windows")] - let icon = include_bytes!("icon.ico").to_vec(); - // macOS require Vec PNG file - #[cfg(target_os = "macos")] - let icon = include_bytes!("icon.png").to_vec(); - // Linux require Pathbuf to PNG file - #[cfg(target_os = "linux")] - let icon = Path::new(env!("CARGO_MANIFEST_DIR")).join("examples/icon.png"); - - // linux require a menu so let's add only a open button - let open_menu_id = MenuId::new("open_menu"); - let quit_menu_id = MenuId::new("quit_menu"); - #[cfg(target_os = "linux")] - { - let mut menu = ContextMenu::new(); - menu.add_item(MenuItemAttributes::new("Open").with_id(open_menu_id)); - menu.add_item(MenuItemAttributes::new("Quit").with_id(quit_menu_id)); - let _system_tray = SystemTrayBuilder::new(icon, Some(menu)) - .build(&event_loop) - .unwrap(); - } - - #[cfg(any(target_os = "macos", target_os = "windows"))] - let _system_tray = SystemTrayBuilder::new(icon, None) - .build(&event_loop) - .unwrap(); - - // little helper to position our window - // centered with tray bounds - fn window_position_center_tray( - rectangle: &mut Rectangle, - window_size: LogicalSize, - ) -> PhysicalPosition { - // center X axis with tray icon position - let window_x = - rectangle.position.x + ((rectangle.size.width / 2.0) - (window_size.width / 2.0)); - rectangle.position.x = window_x; - - // position Y axis (Windows only) - #[cfg(target_os = "windows")] - { - rectangle.position.y = rectangle.position.y - window_size.height - rectangle.size.height; - } - - (*rectangle).position - } - - // launch WRY process - event_loop.run(move |event, event_loop, control_flow| { - *control_flow = ControlFlow::Wait; - - let mut create_window_or_focus = - |window_size: LogicalSize, window_position: PhysicalPosition| { - // if we already have one webview, let's focus instead of opening - if !webviews.is_empty() { - for window in webviews.values() { - window.window().set_focus(); - } - return; - } - - // create our new window / webview instance - let mut window_builder = WindowBuilder::new(); - window_builder = window_builder - .with_position(window_position) - .with_inner_size(window_size); - - #[cfg(any(target_os = "windows", target_os = "linux"))] - { - window_builder = window_builder.with_skip_taskbar(true); - } - - let window = window_builder.build(event_loop).unwrap(); - - let id = window.id(); - - let webview = WebViewBuilder::new(window) - .unwrap() - .with_custom_protocol("wry.dev".into(), move |_uri| { - ResponseBuilder::new() - .mimetype("text/html") - .body(index_html.as_bytes().into()) - }) - .with_url("wry.dev://") - .unwrap() - .build() - .unwrap(); - - webviews.insert(id, webview); - }; - - match event { - Event::NewEvents(StartCause::Init) => println!("Wry has started!"), - Event::WindowEvent { - event: WindowEvent::CloseRequested, - window_id, - .. - } => { - println!("Window {:?} has received the signal to close", window_id); - // Remove webview from our hashmap - webviews.remove(&window_id); - } - // open app on left click centered with traty icon bound - Event::TrayEvent { - event: tao::event::TrayEvent::LeftClick, - mut bounds, - .. - } => { - let window_inner_size = LogicalSize::new(200.0, 200.0); - let position = window_position_center_tray(&mut bounds, window_inner_size); - create_window_or_focus(window_inner_size, position); - } - // open new window (linux) - Event::MenuEvent { menu_id, .. } if menu_id == open_menu_id => { - let window_inner_size = LogicalSize::new(200.0, 200.0); - let position = PhysicalPosition::new(450.0, 450.0); - create_window_or_focus(window_inner_size, position); - } - // request to quit (linux) - Event::MenuEvent { menu_id, .. } if menu_id == quit_menu_id => { - *control_flow = ControlFlow::Exit - } - _ => (), - } - }); -} - -#[cfg(target_os = "ios")] -fn main() { - println!("This platform doesn't support system_tray."); -} - -// Tray feature flag disabled but can be available. -#[cfg(any(target_os = "windows", target_os = "linux", target_os = "macos"))] -#[cfg(not(feature = "tray"))] -fn main() { - println!("This platform doesn't have the `tray` or `ayatana` feature enabled."); -}