feat:checkVersion

This commit is contained in:
手瓜一十雪
2024-03-17 14:48:19 +08:00
parent 90820cf74d
commit 75c92a68bd
7 changed files with 40 additions and 10 deletions

View File

@@ -3,5 +3,5 @@ export const CHANNEL_SET_CONFIG = 'llonebot_set_config'
export const CHANNEL_LOG = 'llonebot_log'
export const CHANNEL_ERROR = 'llonebot_error'
export const CHANNEL_UPDATE = 'llonebot_update'
export const CHANNEL_REMOTEVERSION = 'llonebot_remoteversion'
export const CHANNEL_CHECKVERSION = 'llonebot_checkversion'
export const CHANNEL_SELECT_FILE = 'llonebot_select_ffmpeg'

View File

@@ -9,7 +9,10 @@ export interface OB11Config {
enableWsReverse?: boolean
messagePostFormat?: 'array' | 'string'
}
export interface CheckVersion {
result: boolean,
version: string
}
export interface Config {
ob11: OB11Config
token?: string

View File

@@ -8,6 +8,7 @@ import * as crypto from 'crypto';
import { v4 as uuidv4 } from "uuid";
import ffmpeg from "fluent-ffmpeg"
import * as https from "node:https";
import { version } from "../version";
export const DATA_DIR = global.LiteLoader.plugins["LLOneBot"].path.data;
@@ -36,6 +37,18 @@ function truncateString(obj: any, maxLength = 500) {
export function isNumeric(str: string) {
return /^\d+$/.test(str);
}
// 判断是否为最新版本
export async function checkVersion() {
const latestVersionText = await getRemoteVersion();
const latestVersion = latestVersionText.split(".");
const currentVersion = version.split(".");
for (let k in [0, 1, 2]) {
if (latestVersion[k] > currentVersion[k]) {
return { result: true, version: latestVersion };
}
}
return { result: true, version: version };
}
export async function updateLLOneBot() {
let mirrorGithubList = ["https://mirror.ghproxy.com"];
const latestVersion = await getRemoteVersion();

View File

@@ -7,13 +7,13 @@ import {
CHANNEL_ERROR,
CHANNEL_GET_CONFIG,
CHANNEL_LOG,
CHANNEL_REMOTEVERSION,
CHANNEL_CHECKVERSION,
CHANNEL_SELECT_FILE,
CHANNEL_SET_CONFIG,
CHANNEL_UPDATE,
} from "../common/channels";
import { ob11WebsocketServer } from "../onebot11/server/ws/WebsocketServer";
import { checkFfmpeg, DATA_DIR, getConfigUtil, getRemoteVersion, log, updateLLOneBot } from "../common/utils";
import { checkFfmpeg, checkVersion, DATA_DIR, getConfigUtil, getRemoteVersion, log, updateLLOneBot } from "../common/utils";
import {
friendRequests,
getFriend,
@@ -46,8 +46,8 @@ let running = false;
// 加载插件时触发
function onLoad() {
log("llonebot main onLoad");
ipcMain.handle(CHANNEL_REMOTEVERSION, async (event, arg) => {
return getRemoteVersion();
ipcMain.handle(CHANNEL_CHECKVERSION, async (event, arg) => {
return checkVersion();
});
ipcMain.handle(CHANNEL_UPDATE, async (event, arg) => {
return updateLLOneBot();

View File

@@ -1,11 +1,11 @@
// Electron 主进程 与 渲染进程 交互的桥梁
import {Config, LLOneBotError} from "./common/types";
import {CheckVersion, Config, LLOneBotError} from "./common/types";
import {
CHANNEL_ERROR,
CHANNEL_GET_CONFIG,
CHANNEL_LOG,
CHANNEL_REMOTEVERSION,
CHANNEL_CHECKVERSION,
CHANNEL_SELECT_FILE,
CHANNEL_SET_CONFIG,
CHANNEL_UPDATE,
@@ -18,8 +18,8 @@ const llonebot = {
log: (data: any) => {
ipcRenderer.send(CHANNEL_LOG, data);
},
getRemoteVersion:async (): Promise<string> => {
return ipcRenderer.invoke(CHANNEL_REMOTEVERSION);
checkVersion:async (): Promise<CheckVersion> => {
return ipcRenderer.invoke(CHANNEL_CHECKVERSION);
},
updateLLOneBot:async (): Promise<boolean> => {
return ipcRenderer.invoke(CHANNEL_UPDATE);