Fix links opening twice

This commit is contained in:
Bleak Grey 2020-08-01 19:47:49 +03:00
parent e9e89b7e4e
commit e2e3400c86
1 changed files with 5 additions and 12 deletions

View File

@ -21,7 +21,6 @@ public class Tootle.Widgets.RichLabel : Label {
justify = Justification.LEFT; justify = Justification.LEFT;
single_line_mode = false; single_line_mode = false;
set_line_wrap (true); set_line_wrap (true);
activate_link.connect (open_link);
} }
public RichLabel (string text) { public RichLabel (string text) {
@ -43,10 +42,7 @@ public class Tootle.Widgets.RichLabel : Label {
.replace (""", "\""); .replace (""", "\"");
} }
public bool open_link (string url) { public override bool activate_link (string url) {
if ("tootle://" in url)
return false;
if (mentions != null){ if (mentions != null){
mentions.@foreach (mention => { mentions.@foreach (mention => {
if (url == mention.url) if (url == mention.url)
@ -63,23 +59,20 @@ public class Tootle.Widgets.RichLabel : Label {
} }
var resolve = "@" in url; var resolve = "@" in url;
var resolved = false; if (!resolve)
if (resolve) { Desktop.open_uri (url);
else {
accounts.active.resolve.begin (url, (obj, res) => { accounts.active.resolve.begin (url, (obj, res) => {
try { try {
accounts.active.resolve.end (res).open (); accounts.active.resolve.end (res).open ();
resolved = true;
} }
catch (Error e) { catch (Error e) {
warning (@"Failed to resolve URL \"$url\":"); warning (@"Failed to resolve URL \"$url\":");
warning (e.message); warning (e.message);
Desktop.open_uri (url);
} }
}); });
} }
if (!resolved)
Desktop.open_uri (url);
return true; return true;
} }