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..c084009 100644 --- a/meson.build +++ b/meson.build @@ -11,7 +11,16 @@ 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') 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/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 new file mode 100644 index 0000000..a83da4a --- /dev/null +++ b/plugins/com.messenger/meson.build @@ -0,0 +1,10 @@ +name = 'com.messenger' + +sources += [ + join_paths(meson.source_root(), meson.current_source_dir(), name + '.vala') +] + +install_data( + name + '.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/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 new file mode 100644 index 0000000..c2b22ec --- /dev/null +++ b/plugins/com.slack/meson.build @@ -0,0 +1,10 @@ +name = 'com.slack' + +sources += [ + join_paths(meson.source_root(), meson.current_source_dir(), name + '.vala') +] + +install_data( + name + '.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/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 new file mode 100644 index 0000000..0a666f4 --- /dev/null +++ b/plugins/com.whatsapp.web/meson.build @@ -0,0 +1,10 @@ +name = 'com.whatsapp.web' + +sources += [ + join_paths(meson.source_root(), meson.current_source_dir(), name + '.vala') +] + +install_data( + name + '.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..7e1c423 --- /dev/null +++ b/plugins/org.telegram.web/meson.build @@ -0,0 +1,10 @@ +name = 'org.telegram.web' + +sources += [ + join_paths(meson.source_root(), meson.current_source_dir(), name + '.vala') +] + +install_data( + name + '.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 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/Application.vala b/src/Application.vala index ccd1458..5c03d9a 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 (); }); @@ -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) { 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..e36af81 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 = true; 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 50% rename from src/Services/Messengers.vala rename to src/Services/PluginManager.vala index 3162a34..819c36b 100644 --- a/src/Services/Messengers.vala +++ b/src/Services/PluginManager.vala @@ -19,22 +19,29 @@ * 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 { - 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; } } @@ -52,39 +59,27 @@ 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 ComMessenger (); + _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 ComSlack (); + _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 OrgTelegramWeb (); + _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 ComWhatsappWeb (); + _data.append_val (plugin); } } } 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/Views/MainView.vala b/src/Views/MainView.vala index 9cb7127..11e871a 100644 --- a/src/Views/MainView.vala +++ b/src/Views/MainView.vala @@ -22,107 +22,106 @@ 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); - var messengers = Services.Messengers.get_default ().data; - for (var i = 0; i < messengers.length; i++) { - var messenger = messengers.index (i); + var view = new Widgets.PluginView (plugin); + stack.add_named (view, plugin.id); - var view = new Widgets.MessengerView (messenger); - stack.add_named (view, messenger.id); + 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); - 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 unread_notifications = new Gtk.Label ( - (messenger.unread_notifications > 0) ? "%u".printf (messenger.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) { - unread_notifications.label = ""; + menu_item.badge = + (plugin.unread_notifications > 0) ? "%u".printf (plugin.unread_notifications) : ""; + } else if (plugin.unread_notifications == 0) { + menu_item.badge = ""; } - uint unread_notifications_sum = 0; - foreach (var m in messengers.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); + 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; + } + } - list_box.insert (menu_item, i); - } + if (plugin == null) { + return; + }; - list_box.row_activated.connect ((row) => { - for (var i = 0; i < messengers.length; i++) { - if (row.get_index () == i) { - Services.Messengers.get_default ().visible = messengers.index (i).id; + foreach (var item in source_list.root.children) { + if (item.name == plugin.name) { + source_list.scroll_to_item (item); + source_list.selected = item; break; } } }); - Services.Messengers.get_default ().notify["visible"].connect (() => { - var visible = Services.Messengers.get_default ().visible; - int index = 0; - for (var i = 0; i < messengers.length; i++) { - if (visible == messengers.index (i).id) { - index = i; + pack1 (source_list, false, false); + add2 (stack); + + source_list.item_selected.connect ((item) => { + if (item == null) { + return; + } + + for (var i = 0; i < plugins.length; 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.MessengerView).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); + } + }); } } diff --git a/src/Widgets/MessengerView.vala b/src/Widgets/MessengerView.vala deleted file mode 100644 index 19f82e4..0000000 --- a/src/Widgets/MessengerView.vala +++ /dev/null @@ -1,67 +0,0 @@ -/* -* 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 Widgets.MessengerView : WebKit.WebView { - private Models.Messenger messenger; - private GLib.Icon icon; - - public MessengerView (Models.Messenger messenger) { - this.messenger = messenger; - this.icon = Utilities.load_shared_icon (this.messenger.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.messenger.url)); - var disallowed_origins = new List (); - - web_context.init_notification_permissions (allowed_origins, disallowed_origins); - }); - - show_notification.connect ((notification) => { - 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); - - this.messenger.unread_notifications += 1; - - debug ("[%s] got notification".printf (this.messenger.id)); - - return true; - }); - - load_uri (this.messenger.url); - } - - public Models.Messenger model { - get { - return this.messenger; - } - } -} diff --git a/src/Widgets/PluginView.vala b/src/Widgets/PluginView.vala new file mode 100644 index 0000000..f01ccf5 --- /dev/null +++ b/src/Widgets/PluginView.vala @@ -0,0 +1,92 @@ +/* +* 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 Widgets.PluginView : WebKit.WebView { + private Models.Plugin plugin; + private GLib.Icon icon; + + public PluginView (Models.Plugin plugin) { + this.plugin = plugin; + this.icon = Utilities.load_shared_icon (this.plugin.id); + + web_context.initialize_notification_permissions.connect (() => { + var allowed_origins = new List (); + 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); + }); + + show_notification.connect ((notification) => { + 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.plugin.id); + native_notification.set_default_action_and_target_value ("app.show-tab", target); + Application.instance.send_notification (this.plugin.id, native_notification); + + this.plugin.unread_notifications += 1; + + debug ("[%s] got notification".printf (this.plugin.id)); + + return true; + }); + + 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_page_cache = 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 d8b9367..68e449a 100644 --- a/src/meson.build +++ b/src/meson.build @@ -1,21 +1,18 @@ -sources = [ +sources += [ 'Config/Constants.vala', - 'Models/Messenger.vala', - 'Services/Messengers.vala', + 'Models/Plugin.vala', + 'Services/PluginManager.vala', 'Services/Settings.vala', 'Utilities/Icon.vala', + 'Utilities/WebContext.vala', 'Views/MainView.vala', - 'Widgets/MessengerView.vala', + 'Widgets/PluginView.vala', 'MainWindow.vala' ] executable( meson.project_name(), sources + ['Application.vala'], - dependencies: [ - gtk_plus_3_dep, - granite_dep, - webkit2gtk_4_dep, - ], + dependencies: dependencies, install: true )