diff --git a/Cargo.lock b/Cargo.lock index e00ab38..ebc935d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -233,9 +233,9 @@ dependencies = [ [[package]] name = "gio" -version = "0.20.6" +version = "0.20.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8826d2a9ad56ce3de1f04bea0bea0daff6f5f1c913cc834996cfea1f9401361c" +checksum = "a517657589a174be9f60c667f1fec8b7ac82ed5db4ebf56cf073a3b5955d8e2e" dependencies = [ "futures-channel", "futures-core", @@ -263,9 +263,9 @@ dependencies = [ [[package]] name = "glib" -version = "0.20.6" +version = "0.20.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86bd3e4ee7998ab5a135d900db56930cc19ad16681adf245daff54f618b9d5e1" +checksum = "f969edf089188d821a30cde713b6f9eb08b20c63fc2e584aba2892a7984a8cc0" dependencies = [ "bitflags", "futures-channel", diff --git a/Cargo.toml b/Cargo.toml index 5273669..ade9f17 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,8 +14,8 @@ build = "build.rs" adw = { package = "libadwaita", version = "0.7.0", features = ["v1_6"] } async-channel = "2.3.1" futures-util = { version = "0.3.31", default-features = false } -glib = { version = "0.20.5", features = ["log", "log_macros"] } -gtk = { package = "gtk4", version = "0.9.2", features = ["gnome_47"] } +glib = { version = "0.20.7", features = ["log", "log_macros"] } +gtk = { package = "gtk4", version = "0.9.4", features = ["gnome_47"] } log = "0.4.22" macaddr = { version = "1.0.1", default-features = false } serde = { version = "1.0.210", features = ["derive"] } diff --git a/src/app/searchprovider.rs b/src/app/searchprovider.rs index 64c9a3f..ea9fbd5 100644 --- a/src/app/searchprovider.rs +++ b/src/app/searchprovider.rs @@ -7,14 +7,11 @@ //! Utilities for the search provider of Turn On. use glib::{dpgettext2, ControlFlow, Variant, VariantDict}; -use gtk::gio::{ - DBusMethodInvocation, ListStore, Notification, NotificationPriority, RegistrationId, -}; +use gtk::gio::{ListStore, Notification, NotificationPriority, RegistrationId}; use gtk::prelude::*; use crate::app::TurnOnApplication; use crate::config::G_LOG_DOMAIN; -use crate::dbus::invocation::DBusMethodInvocationExt; use crate::dbus::searchprovider2::{self, ActivateResult, GetResultMetas, MethodCall}; use super::model::Device; @@ -177,16 +174,6 @@ async fn dispatch_method_call( } } -fn handle_search_provider_method_call( - app: TurnOnApplication, - method_name: &str, - parameters: Variant, - invocation: DBusMethodInvocation, -) { - let call = searchprovider2::MethodCall::parse(method_name, parameters); - invocation.return_future_local(async move { dispatch_method_call(app, call?).await }); -} - /// Register the Turn On search provider for `app`. /// /// Register a search provider for devices on the DBus connection of `app`. @@ -197,18 +184,13 @@ pub fn register_app_search_provider(app: TurnOnApplication) -> Option() + .invoke_and_return_future_local(glib::clone!( #[strong] app, - move |_, sender, object_path, interface_name, method_name, parameters, invocation| { - glib::debug!("Sender {sender} called method {method_name} of {interface_name} on object {object_path}"); - assert!(interface_name == searchprovider2::INTERFACE_NAME); - handle_search_provider_method_call( - app.clone(), - method_name, - parameters, - invocation, - ); + move |_, sender, call| { + glib::debug!("Sender {sender:?} called method {call:?}"); + dispatch_method_call(app.clone(), call) } )) .build() diff --git a/src/dbus.rs b/src/dbus.rs index 209a81d..8cc7cd5 100644 --- a/src/dbus.rs +++ b/src/dbus.rs @@ -6,5 +6,4 @@ //! DBus interface definitions and helpers. -pub mod invocation; pub mod searchprovider2; diff --git a/src/dbus/invocation.rs b/src/dbus/invocation.rs deleted file mode 100644 index b37dedc..0000000 --- a/src/dbus/invocation.rs +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright Sebastian Wiesner - -// This Source Code Form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at http://mozilla.org/MPL/2.0/. - -use glib::VariantTy; -use gtk::gio::DBusMethodInvocation; - -pub type InvocationResult = Result, glib::Error>; - -/// Extensions for DBus method invocations. -/// -/// Being upstreamed at -pub trait DBusMethodInvocationExt { - fn return_result(self, result: InvocationResult); - - fn return_future_local(self, f: F) -> glib::JoinHandle<()> - where - F: std::future::Future + 'static; -} - -impl DBusMethodInvocationExt for DBusMethodInvocation { - fn return_result(self, result: Result, glib::Error>) { - match result { - Ok(Some(value)) if !value.is_type(VariantTy::TUPLE) => { - let tupled = glib::Variant::tuple_from_iter(std::iter::once(value)); - self.return_value(Some(&tupled)); - } - Ok(value) => self.return_value(value.as_ref()), - Err(error) => self.return_gerror(error), - } - } - - fn return_future_local(self, f: F) -> glib::JoinHandle<()> - where - F: std::future::Future + 'static, - { - glib::spawn_future_local(async move { - self.return_result(f.await); - }) - } -} diff --git a/src/dbus/searchprovider2.rs b/src/dbus/searchprovider2.rs index 5854786..7acaa82 100644 --- a/src/dbus/searchprovider2.rs +++ b/src/dbus/searchprovider2.rs @@ -7,7 +7,10 @@ //! The search provider dbus interface. use glib::Variant; -use gtk::gio::{DBusInterfaceInfo, DBusNodeInfo, IOErrorEnum}; +use gtk::{ + gio::{DBusInterfaceInfo, DBusNodeInfo, IOErrorEnum}, + prelude::DBusMethodCall, +}; /// The literal XML definition of the interface. static XML: &str = include_str!("../../dbus-1/org.gnome.ShellSearchProvider2.xml"); @@ -71,27 +74,37 @@ fn invalid_parameters() -> glib::Error { ) } -impl MethodCall { - /// Parse a method call to a search provider. - pub fn parse(method_name: &str, parameters: Variant) -> Result { - match method_name { - "GetInitialResultSet" => parameters +impl DBusMethodCall for MethodCall { + fn parse_call( + _obj_path: &str, + interface: Option<&str>, + method: &str, + params: glib::Variant, + ) -> Result { + if interface != Some(INTERFACE_NAME) { + return Err(glib::Error::new( + IOErrorEnum::InvalidArgument, + "Unexpected interface", + )); + } + match method { + "GetInitialResultSet" => params .get::() .map(MethodCall::GetInitialResultSet) .ok_or_else(invalid_parameters), - "GetSubsearchResultSet" => parameters + "GetSubsearchResultSet" => params .get::() .map(MethodCall::GetSubsearchResultSet) .ok_or_else(invalid_parameters), - "GetResultMetas" => parameters + "GetResultMetas" => params .get::() .map(MethodCall::GetResultMetas) .ok_or_else(invalid_parameters), - "ActivateResult" => parameters + "ActivateResult" => params .get::() .map(MethodCall::ActivateResult) .ok_or_else(invalid_parameters), - "LaunchSearch" => parameters + "LaunchSearch" => params .get::() .map(MethodCall::LaunchSearch) .ok_or_else(invalid_parameters), diff --git a/supply-chain/imports.lock b/supply-chain/imports.lock index b2b5b7c..ea528c9 100644 --- a/supply-chain/imports.lock +++ b/supply-chain/imports.lock @@ -57,8 +57,8 @@ user-login = "sdroege" user-name = "Sebastian Dröge" [[publisher.gio]] -version = "0.20.6" -when = "2024-11-12" +version = "0.20.7" +when = "2024-12-16" user-id = 3623 user-login = "sdroege" user-name = "Sebastian Dröge" @@ -71,8 +71,8 @@ user-login = "sdroege" user-name = "Sebastian Dröge" [[publisher.glib]] -version = "0.20.6" -when = "2024-11-12" +version = "0.20.7" +when = "2024-12-16" user-id = 3623 user-login = "sdroege" user-name = "Sebastian Dröge"