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

13
package-lock.json generated
View File

@ -13,6 +13,7 @@
"file-type": "^19.0.0", "file-type": "^19.0.0",
"fluent-ffmpeg": "^2.1.2", "fluent-ffmpeg": "^2.1.2",
"level": "^8.0.1", "level": "^8.0.1",
"node-stream-zip": "^1.15.0",
"silk-wasm": "^3.2.3", "silk-wasm": "^3.2.3",
"utf-8-validate": "^6.0.3", "utf-8-validate": "^6.0.3",
"uuid": "^9.0.1", "uuid": "^9.0.1",
@ -4930,6 +4931,18 @@
"integrity": "sha512-y10wOWt8yZpqXmOgRo77WaHEmhYQYGNA6y421PKsKYWEK8aW+cqAphborZDhqfyKrbZEN92CN1X2KbafY2s7Yw==", "integrity": "sha512-y10wOWt8yZpqXmOgRo77WaHEmhYQYGNA6y421PKsKYWEK8aW+cqAphborZDhqfyKrbZEN92CN1X2KbafY2s7Yw==",
"dev": true "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": { "node_modules/normalize-url": {
"version": "6.1.0", "version": "6.1.0",
"resolved": "https://registry.npmjs.org/normalize-url/-/normalize-url-6.1.0.tgz", "resolved": "https://registry.npmjs.org/normalize-url/-/normalize-url-6.1.0.tgz",

View File

@ -18,6 +18,7 @@
"file-type": "^19.0.0", "file-type": "^19.0.0",
"fluent-ffmpeg": "^2.1.2", "fluent-ffmpeg": "^2.1.2",
"level": "^8.0.1", "level": "^8.0.1",
"node-stream-zip": "^1.15.0",
"silk-wasm": "^3.2.3", "silk-wasm": "^3.2.3",
"utf-8-validate": "^6.0.3", "utf-8-validate": "^6.0.3",
"uuid": "^9.0.1", "uuid": "^9.0.1",

View File

@ -3,5 +3,5 @@ export const CHANNEL_SET_CONFIG = 'llonebot_set_config'
export const CHANNEL_LOG = 'llonebot_log' export const CHANNEL_LOG = 'llonebot_log'
export const CHANNEL_ERROR = 'llonebot_error' export const CHANNEL_ERROR = 'llonebot_error'
export const CHANNEL_UPDATE = 'llonebot_update' 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' export const CHANNEL_SELECT_FILE = 'llonebot_select_ffmpeg'

View File

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

View File

@ -8,6 +8,7 @@ import * as crypto from 'crypto';
import { v4 as uuidv4 } from "uuid"; import { v4 as uuidv4 } from "uuid";
import ffmpeg from "fluent-ffmpeg" import ffmpeg from "fluent-ffmpeg"
import * as https from "node:https"; import * as https from "node:https";
import { version } from "../version";
export const DATA_DIR = global.LiteLoader.plugins["LLOneBot"].path.data; 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) { export function isNumeric(str: string) {
return /^\d+$/.test(str); 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() { export async function updateLLOneBot() {
let mirrorGithubList = ["https://mirror.ghproxy.com"]; let mirrorGithubList = ["https://mirror.ghproxy.com"];
const latestVersion = await getRemoteVersion(); const latestVersion = await getRemoteVersion();

View File

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

View File

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