[extensions-web] Implement control of some Shell settings.



commit ccf045e46201b197c18dbf4815075a86f95f2253
Author: Yuri Konotopov <ykonotopov gnome org>
Date:   Mon Jan 7 22:29:00 2019 +0400

    Implement control of some Shell settings.
    
    Two settings can be controlled now on "Installed extensions" page:
    1. disable-user-extensions
    2. disable-extension-version-validation
    
    As part of this change "disable-user-extensions" setting now affects on/off
    switch of each installed extension.
    
    Fixes: https://gitlab.gnome.org/GNOME/chrome-gnome-shell/issues/2

 .../extensions/templates/extensions/local.html     |   5 +-
 sweettooth/static/css/sweettooth.css               |  26 ++++-
 sweettooth/static/js/extensions.js                 |   2 +
 sweettooth/static/js/main.js                       |  14 ++-
 sweettooth/static/js/settings.js                   | 117 +++++++++++++++++++++
 .../js/templates/extensions/settings.mustache      |   8 ++
 sweettooth/static/js/templates/templatedata.js     |   1 +
 7 files changed, 165 insertions(+), 8 deletions(-)
---
diff --git a/sweettooth/extensions/templates/extensions/local.html 
b/sweettooth/extensions/templates/extensions/local.html
index 6fdc45f..0eff07d 100644
--- a/sweettooth/extensions/templates/extensions/local.html
+++ b/sweettooth/extensions/templates/extensions/local.html
@@ -1,7 +1,10 @@
 {% extends "base.html" %}
 {% block title %}Installed Extensions - {{ block.super }}{% endblock %}
 {% block body %}
-<h2> Installed Extensions </h2>
+<h2>Shell settings</h2>
+<div id='shell_settings'></div>
+
+<h2>Installed Extensions</h2>
 <div id="local_extensions">
 </div>
 {% endblock %}
diff --git a/sweettooth/static/css/sweettooth.css b/sweettooth/static/css/sweettooth.css
index 0cb2a74..f89d424 100644
--- a/sweettooth/static/css/sweettooth.css
+++ b/sweettooth/static/css/sweettooth.css
@@ -224,12 +224,14 @@ li.extension {
     margin-left: 0px;
 }
 
-li.extension, #local_extensions div.extension {
+li.extension, #local_extensions div.extension, #shell_settings div.setting {
     border-bottom: 1px solid #ccc;
     border-bottom-color: rgba(0, 0, 0, 0.2);
 }
 
-li.extension:last-child, #local_extensions div.extension:last-child {
+li.extension:last-child,
+#local_extensions div.extension:last-child,
+#shell_settings div.setting:last-child {
     border-bottom: 0;
 }
 
@@ -247,12 +249,12 @@ li.extension:last-child, #local_extensions div.extension:last-child {
     opacity: 1.0;
 }
 
