Skip to content

Commit da9cd9d

Browse files
committed
feat: add ignore this version
1 parent f44df78 commit da9cd9d

2 files changed

Lines changed: 70 additions & 5 deletions

File tree

src/components/UpdateNotifier.vue

Lines changed: 69 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<script lang="ts">
22
/* eslint-disable vue/valid-template-root */
33
import { h, onMounted } from 'vue';
4-
import { VERSION } from '../const';
4+
import { STORAGE_UPDATE_IGNORE, VERSION } from '../const';
55
import { useNotification, NButton } from 'naive-ui';
66
import { getRecorderLatestVersion } from '../utils/version';
77
import { compare as compareVersion } from 'semver';
@@ -16,11 +16,20 @@ onMounted(() => {
1616
getRecorderLatestVersion().then((version) => {
1717
try {
1818
if (compareVersion(version.webui.version, VERSION) > 0) {
19+
const store = JSON.parse(localStorage.getItem(STORAGE_UPDATE_IGNORE) || '{}');
20+
if (store.webui && store.webui === version.webui.version) {
21+
return;
22+
}
1923
const n = notification.warning({
2024
title: '更新提醒',
2125
content: `检测到新版本WebUI:${version.webui.version},请及时更新!`,
2226
duration: 0,
23-
action: () =>
27+
action: () => h('div', {
28+
style: {
29+
display: 'flex',
30+
gap: '1rem',
31+
},
32+
}, [
2433
h(NButton, {
2534
type: 'primary',
2635
text: true,
@@ -29,6 +38,28 @@ onMounted(() => {
2938
window.open(version.webui.url);
3039
},
3140
}, () => '立即更新'),
41+
h(NButton, {
42+
type: 'default',
43+
text: true,
44+
onClick: () => {
45+
n.destroy();
46+
},
47+
}, () => '忽略'),
48+
h(NButton, {
49+
type: 'default',
50+
text: true,
51+
onClick: () => {
52+
n.destroy();
53+
try {
54+
const store = JSON.parse(localStorage.getItem(STORAGE_UPDATE_IGNORE) || '{}');
55+
store.webui = version.webui.version;
56+
localStorage.setItem(STORAGE_UPDATE_IGNORE, JSON.stringify(store));
57+
} catch (error) {
58+
// ignore
59+
}
60+
},
61+
}, () => '忽略此版本'),
62+
]),
3263
});
3364
}
3465
} catch (e) {
@@ -41,15 +72,21 @@ const notified: { [key: string]: boolean } = {};
4172
4273
function onRecorderChange() {
4374
if (recorderController.recorder !== null) {
44-
if (notified[recorderController.recorder.meta.id]) {
75+
const recorderMeta = recorderController.recorder.meta;
76+
77+
if (notified[recorderMeta.id]) {
4578
return;
4679
}
47-
const recorderMeta = recorderController.recorder.meta;
80+
4881
recorderController.recorder.getVersion().then((v) => {
4982
const serverVersion = v.fullSemVer;
5083
getRecorderLatestVersion().then((version) => {
5184
try {
5285
if (compareVersion(version.recorder.version, serverVersion) > 0) {
86+
const store = JSON.parse(localStorage.getItem(STORAGE_UPDATE_IGNORE) || '{}');
87+
if (store[recorderMeta.id] && store[recorderMeta.id] === version.webui.version) {
88+
return;
89+
}
5390
notified[recorderMeta.id] = true;
5491
const n = notification.warning({
5592
title: '更新提醒',
@@ -65,7 +102,12 @@ function onRecorderChange() {
65102
];
66103
},
67104
duration: 0,
68-
action: () =>
105+
action: () => h('div', {
106+
style: {
107+
display: 'flex',
108+
gap: '1rem',
109+
},
110+
}, [
69111
h(NButton, {
70112
type: 'primary',
71113
text: true,
@@ -74,6 +116,28 @@ function onRecorderChange() {
74116
window.open(version.recorder.url);
75117
},
76118
}, () => '立即更新'),
119+
h(NButton, {
120+
type: 'default',
121+
text: true,
122+
onClick: () => {
123+
n.destroy();
124+
},
125+
}, () => '忽略'),
126+
h(NButton, {
127+
type: 'default',
128+
text: true,
129+
onClick: () => {
130+
n.destroy();
131+
try {
132+
const store = JSON.parse(localStorage.getItem(STORAGE_UPDATE_IGNORE) || '{}');
133+
store[recorderMeta.id] = version.webui.version;
134+
localStorage.setItem(STORAGE_UPDATE_IGNORE, JSON.stringify(store));
135+
} catch (error) {
136+
// ignore
137+
}
138+
},
139+
}, () => '忽略此版本'),
140+
]),
77141
});
78142
}
79143
} catch (e) {

src/const.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ export const STORAGE_THEME = 'brec.theme';
77
export const STORAGE_LATEST_VERSION = 'brec.latestVersion';
88
export const STORAGE_FILES_SORT_OPTION = 'brec.filesSortOption';
99
export const STORAGE_ROOM_ORDER_METHOD = 'brec.roomOrderMethod';
10+
export const STORAGE_UPDATE_IGNORE = 'brec.updateIgnore';

0 commit comments

Comments
 (0)