fix: use original-fs to bypass Electron asar interception

This commit is contained in:
2026-04-16 09:38:00 -07:00
parent 691b363f88
commit 255befd1b8
3 changed files with 10 additions and 7 deletions
+6 -5
View File
@@ -1,6 +1,7 @@
import { app, BrowserWindow, Menu, clipboard, ipcMain, safeStorage, session, shell } from 'electron'; import { app, BrowserWindow, Menu, clipboard, ipcMain, safeStorage, session, shell } from 'electron';
import { join, dirname } from 'path'; 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 { get as httpsGet } from 'https';
import { execFile } from 'child_process'; import { execFile } from 'child_process';
import * as os from 'os'; import * as os from 'os';
@@ -179,8 +180,8 @@ app.whenReady().then(async () => {
// Clean up stale pending asar from a previous failed swap // Clean up stale pending asar from a previous failed swap
const resourcesDir = join(dirname(app.getPath('exe')), 'resources'); const resourcesDir = join(dirname(app.getPath('exe')), 'resources');
const stalePending = join(resourcesDir, 'app-pending.asar'); const stalePending = join(resourcesDir, 'app-pending.asar');
if (existsSync(stalePending)) { if (origExistsSync(stalePending)) {
try { unlinkSync(stalePending); } catch { /* ignore */ } try { origUnlinkSync(stalePending); } catch { /* ignore */ }
} }
try { try {
@@ -213,8 +214,8 @@ app.whenReady().then(async () => {
} catch (err) { } catch (err) {
electronLog.error('[KCC] Patch download failed:', err); electronLog.error('[KCC] Patch download failed:', err);
// Clean up failed download // Clean up failed download
if (existsSync(pendingPath)) { if (origExistsSync(pendingPath)) {
try { unlinkSync(pendingPath); } catch { /* ignore */ } try { origUnlinkSync(pendingPath); } catch { /* ignore */ }
} }
if (!updateWin.isDestroyed()) updateWin.close(); if (!updateWin.isDestroyed()) updateWin.close();
} }
+3 -1
View File
@@ -1,5 +1,7 @@
import { get as httpsGet } from 'https'; 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 { join, dirname } from 'path';
import { createHash } from 'crypto'; import { createHash } from 'crypto';
import { spawn } from 'child_process'; import { spawn } from 'child_process';
+1 -1
View File
@@ -20,7 +20,7 @@ export default defineConfig({
outDir: 'dist/main', outDir: 'dist/main',
emptyDirBefore: true, emptyDirBefore: true,
rollupOptions: { rollupOptions: {
external: ['electron', 'electron-store', ...nodeBuiltins], external: ['electron', 'electron-store', 'original-fs', ...nodeBuiltins],
}, },
target: 'node20', target: 'node20',
minify: isProd, minify: isProd,