Feat: layout version update func

This commit is contained in:
unitwk 2023-11-18 16:38:18 +08:00
parent 858763c2c3
commit 85365557ce
2 changed files with 14 additions and 1 deletions

View File

@ -2,6 +2,7 @@ import { v4 } from "uuid";
import { IPageLayoutConfig } from "../../../../common/global";
import { $t as t } from "../i18n";
import storage from "../common/system_storage";
import { GlobalVariable } from "common";
const LAYOUT_CONFIG_NAME = "layout.json";
@ -15,6 +16,18 @@ export function getFrontendLayoutConfig(): string {
layoutConfig = storage.readFile(LAYOUT_CONFIG_NAME);
}
if (layoutConfig) {
if (GlobalVariable.get("versionChange")) {
const latestLayoutConfig = getDefaultFrontendLayoutConfig();
const currentLayoutConfig = JSON.parse(layoutConfig) as IPageLayoutConfig[];
for (const page of latestLayoutConfig) {
if (!currentLayoutConfig.find((item) => item.page === page.page)) {
currentLayoutConfig.push(page);
}
}
GlobalVariable.set("versionChange", null);
setFrontendLayoutConfig(currentLayoutConfig);
return JSON.stringify(currentLayoutConfig);
}
return layoutConfig as string;
} else {
return JSON.stringify(getDefaultFrontendLayoutConfig());

View File

@ -32,7 +32,7 @@ export function initVersionManager() {
if (currentVersion && storage.fileExists(VERSION_LOG_TEXT_NAME)) {
const LastLaunchedVersion = storage.readFile(VERSION_LOG_TEXT_NAME);
if (LastLaunchedVersion && LastLaunchedVersion != currentVersion) {
logger.info(`Version changed from ${LastLaunchedVersion} to ${currentVersion}`);
logger.warn(`Version changed from ${LastLaunchedVersion} to ${currentVersion}`);
GlobalVariable.set("versionChange", currentVersion);
}
}