修改版本更新
This commit is contained in:
parent
0971e100a4
commit
f73335daf7
@ -9,6 +9,17 @@ app.commandLine.appendSwitch("disable-features", "CalculateNativeWinOcclusion");
|
|||||||
|
|
||||||
declare const __APP_VERSION__: string | undefined;
|
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"]);
|
const SKIP_ENTRIES = new Set(["logs", "oss", "db2.sqlite"]);
|
||||||
|
|
||||||
function copyDir(src: string, dest: string, overwrite = false): void {
|
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 {
|
function initializeData(): void {
|
||||||
const srcDir = path.join(process.resourcesPath, "data");
|
const srcDir = path.join(process.resourcesPath, "data");
|
||||||
const destDir = path.join(app.getPath("userData"), "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 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) {
|
if (!userVersion) {
|
||||||
copyDir(srcDir, destDir);
|
copyDir(srcDir, destDir);
|
||||||
|
|||||||
@ -15,21 +15,22 @@ const APP_VERSION: string = (() => {
|
|||||||
})();
|
})();
|
||||||
|
|
||||||
export default async (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)) {
|
if (!fs.existsSync(versionFile)) {
|
||||||
fs.mkdirSync(path.dirname(versionFile), { recursive: true });
|
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 () => {
|
export const getVersion = async () => {
|
||||||
const versionFile = path.join(getPath(), "version.txt");
|
const versionFile = path.join(getPath(), "update.json");
|
||||||
if (fs.existsSync(versionFile)) {
|
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)) {
|
if (!fs.existsSync(versionFile)) {
|
||||||
fs.mkdirSync(path.dirname(versionFile), { recursive: true });
|
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;
|
return APP_VERSION;
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user