修改版本更新

This commit is contained in:
ACT丶流星雨 2026-04-06 03:56:49 +08:00
parent 0971e100a4
commit f73335daf7
2 changed files with 19 additions and 7 deletions

View File

@ -9,6 +9,17 @@ app.commandLine.appendSwitch("disable-features", "CalculateNativeWinOcclusion");
declare const __APP_VERSION__: string | undefined;
/**
* extraResources data
*/
function getVersionFromUpdateJson(filePath: string): string | null {
try {
return JSON.parse(fs.readFileSync(filePath, "utf8")).version ?? null;
} catch {}
return null;
}
const SKIP_ENTRIES = new Set(["logs", "oss", "db2.sqlite"]);
function copyDir(src: string, dest: string, overwrite = false): void {
@ -29,9 +40,9 @@ function copyDir(src: string, dest: string, overwrite = false): void {
function initializeData(): void {
const srcDir = path.join(process.resourcesPath, "data");
const destDir = path.join(app.getPath("userData"), "data");
const updateJsonFile = path.join(destDir, "version.txt");
const updateJsonFile = path.join(destDir, "update.json");
const currentVersion = typeof __APP_VERSION__ !== "undefined" ? __APP_VERSION__ : "0.0.0";
const userVersion = fs.existsSync(updateJsonFile) ? fs.readFileSync(updateJsonFile, "utf8") : null;
const userVersion = getVersionFromUpdateJson(updateJsonFile);
if (!userVersion) {
copyDir(srcDir, destDir);

View File

@ -15,21 +15,22 @@ const APP_VERSION: string = (() => {
})();
export default async (version?: string) => {
const versionFile = path.join(getPath(), "version.txt");
const versionFile = path.join(getPath(), "update.json");
if (!fs.existsSync(versionFile)) {
fs.mkdirSync(path.dirname(versionFile), { recursive: true });
}
await fs.promises.writeFile(versionFile, version ?? APP_VERSION, "utf8");
await fs.promises.writeFile(versionFile, JSON.stringify({ version: version ?? APP_VERSION }, null, 4), "utf8");
};
export const getVersion = async () => {
const versionFile = path.join(getPath(), "version.txt");
const versionFile = path.join(getPath(), "update.json");
if (fs.existsSync(versionFile)) {
return fs.readFileSync(versionFile, "utf8");
const data = JSON.parse(fs.readFileSync(versionFile, "utf8"));
return data.version || null;
}
if (!fs.existsSync(versionFile)) {
fs.mkdirSync(path.dirname(versionFile), { recursive: true });
}
await fs.promises.writeFile(versionFile, APP_VERSION, "utf8");
await fs.promises.writeFile(versionFile, JSON.stringify({ version: APP_VERSION }, null, 4), "utf8");
return APP_VERSION;
};