Skip to content

Commit

Permalink
feat: add ignore this version
Browse files Browse the repository at this point in the history
  • Loading branch information
shugen002 committed Mar 30, 2024
1 parent f44df78 commit da9cd9d
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 5 deletions.
74 changes: 69 additions & 5 deletions src/components/UpdateNotifier.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script lang="ts">
/* eslint-disable vue/valid-template-root */
import { h, onMounted } from 'vue';
import { VERSION } from '../const';
import { STORAGE_UPDATE_IGNORE, VERSION } from '../const';
import { useNotification, NButton } from 'naive-ui';
import { getRecorderLatestVersion } from '../utils/version';
import { compare as compareVersion } from 'semver';
Expand All @@ -16,11 +16,20 @@ onMounted(() => {
getRecorderLatestVersion().then((version) => {
try {
if (compareVersion(version.webui.version, VERSION) > 0) {
const store = JSON.parse(localStorage.getItem(STORAGE_UPDATE_IGNORE) || '{}');
if (store.webui && store.webui === version.webui.version) {
return;
}
const n = notification.warning({
title: '更新提醒',
content: `检测到新版本WebUI:${version.webui.version},请及时更新!`,
duration: 0,
action: () =>
action: () => h('div', {
style: {
display: 'flex',
gap: '1rem',
},
}, [
h(NButton, {
type: 'primary',
text: true,
Expand All @@ -29,6 +38,28 @@ onMounted(() => {
window.open(version.webui.url);
},
}, () => '立即更新'),
h(NButton, {
type: 'default',
text: true,
onClick: () => {
n.destroy();
},
}, () => '忽略'),
h(NButton, {
type: 'default',
text: true,
onClick: () => {
n.destroy();
try {
const store = JSON.parse(localStorage.getItem(STORAGE_UPDATE_IGNORE) || '{}');
store.webui = version.webui.version;
localStorage.setItem(STORAGE_UPDATE_IGNORE, JSON.stringify(store));
} catch (error) {
// ignore
}
},
}, () => '忽略此版本'),
]),
});
}
} catch (e) {
Expand All @@ -41,15 +72,21 @@ const notified: { [key: string]: boolean } = {};
function onRecorderChange() {
if (recorderController.recorder !== null) {
if (notified[recorderController.recorder.meta.id]) {
const recorderMeta = recorderController.recorder.meta;
if (notified[recorderMeta.id]) {
return;
}
const recorderMeta = recorderController.recorder.meta;
recorderController.recorder.getVersion().then((v) => {
const serverVersion = v.fullSemVer;
getRecorderLatestVersion().then((version) => {
try {
if (compareVersion(version.recorder.version, serverVersion) > 0) {
const store = JSON.parse(localStorage.getItem(STORAGE_UPDATE_IGNORE) || '{}');
if (store[recorderMeta.id] && store[recorderMeta.id] === version.webui.version) {
return;
}
notified[recorderMeta.id] = true;
const n = notification.warning({
title: '更新提醒',
Expand All @@ -65,7 +102,12 @@ function onRecorderChange() {
];
},
duration: 0,
action: () =>
action: () => h('div', {
style: {
display: 'flex',
gap: '1rem',
},
}, [
h(NButton, {
type: 'primary',
text: true,
Expand All @@ -74,6 +116,28 @@ function onRecorderChange() {
window.open(version.recorder.url);
},
}, () => '立即更新'),
h(NButton, {
type: 'default',
text: true,
onClick: () => {
n.destroy();
},
}, () => '忽略'),
h(NButton, {
type: 'default',
text: true,
onClick: () => {
n.destroy();
try {
const store = JSON.parse(localStorage.getItem(STORAGE_UPDATE_IGNORE) || '{}');
store[recorderMeta.id] = version.webui.version;
localStorage.setItem(STORAGE_UPDATE_IGNORE, JSON.stringify(store));
} catch (error) {
// ignore
}
},
}, () => '忽略此版本'),
]),
});
}
} catch (e) {
Expand Down
1 change: 1 addition & 0 deletions src/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ export const STORAGE_THEME = 'brec.theme';
export const STORAGE_LATEST_VERSION = 'brec.latestVersion';
export const STORAGE_FILES_SORT_OPTION = 'brec.filesSortOption';
export const STORAGE_ROOM_ORDER_METHOD = 'brec.roomOrderMethod';
export const STORAGE_UPDATE_IGNORE = 'brec.updateIgnore';

0 comments on commit da9cd9d

Please sign in to comment.