Skip to content

Commit 19c939f

Browse files
committed
WIP: Add support for opening links
1 parent d3e6c05 commit 19c939f

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

data/com.github.melix99.telegrand.desktop.in.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Exec=telegrand
66
Terminal=false
77
Categories=GNOME;GTK;
88
Keywords=Gnome;GTK;
9+
MimeType=x-scheme-handler/tg;
910
# Translators: Do NOT translate or transliterate this text (this is an icon file name)!
1011
Icon=@icon@
1112
StartupNotify=true

src/application.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,15 @@ mod imp {
6565
obj.setup_accels();
6666
obj.load_color_scheme();
6767
}
68+
69+
fn open(&self, files: &[gio::File], _hint: &str) {
70+
let app = self.obj();
71+
let url = files.first().map(|f| f.uri().into()).unwrap();
72+
println!("file opened");
73+
app.main_window()
74+
.session_manager()
75+
.handle_telegram_link(url);
76+
}
6877
}
6978

7079
impl GtkApplicationImpl for Application {}
@@ -88,6 +97,7 @@ impl Application {
8897
glib::Object::builder()
8998
.property("application-id", APP_ID)
9099
.property("resource-base-path", "/com/github/melix99/telegrand/")
100+
.property("flags", gio::ApplicationFlags::HANDLES_OPEN)
91101
.build()
92102
}
93103

src/session_manager.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ use gtk::prelude::*;
3636
use gtk::subclass::prelude::*;
3737
use gtk::{gio, glib, CompositeTemplate};
3838
use std::borrow::Borrow;
39+
use std::fmt::Debug;
3940
use std::fs;
4041
use std::time::{SystemTime, UNIX_EPOCH};
4142
use tdlib::enums::{self, AuthorizationState, Update};
@@ -729,6 +730,35 @@ impl SessionManager {
729730
}
730731
}
731732

733+
pub(crate) fn handle_telegram_link(&self, link: String) {
734+
let client_id = self.active_logged_in_client_id();
735+
if let Some(client_id) = client_id {
736+
spawn(clone!(@weak self as obj => async move {
737+
let result = functions::get_internal_link_type(link, client_id).await;
738+
if let Some(link_type) = result.ok() {
739+
use enums::InternalLinkType::*;
740+
match link_type {
741+
PublicChat(data) => obj.open_chat_by_username(data.chat_username),
742+
_ => (),
743+
}
744+
}
745+
}));
746+
}
747+
}
748+
749+
pub(crate) fn open_chat_by_username(&self, username: String) {
750+
let client_id = self.active_logged_in_client_id();
751+
if let Some(client_id) = client_id {
752+
spawn(clone!(@weak self as obj => async move {
753+
let result = functions::search_public_chat(username, client_id).await;
754+
if let Ok(chat) = result {
755+
let enums::Chat::Chat(chat) = chat;
756+
obj.select_chat(client_id, chat.id);
757+
}
758+
}))
759+
}
760+
}
761+
732762
pub(crate) fn begin_chats_search(&self) {
733763
if let Some(client_id) = self.active_logged_in_client_id() {
734764
let clients = self.imp().clients.borrow();

0 commit comments

Comments
 (0)