mirror of https://github.com/keeweb/keeweb.git
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 Transport = require('../comp/transport');
|
||||
const Logger = require('../util/logger');
|
||||
const SemVer = require('../util/semver');
|
||||
const publicKey = require('raw-loader!../../resources/public-key.pem');
|
||||
|
||||
const logger = new Logger('updater');
|
||||
|
@ -113,7 +114,7 @@ const Updater = {
|
|||
}
|
||||
if (!startedByUser && this.getAutoUpdateType() === 'install') {
|
||||
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');
|
||||
}
|
||||
},
|
||||
|
@ -133,7 +134,7 @@ const Updater = {
|
|||
canAutoUpdate: function() {
|
||||
const minLauncherVersion = UpdateModel.instance.get('lastCheckUpdMin');
|
||||
if (minLauncherVersion) {
|
||||
const cmp = this.compareVersions(Launcher.version, minLauncherVersion);
|
||||
const cmp = SemVer.compareVersions(Launcher.version, minLauncherVersion);
|
||||
if (cmp < 0) {
|
||||
UpdateModel.instance.set({ updateStatus: 'ready', updateManual: true });
|
||||
return false;
|
||||
|
@ -142,29 +143,13 @@ const Updater = {
|
|||
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) {
|
||||
const ver = UpdateModel.instance.get('lastVersion');
|
||||
if (!this.enabled) {
|
||||
logger.info('Updater is disabled');
|
||||
return;
|
||||
}
|
||||
if (this.compareVersions(RuntimeInfo.version, ver) >= 0) {
|
||||
if (SemVer.compareVersions(RuntimeInfo.version, ver) >= 0) {
|
||||
logger.info('You are using the latest version');
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -8,6 +8,8 @@ const IoCache = require('../storage/io-cache');
|
|||
const AppSettingsModel = require('../models/app-settings-model');
|
||||
const BaseLocale = require('../locales/base.json');
|
||||
const SignatureVerifier = require('../util/signature-verifier');
|
||||
const SemVer = require('../util/semver');
|
||||
const RuntimeInfo = require('../comp/runtime-info');
|
||||
|
||||
const commonLogger = new Logger('plugin');
|
||||
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))) {
|
||||
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) {
|
||||
|
|
|
@ -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 FeatureDetector = require('../../util/feature-detector');
|
||||
const Locale = require('../../util/locale');
|
||||
const SemVer = require('../../util/semver');
|
||||
const Links = require('../../const/links');
|
||||
const AutoType = require('../../auto-type');
|
||||
|
||||
|
@ -131,7 +132,7 @@ const SettingsGeneralView = Backbone.View.extend({
|
|||
return errMsg;
|
||||
case 'ok':
|
||||
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) {
|
||||
msg += Locale.setGenLatestVer;
|
||||
} else {
|
||||
|
|
|
@ -6,9 +6,10 @@ const AppSettingsModel = require('../../models/app-settings-model');
|
|||
const Comparators = require('../../util/comparators');
|
||||
const Format = require('../../util/format');
|
||||
const SettingsManager = require('../../comp/settings-manager');
|
||||
const Launcher = require('../../comp/launcher');
|
||||
const SignatureVerifier = require('../../util/signature-verifier');
|
||||
const FeatureDetector = require('../../util/feature-detector');
|
||||
const SemVer = require('../../util/semver');
|
||||
const RuntimeInfo = require('../../comp/runtime-info');
|
||||
const Links = require('../../const/links');
|
||||
|
||||
const SettingsPluginsView = Backbone.View.extend({
|
||||
|
@ -87,12 +88,26 @@ const SettingsPluginsView = Backbone.View.extend({
|
|||
installError: this.installErrors[pl.url],
|
||||
official: pl.manifest.publicKey === publicKey
|
||||
}))
|
||||
.filter(pl => !plugins.get(pl.manifest.name) &&
|
||||
(!pl.manifest.locale || !SettingsManager.allLocales[pl.manifest.locale.name]) &&
|
||||
(!pl.manifest.desktop || Launcher))
|
||||
.filter(pl => !plugins.get(pl.manifest.name) && this.canInstallPlugin(pl))
|
||||
.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() {
|
||||
const installBtn = this.$el.find('.settings_plugins-install-btn');
|
||||
const urlTextBox = this.$el.find('#settings__plugins-install-url');
|
||||
|
|
Loading…
Reference in New Issue