Skip to content

Add “Watcher” Mode to Monitor Local File Changes#512

Open
eliyya wants to merge 19 commits intoAykutSarac:mainfrom
eliyya:watcher
Open

Add “Watcher” Mode to Monitor Local File Changes#512
eliyya wants to merge 19 commits intoAykutSarac:mainfrom
eliyya:watcher

Conversation

@eliyya
Copy link
Copy Markdown

@eliyya eliyya commented Oct 6, 2025

Description

This PR introduces a new “Watcher” mode under the File > Import menu, allowing users to monitor changes to a selected local file and automatically update the editor and graph.

Motivation

I work a lot with generating JSON files and I use jsoncrack.com a lot to view the generation, but having to re-import the JSON every time it is regenerated really disrupts my workflow. jsoncrack.com is already perfect, but I thought that if the tool had a watch mode it would be much better, so I implemented that option.

Implementation Details

  • Added a "Watcher" button in the import modal.
image
  • If the FilePicker API is not disponible, the button was not disponibe annd shows a message
image
  • When activated, the file picker (window.showOpenFilePicker) opens for the user to select a file.
  • The selected file is loaded initially, and a setInterval runs every 3 seconds to check for changes using fileHandle.getFile().
  • If the file changes, the content is reloaded into the editor, the graph is refreshed and a toast appears.
image
  • A global state is used to manage the watcher and its interval.
  • While watcher mode is active:
    • The editor is set to readonly.
    • Format change options and Live Transform are disabled.
  • A “Stop Watching” button is available to stop the watcher, clear the interval, and re-enable disabled features.
image

Benefits

  • Allows real-time monitoring and visualization of local files without manual re-import.
  • Ideal for workflows where files are generated or updated externally.
  • Maintains compatibility with the existing import flow.

eliyya and others added 2 commits October 6, 2025 18:07
Co-authored-by: Ted Thibodeau Jr <tthibodeau@openlinksw.com>
@AykutSarac
Copy link
Copy Markdown
Owner

I ran into an error when I clicked the Watcher button, we should add 'showOpenFilePicker' in window to check if user's browser supports the feature. Apparently it's disabled in Brave for privacy reasons, so I couldn't test it at the moment.

I like the idea though, good job! Let's wait for comments on the PR for now. 🏁

@AykutSarac AykutSarac added the open to review Please share your insights about this issue/PR label Oct 16, 2025
@eliyya
Copy link
Copy Markdown
Author

eliyya commented Oct 19, 2025

To show it in the UI, I think it would be good to disable the button and use a tooltip with a 500ms delay to show the reason like a...

image

Any opinion?

Copy link
Copy Markdown

@atilaahmettaner atilaahmettaner left a comment

Choose a reason for hiding this comment

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

The initial watch state does not transfer the file to the editor, it transfers it when changes are made. Can you also resolve the initial watch state here?

Copy link
Copy Markdown

@atilaahmettaner atilaahmettaner left a comment

Choose a reason for hiding this comment

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

I tested the watch mode on Chrome overall and it works well. File updates from an external editor trigger the "File updated!" toast properly, the editor goes read-only as expected, and the graph refreshes correctly. Good job on the implementation.

However I found a few issues:

  1. Initial file content not loading on first watch

When I first open the app and click the Watcher button, the selected file's content doesn't load into the editor. The old content stays. It gets updated only when the file is modified externally. This doesn't happen every time but specifically when you first open the app and immediately start watch mode.

  1. Closing the modal stops watch mode

If watch mode is active and you open the Import Modal again and close it, watch mode gets stopped. The onClose handler calls toggleWatchMode(false) which kills the watcher. The user might just want to close the modal, not stop watching.
toggleWatchMode(false);

this stops watch mode unintentionally

  1. console.log left in code

There's a console.log(file) left in the import handler that should be removed before merging.

@atilaahmettaner
Copy link
Copy Markdown

@eliyya looks good, just a small typo — "suported" should be "supported" in the tooltip text. other than that everything works fine 👍

@eliyya
Copy link
Copy Markdown
Author

eliyya commented Mar 24, 2026

When I first open the app and click the Watcher button, the selected file's content doesn't load into the editor. The old content stays. It gets updated only when the file is modified externally. This doesn't happen every time but specifically when you first open the app and immediately start watch mode.

I can't reproduce this bug. In the initials commits I fixed that, so, I don't know if the bug i'ts appearing again or i'ts an old bug. It still appearing yet?

Im still usin a lot the watcher, tnx for the feedback and sorry for the typos, english is not my first language

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

open to review Please share your insights about this issue/PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants