Skip to content

Commit

Permalink
refactor(tray): split gtk and ayatana appindicator features (#362)
Browse files Browse the repository at this point in the history
* refactor(tray): split gtk and ayatana appindicator features

* fix ci

* install dev package

* fix: use v3

* chore: short feature flag name
  • Loading branch information
lucasfernog committed Apr 5, 2022
1 parent 089f387 commit 40ec796
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 13 deletions.
5 changes: 5 additions & 0 deletions .changes/refactor-tray-features.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tao": minor
---

**Breaking change:** Renamed the `ayatana` Cargo feature to `ayatana-tray`, now the default feature for tray on Linux, and added the `gtk-tray` feature.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ jobs:
sudo apt-get update
sudo apt-get install -y libgtk-3-dev
- name: Install libappindicator3 (ubuntu[default/tray] only)
- name: Install ayatana-libappindicator (ubuntu[default/tray] only)
if: matrix.platform.id == 'ubuntu'
run: |
sudo apt-get install -y libappindicator3-dev
sudo apt-get install -y libayatana-appindicator3-dev
- name: Install GCC Multilib
if: (matrix.platform.os == 'ubuntu-latest') && contains(matrix.platform.target, 'i686')
Expand Down
7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ targets = [
]

[features]
default = [ "tray" ]
tray = [ "libappindicator" ]
ayatana = [ "libayatana-appindicator" ]
default = [ "tray", "ayatana-tray" ]
tray = []
gtk-tray = [ "tray", "libappindicator" ]
ayatana-tray = [ "tray", "libayatana-appindicator" ]
dox = [ "gtk/dox" ]

[dependencies]
Expand Down
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ 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).
* `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 `libappindicator` package.
* `ayatana`: Enable this if you wish to use more update `libayatana-appindicator` since `libappindicator` is no longer
maintained.
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.
* `ayatana-tray`: Enable this if you wish to use more update `libayatana-appindicator` since `libappindicator` is no longer maintained.
This flag is enabled by default. Disable this if you don't want to install the `libayatana-appindicator` package.
* `gtk-tray`: Enable this if you wish ot use `libappindicator` for tray on **Linux**. The package is supported on more Linux distributions, but it is not maintained anymore.
Note that `ayatana-tray` and `gtk-tray` cannot be enabled at the same time, so `default-features` must be set to `false`.

## Platform-specific notes

Expand Down
6 changes: 5 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,11 @@ mod platform_impl;
target_os = "netbsd",
target_os = "openbsd"
))]
#[cfg(any(feature = "tray", feature = "ayatana"))]
#[cfg(all(
feature = "tray",
any(feature = "gtk-tray", feature = "ayatana-tray"),
not(all(feature = "gtk-tray", feature = "ayatana-tray"))
))]
pub mod system_tray;
pub mod window;

Expand Down
20 changes: 18 additions & 2 deletions src/platform_impl/linux/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,34 @@
target_os = "openbsd"
))]

#[cfg(all(feature = "tray", feature = "gtk-tray", feature = "ayatana-tray"))]
compile_error!("`gtk-tray` and `ayatana-tray` Cargo features cannot be enabled at the same time");
#[cfg(all(
feature = "tray",
not(any(feature = "gtk-tray", feature = "ayatana-tray"))
))]
compile_error!("You must enable one of `gtk-tray` or `ayatana-tray` Cargo features");

mod clipboard;
mod event_loop;
mod global_shortcut;
mod keyboard;
mod keycode;
mod menu;
mod monitor;
#[cfg(any(feature = "tray", feature = "ayatana"))]
#[cfg(all(
feature = "tray",
any(feature = "gtk-tray", feature = "ayatana-tray"),
not(all(feature = "gtk-tray", feature = "ayatana-tray"))
))]
mod system_tray;
mod window;

#[cfg(any(feature = "tray", feature = "ayatana"))]
#[cfg(all(
feature = "tray",
any(feature = "gtk-tray", feature = "ayatana-tray"),
not(all(feature = "gtk-tray", feature = "ayatana-tray"))
))]
pub use self::system_tray::{SystemTray, SystemTrayBuilder};
pub use self::{
clipboard::Clipboard,
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,9 +9,9 @@ use glib::Sender;
use std::path::PathBuf;

use gtk::{prelude::WidgetExt, AccelGroup};
#[cfg(not(feature = "ayatana"))]
#[cfg(feature = "gtk-tray")]
use libappindicator::{AppIndicator, AppIndicatorStatus};
#[cfg(feature = "ayatana")]
#[cfg(feature = "ayatana-tray")]
use libayatana_appindicator::{AppIndicator, AppIndicatorStatus};

use super::{menu::Menu, window::WindowRequest, WindowId};
Expand Down

0 comments on commit 40ec796

Please sign in to comment.