From 0acf8f77bab1660edab51fcb512969b9a262d52c Mon Sep 17 00:00:00 2001 From: Artem Anufrij Date: Sun, 10 Sep 2017 22:51:20 +0200 Subject: [PATCH] open webapp by clicking desktop notification --- src/Application.vala | 20 ++++++++++++++++---- src/Objects/DesktopFile.vala | 9 ++++++--- src/WebWindow.vala | 6 ++---- src/Widgets/WebApp.vala | 1 - 4 files changed, 24 insertions(+), 12 deletions(-) diff --git a/src/Application.vala b/src/Application.vala index f062c23..81b0976 100644 --- a/src/Application.vala +++ b/src/Application.vala @@ -48,6 +48,15 @@ namespace Webpin { app_launcher = application_id + ".desktop"; flags |= GLib.ApplicationFlags.HANDLES_OPEN; app_list = new GLib.List (); + + var open_web_app = new SimpleAction ("open-web-app", GLib.VariantType.STRING); + add_action (open_web_app); + open_web_app.activate.connect ((parameter) => { + if (parameter != null) { + debug ("start web app over action: '%s'", parameter.get_string ()); + start_webapp (parameter.get_string ()); + } + }); } public Gtk.Window mainwindow; @@ -64,24 +73,27 @@ namespace Webpin { } public override void open (File[] files, string hint) { - debug (files [0].get_uri ()); + debug ("%s", files [0].get_uri ()); start_webapp (files [0].get_uri ()); } - + public void start_webapp (string url) { foreach (var item in app_list) { + debug ("running webapp: %s", item.desktop_file.url); if (item.desktop_file.url == url) { + debug ("open runing app: %s", url); item.present (); return; } } + debug ("create a new web app: %s", url); var app_info = Webpin.DesktopFile.get_app_by_url (url); var desktop_file = new Webpin.DesktopFile.from_desktopappinfo(app_info); - var app = new WebWindow(desktop_file); + var app = new WebWindow (desktop_file); + app_list.append (app); app.destroy.connect (() => { app_list.remove (app); }); app.set_application (this); - app_list.append (app); } } } diff --git a/src/Objects/DesktopFile.vala b/src/Objects/DesktopFile.vala index 1db111c..2cb93bd 100644 --- a/src/Objects/DesktopFile.vala +++ b/src/Objects/DesktopFile.vala @@ -180,10 +180,13 @@ namespace Webpin { var desktop_app = new GLib.DesktopAppInfo(app.get_id ()); - var exec = desktop_app.get_string ("Exec").replace ("%%", "%"); + var exec = desktop_app.get_string ("Exec"); - if (exec != null && exec.contains (url)) { - return desktop_app; + if (exec != null) { + exec = exec.replace ("%%", "%"); + if (exec.contains (url)) { + return desktop_app; + } } } return null; diff --git a/src/WebWindow.vala b/src/WebWindow.vala index 3d3f50d..fcb0b08 100644 --- a/src/WebWindow.vala +++ b/src/WebWindow.vala @@ -37,7 +37,6 @@ namespace Webpin { Gtk.Spinner spinner; public DesktopFile desktop_file { get; private set; } - private Notification desktop_notification; public WebWindow (DesktopFile desktop_file) { this.desktop_file = desktop_file; @@ -46,8 +45,6 @@ namespace Webpin { set_wmclass (desktop_file.url, desktop_file.url); web_app = new WebApp (desktop_file.url); - desktop_notification = new Notification (""); - var headerbar = new Gtk.HeaderBar (); headerbar.title = desktop_file.name; headerbar.show_close_button = true; @@ -105,9 +102,10 @@ namespace Webpin { }); web_app.desktop_notification.connect ((title, body, icon) => { - desktop_notification.set_title (title); + var desktop_notification = new Notification (title); desktop_notification.set_body (body); desktop_notification.set_icon (icon); + desktop_notification.add_button_with_target_value (_("Open %s").printf (desktop_file.name), "app.open-web-app", new GLib.Variant.string (desktop_file.url)); WebpinApp.instance.send_notification (null, desktop_notification); }); diff --git a/src/Widgets/WebApp.vala b/src/Widgets/WebApp.vala index b8eaa00..45adb15 100644 --- a/src/Widgets/WebApp.vala +++ b/src/Widgets/WebApp.vala @@ -108,7 +108,6 @@ namespace Webpin { try { icon = new Gtk.Image.from_pixbuf (new Gdk.Pixbuf.from_file_at_scale (file.icon, 48, 48, true)); icon_for_notification = GLib.Icon.new_for_string (file.icon); - } catch (Error e) { warning (e.message); icon = new Gtk.Image.from_icon_name ("artemanufrij.webpin", Gtk.IconSize.DIALOG);