-.extension .extension-name a {
+.extension .extension-name a, .setting .setting-name a {
     color: #000;
     text-decoration: none;
 }
 
-.extension .extension-name {
+.extension .extension-name, .setting .setting-name {
     display: inline-block;
     line-height: 32px;
     margin: 0;
@@ -306,7 +308,7 @@ li.extension:last-child, #local_extensions div.extension:last-child {
 
 /* Upgrade, Configure, Uninstall buttons */
 
-.extension .controls {
+.extension .controls, .setting .controls {
     float: right;
     width: 180px;
 }
@@ -842,3 +844,17 @@ textarea:focus {
 .expandy_header.expanded:before {
     transform: rotate(90deg);
 }
+
+/* Settings */
+/* ==================================================================== */
+
+.setting .description {
+    margin: 0.5em 32px 0.5em 0em;
+    font-size: 1.2em;
+    overflow: auto;
+    white-space: pre-line;
+}
+
+#shell_settings .form-horizontal .form-group label {
+       text-align: left;
+}
diff --git a/sweettooth/static/js/extensions.js b/sweettooth/static/js/extensions.js
index b8e3e26..ab1957a 100644
--- a/sweettooth/static/js/extensions.js
+++ b/sweettooth/static/js/extensions.js
@@ -375,6 +375,8 @@ define(['jquery', 'messages', 'dbus!_', 'extensionUtils', 'templates', 'paginato
                                        $elem.addClass('out-of-date');
                                        $switch.switchify('customize', "OUTDATED", 'outdated');
                                }
+
+                               $switch.switchify(dbusProxy.GetUserExtensionsDisabled() ? 'disable' : 
'enable');
                        });
 
                        $elem.on('type-changed', function (e, newType) {
diff --git a/sweettooth/static/js/main.js b/sweettooth/static/js/main.js
index 64d6c58..7a21c99 100644
--- a/sweettooth/static/js/main.js
+++ b/sweettooth/static/js/main.js
@@ -1,7 +1,16 @@
-// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
+/*
+    GNOME Shell extensions repository
+    Copyright (C) 2011-2013  Jasper St. Pierre <jstpierre mecheye net>
+    Copyright (C) 2016-2019  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.
+ */
 
 define(['jquery', 'messages', 'modal', 'hashParamUtils',
-        'templates', 'staticfiles', 'js.cookie', 'extensions', 'uploader', 'fsui',
+        'templates', 'staticfiles', 'js.cookie', 'extensions', 'uploader', 'fsui', 'settings',
         'jquery.jeditable', 'jquery.timeago', 'jquery.raty', 'jquery.colorbox'],
 function($, messages, modal, hashParamUtils, templates, staticfiles, cookie) {
     "use strict";
@@ -60,6 +69,7 @@ function($, messages, modal, hashParamUtils, templates, staticfiles, cookie) {
             $(this).csrfEditable('/accounts/change_display_name/' + pk);
         });
 
+        $('#shell_settings').addShellSettings();
         $('#local_extensions').addLocalExtensions();
         $('.extension.single-page').addExtensionSwitch();
         $('.extension.single-page').addDownloadOptions();
diff --git a/sweettooth/static/js/settings.js b/sweettooth/static/js/settings.js
new file mode 100644
index 0000000..a99c555
--- /dev/null
+++ b/sweettooth/static/js/settings.js
@@ -0,0 +1,117 @@
+/*
+    GNOME Shell extensions repository
+    Copyright (C) 2019  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.
+ */
+
+define(['jquery', 'dbus!_', 'templates'], function ($, dbusProxy, templates) {
+               "use strict";
+               const SETTINGS = [
+                       {
+                               id: 'disable-user-extensions',
+                               name: 'Disable all extensions',
+                               description: 'Disable all extensions regardless per-extension enable 
setting.',
+                               enabled: () => {
+                                       return typeof(dbusProxy.UserExtensionsDisabled) !== 'undefined';
+                               },
+                               get: () => {
+                                       if(dbusProxy.IsDummy)
+                                       {
+                                               return;
+                                       }
+
+                                       return dbusProxy.GetUserExtensionsDisabled();
+                               },
+                               change: (value) => {
+                                       return dbusProxy.SetUserExtensionsDisabled(value);
+                               }
+                       },
+                       {
+                               id: 'disable-extension-version-validation',
+                               name: 'Disable version validation',
+                               description: 'Allow to load extensions that do not claims to support running 
Shell version. Default to enabled for recent Shell versions.',
+                               enabled: () => {
+                                       return typeof(dbusProxy.VersionValidationEnabled) !== 'undefined';
+                               },
+                               get: () => {
+                                       if(dbusProxy.IsDummy)
+                                       {
+                                               return;
+                                       }
+
+                                       return dbusProxy.GetVersionValidationDisabled();
+                               },
+                               change: (value) => {
+                                       return dbusProxy.SetVersionValidationDisabled(value);
+                               }
+                       }
+               ];
+
+               function refreshExtensionsDisableState() {
+                       
$('#local_extensions').find('.switch').switchify(dbusProxy.GetUserExtensionsDisabled() ? 'disable' : 
'enable');
+               }
+
+               dbusProxy.shellSettingChangedHandler = (key, value) => {
+                       if(key === 'disable-user-extensions')
+                       {
+                               refreshExtensionsDisableState();
+                       }
+
+                       $('#setting-' + key)
+                               .data('value', value)
+                               .trigger('setting-changed');
+               };
+
+               $.fn.addShellSettings = function() {
+                       this.each(function() {
+                               let $container = $(this);
+
+                               for(let setting of SETTINGS)
+                               {
+                                       let $elem = $(templates.get('extensions/settings')(setting))
+                                       $elem.data('value', setting.get());
+                                       $container.append($elem)
+
+                                       let $switch = $container.find('.switch');
+                                       $switch.switchify('disable');
+
+                                       $switch.on('changed', function (event, newValue) {
+                                               if(newValue == $elem.data('value'))
+                                               {
+                                                       return;
+                                               }
+
+                                               setting.change(newValue).then((status) => {
+                                                       if(!status)
+                                                       {
+                                                               console.log(`Unable to set value of 
${setting.id}`);
+                                                       }
+                                                       else
+                                                       {
+                                                               $elem.data('value', newValue);
+                                                       }
+                                               });
+                                       });
+
+                                       $elem.on('setting-changed', function(event) {
+                                               if(setting.enabled())
+                                               {
+                                                       $switch.switchify('enable');
+                                                       $switch.switchify('activate', setting.get());
+                                               }
+                                               else
+                                               {
+                                                       $switch.switchify('disable');
+                                               }
+                                       });
+
+                                       $elem.trigger('setting-changed');
+                               }
+                       });
+               }
+       }
+);
diff --git a/sweettooth/static/js/templates/extensions/settings.mustache 
b/sweettooth/static/js/templates/extensions/settings.mustache
new file mode 100644
index 0000000..e53cbe0
--- /dev/null
+++ b/sweettooth/static/js/templates/extensions/settings.mustache
@@ -0,0 +1,8 @@
+<div class='setting' id='setting-{{id}}'>
+       <h3 class="setting-name">{{name}}</h3>
+       <div class="controls">
+               <div class="switch"></div>
+       </div>
+       <div style="clear: both"></div>
+       <p class="description">{{description}}</p>
+</div>
diff --git a/sweettooth/static/js/templates/templatedata.js b/sweettooth/static/js/templates/templatedata.js
index 9420127..bda9955 100644
--- a/sweettooth/static/js/templates/templatedata.js
+++ b/sweettooth/static/js/templates/templatedata.js
@@ -9,6 +9,7 @@ define({
   "extensions/info": "<div class=\"extension\" data-uuid=\"{{uuid}}\">\n  
{{>extensions/info_contents}}\n</div>",
   "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/settings": "<div class='setting' id='setting-{{id}}'>\n\t<h3 
class=\"setting-name\">{{name}}</h3>\n\t<div class=\"controls\">\n\t\t<div 
class=\"switch\"></div>\n\t</div>\n\t<div style=\"clear: both\"></div>\n\t<p 
class=\"description\">{{description}}</p>\n</div>",
   "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.",


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]