* (ui): fix the version check - strip the v prefix

This commit is contained in:
Andrey Meshkov 2020-07-23 12:27:14 +03:00
parent 4f4a688ee6
commit 1e5419714d
5 changed files with 32 additions and 13 deletions

View File

@ -196,7 +196,7 @@ define write_version_file
echo " \"version\": \"$(version)\"," >> $(DIST_DIR)/version.json echo " \"version\": \"$(version)\"," >> $(DIST_DIR)/version.json
echo " \"announcement\": \"AdGuard Home $(version) is now available!\"," >> $(DIST_DIR)/version.json echo " \"announcement\": \"AdGuard Home $(version) is now available!\"," >> $(DIST_DIR)/version.json
echo " \"announcement_url\": \"https://github.com/AdguardTeam/AdGuardHome/releases\"," >> $(DIST_DIR)/version.json echo " \"announcement_url\": \"https://github.com/AdguardTeam/AdGuardHome/releases\"," >> $(DIST_DIR)/version.json
echo " \"selfupdate_min_version\": \"v0.0\"," >> $(DIST_DIR)/version.json echo " \"selfupdate_min_version\": \"0.0\"," >> $(DIST_DIR)/version.json
# Windows builds # Windows builds
echo " \"download_windows_amd64\": \"$(BASE_URL)/AdGuardHome_windows_amd64.zip\"," >> $(DIST_DIR)/version.json echo " \"download_windows_amd64\": \"$(BASE_URL)/AdGuardHome_windows_amd64.zip\"," >> $(DIST_DIR)/version.json

View File

@ -1,9 +1,9 @@
module.exports = { module.exports = {
"disableEmoji": true, "disableEmoji": true,
"list": [ "list": [
"+", "+ ",
"*", "* ",
"-", "- ",
], ],
"maxMessageLength": 64, "maxMessageLength": 64,
"minMessageLength": 3, "minMessageLength": 3,
@ -12,7 +12,7 @@ module.exports = {
"scope", "scope",
"subject", "subject",
"body", "body",
"issues" "issues",
], ],
"scopes": [ "scopes": [
"", "",
@ -26,20 +26,20 @@ module.exports = {
"documentation", "documentation",
], ],
"types": { "types": {
"+": { "+ ": {
"description": "A new feature", "description": "A new feature",
"emoji": "", "emoji": "",
"value": "+" "value": "+ "
}, },
"*": { "* ": {
"description": "A code change that neither fixes a bug or adds a feature", "description": "A code change that neither fixes a bug or adds a feature",
"emoji": "", "emoji": "",
"value": "*" "value": "* "
}, },
"-": { "- ": {
"description": "A bug fix", "description": "A bug fix",
"emoji": "", "emoji": "",
"value": "-" "value": "- "
} }
} }
}; };

View File

@ -4,6 +4,7 @@ import axios from 'axios';
import { splitByNewLine, sortClients } from '../helpers/helpers'; import { splitByNewLine, sortClients } from '../helpers/helpers';
import { CHECK_TIMEOUT, SETTINGS_NAMES } from '../helpers/constants'; import { CHECK_TIMEOUT, SETTINGS_NAMES } from '../helpers/constants';
import { areEqualVersions } from '../helpers/version';
import { getTlsStatus } from './encryption'; import { getTlsStatus } from './encryption';
import apiClient from '../api/Api'; import apiClient from '../api/Api';
import { addErrorToast, addNoticeToast, addSuccessToast } from './toasts'; import { addErrorToast, addNoticeToast, addSuccessToast } from './toasts';
@ -121,7 +122,7 @@ export const getVersion = (recheck = false) => async (dispatch, getState) => {
const { dnsVersion } = getState().dashboard; const { dnsVersion } = getState().dashboard;
const currentVersion = dnsVersion === 'undefined' ? 0 : dnsVersion; const currentVersion = dnsVersion === 'undefined' ? 0 : dnsVersion;
if (data && currentVersion !== data.new_version) { if (data && !areEqualVersions(currentVersion, data.new_version)) {
dispatch(addSuccessToast('updates_checked')); dispatch(addSuccessToast('updates_checked'));
} else { } else {
dispatch(addSuccessToast('updates_version_equal')); dispatch(addSuccessToast('updates_version_equal'));

View File

@ -0,0 +1,17 @@
/**
* Checks if versions are equal.
* Please note, that this method strips the "v" prefix.
*
* @param left {string} - left version
* @param right {string} - right version
* @return {boolean} true if versions are equal
*/
export const areEqualVersions = (left, right) => {
if (!left || !right) {
return false;
}
const leftVersion = left.replace(/^v/, '');
const rightVersion = right.replace(/^v/, '');
return leftVersion === rightVersion;
};

View File

@ -14,6 +14,7 @@ import stats from './stats';
import queryLogs from './queryLogs'; import queryLogs from './queryLogs';
import dnsConfig from './dnsConfig'; import dnsConfig from './dnsConfig';
import filtering from './filtering'; import filtering from './filtering';
import { areEqualVersions } from '../helpers/version';
const settings = handleActions( const settings = handleActions(
{ {
@ -81,7 +82,7 @@ const dashboard = handleActions(
[actions.getVersionSuccess]: (state, { payload }) => { [actions.getVersionSuccess]: (state, { payload }) => {
const currentVersion = state.dnsVersion === 'undefined' ? 0 : state.dnsVersion; const currentVersion = state.dnsVersion === 'undefined' ? 0 : state.dnsVersion;
if (!payload.disabled && currentVersion !== payload.new_version) { if (!payload.disabled && !areEqualVersions(currentVersion, payload.new_version)) {
const { const {
announcement_url: announcementUrl, announcement_url: announcementUrl,
new_version: newVersion, new_version: newVersion,