Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: config reset on app restart and improve migrations handling #394

Merged
merged 2 commits into from
Jan 29, 2025

Conversation

cazala
Copy link
Contributor

@cazala cazala commented Jan 28, 2025

Fix config reset on app restart and improve migrations handling

Config Reset Bug

The config was being reset to default values on app restart because we were incorrectly using storage.get('') to check for config existence. This was unreliable and caused the config to reset even when valid data existed.

Fix

  • Added getAll() and setAll() methods to read/write entire config state at once
  • Properly merge existing config with defaults
  • Write back merged config only when necessary
  • Added better logging for debugging

Migrations Improvement

Added synchronization to prevent race conditions between config operations and migrations:

  • Created waitForMigrations() utility using fp-future
  • Modified getConfig() to await migrations before proceeding
  • Single source of truth for migrations status

V2 Migration

Added version-based migration that automatically includes scene directories in workspace:

  • Scans scenesPath for valid scenes (containing scene.json)
  • Adds scene paths to workspace while preserving existing paths
  • Ensures no duplicate paths in workspace
  • Updates config version to 2

Testing

  1. Start app fresh
  2. Import scenes
  3. Restart app
  4. Verify scenes persist
  5. Verify config settings persist
  6. Verify scenes from scenesPath are added to workspace
  7. Verify migration only runs once (on next restart)

Copy link

github-actions bot commented Jan 28, 2025

Test this pull request on windows-latest

Download the correct version for your architecture:

win-x64

Copy link

github-actions bot commented Jan 28, 2025

Test this pull request on macos-latest

Download the correct version for your architecture:

mac-arm64
mac-x64

Click here if you don't know which version to download

For running this unsigned version of the app, you will need to run the xattr command on it:

  1. Extract the app from the downloaded .dmg file (double-click it)
  2. Place the extracted app anywhere you like in your file system
  3. Open a terminal on the directory where the app is
  4. Run xattr -c app-name, replacing "app-name" for the actual name of the app
  5. Double-click the app ✅

@cazala cazala changed the title feat: set default path for import fix: config reset on app restart and improve migrations handling Jan 28, 2025

// Initialize with default values if empty
const existingConfig = await storage.get<Record<string, any>>('');
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line was the bug, this always returns undefined, and causes the default config to be applied over the existing one.

const [projectPath] = await invoke('electron.showOpenDialog', {
title: 'Import project',
properties: ['openDirectory'],
defaultPath: config.settings.scenesPath,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a quality-of-life improvement for users

for (const [key, value] of Object.entries(mergedConfig)) {
await storage.set(key, value);
export async function getConfig(): Promise<IFileSystemStorage> {
await waitForMigrations();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just to avoid possible race conditions between the migration of the config and the initialization of the default values.

@cazala cazala force-pushed the feat/set-default-path-import-project branch 2 times, most recently from 266c68e to 7b01fac Compare January 28, 2025 16:33
@cazala cazala force-pushed the feat/set-default-path-import-project branch from 7b01fac to cb87e5d Compare January 28, 2025 16:34
@Ludmilafantaniella Ludmilafantaniella self-requested a review January 28, 2025 23:58
@cazala cazala merged commit 3e9ffb8 into main Jan 29, 2025
10 checks passed
@cazala cazala deleted the feat/set-default-path-import-project branch January 29, 2025 13:30
@Ludmilafantaniella
Copy link

Ludmilafantaniella commented Jan 29, 2025

I just finished testing on Windows and Mac 🤦🏽. Anyways, here's the evidence and the tests performed:

  • Scenes created in previous builds are present. ✅
  • Closing and reopening the app, scenes persist. ✅
  • Create a new scene. ✅
  • Close and reopen to check persistence. ✅
  • Preview the scene. ✅
  • Publish the scene. ✅

Scene Preview:

ch.persist.mp4

Scenes persist after restarting:

CH.V0.17.0.FIX.mp4

Publish a scene:

scene.published.mp4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants