diff --git a/package-lock.json b/package-lock.json index e2030ae..cda8ff2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,6 +13,7 @@ "file-type": "^19.0.0", "fluent-ffmpeg": "^2.1.2", "level": "^8.0.1", + "node-stream-zip": "^1.15.0", "silk-wasm": "^3.2.3", "utf-8-validate": "^6.0.3", "uuid": "^9.0.1", @@ -4930,6 +4931,18 @@ "integrity": "sha512-y10wOWt8yZpqXmOgRo77WaHEmhYQYGNA6y421PKsKYWEK8aW+cqAphborZDhqfyKrbZEN92CN1X2KbafY2s7Yw==", "dev": true }, + "node_modules/node-stream-zip": { + "version": "1.15.0", + "resolved": "https://registry.npmjs.org/node-stream-zip/-/node-stream-zip-1.15.0.tgz", + "integrity": "sha512-LN4fydt9TqhZhThkZIVQnF9cwjU3qmUH9h78Mx/K7d3VvfRqqwthLwJEUOEL0QPZ0XQmNN7be5Ggit5+4dq3Bw==", + "engines": { + "node": ">=0.12.0" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/antelle" + } + }, "node_modules/normalize-url": { "version": "6.1.0", "resolved": "https://registry.npmjs.org/normalize-url/-/normalize-url-6.1.0.tgz", diff --git a/package.json b/package.json index 6628ec2..a3392fc 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,7 @@ "file-type": "^19.0.0", "fluent-ffmpeg": "^2.1.2", "level": "^8.0.1", + "node-stream-zip": "^1.15.0", "silk-wasm": "^3.2.3", "utf-8-validate": "^6.0.3", "uuid": "^9.0.1", diff --git a/src/common/channels.ts b/src/common/channels.ts index 5bb8ee6..c4d76b6 100644 --- a/src/common/channels.ts +++ b/src/common/channels.ts @@ -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' diff --git a/src/common/types.ts b/src/common/types.ts index f7a7a71..98e495c 100644 --- a/src/common/types.ts +++ b/src/common/types.ts @@ -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 diff --git a/src/common/utils.ts b/src/common/utils.ts index d1fa501..616f666 100644 --- a/src/common/utils.ts +++ b/src/common/utils.ts @@ -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(); diff --git a/src/main/main.ts b/src/main/main.ts index 4f9aef5..2142073 100644 --- a/src/main/main.ts +++ b/src/main/main.ts @@ -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(); diff --git a/src/preload.ts b/src/preload.ts index f20f404..ed83aa0 100644 --- a/src/preload.ts +++ b/src/preload.ts @@ -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 => { - return ipcRenderer.invoke(CHANNEL_REMOTEVERSION); + checkVersion:async (): Promise => { + return ipcRenderer.invoke(CHANNEL_CHECKVERSION); }, updateLLOneBot:async (): Promise => { return ipcRenderer.invoke(CHANNEL_UPDATE);