Skip to content

Commit

Permalink
Update to glib/gio 0.20.7
Browse files Browse the repository at this point in the history
Use new DBus APIs and remove our own GDBus extensions.
  • Loading branch information
swsnr committed Dec 17, 2024
1 parent a0c269e commit 9b9fe20
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 88 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
30 changes: 6 additions & 24 deletions src/app/searchprovider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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`.
Expand All @@ -197,18 +184,13 @@ pub fn register_app_search_provider(app: TurnOnApplication) -> Option<Registrati
let interface_info = searchprovider2::interface();
let registration_id = connection
.register_object("/de/swsnr/turnon/search", &interface_info)
.method_call(glib::clone!(
.typed_method_call::<searchprovider2::MethodCall>()
.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()
Expand Down
1 change: 0 additions & 1 deletion src/dbus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@

//! DBus interface definitions and helpers.
pub mod invocation;
pub mod searchprovider2;
43 changes: 0 additions & 43 deletions src/dbus/invocation.rs

This file was deleted.

33 changes: 23 additions & 10 deletions src/dbus/searchprovider2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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<MethodCall, glib::Error> {
match method_name {
"GetInitialResultSet" => parameters
impl DBusMethodCall for MethodCall {
fn parse_call(
_obj_path: &str,
interface: Option<&str>,
method: &str,
params: glib::Variant,
) -> Result<Self, glib::Error> {
if interface != Some(INTERFACE_NAME) {
return Err(glib::Error::new(
IOErrorEnum::InvalidArgument,
"Unexpected interface",
));
}
match method {
"GetInitialResultSet" => params
.get::<GetInitialResultSet>()
.map(MethodCall::GetInitialResultSet)
.ok_or_else(invalid_parameters),
"GetSubsearchResultSet" => parameters
"GetSubsearchResultSet" => params
.get::<GetSubsearchResultSet>()
.map(MethodCall::GetSubsearchResultSet)
.ok_or_else(invalid_parameters),
"GetResultMetas" => parameters
"GetResultMetas" => params
.get::<GetResultMetas>()
.map(MethodCall::GetResultMetas)
.ok_or_else(invalid_parameters),
"ActivateResult" => parameters
"ActivateResult" => params
.get::<ActivateResult>()
.map(MethodCall::ActivateResult)
.ok_or_else(invalid_parameters),
"LaunchSearch" => parameters
"LaunchSearch" => params
.get::<LaunchSearch>()
.map(MethodCall::LaunchSearch)
.ok_or_else(invalid_parameters),
Expand Down
8 changes: 4 additions & 4 deletions supply-chain/imports.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down

0 comments on commit 9b9fe20

Please sign in to comment.