Skip to content

Add autosave support for File System Access API#330

Merged
tracygardner merged 2 commits intomainfrom
claude/add-autosave-feature-sn580
Feb 27, 2026
Merged

Add autosave support for File System Access API#330
tracygardner merged 2 commits intomainfrom
claude/add-autosave-feature-sn580

Conversation

@tracygardner
Copy link
Contributor

Summary

This PR adds autosave functionality for files saved via the File System Access API, allowing users to automatically save their work back to the same file without showing the file picker on subsequent saves.

Key Changes

  • Added currentFileHandle module-level variable to track the last explicitly saved file handle from the File System Access API
  • Modified exportCode() to store the file handle when a user explicitly saves via the file picker
  • Created new autoSaveToFile() function that writes workspace data to the previously saved file handle without user interaction
  • Updated the autosave interval in main.js to call both saveWorkspace() (localStorage) and autoSaveToFile() (file system) every 30 seconds
  • Added error handling in autoSaveToFile() to gracefully handle cases where the file handle is unavailable or invalid

Implementation Details

  • The autosave only triggers if a file handle exists (user has explicitly saved at least once)
  • Both autosave methods run in parallel: localStorage backup and file system save
  • Error logging is included for file system autosave failures to aid debugging
  • The implementation maintains backward compatibility - if no file handle is available, only localStorage autosave occurs

https://claude.ai/code/session_01SD7tmTxQf83oQYKAjTHUuV

Once a user saves their project via the file picker (File System Access API),
the returned FileSystemFileHandle is stored. The 30-second autosave interval
now also writes to that file handle automatically, keeping the saved file in
sync without prompting the user again.

https://claude.ai/code/session_01SD7tmTxQf83oQYKAjTHUuV
When a new file or example was opened, currentFileHandle was never
cleared, so the 30-second autosave kept writing back to the previously
saved file. Now clearFileHandle() is called in all four load paths
(file input, drag-and-drop, load example, new project) to reset the
handle whenever the active project changes.

https://claude.ai/code/session_01SD7tmTxQf83oQYKAjTHUuV
@tracygardner tracygardner merged commit 3728ef7 into main Feb 27, 2026
5 checks passed
@tracygardner tracygardner deleted the claude/add-autosave-feature-sn580 branch February 27, 2026 21:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants