[extensions-web/feature/inline-installation: 2/2] Added inline installation of browser extension.
- From: Yuri Konotopov <ykonotopov src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [extensions-web/feature/inline-installation: 2/2] Added inline installation of browser extension.
- Date: Sat, 25 Feb 2017 14:11:30 +0000 (UTC)
commit 2aeeb9e81f825c22efdf55331e7efbc6526f86c6
Author: Yuri Konotopov <ykonotopov gnome org>
Date: Sat Feb 25 18:10:48 2017 +0400
Added inline installation of browser extension.
sweettooth/static/js/browser_extension.js | 49 ++++++++++++++++++++
sweettooth/static/js/extensions.js | 13 ++++-
.../templates/messages/browser_extension.mustache | 2 +
sweettooth/static/js/templates/templatedata.js | 1 +
sweettooth/templates/base.html | 1 +
5 files changed, 63 insertions(+), 3 deletions(-)
---
diff --git a/sweettooth/static/js/browser_extension.js b/sweettooth/static/js/browser_extension.js
new file mode 100644
index 0000000..5409fb7
--- /dev/null
+++ b/sweettooth/static/js/browser_extension.js
@@ -0,0 +1,49 @@
+/*
+ GNOME Shell extensions repository
+ Copyright (C) 2017 Yuri Konotopov <ykonotopov gnome org>
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+ */
+
+IS_CHROME = (typeof(chrome) !== 'undefined' && typeof(chrome.webstore) !== 'undefined');
+IS_FIREFOX = (typeof(InstallTrigger) !== 'undefined');
+IS_OPERA = (typeof(opr) !== 'undefined');
+
+function browser_extension_install() {
+ function reload_page() {
+ location.reload();
+ }
+
+ if (IS_OPERA)
+ {
+ opr.addons.installExtension(
+ 'olkooankbfblcebocnkjganpdmflbnbk',
+ reload_page
+ );
+ }
+ else if(IS_FIREFOX)
+ {
+ // https://developer.mozilla.org/en-US/docs/Web/API/InstallTrigger/install
+ InstallTrigger.install({
+ 'GNOME Shell integration': {
+ 'URL':
'https://addons.mozilla.org/firefox/downloads/latest/gnome-shell-integration/platform:2/addon-751081-latest.xpi'
+ }
+ }, function(url, status) {
+ if (status == 0) {
+ reload_page();
+ }
+ });
+ }
+ else if (IS_CHROME)
+ {
+ chrome.webstore.install(
+ undefined,
+ reload_page
+ );
+ }
+
+ return false;
+}
diff --git a/sweettooth/static/js/extensions.js b/sweettooth/static/js/extensions.js
index 8427a01..a51090e 100644
--- a/sweettooth/static/js/extensions.js
+++ b/sweettooth/static/js/extensions.js
@@ -44,9 +44,16 @@ define(['jquery', 'messages', 'dbus!_', 'extensionUtils', 'templates', 'paginato
// is running with an old Shell version but a newer plugin, error out.
if (dbusProxy.IsDummy)
{
- // We don't have a proper DBus proxy -- it's probably an old
- // version of GNOME3 or the Shell.
- messages.addError(templates.get('messages/dummy_proxy')());
+ // We don't have a proper DBus proxy
+ if (IS_CHROME || IS_FIREFOX || IS_OPERA) // browser_extension.js should be included
globally
+ {
+ // Help user to install browser extension for supported browsers
+ messages.addInfo(templates.get('messages/browser_extension')());
+ }
+ else
+ {
+ messages.addError(templates.get('messages/dummy_proxy')());
+ }
$.fn.addExtensionSwitch = function () {
// Don't show our switches -- CSS styles define a clickable
diff --git a/sweettooth/static/js/templates/messages/browser_extension.mustache
b/sweettooth/static/js/templates/messages/browser_extension.mustache
new file mode 100644
index 0000000..426945d
--- /dev/null
+++ b/sweettooth/static/js/templates/messages/browser_extension.mustache
@@ -0,0 +1,2 @@
+To control GNOME Shell extensions using this site you must install GNOME Shell integration that consists of
two parts: browser extension and native host messaging application.<br />
+<a href="#" title="Install GNOME Shell integration browser extension" onclick="return
browser_extension_install();">Click here to install browser extension</a>. See <a
href="https://wiki.gnome.org/Projects/GnomeShellIntegrationForChrome/Installation"
onclick="window.open(this.href); return false;">wiki page</a> for native host connector installation
instructions.
diff --git a/sweettooth/static/js/templates/templatedata.js b/sweettooth/static/js/templates/templatedata.js
index 8514a8a..fbdb079 100644
--- a/sweettooth/static/js/templates/templatedata.js
+++ b/sweettooth/static/js/templates/templatedata.js
@@ -9,6 +9,7 @@ define({
"extensions/info_contents": "<h3 class=\"extension-name\">\n {{#link}}\n <a href=\"{{link}}\"
class=\"title-link\"><img src=\"{{icon}}\" class=\"icon\">{{name}}</a>\n {{/link}}\n {{^link}}\n <span
class=\"icon plugin-unknown\"></span>{{name}}\n {{/link}}\n</h3>\n{{#creator}}\n <span class=\"author\">by
<a href=\"{{creator_url}}\">{{creator}}</a></span>\n{{/creator}}\n<div class=\"controls\">\n <div
class=\"switch\"></div>\n <div class=\"extra-buttons\">\n <div class=\"upgrade-button\" title=\"Upgrade
this extension\"></div>\n <div class=\"configure-button\" title=\"Configure this extension\"></div>\n
<div class=\"uninstall-button\" title=\"Uninstall this extension\"></div>\n </div>\n</div>\n<div
style=\"clear: both\"></div>\n<div class='system-extension' title='System extension should be uninstalled
using package manager. See \u00abAbout\u00bb page for more details.'>System extension</div>\n<p
class=\"description\">{{first_line_of_description}}</p>",
"extensions/info_list": "<ul class=\"extensions\">\n{{#extensions}}\n <li class=\"extension\"
data-svm=\"{{shell_version_map}}\">\n {{>extensions/info_contents}}\n </li>\n{{/extensions}}\n</ul>",
"extensions/uninstall": "You uninstalled <b>{{name}}</b>.",
+ "messages/browser_extension": "To control GNOME Shell extensions using this site you must install GNOME
Shell integration that consists of two parts: browser extension and native host messaging application.<br
/>\n<a href=\"#\" title=\"Install GNOME Shell integration browser extension\" onclick=\"return
browser_extension_install();\">Click here to install browser extension</a>. See <a
href=\"https://wiki.gnome.org/Projects/GnomeShellIntegrationForChrome/Installation\"
onclick=\"window.open(this.href); return false;\">wiki page</a> for native host connector installation
instructions.",
"messages/cannot_list_errors": "GNOME Shell Extensions cannot automatically detect any errors.",
"messages/cannot_list_local": "GNOME Shell Extensions cannot list your installed extensions.",
"messages/dummy_proxy": "We cannot detect a running copy of GNOME on this system, so some parts of the
interface may be disabled. See <a href=\"/about/#no-detection\">our troubleshooting entry</a> for more
information."
diff --git a/sweettooth/templates/base.html b/sweettooth/templates/base.html
index a42e595..4e161be 100644
--- a/sweettooth/templates/base.html
+++ b/sweettooth/templates/base.html
@@ -19,6 +19,7 @@
var django_static_images = {% static_img_paths %};
</script>
+ <script src="{% static 'js/browser_extension.js' %}"></script>
<script src="{% static 'js/require.js' %}"></script>
<script src="{% static 'js/jquery.js' %}"></script>
<script>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]