mirror of
https://github.com/AutoMaker-Org/automaker.git
synced 2026-01-30 06:12:03 +00:00
fix: resolve data directory persistence between Electron and Web modes
This commit fixes bidirectional data synchronization between Electron and Web modes by addressing multiple interconnected issues: **Core Fixes:** 1. **Electron userData Path (main.ts)** - Explicitly set userData path in development using app.setPath() - Navigate from __dirname to project root instead of relying on process.cwd() - Ensures Electron reads from /data instead of ~/.config/Automaker 2. **Server DataDir Path (main.ts, start-automaker.sh)** - Fixed startServer() to use __dirname for reliable path calculation - Export DATA_DIR environment variable in start-automaker.sh - Server now consistently uses shared /data directory 3. **Settings Sync Protection (settings-service.ts)** - Modified wipe protection to distinguish legitimate removals from accidents - Allow empty projects array if trashedProjects has items - Prevent false-positive wipe detection when removing projects 4. **Diagnostics & Logging** - Enhanced cache loading logging in use-settings-migration.ts - Detailed migration decision logs for troubleshooting - Track project counts from both cache and server **Impact:** - Projects created in Electron now appear in Web mode after restart - Projects removed in Web mode stay removed in Electron after restart - Settings changes sync bidirectionally across mode switches - No more data loss or project duplication issues **Testing:** - Verified Electron uses /home/dhanush/Projects/automaker/data - Confirmed server startup logs show correct DATA_DIR - Tested project persistence across mode restarts - Validated no writes to ~/.config/Automaker in dev mode Fixes: Data persistence between Electron and Web modes Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -273,13 +273,39 @@ export class SettingsService {
|
||||
};
|
||||
|
||||
const currentProjectsLen = Array.isArray(current.projects) ? current.projects.length : 0;
|
||||
// Check if this is a legitimate project removal (moved to trash) vs accidental wipe
|
||||
const newTrashedProjectsLen = Array.isArray(sanitizedUpdates.trashedProjects)
|
||||
? sanitizedUpdates.trashedProjects.length
|
||||
: Array.isArray(current.trashedProjects)
|
||||
? current.trashedProjects.length
|
||||
: 0;
|
||||
|
||||
if (
|
||||
Array.isArray(sanitizedUpdates.projects) &&
|
||||
sanitizedUpdates.projects.length === 0 &&
|
||||
currentProjectsLen > 0
|
||||
) {
|
||||
attemptedProjectWipe = true;
|
||||
delete sanitizedUpdates.projects;
|
||||
// Only treat as accidental wipe if trashedProjects is also empty
|
||||
// (If projects are moved to trash, they appear in trashedProjects)
|
||||
if (newTrashedProjectsLen === 0) {
|
||||
logger.warn(
|
||||
'[WIPE_PROTECTION] Attempted to set projects to empty array with no trash! Ignoring update.',
|
||||
{
|
||||
currentProjectsLen,
|
||||
newProjectsLen: 0,
|
||||
newTrashedProjectsLen,
|
||||
currentProjects: current.projects?.map((p) => p.name),
|
||||
}
|
||||
);
|
||||
attemptedProjectWipe = true;
|
||||
delete sanitizedUpdates.projects;
|
||||
} else {
|
||||
logger.info('[LEGITIMATE_REMOVAL] Removing all projects to trash', {
|
||||
currentProjectsLen,
|
||||
newProjectsLen: 0,
|
||||
movedToTrash: newTrashedProjectsLen,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
ignoreEmptyArrayOverwrite('trashedProjects');
|
||||
|
||||
Reference in New Issue
Block a user