Skip to content

Commit

Permalink
feat: split feature flags (tray/menu)
Browse files Browse the repository at this point in the history
Tray is on  by default.
If tray or menu is enabled, the linux `MenuItem` impl are  added.
  • Loading branch information
lemarier committed May 10, 2021
1 parent a8c6637 commit 6d9515f
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 22 deletions.
21 changes: 11 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -26,8 +26,9 @@ targets = [
]

[features]
default = [ "menu" ]
menu = [ "sourceview", "libappindicator" ]
default = [ "tray" ]
menu = [ "sourceview" ]
tray = [ "sourceview", "libappindicator" ]
dox = [ "gtk/dox", "sourceview/dox" ]

[dependencies]
Expand Down Expand Up @@ -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",
Expand Down
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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() {
Expand Down
12 changes: 6 additions & 6 deletions src/platform_impl/linux/event_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -492,7 +492,7 @@ impl<T: 'static> EventLoop<T> {
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() {
Expand All @@ -508,7 +508,7 @@ impl<T: 'static> EventLoop<T> {
}
}
}
#[cfg(feature = "menu")]
#[cfg(any(feature = "menu", feature = "tray"))]
MenuItem::Copy => {
if let Some(widget) = window.get_focus() {
if widget.has_focus() {
Expand All @@ -524,7 +524,7 @@ impl<T: 'static> EventLoop<T> {
}
}
}
#[cfg(feature = "menu")]
#[cfg(any(feature = "menu", feature = "tray"))]
MenuItem::Paste => {
if let Some(widget) = window.get_focus() {
if widget.has_focus() {
Expand All @@ -540,7 +540,7 @@ impl<T: 'static> EventLoop<T> {
}
}
}
#[cfg(feature = "menu")]
#[cfg(any(feature = "menu", feature = "tray"))]
MenuItem::SelectAll => {
if let Some(widget) = window.get_focus() {
if widget.has_focus() {
Expand Down
4 changes: 2 additions & 2 deletions src/platform_impl/linux/system_tray.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::{
pub struct SystemTray {}

impl SystemTray {
#[cfg(feature = "menu")]
#[cfg(feature = "tray")]
pub(crate) fn initialize<T>(
window_target: &EventLoopWindowTarget<T>,
system_tray: &RootSystemTray,
Expand Down Expand Up @@ -58,7 +58,7 @@ impl SystemTray {
Ok(())
}

#[cfg(not(feature = "menu"))]
#[cfg(not(feature = "tray"))]
pub(crate) fn initialize<T>(
_window_target: &EventLoopWindowTarget<T>,
_system_tray: &RootSystemTray,
Expand Down

0 comments on commit 6d9515f

Please sign in to comment.