Skip to content

Conversation

@BetaHuhn
Copy link
Member

@BetaHuhn BetaHuhn commented Oct 23, 2025

Description

Watches the resource directory in the system's file system and keeps track of file additions, moving and deletions to update the resources within Surf.

Behavior:

  • new files: imports them into Surf as new resources
  • renaming a file: updates the resource path and name in Surf
  • deleting a file: deletes the matching resource from Surf

Unfortunately our cross renderer reactivity seems to be bonked again so you need to reload the "Media" tab for the resources to update.

Implementation

Initially wanted to use an existing library to watch for changes but none matched the requirements of reliably tracking file renaming and not having too many external dependencies.

Instead created my own FileWatcher module which tracks files using inode numbers - unique filesystem identifiers that persist across renames but change for new files. It scans the directory on startup to build an inode-to-filename map, then batches fs.watch() events in a 100ms debounce window to catch related operations.

After debouncing, it re-scans and compares states: same inode + different filename = rename, missing inode = delete, new inode = create. This is very accurate on Unix systems (MacOS + Linux). On Windows we fall back to less reliable size-based matching as Windows doesn't have reliable inode support.

When file movements are detected the main process sends an IPC event to the core renderer which then handles updating the resources using our SFFS APIs. Had to add a API endpoint to fetch a resource by the resource path to find the matching resource for a given file.

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.

1 participant