mirror of
https://github.com/NeuralNomadsAI/CodeNomad.git
synced 2026-08-19 13:23:27 +00:00
fix(electron): isolate packaged session storage
This commit is contained in:
parent
1f46092f4d
commit
ecfbc9e5d1
1 changed files with 46 additions and 2 deletions
|
|
@ -1,7 +1,7 @@
|
|||
import { app, BrowserView, BrowserWindow, nativeImage, session, shell } from "electron"
|
||||
import http from "node:http"
|
||||
import https from "node:https"
|
||||
import { existsSync, mkdirSync } from "fs"
|
||||
import { existsSync, mkdirSync, rmSync } from "fs"
|
||||
import { dirname, join } from "path"
|
||||
import { fileURLToPath } from "url"
|
||||
import { createApplicationMenu } from "./menu"
|
||||
|
|
@ -39,6 +39,49 @@ function configureDevStoragePaths() {
|
|||
|
||||
configureDevStoragePaths()
|
||||
|
||||
function configurePackagedStoragePaths() {
|
||||
if (!app.isPackaged) {
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
const sessionDataPath = join(app.getPath("userData"), "session-data-v2")
|
||||
mkdirSync(sessionDataPath, { recursive: true })
|
||||
app.setPath("sessionData", sessionDataPath)
|
||||
} catch (error) {
|
||||
console.warn("[electron-startup] failed to configure packaged session data path", error)
|
||||
}
|
||||
}
|
||||
|
||||
configurePackagedStoragePaths()
|
||||
|
||||
function cleanupPackagedChromiumStorage() {
|
||||
if (!app.isPackaged) {
|
||||
return
|
||||
}
|
||||
|
||||
const roots = [app.getPath("sessionData"), app.getPath("userData"), join(app.getPath("userData"), "session-data")]
|
||||
const names = ["Service Worker", "QuotaManager", "QuotaManager-journal"]
|
||||
|
||||
for (const root of roots) {
|
||||
for (const name of names) {
|
||||
const candidate = join(root, name)
|
||||
if (!existsSync(candidate)) {
|
||||
continue
|
||||
}
|
||||
|
||||
try {
|
||||
rmSync(candidate, { recursive: true, force: true })
|
||||
console.info("[electron-startup] removed stale Chromium storage", candidate)
|
||||
} catch (error) {
|
||||
console.warn("[electron-startup] failed to remove stale Chromium storage", candidate, error)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cleanupPackagedChromiumStorage()
|
||||
|
||||
const cliManager = new CliProcessManager()
|
||||
let mainWindow: BrowserWindow | null = null
|
||||
let currentCliUrl: string | null = null
|
||||
|
|
@ -129,7 +172,8 @@ function isIgnorableNavigationError(error: unknown): boolean {
|
|||
}
|
||||
|
||||
const code = "code" in error ? String((error as { code?: unknown }).code ?? "") : ""
|
||||
return code === "ERR_ABORTED" || code === "ERR_FAILED"
|
||||
const message = "message" in error ? String((error as { message?: unknown }).message ?? "") : ""
|
||||
return code === "ERR_ABORTED" || code === "ERR_FAILED" || message.includes("ERR_ABORTED") || message.includes("ERR_FAILED")
|
||||
}
|
||||
|
||||
function getAllowedRendererOrigins(window?: BrowserWindow | null): string[] {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue