From 66604868ce5471dc0410d6d3b10db2270ae0384a Mon Sep 17 00:00:00 2001 From: Marius Meisenzahl Date: Fri, 14 Feb 2020 18:29:58 +0100 Subject: [PATCH 1/8] Move plugins to separate folder --- data/meson.build | 14 -------------- meson.build | 1 + .../com.messenger}/com.messenger.svg | 0 plugins/com.messenger/meson.build | 6 ++++++ .../share => plugins/com.slack}/com.slack.svg | 0 plugins/com.slack/meson.build | 6 ++++++ .../com.whatsapp.web}/com.whatsapp.web.svg | 0 plugins/com.whatsapp.web/meson.build | 6 ++++++ plugins/meson.build | 4 ++++ plugins/org.telegram.web/meson.build | 6 ++++++ .../org.telegram.web}/org.telegram.web.svg | 0 11 files changed, 29 insertions(+), 14 deletions(-) rename {data/icons/share => plugins/com.messenger}/com.messenger.svg (100%) create mode 100644 plugins/com.messenger/meson.build rename {data/icons/share => plugins/com.slack}/com.slack.svg (100%) create mode 100644 plugins/com.slack/meson.build rename {data/icons/share => plugins/com.whatsapp.web}/com.whatsapp.web.svg (100%) create mode 100644 plugins/com.whatsapp.web/meson.build create mode 100644 plugins/meson.build create mode 100644 plugins/org.telegram.web/meson.build rename {data/icons/share => plugins/org.telegram.web}/org.telegram.web.svg (100%) diff --git a/data/meson.build b/data/meson.build index 175f37d..79ac674 100644 --- a/data/meson.build +++ b/data/meson.build @@ -11,20 +11,6 @@ foreach i : icon_sizes ) endforeach -shared_icons = [ - 'com.messenger', - 'com.slack', - 'com.whatsapp.web', - 'org.telegram.web' -] - -foreach icon : shared_icons - install_data( - join_paths('icons', 'share', icon + '.svg'), - install_dir: join_paths(get_option('datadir'), meson.project_name(), 'icons') - ) -endforeach - i18n.merge_file( input: meson.project_name() + '.desktop.in', output: meson.project_name() + '.desktop', diff --git a/meson.build b/meson.build index 52f65e5..f012111 100644 --- a/meson.build +++ b/meson.build @@ -14,5 +14,6 @@ webkit2gtk_4_dep = dependency('webkit2gtk-4.0') subdir('data') subdir('po') subdir('src') +subdir('plugins') meson.add_install_script('meson/post_install.py') diff --git a/data/icons/share/com.messenger.svg b/plugins/com.messenger/com.messenger.svg similarity index 100% rename from data/icons/share/com.messenger.svg rename to plugins/com.messenger/com.messenger.svg diff --git a/plugins/com.messenger/meson.build b/plugins/com.messenger/meson.build new file mode 100644 index 0000000..28d2a42 --- /dev/null +++ b/plugins/com.messenger/meson.build @@ -0,0 +1,6 @@ +sources += [] + +install_data( + join_paths('com.messenger.svg'), + install_dir: join_paths(get_option('datadir'), meson.project_name(), 'icons') +) diff --git a/data/icons/share/com.slack.svg b/plugins/com.slack/com.slack.svg similarity index 100% rename from data/icons/share/com.slack.svg rename to plugins/com.slack/com.slack.svg diff --git a/plugins/com.slack/meson.build b/plugins/com.slack/meson.build new file mode 100644 index 0000000..6774425 --- /dev/null +++ b/plugins/com.slack/meson.build @@ -0,0 +1,6 @@ +sources += [] + +install_data( + join_paths('com.slack.svg'), + install_dir: join_paths(get_option('datadir'), meson.project_name(), 'icons') +) diff --git a/data/icons/share/com.whatsapp.web.svg b/plugins/com.whatsapp.web/com.whatsapp.web.svg similarity index 100% rename from data/icons/share/com.whatsapp.web.svg rename to plugins/com.whatsapp.web/com.whatsapp.web.svg diff --git a/plugins/com.whatsapp.web/meson.build b/plugins/com.whatsapp.web/meson.build new file mode 100644 index 0000000..e1c7a92 --- /dev/null +++ b/plugins/com.whatsapp.web/meson.build @@ -0,0 +1,6 @@ +sources += [] + +install_data( + join_paths('com.whatsapp.web.svg'), + install_dir: join_paths(get_option('datadir'), meson.project_name(), 'icons') +) diff --git a/plugins/meson.build b/plugins/meson.build new file mode 100644 index 0000000..3aebd79 --- /dev/null +++ b/plugins/meson.build @@ -0,0 +1,4 @@ +subdir('com.messenger') +subdir('com.slack') +subdir('com.whatsapp.web') +subdir('org.telegram.web') diff --git a/plugins/org.telegram.web/meson.build b/plugins/org.telegram.web/meson.build new file mode 100644 index 0000000..ced3215 --- /dev/null +++ b/plugins/org.telegram.web/meson.build @@ -0,0 +1,6 @@ +sources += [] + +install_data( + join_paths('org.telegram.web.svg'), + install_dir: join_paths(get_option('datadir'), meson.project_name(), 'icons') +) diff --git a/data/icons/share/org.telegram.web.svg b/plugins/org.telegram.web/org.telegram.web.svg similarity index 100% rename from data/icons/share/org.telegram.web.svg rename to plugins/org.telegram.web/org.telegram.web.svg From 843a593100949d000ba6b066dc256dce5410d8c8 Mon Sep 17 00:00:00 2001 From: Marius Meisenzahl Date: Mon, 17 Feb 2020 15:19:16 +0100 Subject: [PATCH 2/8] Use plugin instead of messenger for names --- src/Application.vala | 4 +- src/Models/{Messenger.vala => Plugin.vala} | 12 +++- .../{Messengers.vala => PluginManager.vala} | 56 +++++++++---------- src/Views/MainView.vala | 40 ++++++------- .../{MessengerView.vala => PluginView.vala} | 28 +++++----- src/meson.build | 6 +- 6 files changed, 78 insertions(+), 68 deletions(-) rename src/Models/{Messenger.vala => Plugin.vala} (87%) rename src/Services/{Messengers.vala => PluginManager.vala} (51%) rename src/Widgets/{MessengerView.vala => PluginView.vala} (72%) diff --git a/src/Application.vala b/src/Application.vala index ccd1458..5bb170e 100644 --- a/src/Application.vala +++ b/src/Application.vala @@ -13,11 +13,11 @@ public class Application : Granite.Application { } construct { - var action = new SimpleAction ("show-messenger", VariantType.STRING); + var action = new SimpleAction ("show-tab", VariantType.STRING); action.activate.connect ((parameter) => { this.hold (); string id = parameter.get_string (); - Services.Messengers.get_default ().visible = id; + Services.PluginManager.get_default ().visible = id; this.release (); }); diff --git a/src/Models/Messenger.vala b/src/Models/Plugin.vala similarity index 87% rename from src/Models/Messenger.vala rename to src/Models/Plugin.vala index 8e3c8c4..af6aa96 100644 --- a/src/Models/Messenger.vala +++ b/src/Models/Plugin.vala @@ -19,10 +19,11 @@ * Authored by: Marius Meisenzahl */ -public class Models.Messenger : Object { +public class Models.Plugin : Object { private string _id; private string _name; private string _url; + private bool _enabled = false; private uint _unread_notifications = 0; public string id { @@ -52,6 +53,15 @@ public class Models.Messenger : Object { } } + public bool enabled { + get { + return _enabled; + } + set { + _enabled = value; + } + } + public uint unread_notifications { get { return _unread_notifications; diff --git a/src/Services/Messengers.vala b/src/Services/PluginManager.vala similarity index 51% rename from src/Services/Messengers.vala rename to src/Services/PluginManager.vala index 3162a34..9c9ab5e 100644 --- a/src/Services/Messengers.vala +++ b/src/Services/PluginManager.vala @@ -19,20 +19,20 @@ * Authored by: Marius Meisenzahl */ -public class Services.Messengers : Object { - private static Messengers instance; - private Array _data; +public class Services.PluginManager : Object { + private static PluginManager instance; + private Array _data; private string _visible; - public static Messengers get_default () { + public static PluginManager get_default () { if (instance == null) { - instance = new Messengers (); + instance = new PluginManager (); } return instance; } - public Array data { + public Array data { get { return _data; } @@ -52,39 +52,39 @@ public class Services.Messengers : Object { } } - private Messengers () { - _data = new Array (); + private PluginManager () { + _data = new Array (); { - var messenger = new Models.Messenger (); - messenger.id = "com.messenger"; - messenger.name = "Messenger"; - messenger.url = "https://www.messenger.com/"; - _data.append_val (messenger); + var plugin = new Models.Plugin (); + plugin.id = "com.messenger"; + plugin.name = "Messenger"; + plugin.url = "https://www.messenger.com/"; + _data.append_val (plugin); } { - var messenger = new Models.Messenger (); - messenger.id = "com.slack"; - messenger.name = "Slack"; - messenger.url = "https://slack.com/signin/"; - _data.append_val (messenger); + var plugin = new Models.Plugin (); + plugin.id = "com.slack"; + plugin.name = "Slack"; + plugin.url = "https://slack.com/signin/"; + _data.append_val (plugin); } { - var messenger = new Models.Messenger (); - messenger.id = "org.telegram.web"; - messenger.name = "Telegram"; - messenger.url = "https://web.telegram.org/"; - _data.append_val (messenger); + var plugin = new Models.Plugin (); + plugin.id = "org.telegram.web"; + plugin.name = "Telegram"; + plugin.url = "https://web.telegram.org/"; + _data.append_val (plugin); } { - var messenger = new Models.Messenger (); - messenger.id = "com.whatsapp.web"; - messenger.name = "WhatsApp"; - messenger.url = "https://web.whatsapp.com/"; - _data.append_val (messenger); + var plugin = new Models.Plugin (); + plugin.id = "com.whatsapp.web"; + plugin.name = "WhatsApp"; + plugin.url = "https://web.whatsapp.com/"; + _data.append_val (plugin); } } } diff --git a/src/Views/MainView.vala b/src/Views/MainView.vala index 9cb7127..4a35d0e 100644 --- a/src/Views/MainView.vala +++ b/src/Views/MainView.vala @@ -31,33 +31,33 @@ public class Views.MainView : Gtk.Paned { list_box.selection_mode = Gtk.SelectionMode.SINGLE; list_box.activate_on_single_click = true; - var messengers = Services.Messengers.get_default ().data; - for (var i = 0; i < messengers.length; i++) { - var messenger = messengers.index (i); + var plugins = Services.PluginManager.get_default ().data; + for (var i = 0; i < plugins.length; i++) { + var plugin = plugins.index (i); - var view = new Widgets.MessengerView (messenger); - stack.add_named (view, messenger.id); + var view = new Widgets.PluginView (plugin); + stack.add_named (view, plugin.id); var menu_item = new Gtk.MenuItem (); - var image = new Gtk.Image.from_gicon (Utilities.load_shared_icon (messenger.id), Gtk.IconSize.DND); - var label = new Gtk.Label (messenger.name); + var image = new Gtk.Image.from_gicon (Utilities.load_shared_icon (plugin.id), Gtk.IconSize.DND); + var label = new Gtk.Label (plugin.name); var unread_notifications = new Gtk.Label ( - (messenger.unread_notifications > 0) ? "%u".printf (messenger.unread_notifications) : "" + (plugin.unread_notifications > 0) ? "%u".printf (plugin.unread_notifications) : "" ); - messenger.notify.connect (() => { - debug ("[%s] unread_notifications: %u", messenger.id, messenger.unread_notifications); + plugin.notify.connect (() => { + debug ("[%s] unread_notifications: %u", plugin.id, plugin.unread_notifications); if (stack.get_visible_child () != view) { unread_notifications.label = - (messenger.unread_notifications > 0) ? "%u".printf (messenger.unread_notifications) : ""; - } else if (messenger.unread_notifications == 0) { + (plugin.unread_notifications > 0) ? "%u".printf (plugin.unread_notifications) : ""; + } else if (plugin.unread_notifications == 0) { unread_notifications.label = ""; } uint unread_notifications_sum = 0; - foreach (var m in messengers.data) { + foreach (var m in plugins.data) { unread_notifications_sum += m.unread_notifications; } @@ -89,19 +89,19 @@ public class Views.MainView : Gtk.Paned { } list_box.row_activated.connect ((row) => { - for (var i = 0; i < messengers.length; i++) { + for (var i = 0; i < plugins.length; i++) { if (row.get_index () == i) { - Services.Messengers.get_default ().visible = messengers.index (i).id; + Services.PluginManager.get_default ().visible = plugins.index (i).id; break; } } }); - Services.Messengers.get_default ().notify["visible"].connect (() => { - var visible = Services.Messengers.get_default ().visible; + Services.PluginManager.get_default ().notify["visible"].connect (() => { + var visible = Services.PluginManager.get_default ().visible; int index = 0; - for (var i = 0; i < messengers.length; i++) { - if (visible == messengers.index (i).id) { + for (var i = 0; i < plugins.length; i++) { + if (visible == plugins.index (i).id) { index = i; break; } @@ -111,7 +111,7 @@ public class Views.MainView : Gtk.Paned { stack.set_visible_child_name (visible); var view = stack.get_visible_child (); - (view as Widgets.MessengerView).model.unread_notifications = 0; + (view as Widgets.PluginView).model.unread_notifications = 0; }); var scroll = new Gtk.ScrolledWindow (null, null); diff --git a/src/Widgets/MessengerView.vala b/src/Widgets/PluginView.vala similarity index 72% rename from src/Widgets/MessengerView.vala rename to src/Widgets/PluginView.vala index 19f82e4..8d34bf8 100644 --- a/src/Widgets/MessengerView.vala +++ b/src/Widgets/PluginView.vala @@ -19,13 +19,13 @@ * Authored by: Marius Meisenzahl */ -public class Widgets.MessengerView : WebKit.WebView { - private Models.Messenger messenger; +public class Widgets.PluginView : WebKit.WebView { + private Models.Plugin plugin; private GLib.Icon icon; - public MessengerView (Models.Messenger messenger) { - this.messenger = messenger; - this.icon = Utilities.load_shared_icon (this.messenger.id); + public PluginView (Models.Plugin plugin) { + this.plugin = plugin; + this.icon = Utilities.load_shared_icon (this.plugin.id); var settings = this.get_settings (); settings.enable_plugins = true; @@ -35,7 +35,7 @@ public class Widgets.MessengerView : WebKit.WebView { web_context.initialize_notification_permissions.connect (() => { var allowed_origins = new List (); - allowed_origins.append (new WebKit.SecurityOrigin.for_uri (this.messenger.url)); + allowed_origins.append (new WebKit.SecurityOrigin.for_uri (this.plugin.url)); var disallowed_origins = new List (); web_context.init_notification_permissions (allowed_origins, disallowed_origins); @@ -45,23 +45,23 @@ public class Widgets.MessengerView : WebKit.WebView { var native_notification = new GLib.Notification (notification.title); native_notification.set_body (notification.body); native_notification.set_icon (this.icon); - Variant target = new Variant.string (this.messenger.id); - native_notification.set_default_action_and_target_value ("app.show-messenger", target); - Application.instance.send_notification (this.messenger.id, native_notification); + Variant target = new Variant.string (this.plugin.id); + native_notification.set_default_action_and_target_value ("app.show-tab", target); + Application.instance.send_notification (this.plugin.id, native_notification); - this.messenger.unread_notifications += 1; + this.plugin.unread_notifications += 1; - debug ("[%s] got notification".printf (this.messenger.id)); + debug ("[%s] got notification".printf (this.plugin.id)); return true; }); - load_uri (this.messenger.url); + load_uri (this.plugin.url); } - public Models.Messenger model { + public Models.Plugin model { get { - return this.messenger; + return this.plugin; } } } diff --git a/src/meson.build b/src/meson.build index d8b9367..69ae88e 100644 --- a/src/meson.build +++ b/src/meson.build @@ -1,11 +1,11 @@ sources = [ 'Config/Constants.vala', - 'Models/Messenger.vala', - 'Services/Messengers.vala', + 'Models/Plugin.vala', + 'Services/PluginManager.vala', 'Services/Settings.vala', 'Utilities/Icon.vala', 'Views/MainView.vala', - 'Widgets/MessengerView.vala', + 'Widgets/PluginView.vala', 'MainWindow.vala' ] From dda7d9737eb9b6dd804c9f9d67d4d72c8c4b9354 Mon Sep 17 00:00:00 2001 From: Marius Meisenzahl Date: Mon, 17 Feb 2020 16:18:33 +0100 Subject: [PATCH 3/8] Set plugin related settings --- meson.build | 10 +++++- plugins/com.messenger/com.messenger.vala | 30 +++++++++++++++++ plugins/com.messenger/meson.build | 8 +++-- plugins/com.slack/com.slack.vala | 30 +++++++++++++++++ plugins/com.slack/meson.build | 8 +++-- .../com.whatsapp.web/com.whatsapp.web.vala | 30 +++++++++++++++++ plugins/com.whatsapp.web/meson.build | 8 +++-- plugins/org.telegram.web/meson.build | 8 +++-- .../org.telegram.web/org.telegram.web.vala | 30 +++++++++++++++++ src/Models/Plugin.vala | 2 +- src/Services/PluginManager.vala | 33 ++++++++----------- src/Views/MainView.vala | 2 +- src/meson.build | 8 ++--- 13 files changed, 171 insertions(+), 36 deletions(-) create mode 100644 plugins/com.messenger/com.messenger.vala create mode 100644 plugins/com.slack/com.slack.vala create mode 100644 plugins/com.whatsapp.web/com.whatsapp.web.vala create mode 100644 plugins/org.telegram.web/org.telegram.web.vala diff --git a/meson.build b/meson.build index f012111..c084009 100644 --- a/meson.build +++ b/meson.build @@ -11,9 +11,17 @@ gtk_plus_3_dep = dependency('gtk+-3.0') granite_dep = dependency('granite') webkit2gtk_4_dep = dependency('webkit2gtk-4.0') +dependencies = [ + gtk_plus_3_dep, + granite_dep, + webkit2gtk_4_dep, +] + +sources = [] + subdir('data') +subdir('plugins') subdir('po') subdir('src') -subdir('plugins') meson.add_install_script('meson/post_install.py') diff --git a/plugins/com.messenger/com.messenger.vala b/plugins/com.messenger/com.messenger.vala new file mode 100644 index 0000000..cda32b0 --- /dev/null +++ b/plugins/com.messenger/com.messenger.vala @@ -0,0 +1,30 @@ +/* +* Copyright (c) 2020 Manexim (https://github.com/manexim) +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public +* License as published by the Free Software Foundation; either +* version 2 of the License, or (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public +* License along with this program; if not, write to the +* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +* Boston, MA 02110-1301 USA +* +* Authored by: Marius Meisenzahl +*/ + +public class ComMessenger : Models.Plugin { + public ComMessenger () { + Object ( + id: "com.messenger", + name: "Messenger", + url: "https://www.messenger.com/" + ); + } +} diff --git a/plugins/com.messenger/meson.build b/plugins/com.messenger/meson.build index 28d2a42..a83da4a 100644 --- a/plugins/com.messenger/meson.build +++ b/plugins/com.messenger/meson.build @@ -1,6 +1,10 @@ -sources += [] +name = 'com.messenger' + +sources += [ + join_paths(meson.source_root(), meson.current_source_dir(), name + '.vala') +] install_data( - join_paths('com.messenger.svg'), + name + '.svg', install_dir: join_paths(get_option('datadir'), meson.project_name(), 'icons') ) diff --git a/plugins/com.slack/com.slack.vala b/plugins/com.slack/com.slack.vala new file mode 100644 index 0000000..ba8ebfb --- /dev/null +++ b/plugins/com.slack/com.slack.vala @@ -0,0 +1,30 @@ +/* +* Copyright (c) 2020 Manexim (https://github.com/manexim) +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public +* License as published by the Free Software Foundation; either +* version 2 of the License, or (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public +* License along with this program; if not, write to the +* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +* Boston, MA 02110-1301 USA +* +* Authored by: Marius Meisenzahl +*/ + +public class ComSlack : Models.Plugin { + public ComSlack () { + Object ( + id: "com.slack", + name: "Slack", + url: "https://slack.com/signin/" + ); + } +} diff --git a/plugins/com.slack/meson.build b/plugins/com.slack/meson.build index 6774425..c2b22ec 100644 --- a/plugins/com.slack/meson.build +++ b/plugins/com.slack/meson.build @@ -1,6 +1,10 @@ -sources += [] +name = 'com.slack' + +sources += [ + join_paths(meson.source_root(), meson.current_source_dir(), name + '.vala') +] install_data( - join_paths('com.slack.svg'), + name + '.svg', install_dir: join_paths(get_option('datadir'), meson.project_name(), 'icons') ) diff --git a/plugins/com.whatsapp.web/com.whatsapp.web.vala b/plugins/com.whatsapp.web/com.whatsapp.web.vala new file mode 100644 index 0000000..68c8cc7 --- /dev/null +++ b/plugins/com.whatsapp.web/com.whatsapp.web.vala @@ -0,0 +1,30 @@ +/* +* Copyright (c) 2020 Manexim (https://github.com/manexim) +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public +* License as published by the Free Software Foundation; either +* version 2 of the License, or (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public +* License along with this program; if not, write to the +* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +* Boston, MA 02110-1301 USA +* +* Authored by: Marius Meisenzahl +*/ + +public class ComWhatsappWeb : Models.Plugin { + public ComWhatsappWeb () { + Object ( + id: "com.whatsapp.web", + name: "WhatsApp", + url: "https://web.whatsapp.com/" + ); + } +} diff --git a/plugins/com.whatsapp.web/meson.build b/plugins/com.whatsapp.web/meson.build index e1c7a92..0a666f4 100644 --- a/plugins/com.whatsapp.web/meson.build +++ b/plugins/com.whatsapp.web/meson.build @@ -1,6 +1,10 @@ -sources += [] +name = 'com.whatsapp.web' + +sources += [ + join_paths(meson.source_root(), meson.current_source_dir(), name + '.vala') +] install_data( - join_paths('com.whatsapp.web.svg'), + name + '.svg', install_dir: join_paths(get_option('datadir'), meson.project_name(), 'icons') ) diff --git a/plugins/org.telegram.web/meson.build b/plugins/org.telegram.web/meson.build index ced3215..7e1c423 100644 --- a/plugins/org.telegram.web/meson.build +++ b/plugins/org.telegram.web/meson.build @@ -1,6 +1,10 @@ -sources += [] +name = 'org.telegram.web' + +sources += [ + join_paths(meson.source_root(), meson.current_source_dir(), name + '.vala') +] install_data( - join_paths('org.telegram.web.svg'), + name + '.svg', install_dir: join_paths(get_option('datadir'), meson.project_name(), 'icons') ) diff --git a/plugins/org.telegram.web/org.telegram.web.vala b/plugins/org.telegram.web/org.telegram.web.vala new file mode 100644 index 0000000..85b9b70 --- /dev/null +++ b/plugins/org.telegram.web/org.telegram.web.vala @@ -0,0 +1,30 @@ +/* +* Copyright (c) 2020 Manexim (https://github.com/manexim) +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public +* License as published by the Free Software Foundation; either +* version 2 of the License, or (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public +* License along with this program; if not, write to the +* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +* Boston, MA 02110-1301 USA +* +* Authored by: Marius Meisenzahl +*/ + +public class OrgTelegramWeb : Models.Plugin { + public OrgTelegramWeb () { + Object ( + id: "org.telegram.web", + name: "Telegram", + url: "https://web.telegram.org/" + ); + } +} diff --git a/src/Models/Plugin.vala b/src/Models/Plugin.vala index af6aa96..e36af81 100644 --- a/src/Models/Plugin.vala +++ b/src/Models/Plugin.vala @@ -23,7 +23,7 @@ public class Models.Plugin : Object { private string _id; private string _name; private string _url; - private bool _enabled = false; + private bool _enabled = true; private uint _unread_notifications = 0; public string id { diff --git a/src/Services/PluginManager.vala b/src/Services/PluginManager.vala index 9c9ab5e..819c36b 100644 --- a/src/Services/PluginManager.vala +++ b/src/Services/PluginManager.vala @@ -32,9 +32,16 @@ public class Services.PluginManager : Object { return instance; } - public Array data { - get { - return _data; + public Array enabled { + owned get { + var array = new Array (); + for (var i = 0; i < _data.length; i++) { + if (_data.index (i).enabled) { + array.append_val (_data.index (i)); + } + } + + return array; } } @@ -56,34 +63,22 @@ public class Services.PluginManager : Object { _data = new Array (); { - var plugin = new Models.Plugin (); - plugin.id = "com.messenger"; - plugin.name = "Messenger"; - plugin.url = "https://www.messenger.com/"; + var plugin = new ComMessenger (); _data.append_val (plugin); } { - var plugin = new Models.Plugin (); - plugin.id = "com.slack"; - plugin.name = "Slack"; - plugin.url = "https://slack.com/signin/"; + var plugin = new ComSlack (); _data.append_val (plugin); } { - var plugin = new Models.Plugin (); - plugin.id = "org.telegram.web"; - plugin.name = "Telegram"; - plugin.url = "https://web.telegram.org/"; + var plugin = new OrgTelegramWeb (); _data.append_val (plugin); } { - var plugin = new Models.Plugin (); - plugin.id = "com.whatsapp.web"; - plugin.name = "WhatsApp"; - plugin.url = "https://web.whatsapp.com/"; + var plugin = new ComWhatsappWeb (); _data.append_val (plugin); } } diff --git a/src/Views/MainView.vala b/src/Views/MainView.vala index 4a35d0e..ba7cb0f 100644 --- a/src/Views/MainView.vala +++ b/src/Views/MainView.vala @@ -31,7 +31,7 @@ public class Views.MainView : Gtk.Paned { list_box.selection_mode = Gtk.SelectionMode.SINGLE; list_box.activate_on_single_click = true; - var plugins = Services.PluginManager.get_default ().data; + var plugins = Services.PluginManager.get_default ().enabled; for (var i = 0; i < plugins.length; i++) { var plugin = plugins.index (i); diff --git a/src/meson.build b/src/meson.build index 69ae88e..c2a90d5 100644 --- a/src/meson.build +++ b/src/meson.build @@ -1,4 +1,4 @@ -sources = [ +sources += [ 'Config/Constants.vala', 'Models/Plugin.vala', 'Services/PluginManager.vala', @@ -12,10 +12,6 @@ sources = [ executable( meson.project_name(), sources + ['Application.vala'], - dependencies: [ - gtk_plus_3_dep, - granite_dep, - webkit2gtk_4_dep, - ], + dependencies: dependencies, install: true ) From 36696f775fac8252545c5d6501b72801ec447085 Mon Sep 17 00:00:00 2001 From: Marius Meisenzahl Date: Sat, 11 Jul 2020 09:05:29 +0200 Subject: [PATCH 4/8] Add custom WebContext --- src/Utilities/WebContext.vala | 50 +++++++++++++++++++++++++++++++++++ src/Widgets/PluginView.vala | 36 ++++++++++++++++++++----- src/meson.build | 1 + 3 files changed, 81 insertions(+), 6 deletions(-) create mode 100644 src/Utilities/WebContext.vala diff --git a/src/Utilities/WebContext.vala b/src/Utilities/WebContext.vala new file mode 100644 index 0000000..4d16b3b --- /dev/null +++ b/src/Utilities/WebContext.vala @@ -0,0 +1,50 @@ +/* +* Copyright (c) 2020 Manexim (https://github.com/manexim) +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public +* License as published by the Free Software Foundation; either +* version 2 of the License, or (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public +* License along with this program; if not, write to the +* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +* Boston, MA 02110-1301 USA +* +* Authored by: Marius Meisenzahl +*/ + +public class WebContext : WebKit.WebContext { + public WebContext () { + Object ( + // This causes a known visual regression with navigation gestures. + // See: https://bugs.webkit.org/show_bug.cgi?id=205651 + process_swap_on_cross_site_navigation_enabled: true + ); + + var cookie_manager = get_cookie_manager (); + cookie_manager.set_accept_policy (WebKit.CookieAcceptPolicy.ALWAYS); + + string config_dir = Path.build_path ( + Path.DIR_SEPARATOR_S, + Environment.get_user_config_dir (), + Environment.get_prgname () + ); + + DirUtils.create_with_parents (config_dir, 0700); + + string cookies = Path.build_filename (config_dir, "cookies"); + cookie_manager.set_persistent_storage ( + cookies, + WebKit.CookiePersistentStorage.SQLITE + ); + + set_process_model (WebKit.ProcessModel.MULTIPLE_SECONDARY_PROCESSES); + set_sandbox_enabled (true); + } +} diff --git a/src/Widgets/PluginView.vala b/src/Widgets/PluginView.vala index 8d34bf8..85b66a3 100644 --- a/src/Widgets/PluginView.vala +++ b/src/Widgets/PluginView.vala @@ -27,12 +27,6 @@ public class Widgets.PluginView : WebKit.WebView { this.plugin = plugin; this.icon = Utilities.load_shared_icon (this.plugin.id); - var settings = this.get_settings (); - settings.enable_plugins = true; - settings.enable_javascript = true; - settings.enable_html5_database = true; - settings.enable_html5_local_storage = true; - web_context.initialize_notification_permissions.connect (() => { var allowed_origins = new List (); allowed_origins.append (new WebKit.SecurityOrigin.for_uri (this.plugin.url)); @@ -59,9 +53,39 @@ public class Widgets.PluginView : WebKit.WebView { load_uri (this.plugin.url); } + construct { + var webkit_settings = new WebKit.Settings () { + default_font_family = Gtk.Settings.get_default ().gtk_font_name, + enable_accelerated_2d_canvas = true, + enable_back_forward_navigation_gestures = true, + enable_dns_prefetching = true, + enable_html5_database = true, + enable_html5_local_storage = true, + enable_javascript = true, + enable_plugins = true, + enable_smooth_scrolling = true, + enable_webgl = true, + hardware_acceleration_policy = WebKit.HardwareAccelerationPolicy.ALWAYS + }; + + settings = webkit_settings; + web_context = new WebContext (); + + context_menu.connect (on_context_menu); + } + public Models.Plugin model { get { return this.plugin; } } + + private bool on_context_menu ( + WebKit.ContextMenu context_menu, + Gdk.Event event, + WebKit.HitTestResult hit_test_result + ) { + // Disable context menu + return true; + } } diff --git a/src/meson.build b/src/meson.build index c2a90d5..68e449a 100644 --- a/src/meson.build +++ b/src/meson.build @@ -4,6 +4,7 @@ sources += [ 'Services/PluginManager.vala', 'Services/Settings.vala', 'Utilities/Icon.vala', + 'Utilities/WebContext.vala', 'Views/MainView.vala', 'Widgets/PluginView.vala', 'MainWindow.vala' From e2e9bd02146dc5495eb8e386d54e7f5c681dfe7f Mon Sep 17 00:00:00 2001 From: Marius Meisenzahl Date: Sat, 11 Jul 2020 13:55:34 +0200 Subject: [PATCH 5/8] Use SourceList --- src/Views/MainView.vala | 112 ++++++++++++++++------------------------ 1 file changed, 44 insertions(+), 68 deletions(-) diff --git a/src/Views/MainView.vala b/src/Views/MainView.vala index ba7cb0f..0bbde5a 100644 --- a/src/Views/MainView.vala +++ b/src/Views/MainView.vala @@ -22,15 +22,11 @@ public class Views.MainView : Gtk.Paned { construct { orientation = Gtk.Orientation.HORIZONTAL; + position = 130; - var grid = new Gtk.Grid (); + var source_list = new Granite.Widgets.SourceList (); var stack = new Gtk.Stack (); - grid.orientation = Gtk.Orientation.VERTICAL; - var list_box = new Gtk.ListBox (); - list_box.selection_mode = Gtk.SelectionMode.SINGLE; - list_box.activate_on_single_click = true; - var plugins = Services.PluginManager.get_default ().enabled; for (var i = 0; i < plugins.length; i++) { var plugin = plugins.index (i); @@ -38,91 +34,71 @@ public class Views.MainView : Gtk.Paned { var view = new Widgets.PluginView (plugin); stack.add_named (view, plugin.id); - var menu_item = new Gtk.MenuItem (); - - var image = new Gtk.Image.from_gicon (Utilities.load_shared_icon (plugin.id), Gtk.IconSize.DND); - var label = new Gtk.Label (plugin.name); - var unread_notifications = new Gtk.Label ( - (plugin.unread_notifications > 0) ? "%u".printf (plugin.unread_notifications) : "" - ); + var menu_item = new Granite.Widgets.SourceList.Item (plugin.name); + menu_item.badge = (plugin.unread_notifications > 0) ? "%u".printf (plugin.unread_notifications) : ""; + menu_item.icon = Utilities.load_shared_icon (plugin.id); + source_list.root.add (menu_item); plugin.notify.connect (() => { debug ("[%s] unread_notifications: %u", plugin.id, plugin.unread_notifications); if (stack.get_visible_child () != view) { - unread_notifications.label = + menu_item.badge = (plugin.unread_notifications > 0) ? "%u".printf (plugin.unread_notifications) : ""; } else if (plugin.unread_notifications == 0) { - unread_notifications.label = ""; + menu_item.badge = ""; } - uint unread_notifications_sum = 0; - foreach (var m in plugins.data) { - unread_notifications_sum += m.unread_notifications; - } - - Granite.Services.Application.set_badge.begin (unread_notifications_sum, (obj, res) => { - try { - Granite.Services.Application.set_badge.end (res); - } catch (GLib.Error e) { - critical (e.message); - } - }); - - Granite.Services.Application.set_badge_visible.begin (unread_notifications_sum != 0U, (obj, res) => { - try { - Granite.Services.Application.set_badge_visible.end (res); - } catch (GLib.Error e) { - critical (e.message); - } - }); + update_app_badge (); }); - - var box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0); - box.pack_start (image, false, false, 0); - box.pack_start (label, false, false, 0); - box.pack_end (unread_notifications, false, false, 0); - - menu_item.add (box); - - list_box.insert (menu_item, i); } - list_box.row_activated.connect ((row) => { - for (var i = 0; i < plugins.length; i++) { - if (row.get_index () == i) { - Services.PluginManager.get_default ().visible = plugins.index (i).id; - break; - } + pack1 (source_list, false, false); + add2 (stack); + + source_list.item_selected.connect ((item) => { + if (item == null) { + return; } - }); - Services.PluginManager.get_default ().notify["visible"].connect (() => { - var visible = Services.PluginManager.get_default ().visible; - int index = 0; for (var i = 0; i < plugins.length; i++) { - if (visible == plugins.index (i).id) { - index = i; + var plugin = plugins.index (i); + if (item.name == plugin.name) { + stack.set_visible_child_name (plugin.id); + plugin.unread_notifications = 0; break; } } - list_box.select_row (list_box.get_row_at_index (index)); + if (item.badge != "" && item.badge != null) { + item.badge = ""; + } - stack.set_visible_child_name (visible); - var view = stack.get_visible_child (); - (view as Widgets.PluginView).model.unread_notifications = 0; + update_app_badge (); }); + } - var scroll = new Gtk.ScrolledWindow (null, null); - scroll.hscrollbar_policy = Gtk.PolicyType.NEVER; - scroll.expand = true; - scroll.add (list_box); + private void update_app_badge () { + uint unread_notifications_sum = 0; + var plugins = Services.PluginManager.get_default ().enabled; + foreach (var m in plugins.data) { + unread_notifications_sum += m.unread_notifications; + } - grid.add (scroll); + Granite.Services.Application.set_badge.begin (unread_notifications_sum, (obj, res) => { + try { + Granite.Services.Application.set_badge.end (res); + } catch (GLib.Error e) { + critical (e.message); + } + }); - pack1 (grid, false, false); - pack2 (stack, true, false); - show_all (); + Granite.Services.Application.set_badge_visible.begin (unread_notifications_sum != 0U, (obj, res) => { + try { + Granite.Services.Application.set_badge_visible.end (res); + } catch (GLib.Error e) { + critical (e.message); + } + }); } } From eb3e3a95b0650a2b88e06dbb9892f9f58869c751 Mon Sep 17 00:00:00 2001 From: Marius Meisenzahl Date: Sat, 11 Jul 2020 16:33:36 +0200 Subject: [PATCH 6/8] React to action show-tab of notifications --- src/Views/MainView.vala | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/Views/MainView.vala b/src/Views/MainView.vala index 0bbde5a..11e871a 100644 --- a/src/Views/MainView.vala +++ b/src/Views/MainView.vala @@ -53,6 +53,29 @@ public class Views.MainView : Gtk.Paned { }); } + Services.PluginManager.get_default ().notify["visible"].connect (() => { + var visible = Services.PluginManager.get_default ().visible; + Models.Plugin? plugin = null; + for (var i = 0; i < plugins.length; i++) { + if (visible == plugins.index (i).id) { + plugin = plugins.index (i); + break; + } + } + + if (plugin == null) { + return; + }; + + foreach (var item in source_list.root.children) { + if (item.name == plugin.name) { + source_list.scroll_to_item (item); + source_list.selected = item; + break; + } + } + }); + pack1 (source_list, false, false); add2 (stack); From 5742a2badb7ff9f74cedc0df1577d60f2e884a83 Mon Sep 17 00:00:00 2001 From: Marius Meisenzahl Date: Sat, 11 Jul 2020 16:33:57 +0200 Subject: [PATCH 7/8] Close application with Q --- src/Application.vala | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Application.vala b/src/Application.vala index 5bb170e..5c03d9a 100644 --- a/src/Application.vala +++ b/src/Application.vala @@ -35,6 +35,14 @@ public class Application : Granite.Application { window = new MainWindow (this); window.show_all (); + + var action_quit = new SimpleAction ("quit", null); + add_action (action_quit); + set_accels_for_action ("app.quit", {"Q"}); + + action_quit.activate.connect (() => { + quit (); + }); } public static int main (string[] args) { From d854346c0fb2450589907a9b115a580c0c19ec28 Mon Sep 17 00:00:00 2001 From: Marius Meisenzahl Date: Sat, 11 Jul 2020 16:34:06 +0200 Subject: [PATCH 8/8] Enable page cache --- src/Widgets/PluginView.vala | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Widgets/PluginView.vala b/src/Widgets/PluginView.vala index 85b66a3..f01ccf5 100644 --- a/src/Widgets/PluginView.vala +++ b/src/Widgets/PluginView.vala @@ -62,6 +62,7 @@ public class Widgets.PluginView : WebKit.WebView { enable_html5_database = true, enable_html5_local_storage = true, enable_javascript = true, + enable_page_cache = true, enable_plugins = true, enable_smooth_scrolling = true, enable_webgl = true,