diff --git a/src/main/index.ts b/src/main/index.ts index d3ae1c7..fcf4955 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -1,6 +1,7 @@ import { app, BrowserWindow, Menu, clipboard, ipcMain, safeStorage, session, shell } from 'electron'; import { join, dirname } from 'path'; -import { existsSync, mkdirSync, unlinkSync, promises as fsp } from 'fs'; +import { existsSync, mkdirSync, promises as fsp } from 'fs'; +import { existsSync as origExistsSync, unlinkSync as origUnlinkSync } from 'original-fs'; import { get as httpsGet } from 'https'; import { execFile } from 'child_process'; import * as os from 'os'; @@ -179,8 +180,8 @@ app.whenReady().then(async () => { // Clean up stale pending asar from a previous failed swap const resourcesDir = join(dirname(app.getPath('exe')), 'resources'); const stalePending = join(resourcesDir, 'app-pending.asar'); - if (existsSync(stalePending)) { - try { unlinkSync(stalePending); } catch { /* ignore */ } + if (origExistsSync(stalePending)) { + try { origUnlinkSync(stalePending); } catch { /* ignore */ } } try { @@ -213,8 +214,8 @@ app.whenReady().then(async () => { } catch (err) { electronLog.error('[KCC] Patch download failed:', err); // Clean up failed download - if (existsSync(pendingPath)) { - try { unlinkSync(pendingPath); } catch { /* ignore */ } + if (origExistsSync(pendingPath)) { + try { origUnlinkSync(pendingPath); } catch { /* ignore */ } } if (!updateWin.isDestroyed()) updateWin.close(); } diff --git a/src/main/updater.ts b/src/main/updater.ts index 5d66ae8..36698e6 100644 --- a/src/main/updater.ts +++ b/src/main/updater.ts @@ -1,5 +1,7 @@ import { get as httpsGet } from 'https'; -import { createReadStream, createWriteStream, writeFileSync, renameSync, unlinkSync, existsSync, mkdirSync } from 'fs'; +// Use original-fs to bypass Electron's asar interception — required for +// writing/renaming .asar files in the resources directory. +import { createReadStream, createWriteStream, writeFileSync, renameSync, unlinkSync, existsSync, mkdirSync } from 'original-fs'; import { join, dirname } from 'path'; import { createHash } from 'crypto'; import { spawn } from 'child_process'; diff --git a/vite.main.config.ts b/vite.main.config.ts index 629089b..8a7d6bf 100644 --- a/vite.main.config.ts +++ b/vite.main.config.ts @@ -20,7 +20,7 @@ export default defineConfig({ outDir: 'dist/main', emptyDirBefore: true, rollupOptions: { - external: ['electron', 'electron-store', ...nodeBuiltins], + external: ['electron', 'electron-store', 'original-fs', ...nodeBuiltins], }, target: 'node20', minify: isProd,