From eac57a17111f9709f93dd9ac5bff7dee082d03ef Mon Sep 17 00:00:00 2001 From: Artem Anufrij Date: Sun, 3 Sep 2017 19:16:39 +0200 Subject: [PATCH] add pin button for webapps --- src/Objects/DesktopFile.vala | 3 --- src/WebWindow.vala | 17 +++++++++++++---- src/Widgets/Assistant.vala | 2 +- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/Objects/DesktopFile.vala b/src/Objects/DesktopFile.vala index 6af60aa..322ffbf 100644 --- a/src/Objects/DesktopFile.vala +++ b/src/Objects/DesktopFile.vala @@ -50,7 +50,6 @@ namespace Webpin { public string name { get; private set; } public string url { get; private set; } public string icon { get; private set; } - public bool stay_open { get; private set; } public bool hide_on_close { get { this.file = new GLib.KeyFile(); @@ -68,7 +67,6 @@ namespace Webpin { this.name = name; this.url = url.replace ("%", "%%"); this.icon = icon; - this.stay_open = stay_open; file = new GLib.KeyFile(); try { @@ -98,7 +96,6 @@ namespace Webpin { this.icon = info.get_icon ().to_string (); try { this.url = file.get_string ("Desktop Entry", "Exec").substring (31); - this.stay_open = file.get_string ("Desktop Entry", "WebpinStayOpen") == "true"; } catch (Error e) { warning (e.message); } diff --git a/src/WebWindow.vala b/src/WebWindow.vala index 1cd0c0c..cd00829 100644 --- a/src/WebWindow.vala +++ b/src/WebWindow.vala @@ -31,7 +31,7 @@ namespace Webpin { private bool is_full_screen = false; - private string style_str = """@define-color titlebar_color @titlebar_color;"""; + private string style_str = """@define-color titlebar_color @titlebar_color;"""; //widgets private WebApp web_app; @@ -54,6 +54,15 @@ namespace Webpin { spinner = new Gtk.Spinner (); spinner.set_size_request (16, 16); headerbar.pack_end (spinner); + + var stay_open = new Gtk.ToggleButton (); + stay_open.active = desktop_file.hide_on_close; + stay_open.toggled.connect (() => { + desktop_file.edit_propertie ("WebpinStayOpen", stay_open.active.to_string ()); + desktop_file.save_to_file (); + }); + stay_open.image = new Gtk.Image.from_icon_name ("view-pin-symbolic", Gtk.IconSize.MENU); + headerbar.pack_start (stay_open); //style if (web_app.ui_color != "none") { @@ -63,7 +72,7 @@ namespace Webpin { var style_provider = new Gtk.CssProvider (); style_provider.load_from_data (style_cp, -1); headerbar.get_style_context ().add_provider (style_provider, -1); - Gtk.Settings.get_default ().set ("gtk-application-prefer-dark-theme", should_use_dark_theme (web_app.ui_color)); + Gtk.Settings.get_default ().gtk_application_prefer_dark_theme = should_use_dark_theme (web_app.ui_color); } catch (GLib.Error err) { warning("Loading style failed"); } @@ -76,7 +85,7 @@ namespace Webpin { var style_provider = new Gtk.CssProvider (); style_provider.load_from_data (style_cp, -1); headerbar.get_style_context ().add_provider (style_provider, -1); - Gtk.Settings.get_default ().set ("gtk-application-prefer-dark-theme", should_use_dark_theme (color)); + Gtk.Settings.get_default ().gtk_application_prefer_dark_theme = should_use_dark_theme (color); } catch (GLib.Error err) { warning("Loading style failed"); } @@ -106,7 +115,7 @@ namespace Webpin { this.delete_event.connect (() => { update_window_state(this.get_allocated_width (), this.get_allocated_height (), this.is_maximized); if (desktop_file.hide_on_close) { - this.hide (); + this.hide_on_delete (); } return desktop_file.hide_on_close; }); diff --git a/src/Widgets/Assistant.vala b/src/Widgets/Assistant.vala index d93a536..7be9ec8 100644 --- a/src/Widgets/Assistant.vala +++ b/src/Widgets/Assistant.vala @@ -326,7 +326,7 @@ namespace Webpin { app_name_entry.set_sensitive (false); app_url_entry.text = desktop_file.url.replace ("%%", "%"); icon_name_entry.text = desktop_file.icon; - stay_open_when_closed.active = desktop_file.stay_open; + stay_open_when_closed.active = desktop_file.hide_on_close; update_app_icon (); } }