From 6d9515fda12b13e3e749bd34f797d57686a01906 Mon Sep 17 00:00:00 2001 From: David Lemarier Date: Mon, 10 May 2021 09:01:58 -0400 Subject: [PATCH] feat: split feature flags (tray/menu) Tray is on by default. If tray or menu is enabled, the linux `MenuItem` impl are added. --- Cargo.toml | 21 +++++++++++---------- README.md | 9 +++++---- src/platform_impl/linux/event_loop.rs | 12 ++++++------ src/platform_impl/linux/system_tray.rs | 4 ++-- 4 files changed, 24 insertions(+), 22 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 9c7ef15dd..21a39cc7a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,7 +15,7 @@ documentation = "https://docs.rs/tao" categories = [ "gui" ] [package.metadata.docs.rs] -features = [ "serde", "menu", "dox" ] +features = [ "serde", "menu", "tray", "dox" ] default-target = "x86_64-unknown-linux-gnu" targets = [ "i686-pc-windows-msvc", @@ -26,8 +26,9 @@ targets = [ ] [features] -default = [ "menu" ] -menu = [ "sourceview", "libappindicator" ] +default = [ "tray" ] +menu = [ "sourceview" ] +tray = [ "sourceview", "libappindicator" ] dox = [ "gtk/dox", "sourceview/dox" ] [dependencies] @@ -58,17 +59,17 @@ core-graphics = "0.22" dispatch = "0.2" scopeguard = "1.1" - [target."cfg(target_os = \"macos\")".dependencies.core-video-sys] - version = "0.1" - default_features = false - features = [ "display_link" ] +[target."cfg(target_os = \"macos\")".dependencies.core-video-sys] +version = "0.1" +default_features = false +features = [ "display_link" ] [target."cfg(target_os = \"windows\")".dependencies] parking_lot = "0.11" - [target."cfg(target_os = \"windows\")".dependencies.winapi] - version = "0.3" - features = [ +[target."cfg(target_os = \"windows\")".dependencies.winapi] +version = "0.3" +features = [ "combaseapi", "commctrl", "dwmapi", diff --git a/README.md b/README.md index cda5c9c52..1ced42f57 100644 --- a/README.md +++ b/README.md @@ -16,10 +16,10 @@ Windows, macOS, Linux, iOS and Android. Built for you, maintained for Tauri. Tao provides the following features, which can be enabled in your `Cargo.toml` file: * `serde`: Enables serialization/deserialization of certain types with [Serde](https://crates.io/crates/serde). -* `menu`: Enables system tray and more menu item variants on **Linux**. This flag is enabled by default. - You can still create those types if you disable it. They just don't create the actual objects. We set this flag - because some implementations require more installed packages. Disable this if you don't want to install those - additional packages. +* `tray`: Enables system tray and more menu item variants on **Linux**. This flag is enabled by default. + You can still create those types if you disable it. They just don't create the actual objects. We set this flag because some implementations require more installed packages. Disable this if you don't want to install those additional packages. +* `menu`: Enables menu item variants on **Linux**. If you enable `tray`, this flag is not required. + You can still create those types if you disable it. They just don't create the actual objects. We set this flag because some implementations require more installed packages. Disable this if you don't want to install those additional packages. ## Platform-specific notes @@ -35,6 +35,7 @@ crate-type = ["cdylib"] ``` And add this to the example file to add the native activity glue: + ```rust #[cfg_attr(target_os = "android", ndk_glue::main(backtrace = "on"))] fn main() { diff --git a/src/platform_impl/linux/event_loop.rs b/src/platform_impl/linux/event_loop.rs index 9d24e2496..0c225e660 100644 --- a/src/platform_impl/linux/event_loop.rs +++ b/src/platform_impl/linux/event_loop.rs @@ -15,9 +15,9 @@ use gio::{prelude::*, Cancellable}; use glib::{source::idle_add_local, Continue, MainContext}; use gtk::{prelude::*, AboutDialog, ApplicationWindow, Inhibit}; -#[cfg(feature = "menu")] +#[cfg(any(feature = "menu", feature = "tray"))] use glib::Cast; -#[cfg(feature = "menu")] +#[cfg(any(feature = "menu", feature = "tray"))] use gtk::{Clipboard, Entry}; use crate::{ @@ -492,7 +492,7 @@ impl EventLoop { MenuItem::Quit => { keep_running_.replace(false); } - #[cfg(feature = "menu")] + #[cfg(any(feature = "menu", feature = "tray"))] MenuItem::Cut => { if let Some(widget) = window.get_focus() { if widget.has_focus() { @@ -508,7 +508,7 @@ impl EventLoop { } } } - #[cfg(feature = "menu")] + #[cfg(any(feature = "menu", feature = "tray"))] MenuItem::Copy => { if let Some(widget) = window.get_focus() { if widget.has_focus() { @@ -524,7 +524,7 @@ impl EventLoop { } } } - #[cfg(feature = "menu")] + #[cfg(any(feature = "menu", feature = "tray"))] MenuItem::Paste => { if let Some(widget) = window.get_focus() { if widget.has_focus() { @@ -540,7 +540,7 @@ impl EventLoop { } } } - #[cfg(feature = "menu")] + #[cfg(any(feature = "menu", feature = "tray"))] MenuItem::SelectAll => { if let Some(widget) = window.get_focus() { if widget.has_focus() { diff --git a/src/platform_impl/linux/system_tray.rs b/src/platform_impl/linux/system_tray.rs index 7de42d49f..1f09036ee 100644 --- a/src/platform_impl/linux/system_tray.rs +++ b/src/platform_impl/linux/system_tray.rs @@ -9,7 +9,7 @@ use crate::{ pub struct SystemTray {} impl SystemTray { - #[cfg(feature = "menu")] + #[cfg(feature = "tray")] pub(crate) fn initialize( window_target: &EventLoopWindowTarget, system_tray: &RootSystemTray, @@ -58,7 +58,7 @@ impl SystemTray { Ok(()) } - #[cfg(not(feature = "menu"))] + #[cfg(not(feature = "tray"))] pub(crate) fn initialize( _window_target: &EventLoopWindowTarget, _system_tray: &RootSystemTray,