Skip to content

Send files directly between devices over the internet - no cloud storage, no size limits.

move windows app data out of squirrel install folder

Denis Lupookov1272844a9a7a
diff --git a/apps/desktop/src/electron/migrateLegacyStore.ts b/apps/desktop/src/electron/migrateLegacyStore.ts
new file mode 100644
index 0000000..c471a36
--- /dev/null
+++ b/apps/desktop/src/electron/migrateLegacyStore.ts
@@ -0,0 +1,31 @@
+import fs from 'fs'
+import path from 'path'
+
+const STORE_ENTRIES = ['app-storage', 'identity', 'pear-runtime']
+
+export function migrateLegacyStore(legacyDir: string, dir: string): void {
+ if (legacyDir === dir || !fs.existsSync(legacyDir)) return
+
+ try {
+ fs.mkdirSync(dir, { recursive: true })
+ } catch (err) {
+ console.warn('[runtime] store migration failed to create target:', err)
+ return
+ }
+
+ for (const entry of STORE_ENTRIES) {
+ const from = path.join(legacyDir, entry)
+ if (!fs.existsSync(from)) continue
+
+ const to = fs.existsSync(path.join(dir, entry))
+ ? path.join(legacyDir, `legacy-${entry}`)
+ : path.join(dir, entry)
+ if (fs.existsSync(to)) continue
+
+ try {
+ fs.renameSync(from, to)
+ } catch (err) {
+ console.warn(`[runtime] store migration failed for ${entry}:`, err)
+ }
+ }
+}
diff --git a/apps/desktop/src/electron/runtime.ts b/apps/desktop/src/electron/runtime.ts
index fb525c4..cbb0dd2 100644
--- a/apps/desktop/src/electron/runtime.ts
+++ b/apps/desktop/src/electron/runtime.ts
@@ -11,6 +11,7 @@ import {
type WorkerClient
} from '@altersend/core'
import { writeFileViaTemp } from './writeFileViaTemp.js'
+import { migrateLegacyStore } from './migrateLegacyStore.js'
import { isMac, isLinux, isWindows } from 'which-runtime'
import { command, flag, sloppy } from 'paparam'
import { createRequire } from 'module'
@@ -144,11 +145,13 @@ async function initDeviceKeychain(client: WorkerClient, identityRoot: string): P
}
function appDataDir(name: string): string {
- return isMac
- ? path.join(os.homedir(), 'Library', 'Application Support', name)
- : isLinux
- ? path.join(os.homedir(), '.config', name)
- : path.join(os.homedir(), 'AppData', 'Local', name)
+ if (isMac) return path.join(os.homedir(), 'Library', 'Application Support', name)
+ if (isLinux) return path.join(os.homedir(), '.config', name)
+ return path.join(os.homedir(), 'AppData', 'Roaming', name)
+}
+
+function squirrelInstallDir(name: string): string {
+ return path.join(os.homedir(), 'AppData', 'Local', name)
}
export function createDesktopRuntime({ broadcast }: { broadcast: Broadcast }): DesktopRuntime {
@@ -160,7 +163,10 @@ export function createDesktopRuntime({ broadcast }: { broadcast: Broadcast }): D
if (pear) return pear
const appPath = getAppPath()
- const dir = pearStore || appDataDir(appPath === null ? `${productName}-dev` : productName)
+ const name = appPath === null ? `${productName}-dev` : productName
+ const dir = pearStore || appDataDir(name)
+
+ if (!pearStore && isWindows) migrateLegacyStore(squirrelInstallDir(name), dir)
const extension = isLinux ? '.AppImage' : isMac ? '.app' : '.msix'
const instance: PearRuntimeInstance = new PearRuntime({