fix: use original-fs to bypass Electron asar interception
This commit is contained in:
+6
-5
@@ -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();
|
||||
}
|
||||
|
||||
+3
-1
@@ -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';
|
||||
|
||||
+1
-1
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user