feat: update

This commit is contained in:
手瓜一十雪
2024-03-17 13:34:39 +08:00
parent 17d9c48e68
commit f149594e23
4 changed files with 88 additions and 28 deletions

View File

@@ -2,4 +2,6 @@ export const CHANNEL_GET_CONFIG = 'llonebot_get_config'
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_SELECT_FILE = 'llonebot_select_ffmpeg'

View File

@@ -7,6 +7,7 @@ import fs from 'fs';
import * as crypto from 'crypto';
import { v4 as uuidv4 } from "uuid";
import ffmpeg from "fluent-ffmpeg"
import * as https from "node:https";
export const DATA_DIR = global.LiteLoader.plugins["LLOneBot"].path.data;
@@ -35,8 +36,50 @@ function truncateString(obj: any, maxLength = 500) {
export function isNumeric(str: string) {
return /^\d+$/.test(str);
}
export async function updateLLOneBot() {
let mirrorGithubList = ["https://mirror.ghproxy.com"];
return true;
}
export async function getRemoteVersion() {
let mirrorGithubList = ["https://521github.com"];
let Version = "";
for (let i = 0; i < mirrorGithubList.length; i++) {
let mirrorGithub = mirrorGithubList[i];
let tVersion = await getRemoteVersionByMirror(mirrorGithub);
console.log("tVersion", tVersion);
if (tVersion && tVersion != "") {
Version = tVersion;
break;
}
}
return Version;
}
export async function getRemoteVersionByMirror(mirrorGithub: string) {
let releasePage = "error";
let reqPromise = async function (): Promise<string> {
return new Promise((resolve, reject) => {
https.get(mirrorGithub + "/LLOneBot/LLOneBot/releases", res => {
let list = [];
res.on('data', chunk => {
list.push(chunk);
});
res.on('end', () => {
resolve(Buffer.concat(list).toString());
});
}).on('error', err => {
reject();
});
});
}
try {
releasePage = await reqPromise();
if (releasePage === "error") return "";
return releasePage.match(new RegExp('(?<=(tag/v)).*?(?=("))'))[0];
}
catch { }
return "";
}
export function log(...msg: any[]) {
if (!getConfigUtil().getConfig().log) {
return //console.log(...msg);

View File

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

View File

@@ -5,8 +5,10 @@ import {
CHANNEL_ERROR,
CHANNEL_GET_CONFIG,
CHANNEL_LOG,
CHANNEL_REMOTEVERSION,
CHANNEL_SELECT_FILE,
CHANNEL_SET_CONFIG,
CHANNEL_UPDATE,
} from "./common/channels";
const {contextBridge} = require("electron");
@@ -16,6 +18,12 @@ const llonebot = {
log: (data: any) => {
ipcRenderer.send(CHANNEL_LOG, data);
},
getRemoteVersion:async (): Promise<string> => {
return ipcRenderer.invoke(CHANNEL_REMOTEVERSION);
},
updateLLOneBot:async (): Promise<boolean> => {
return ipcRenderer.invoke(CHANNEL_UPDATE);
},
setConfig: (config: Config) => {
ipcRenderer.send(CHANNEL_SET_CONFIG, config);
},