Skip to content

Commit

Permalink
Merge pull request #33 from 101100/zbus-option
Browse files Browse the repository at this point in the history
Add zbus option
  • Loading branch information
Sinono3 authored Feb 11, 2023
2 parents ccd7a75 + 029c223 commit f169034
Show file tree
Hide file tree
Showing 6 changed files with 933 additions and 468 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,7 @@ jobs:
sudo apt-get install -y libdbus-1-dev pkg-config
if: ${{ runner.os == 'Linux' }}
- name: Build
run: cargo build --release --all-targets --verbose
run: cargo build --release --all-targets --verbose
- name: Build zbus
run: cargo build --release --all-targets --verbose --no-default-features --features=use_zbus
if: ${{ runner.os == 'Linux' }}
12 changes: 10 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,16 @@ dispatch = "0.2.0"
objc = "0.2.7"

[target.'cfg(all(unix, not(target_os = "macos")))'.dependencies]
dbus = "0.9.5"
dbus-crossroads = "0.5.0"
dbus = { version = "0.9.5", optional = true }
dbus-crossroads = { version = "0.5.0", optional = true }
zbus = { version = "3.9", optional = true }
zvariant = { version = "3.10", optional = true }
pollster = { version = "0.3", optional = true }

[features]
default = ["use_dbus"]
use_dbus = ["dbus", "dbus-crossroads"]
use_zbus = ["zbus", "zvariant", "pollster"]

[dev-dependencies]
winit = "0.27.0"
Expand Down
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,19 @@ The main struct is `MediaControls`. In order to create this struct you need a `P
- Windows:
- `hwnd`: In this platform, a window needs to be opened to create media controls. The argument required is an `HWND`, a value of type `*mut c_void`. This value can be extracted when you open a window in your program, for example using the `raw_window_handle` in winit.

### Linux backends: D-Bus and `zbus`

When using the library on Linux, the default backend is `dbus-crossroads`. This backend has some issues with consistency in general, but is more stable and uses the native D-Bus library behind the scenes. The zbus backend however, is more modern and is written in pure Rust. It spawns another thread and stars an async `pollster` runtime, handling the incoming MPRIS messages.

To enable the zbus backend, in your Cargo.toml, set `default-features` to false and enable the `use_zbus` feature:

```toml
souvlaki = { version = "<version>", default-features = false, features = ["use_zbus"] }
```


**Note:** If you think there's a better way of using the zbus library regarding the async runtime in another thread, feel free to leave a PR or issue.

## Example

```rust
Expand Down
Loading

0 comments on commit f169034

Please sign in to comment.