rubick/src/main/common/versionHandler.ts
muwoo bde5377282 🐛 修复 #264
 支持 db.postAttachment 和 db.getAttachment
♻️ 重构版本更新机制
2023-10-18 11:02:14 +08:00

46 lines
1.2 KiB
TypeScript

import { dialog, shell } from 'electron';
import pkg from '../../../package.json';
import { lt } from 'semver';
import { getLatestVersion } from './getLatestVersion';
const version = pkg.version;
const downloadUrl = 'https://github.com/rubickCenter/rubick/releases/latest';
const checkVersion = async () => {
const res: string = await getLatestVersion();
if (res !== '') {
const latest = res;
const result = compareVersion2Update(version, latest);
if (result) {
dialog
.showMessageBox({
type: 'info',
title: 'Rubick 更新提示',
buttons: ['Yes', 'No'],
message: `发现新版本 v${latest},是否更新?`,
})
.then((res) => {
if (res.response === 0) {
// if selected yes
shell.openExternal(downloadUrl);
}
});
}
} else {
return false;
}
};
// if true -> update else return false
const compareVersion2Update = (current: string, latest: string) => {
try {
if (latest.includes('beta')) {
return false;
}
return lt(current, latest);
} catch (e) {
return false;
}
};
export default checkVersion;