完善版本更新
This commit is contained in:
parent
6eabf8df35
commit
28496b35f3
1542
data/web/index.html
1542
data/web/index.html
File diff suppressed because one or more lines are too long
@ -19,14 +19,60 @@ function copyDir(src: string, dest: string): void {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
declare const __APP_VERSION__: string;
|
||||||
|
|
||||||
|
function compareVersions(a: string, b: string): number {
|
||||||
|
const pa = a
|
||||||
|
.split(".")
|
||||||
|
.map((n) => Number.parseInt(n, 10))
|
||||||
|
.filter((n) => Number.isFinite(n));
|
||||||
|
const pb = b
|
||||||
|
.split(".")
|
||||||
|
.map((n) => Number.parseInt(n, 10))
|
||||||
|
.filter((n) => Number.isFinite(n));
|
||||||
|
const len = Math.max(pa.length, pb.length);
|
||||||
|
for (let i = 0; i < len; i++) {
|
||||||
|
const va = pa[i] ?? 0;
|
||||||
|
const vb = pb[i] ?? 0;
|
||||||
|
if (va > vb) return 1;
|
||||||
|
if (va < vb) return -1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
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");
|
||||||
for (const dir of TARGET_ENTRIES) {
|
const versionFilePath = path.join(destDir, "version.txt");
|
||||||
if (!fs.existsSync(path.join(destDir, dir))) {
|
|
||||||
copyDir(path.join(srcDir, dir), path.join(destDir, dir));
|
let shouldForceReplace = false;
|
||||||
|
if (!fs.existsSync(versionFilePath)) {
|
||||||
|
shouldForceReplace = true;
|
||||||
|
} else {
|
||||||
|
const localVersion = fs.readFileSync(versionFilePath, "utf-8").trim();
|
||||||
|
if (compareVersions(localVersion, __APP_VERSION__) < 0) {
|
||||||
|
shouldForceReplace = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log("%c Line:55 🍕 shouldForceReplace", "background:#2eafb0", shouldForceReplace);
|
||||||
|
|
||||||
|
for (const dir of TARGET_ENTRIES) {
|
||||||
|
const targetDir = path.join(destDir, dir);
|
||||||
|
if (shouldForceReplace) {
|
||||||
|
fs.rmSync(targetDir, { recursive: true, force: true });
|
||||||
|
copyDir(path.join(srcDir, dir), targetDir);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (!fs.existsSync(targetDir)) {
|
||||||
|
copyDir(path.join(srcDir, dir), targetDir);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (shouldForceReplace) {
|
||||||
|
fs.mkdirSync(destDir, { recursive: true });
|
||||||
|
fs.writeFileSync(versionFilePath, `${__APP_VERSION__}\n`, "utf-8");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//获取全部依赖路径,优先从 unpacked 加载原生模块,其他模块从 asar 加载
|
//获取全部依赖路径,优先从 unpacked 加载原生模块,其他模块从 asar 加载
|
||||||
@ -206,7 +252,7 @@ app.whenReady().then(async () => {
|
|||||||
const url = new URL(request.url);
|
const url = new URL(request.url);
|
||||||
const pathname = url.hostname.toLowerCase();
|
const pathname = url.hostname.toLowerCase();
|
||||||
const handlers: Record<string, () => object> = {
|
const handlers: Record<string, () => object> = {
|
||||||
getport: () => ({ port: port }),
|
getappurl: () => ({ url: process.env.URL ?? `http://localhost:${port}/api` }),
|
||||||
windowminimize: () => {
|
windowminimize: () => {
|
||||||
mainWindow?.minimize();
|
mainWindow?.minimize();
|
||||||
return { ok: true };
|
return { ok: true };
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user