[extensions-web/bugfix/incompatible-extensions/776460] extension: find "best" version if Shell version check is disabled.
- From: Yuri Konotopov <ykonotopov src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [extensions-web/bugfix/incompatible-extensions/776460] extension: find "best" version if Shell version check is disabled.
- Date: Sun, 9 Apr 2017 10:25:56 +0000 (UTC)
commit e745fa7f2d0f54091351e41424bb877542498fba
Author: Yuri Konotopov <ykonotopov gnome org>
Date: Sun Apr 9 14:25:33 2017 +0400
extension: find "best" version if Shell version check is disabled.
Bug: https://bugzilla.gnome.org/show_bug.cgi?id=776460
sweettooth/static/js/extensionUtils.js | 65 ++++++++++++++++++++++++++++++-
sweettooth/static/js/extensions.js | 13 +++++-
sweettooth/static/js/test/extensions.js | 15 +++++++
3 files changed, 89 insertions(+), 4 deletions(-)
---
diff --git a/sweettooth/static/js/extensionUtils.js b/sweettooth/static/js/extensionUtils.js
index 63a99da..77c60dd 100644
--- a/sweettooth/static/js/extensionUtils.js
+++ b/sweettooth/static/js/extensionUtils.js
@@ -37,8 +37,61 @@ define([], function () {
PER_USER: 2
};
- exports.grabProperExtensionVersion = function (map, current) {
- if (!map)
+ exports.grabProperExtensionVersion = function (map, current, findBestVersion) {
+ function getBestShellVersion() {
+ function versionCompare(a, b) {
+ function toInt(value) {
+ return parseInt(value);
+ }
+
+ if (a == b)
+ {
+ return 0;
+ }
+
+ a = a.split('.').map(toInt);
+ b = b.split('.').map(toInt);
+
+ for (let i = 0; i < Math.max(a.length, b.length); i++)
+ {
+ if (a.length < i + 1)
+ {
+ return -1;
+ }
+
+ if (b.length < i + 1)
+ {
+ return 1;
+ }
+
+ if (a[i] < b[i])
+ {
+ return -1;
+ }
+
+ if (b[i] < a[i])
+ {
+ return 1;
+ }
+ }
+
+ return 0;
+ }
+
+ let supported_shell_versions = Object.keys(map).sort(versionCompare);
+
+ if (versionCompare(supported_shell_versions[0], current) == 1)
+ {
+ return supported_shell_versions[0];
+ }
+ else
+ {
+ return supported_shell_versions[supported_shell_versions.length - 1];
+ }
+ }
+
+
+ if (!map || !current)
{
return null;
}
@@ -57,6 +110,10 @@ define([], function () {
{
return versionA;
}
+ else if(findBestVersion)
+ {
+ return map[getBestShellVersion()];
+ }
else
{
return null;
@@ -77,6 +134,10 @@ define([], function () {
{
return versionB;
}
+ else if(findBestVersion)
+ {
+ return map[getBestShellVersion()];
+ }
else
{
return null;
diff --git a/sweettooth/static/js/extensions.js b/sweettooth/static/js/extensions.js
index 77b304d..f08f437 100644
--- a/sweettooth/static/js/extensions.js
+++ b/sweettooth/static/js/extensions.js
@@ -213,7 +213,12 @@ define(['jquery', 'messages', 'dbus!_', 'extensionUtils', 'templates', 'paginato
$switch.switchify();
var svm = meta.shell_version_map || $elem.data('svm');
- var latest = extensionUtils.grabProperExtensionVersion(svm, dbusProxy.ShellVersion);
+ var latest = extensionUtils.grabProperExtensionVersion(
+ svm,
+ dbusProxy.ShellVersion,
+ !dbusProxy.VersionValidationEnabled
+ );
+
if (_state !== ExtensionState.UNINSTALLED && latest !== null &&
(!meta.version || latest.version > meta.version || _state ===
ExtensionState.OUT_OF_DATE))
{
@@ -466,7 +471,11 @@ define(['jquery', 'messages', 'dbus!_', 'extensionUtils', 'templates', 'paginato
return;
}
- var vpk = extensionUtils.grabProperExtensionVersion(svm,
dbusProxy.ShellVersion);
+ var vpk = extensionUtils.grabProperExtensionVersion(
+ svm,
+ dbusProxy.ShellVersion,
+ !dbusProxy.VersionValidationEnabled
+ );
if (vpk === null)
{
$elem.addClass('out-of-date');
diff --git a/sweettooth/static/js/test/extensions.js b/sweettooth/static/js/test/extensions.js
index 681901d..35fb4e6 100644
--- a/sweettooth/static/js/test/extensions.js
+++ b/sweettooth/static/js/test/extensions.js
@@ -20,6 +20,21 @@ require(['extensionUtils', 'jquery', 'test/qunit'], function(extensionUtils) {
equal(grabProperExtensionVersion(map, "3.4.1.1").version, 7);
});
+ test("getBestExtensionVersion", function() {
+ var map = { "3.10": { version: 1, pk: 1 },
+ "3.13.4": { version: 2, pk: 2 },
+ "3.20": { version: 3, pk: 3 } };
+
+ equal(grabProperExtensionVersion(map, "3.4.0", true).version, 1);
+ equal(grabProperExtensionVersion(map, "3.7.4.1", true).version, 1);
+ equal(grabProperExtensionVersion(map, "3.10.0", true).version, 1);
+ equal(grabProperExtensionVersion(map, "3.13.4", true).version, 2);
+ equal(grabProperExtensionVersion(map, "3.11.2", true).version, 3);
+ equal(grabProperExtensionVersion(map, "3.20.0", true).version, 3);
+ equal(grabProperExtensionVersion(map, "3.24.0", true).version, 3);
+ equal(grabProperExtensionVersion(map, "4.14.0", true).version, 3);
+ });
+
function nhvEqual(versions, current, operation, stability, version) {
var vm = {};
versions.forEach(function(v) { vm[v] = true; });
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]