mirror of
https://github.com/MCSManager/MCSManager.git
synced 2025-01-24 15:14:01 +08:00
Feat: add versionChanged status
This commit is contained in:
parent
5ad53f11e3
commit
479b58a57d
@ -25,6 +25,7 @@ const { updateUserInfo, state } = useAppStateStore();
|
||||
async function checkPanelStatus() {
|
||||
const status = await panelStatus().execute();
|
||||
state.isInstall = status.value?.isInstall ?? true;
|
||||
state.versionChanged = status.value?.versionChange ? true : false;
|
||||
if (!state.isInstall) {
|
||||
return router.push({
|
||||
path: "/init"
|
||||
|
@ -37,6 +37,7 @@ export const panelStatus = useDefineApi<
|
||||
{
|
||||
isInstall: boolean;
|
||||
language: string;
|
||||
versionChange?: string;
|
||||
}
|
||||
>({
|
||||
url: "/api/auth/status",
|
||||
|
@ -7,6 +7,7 @@ import type { BaseUserInfo } from "@/types/user";
|
||||
interface AppStateInfo {
|
||||
userInfo: BaseUserInfo | null;
|
||||
isInstall: boolean;
|
||||
versionChanged: boolean;
|
||||
}
|
||||
|
||||
export const useAppStateStore = createGlobalState(() => {
|
||||
@ -14,7 +15,8 @@ export const useAppStateStore = createGlobalState(() => {
|
||||
|
||||
const state: AppStateInfo = reactive<AppStateInfo>({
|
||||
userInfo: null,
|
||||
isInstall: true
|
||||
isInstall: true,
|
||||
versionChanged: false
|
||||
});
|
||||
|
||||
const cloneState = (): AppStateInfo => {
|
||||
|
@ -10,6 +10,7 @@ import userSystem from "../../service/system_user";
|
||||
import { logger } from "../../service/log";
|
||||
import { $t } from "../../i18n";
|
||||
import axios from "axios";
|
||||
import GlobalVariable from "../../common/global_variable";
|
||||
const router = new Router({ prefix: "/auth" });
|
||||
|
||||
// [Public Permission]
|
||||
@ -66,6 +67,7 @@ router.all(
|
||||
isInstall = false;
|
||||
}
|
||||
ctx.body = {
|
||||
versionChange: GlobalVariable.get("versionChange", null),
|
||||
isInstall,
|
||||
language: systemConfig.language || null
|
||||
};
|
||||
|
@ -1,21 +1,41 @@
|
||||
import * as fs from "fs-extra";
|
||||
import GlobalVariable from "./common/global_variable";
|
||||
import { logger } from "./service/log";
|
||||
import path from "path";
|
||||
|
||||
const PACKAGE_JSON = "package.json";
|
||||
let CURRENT_VERSION = "";
|
||||
const VERSION_LOG_TEXT_PATH = path.normalize(path.join(process.cwd(), "data/current-version.txt"));
|
||||
|
||||
interface PackageInfo {
|
||||
name: string;
|
||||
version: string;
|
||||
daemonVersion: string;
|
||||
description: string;
|
||||
}
|
||||
|
||||
export function initVersionManager() {
|
||||
try {
|
||||
GlobalVariable.set("version", "Unknown");
|
||||
if (fs.existsSync(PACKAGE_JSON)) {
|
||||
const data: any = JSON.parse(fs.readFileSync(PACKAGE_JSON, { encoding: "utf-8" }));
|
||||
const data: PackageInfo = JSON.parse(fs.readFileSync(PACKAGE_JSON, { encoding: "utf-8" }));
|
||||
if (data.version) {
|
||||
GlobalVariable.set("version", data.version);
|
||||
CURRENT_VERSION = String(data.version);
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
logger.error("Version Check failure:", error);
|
||||
}
|
||||
|
||||
if (CURRENT_VERSION && fs.existsSync(VERSION_LOG_TEXT_PATH)) {
|
||||
const LastLaunchedVersion = fs.readFileSync(VERSION_LOG_TEXT_PATH, { encoding: "utf-8" });
|
||||
if (LastLaunchedVersion && LastLaunchedVersion != CURRENT_VERSION) {
|
||||
logger.info(`Version changed from ${LastLaunchedVersion} to ${CURRENT_VERSION}`);
|
||||
GlobalVariable.set("versionChange", CURRENT_VERSION);
|
||||
}
|
||||
}
|
||||
fs.writeFileSync(VERSION_LOG_TEXT_PATH, CURRENT_VERSION, { encoding: "utf-8" });
|
||||
}
|
||||
|
||||
export function getVersion(): string {
|
||||
|
Loading…
Reference in New Issue
Block a user