mirror of
https://github.com/keeweb/keeweb.git
synced 2024-06-22 07:16:38 +02:00
plugin manifest fields: versionMin, versionMax, desktop
This commit is contained in:
parent
1810480cf2
commit
ea0f612747
|
@ -6,6 +6,7 @@ const AppSettingsModel = require('../models/app-settings-model');
|
||||||
const UpdateModel = require('../models/update-model');
|
const UpdateModel = require('../models/update-model');
|
||||||
const Transport = require('../comp/transport');
|
const Transport = require('../comp/transport');
|
||||||
const Logger = require('../util/logger');
|
const Logger = require('../util/logger');
|
||||||
|
const SemVer = require('../util/semver');
|
||||||
const publicKey = require('raw-loader!../../resources/public-key.pem');
|
const publicKey = require('raw-loader!../../resources/public-key.pem');
|
||||||
|
|
||||||
const logger = new Logger('updater');
|
const logger = new Logger('updater');
|
||||||
|
@ -113,7 +114,7 @@ const Updater = {
|
||||||
}
|
}
|
||||||
if (!startedByUser && this.getAutoUpdateType() === 'install') {
|
if (!startedByUser && this.getAutoUpdateType() === 'install') {
|
||||||
this.update(startedByUser);
|
this.update(startedByUser);
|
||||||
} else if (this.compareVersions(UpdateModel.instance.get('lastVersion'), RuntimeInfo.version) > 0) {
|
} else if (SemVer.compareVersions(UpdateModel.instance.get('lastVersion'), RuntimeInfo.version) > 0) {
|
||||||
UpdateModel.instance.set('updateStatus', 'found');
|
UpdateModel.instance.set('updateStatus', 'found');
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -133,7 +134,7 @@ const Updater = {
|
||||||
canAutoUpdate: function() {
|
canAutoUpdate: function() {
|
||||||
const minLauncherVersion = UpdateModel.instance.get('lastCheckUpdMin');
|
const minLauncherVersion = UpdateModel.instance.get('lastCheckUpdMin');
|
||||||
if (minLauncherVersion) {
|
if (minLauncherVersion) {
|
||||||
const cmp = this.compareVersions(Launcher.version, minLauncherVersion);
|
const cmp = SemVer.compareVersions(Launcher.version, minLauncherVersion);
|
||||||
if (cmp < 0) {
|
if (cmp < 0) {
|
||||||
UpdateModel.instance.set({ updateStatus: 'ready', updateManual: true });
|
UpdateModel.instance.set({ updateStatus: 'ready', updateManual: true });
|
||||||
return false;
|
return false;
|
||||||
|
@ -142,29 +143,13 @@ const Updater = {
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
|
|
||||||
compareVersions: function(left, right) {
|
|
||||||
left = left.split('.');
|
|
||||||
right = right.split('.');
|
|
||||||
for (let num = 0; num < left.length; num++) {
|
|
||||||
const partLeft = left[num] | 0;
|
|
||||||
const partRight = right[num] | 0;
|
|
||||||
if (partLeft < partRight) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if (partLeft > partRight) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
},
|
|
||||||
|
|
||||||
update: function(startedByUser, successCallback) {
|
update: function(startedByUser, successCallback) {
|
||||||
const ver = UpdateModel.instance.get('lastVersion');
|
const ver = UpdateModel.instance.get('lastVersion');
|
||||||
if (!this.enabled) {
|
if (!this.enabled) {
|
||||||
logger.info('Updater is disabled');
|
logger.info('Updater is disabled');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (this.compareVersions(RuntimeInfo.version, ver) >= 0) {
|
if (SemVer.compareVersions(RuntimeInfo.version, ver) >= 0) {
|
||||||
logger.info('You are using the latest version');
|
logger.info('You are using the latest version');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,8 @@ const IoCache = require('../storage/io-cache');
|
||||||
const AppSettingsModel = require('../models/app-settings-model');
|
const AppSettingsModel = require('../models/app-settings-model');
|
||||||
const BaseLocale = require('../locales/base.json');
|
const BaseLocale = require('../locales/base.json');
|
||||||
const SignatureVerifier = require('../util/signature-verifier');
|
const SignatureVerifier = require('../util/signature-verifier');
|
||||||
|
const SemVer = require('../util/semver');
|
||||||
|
const RuntimeInfo = require('../comp/runtime-info');
|
||||||
|
|
||||||
const commonLogger = new Logger('plugin');
|
const commonLogger = new Logger('plugin');
|
||||||
const io = new IoCache({
|
const io = new IoCache({
|
||||||
|
@ -111,6 +113,25 @@ const Plugin = Backbone.Model.extend(_.extend({}, PluginStatus, {
|
||||||
(!manifest.locale || !manifest.locale.title || !/^[a-z]{2}(-[A-Z]{2})?$/.test(manifest.locale.name))) {
|
(!manifest.locale || !manifest.locale.title || !/^[a-z]{2}(-[A-Z]{2})?$/.test(manifest.locale.name))) {
|
||||||
return 'Bad plugin locale';
|
return 'Bad plugin locale';
|
||||||
}
|
}
|
||||||
|
if (manifest.desktop && !RuntimeInfo.launcher) {
|
||||||
|
return 'Desktop plugin';
|
||||||
|
}
|
||||||
|
if (manifest.versionMin) {
|
||||||
|
if (!/^\d+\.\d+\.\d+$/.test(manifest.versionMin)) {
|
||||||
|
return 'Invalid versionMin';
|
||||||
|
}
|
||||||
|
if (SemVer.compareVersions(manifest.versionMin, RuntimeInfo.version) > 0) {
|
||||||
|
return `Required min app version is ${manifest.versionMin}, actual ${RuntimeInfo.version}`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (manifest.versionMax) {
|
||||||
|
if (!/^\d+\.\d+\.\d+$/.test(manifest.versionMax)) {
|
||||||
|
return 'Invalid versionMin';
|
||||||
|
}
|
||||||
|
if (SemVer.compareVersions(manifest.versionMax, RuntimeInfo.version) < 0) {
|
||||||
|
return `Required max app version is ${manifest.versionMax}, actual ${RuntimeInfo.version}`;
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
validateUpdatedManifest(newManifest) {
|
validateUpdatedManifest(newManifest) {
|
||||||
|
|
19
app/scripts/util/semver.js
Normal file
19
app/scripts/util/semver.js
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
const SemVer = {
|
||||||
|
compareVersions(left, right) {
|
||||||
|
left = left.split('.');
|
||||||
|
right = right.split('.');
|
||||||
|
for (let num = 0; num < left.length; num++) {
|
||||||
|
const partLeft = left[num] | 0;
|
||||||
|
const partRight = right[num] | 0;
|
||||||
|
if (partLeft < partRight) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (partLeft > partRight) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = SemVer;
|
|
@ -12,6 +12,7 @@ const SettingsManager = require('../../comp/settings-manager');
|
||||||
const Storage = require('../../storage');
|
const Storage = require('../../storage');
|
||||||
const FeatureDetector = require('../../util/feature-detector');
|
const FeatureDetector = require('../../util/feature-detector');
|
||||||
const Locale = require('../../util/locale');
|
const Locale = require('../../util/locale');
|
||||||
|
const SemVer = require('../../util/semver');
|
||||||
const Links = require('../../const/links');
|
const Links = require('../../const/links');
|
||||||
const AutoType = require('../../auto-type');
|
const AutoType = require('../../auto-type');
|
||||||
|
|
||||||
|
@ -131,7 +132,7 @@ const SettingsGeneralView = Backbone.View.extend({
|
||||||
return errMsg;
|
return errMsg;
|
||||||
case 'ok':
|
case 'ok':
|
||||||
let msg = Locale.setGenCheckedAt + ' ' + Format.dtStr(UpdateModel.instance.get('lastCheckDate')) + ': ';
|
let msg = Locale.setGenCheckedAt + ' ' + Format.dtStr(UpdateModel.instance.get('lastCheckDate')) + ': ';
|
||||||
const cmp = Updater.compareVersions(RuntimeInfo.version, UpdateModel.instance.get('lastVersion'));
|
const cmp = SemVer.compareVersions(RuntimeInfo.version, UpdateModel.instance.get('lastVersion'));
|
||||||
if (cmp >= 0) {
|
if (cmp >= 0) {
|
||||||
msg += Locale.setGenLatestVer;
|
msg += Locale.setGenLatestVer;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -6,9 +6,10 @@ const AppSettingsModel = require('../../models/app-settings-model');
|
||||||
const Comparators = require('../../util/comparators');
|
const Comparators = require('../../util/comparators');
|
||||||
const Format = require('../../util/format');
|
const Format = require('../../util/format');
|
||||||
const SettingsManager = require('../../comp/settings-manager');
|
const SettingsManager = require('../../comp/settings-manager');
|
||||||
const Launcher = require('../../comp/launcher');
|
|
||||||
const SignatureVerifier = require('../../util/signature-verifier');
|
const SignatureVerifier = require('../../util/signature-verifier');
|
||||||
const FeatureDetector = require('../../util/feature-detector');
|
const FeatureDetector = require('../../util/feature-detector');
|
||||||
|
const SemVer = require('../../util/semver');
|
||||||
|
const RuntimeInfo = require('../../comp/runtime-info');
|
||||||
const Links = require('../../const/links');
|
const Links = require('../../const/links');
|
||||||
|
|
||||||
const SettingsPluginsView = Backbone.View.extend({
|
const SettingsPluginsView = Backbone.View.extend({
|
||||||
|
@ -87,12 +88,26 @@ const SettingsPluginsView = Backbone.View.extend({
|
||||||
installError: this.installErrors[pl.url],
|
installError: this.installErrors[pl.url],
|
||||||
official: pl.manifest.publicKey === publicKey
|
official: pl.manifest.publicKey === publicKey
|
||||||
}))
|
}))
|
||||||
.filter(pl => !plugins.get(pl.manifest.name) &&
|
.filter(pl => !plugins.get(pl.manifest.name) && this.canInstallPlugin(pl))
|
||||||
(!pl.manifest.locale || !SettingsManager.allLocales[pl.manifest.locale.name]) &&
|
|
||||||
(!pl.manifest.desktop || Launcher))
|
|
||||||
.sort((x, y) => x.manifest.name.localeCompare(y.manifest.name));
|
.sort((x, y) => x.manifest.name.localeCompare(y.manifest.name));
|
||||||
},
|
},
|
||||||
|
|
||||||
|
canInstallPlugin(plugin) {
|
||||||
|
if (plugin.manifest.locale && SettingsManager.allLocales[plugin.manifest.locale.name]) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (plugin.manifest.desktop && !RuntimeInfo.launcher) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (plugin.manifest.versionMin && SemVer.compareVersions(plugin.manufest.versionMin, RuntimeInfo.version) > 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (plugin.manifest.versionMax && SemVer.compareVersions(plugin.manufest.versionMax, RuntimeInfo.version) > 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
|
||||||
installClick() {
|
installClick() {
|
||||||
const installBtn = this.$el.find('.settings_plugins-install-btn');
|
const installBtn = this.$el.find('.settings_plugins-install-btn');
|
||||||
const urlTextBox = this.$el.find('#settings__plugins-install-url');
|
const urlTextBox = this.$el.find('#settings__plugins-install-url');
|
||||||
|
|
Loading…
Reference in New Issue
Block a user