mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2025-07-19 12:03:37 +00:00
feat: 优化webui快速登录&优化代码整体逻辑
This commit is contained in:
@@ -222,6 +222,11 @@ async function handleLoginInner(context: { isLogined: boolean }, logger: LogWrap
|
||||
}`);
|
||||
}
|
||||
loginService.getQRCodePicture();
|
||||
try {
|
||||
await WebUiDataRuntime.runWebUiConfigQuickFunction();
|
||||
} catch (error) {
|
||||
logger.logError('WebUi 快速登录失败 执行失败', error);
|
||||
}
|
||||
}
|
||||
|
||||
loginService.getLoginList().then((res) => {
|
||||
|
@@ -50,20 +50,21 @@ export async function InitWebUi(logger: LogWrapper, pathWrapper: NapCatPathWrapp
|
||||
logger.log('[NapCat] [WebUi] Current WebUi is not run.');
|
||||
return;
|
||||
}
|
||||
setTimeout(async () => {
|
||||
let autoLoginAccount = process.env['NAPCAT_QUICK_ACCOUNT'] || WebUiConfig.getAutoLoginAccount();
|
||||
if (autoLoginAccount) {
|
||||
try {
|
||||
const { result, message } = await WebUiDataRuntime.requestQuickLogin(autoLoginAccount);
|
||||
if (!result) {
|
||||
throw new Error(message);
|
||||
WebUiDataRuntime.setWebUiConfigQuickFunction(
|
||||
async () => {
|
||||
let autoLoginAccount = process.env['NAPCAT_QUICK_ACCOUNT'] || WebUiConfig.getAutoLoginAccount();
|
||||
if (autoLoginAccount) {
|
||||
try {
|
||||
const { result, message } = await WebUiDataRuntime.requestQuickLogin(autoLoginAccount);
|
||||
if (!result) {
|
||||
throw new Error(message);
|
||||
}
|
||||
console.log(`[NapCat] [WebUi] Auto login account: ${autoLoginAccount}`);
|
||||
} catch (error) {
|
||||
console.log(`[NapCat] [WebUi] Auto login account failed.` + error);
|
||||
}
|
||||
console.log(`[NapCat] [WebUi] Auto login account: ${autoLoginAccount}`);
|
||||
} catch (error) {
|
||||
console.log(`[NapCat] [WebUi] Auto login account failed.` + error);
|
||||
}
|
||||
}
|
||||
}, 30000);
|
||||
});
|
||||
// ------------注册中间件------------
|
||||
// 使用express的json中间件
|
||||
app.use(express.json());
|
||||
|
@@ -25,6 +25,9 @@ const LoginRuntime: LoginRuntimeType = {
|
||||
NewQQLoginList: [],
|
||||
},
|
||||
packageJson: packageJson,
|
||||
WebUiConfigQuickFunction: async () => {
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
export const WebUiDataRuntime = {
|
||||
@@ -118,4 +121,11 @@ export const WebUiDataRuntime = {
|
||||
getQQVersion() {
|
||||
return LoginRuntime.QQVersion;
|
||||
},
|
||||
|
||||
setWebUiConfigQuickFunction(func: LoginRuntimeType['WebUiConfigQuickFunction']): void {
|
||||
LoginRuntime.WebUiConfigQuickFunction = func;
|
||||
},
|
||||
runWebUiConfigQuickFunction: async function () {
|
||||
await LoginRuntime.WebUiConfigQuickFunction();
|
||||
}
|
||||
};
|
||||
|
1
src/webui/src/types/data.d.ts
vendored
1
src/webui/src/types/data.d.ts
vendored
@@ -9,6 +9,7 @@ interface LoginRuntimeType {
|
||||
QQLoginUin: string;
|
||||
QQLoginInfo: SelfInfo;
|
||||
QQVersion: string;
|
||||
WebUiConfigQuickFunction: () => Promise<void>;
|
||||
NapCatHelper: {
|
||||
onQuickLoginRequested: (uin: string) => Promise<{ result: boolean; message: string }>;
|
||||
onOB11ConfigChanged: (ob11: OneBotConfig) => Promise<void>;
|
||||
|
Reference in New Issue
Block a user