diff --git a/data/com.github.melix99.telegrand.desktop.in.in b/data/com.github.melix99.telegrand.desktop.in.in index a2fc06d70..d0c7aada0 100644 --- a/data/com.github.melix99.telegrand.desktop.in.in +++ b/data/com.github.melix99.telegrand.desktop.in.in @@ -2,10 +2,13 @@ Name=Telegrand Comment=A Telegram client optimized for the GNOME desktop Type=Application -Exec=telegrand +TryExec=telegrand +Exec=telegrand %U Terminal=false Categories=GNOME;GTK; Keywords=Gnome;GTK; +DBusActivatable=true +MimeType=x-scheme-handler/tg; # Translators: Do NOT translate or transliterate this text (this is an icon file name)! Icon=@icon@ StartupNotify=true diff --git a/data/com.github.melix99.telegrand.service.in b/data/com.github.melix99.telegrand.service.in new file mode 100644 index 000000000..847141960 --- /dev/null +++ b/data/com.github.melix99.telegrand.service.in @@ -0,0 +1,3 @@ +[D-BUS Service] +Name=@application_id@ +Exec=@bindir@/telegrand --gapplication-service diff --git a/data/meson.build b/data/meson.build index 05dec0c2b..e4ed58318 100644 --- a/data/meson.build +++ b/data/meson.build @@ -74,3 +74,15 @@ if glib_compile_schemas.found() ], ) endif + +# D-bus service +service_conf = configuration_data() +service_conf.set('application_id', application_id) +service_conf.set('bindir', bindir) +configure_file( + input: '@0@.service.in'.format(base_id), + output: '@0@.service'.format(application_id), + configuration: service_conf, + install: true, + install_dir: datadir / 'dbus-1' / 'services', +) diff --git a/src/application.rs b/src/application.rs index 89b6cd3d9..648ad1cef 100644 --- a/src/application.rs +++ b/src/application.rs @@ -47,6 +47,16 @@ mod imp { obj.main_window().present(); } + fn open(&self, files: &[gio::File], _hint: &str) { + debug!("Application::open"); + + let app = self.obj(); + let url = files.first().map(|f| f.uri().into()).unwrap(); + app.main_window() + .session_manager() + .handle_telegram_link(url); + } + fn startup(&self) { debug!("GtkApplication::startup"); @@ -88,6 +98,7 @@ impl Application { glib::Object::builder() .property("application-id", APP_ID) .property("resource-base-path", "/com/github/melix99/telegrand/") + .property("flags", gio::ApplicationFlags::HANDLES_OPEN) .build() } diff --git a/src/session_manager.rs b/src/session_manager.rs index 0cb386816..895d139e1 100644 --- a/src/session_manager.rs +++ b/src/session_manager.rs @@ -729,6 +729,37 @@ impl SessionManager { } } + pub(crate) fn handle_telegram_link(&self, link: String) { + let client_id = self.active_logged_in_client_id(); + if let Some(client_id) = client_id { + spawn(clone!(@weak self as obj => async move { + let result = functions::get_internal_link_type(link, client_id).await; + if let Ok(link_type) = result { + use enums::InternalLinkType::*; + // TODO: Support other link types + #[allow(clippy::single_match)] + match link_type { + PublicChat(data) => obj.open_chat_by_username(data.chat_username), + _ => (), + } + } + })); + } + } + + pub(crate) fn open_chat_by_username(&self, username: String) { + let client_id = self.active_logged_in_client_id(); + if let Some(client_id) = client_id { + spawn(clone!(@weak self as obj => async move { + let result = functions::search_public_chat(username, client_id).await; + if let Ok(chat) = result { + let enums::Chat::Chat(chat) = chat; + obj.select_chat(client_id, chat.id); + } + })) + } + } + pub(crate) fn begin_chats_search(&self) { if let Some(client_id) = self.active_logged_in_client_id() { let clients = self.imp().clients.borrow();