DYN-10516 refresh templates and recent files from disk dynamically#17161
Conversation
Add a guard before opening files from the Home screen. `StartPageViewModel` now checks whether the selected Recent file or Template still exists on disk before calling `OpenCommand`. If the file was deleted or moved while Dynamo is running, Dynamo now shows a clearer missing-file warning, removes the stale item from both `RecentFiles` and `TemplateFiles`, and stops the open flow. This prevents the old behavior where a missing path could trigger a confusing invalid-path warning and leave Home stuck. `HomePage.OpenFile` uses the same guard for the WebView Home page. When a stale item is removed, it sends refreshed Recent and Template lists back to DynamoHome so the deleted card/list item disappears from the UI. A new localised resource string was added for the missing-file warning.
Refreshes Home Recent files and Templates whenever the Home page becomes visible. StartPageViewModel now exposes refresh methods that rebuild TemplateFiles from the current templates folder and rebuild RecentFiles from DynamoViewModel.RecentFiles. HomePage calls these methods when ShowStartPage changes to true, then sends the refreshed data to DynamoHome. The send methods now also pass empty lists, so if all recent files or templates were deleted or moved, DynamoHome receives [] and clears the stale Home cards.
There was a problem hiding this comment.
See the ticket for this pull request: https://jira.autodesk.com/browse/DYN-10516
…-Templates-and-Recent-Files-from-disk-dynamically
There was a problem hiding this comment.
Pull request overview
This PR updates Dynamo’s WPF Home page integration (WebView2 + StartPageViewModel) to dynamically refresh Recent files and Templates from disk when the user returns to Home, and to handle stale/missing Home items more safely (e.g., files deleted/moved while Dynamo remains open).
Changes:
- Refreshes
RecentFilesandTemplateFileswhenShowStartPagebecomestrue, and pushes refreshed data to DynamoHome (including empty lists to clear removed items). - Adds missing-file handling before opening items from Home and introduces a clearer localized warning message (
MessageHomeFileMissing). - Adjusts template/recent graph data sending to always call into the frontend with a list (empty or populated) to avoid stale UI.
Reviewed changes
Copilot reviewed 4 out of 5 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| src/DynamoCoreWpf/Views/HomePage/HomePage.xaml.cs | Refreshes/sends updated Home data on StartPage show; always sends template/recent lists; adds missing-file guard before opening. |
| src/DynamoCoreWpf/Controls/StartPage.xaml.cs | Adds refresh helpers; adds missing-file dialog + removal from StartPage collections. |
| src/DynamoCoreWpf/Properties/Resources.resx | Adds new user-facing localized string key for missing Home file warning. |
| src/DynamoCoreWpf/Properties/Resources.en-US.resx | Adds en-US entry for the new missing-file warning string. |
| src/DynamoCoreWpf/Properties/Resources.Designer.cs | Adds strongly-typed accessor for MessageHomeFileMissing. |
Files not reviewed (1)
- src/DynamoCoreWpf/Properties/Resources.Designer.cs: Generated file
| private async void DynamoViewModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) | ||
| { | ||
| if(e.PropertyName == nameof(startPage.DynamoViewModel.ShowStartPage) && dynWebView?.CoreWebView2 != null) | ||
| { | ||
| dynWebView.CoreWebView2.ExecuteScriptAsync(@$"window.setShowStartPageChanged('{startPage.DynamoViewModel.ShowStartPage}')"); | ||
| if (startPage.DynamoViewModel.ShowStartPage) | ||
| { | ||
| startPage.RefreshTemplateFiles(); | ||
| startPage.RefreshRecentFiles(); | ||
|
|
||
| await SendTemplateData(); | ||
| await SendRecentGraphsData(); | ||
| } | ||
|
|
||
| await dynWebView.CoreWebView2.ExecuteScriptAsync(@$"window.setShowStartPageChanged('{startPage.DynamoViewModel.ShowStartPage}')"); | ||
| } | ||
| } |
There was a problem hiding this comment.
This is a valid concern that should be addressed.
There was a problem hiding this comment.
Addressed. I wrapped the awaited Home refresh and WebView update work in DynamoViewModel_PropertyChanged in a try/catch and log any exception through Dynamo’s logger, so failures from SendTemplateData, SendRecentGraphsData, or ExecuteScriptAsync won’t surface as unhandled UI-thread exceptions.
| RemoveMissingFilePath(RecentFiles, path); | ||
| RemoveMissingFilePath(TemplateFiles, path); | ||
|
|
||
| return true; | ||
| } |
There was a problem hiding this comment.
This looks important to fix.
HandleMissingFilePath removes the item from StartPage.RecentFiles (the display collection) but leaves it in DynamoViewModel.RecentFiles, which is the authoritative list — persisted to preferences and also the source for File > Recent Files in the menu. So the deleted file would still show up in the file menu and return to the Start Page list on the next session.
There was a problem hiding this comment.
Please add a test for this scenario.
There was a problem hiding this comment.
Addressed. HandleMissingFilePath now removes the missing path from both the Start Page display collections and DynamoViewModel.RecentFiles, which is the authoritative recent files list and syncs back to preferences. I also added a test to verify the stale path is removed from the display list, DynamoViewModel.RecentFiles, and persisted preferences.
| internal void RefreshTemplateFiles() | ||
| { | ||
| TemplateFiles.Clear(); | ||
| LoadTemplates(); | ||
| } |
There was a problem hiding this comment.
Worth a look, but it may be a minor issue and the solution could be complex. So investigate and address the concern before resolving the conversation
There was a problem hiding this comment.
Addressed with a smaller async refresh. The template file scan and metadata creation now happen off the UI path, and TemplateFiles is updated after the async work completes
| internal bool HandleMissingFilePath(string path) | ||
| { | ||
| if (File.Exists(path)) | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| DynamoMessageBox.Show( | ||
| DynamoViewModel.Owner, | ||
| string.Format(Resources.MessageHomeFileMissing.Replace("\\n", Environment.NewLine), path), | ||
| Resources.MessageErrorOpeningFileGeneral, | ||
| MessageBoxButton.OK, | ||
| MessageBoxImage.Warning); | ||
|
|
||
| RemoveMissingFilePath(RecentFiles, path); | ||
| RemoveMissingFilePath(TemplateFiles, path); | ||
|
|
||
| return true; | ||
| } |
There was a problem hiding this comment.
I think this can be testable without using WebView
There was a problem hiding this comment.
I don’t think we need WebView coverage either, since the loading-state behaviour is covered in the DynamoHome PR. In this PR, we now have coverage for when a recent file is missing, Dynamo removes it from the Home list, the main recent files list and saved preferences. Let me know if you think any additional coverage on the Dynamo side.
jasonstratton
left a comment
There was a problem hiding this comment.
A couple of comments need to be addressed, please
| var templateFiles = startPage.TemplateFiles?.DistinctBy(x => x.ContextData).ToList() ?? new List<StartPageListItem>(); | ||
|
|
||
| _ = LoadGraphs(recentFiles); | ||
| _ = LoadTemplates(templateFiles); |
There was a problem hiding this comment.
_ = LoadGraphs(recentFiles) and _ = LoadTemplates(templateFiles) silently drop any exceptions.
If they fail, the UI the UI will display stale data. Please await the results.
since OpenFile is currently void, it would need to become async Task or async void with a try/catch
There was a problem hiding this comment.
Addressed. OpenFile remains the synchronous UI callback. The async work now runs in OpenFileAsync with a try/catch. The missing-file refresh calls are awaited there, so exceptions are logged instead of dropped.
| string.Equals(template.ContextData, path, StringComparison.OrdinalIgnoreCase)); | ||
| } | ||
|
|
||
| internal bool HandleMissingFilePath(string path) |
There was a problem hiding this comment.
This is probably more of a nitpick because the pattern is used elsewhere in the project. The methods are marked internal so that they can be called in the model and view, etc.
This one in particular is a method on the view model, but it displays a dialog box and so maybe should be on the view?
But there is a mix already in the project. So it probably does not need to be addressed, but pointing out the tech debt across the project.
- Remove missing Home files from the authoritative recent files list so stale entries do not return from preferences or File > Recent Files. - Add test coverage for missing recent file cleanup. - Await Home refresh calls when a missing file is removed and log failures instead of dropping exceptions. - Move template file scanning and metadata creation off the Home UI path before updating TemplateFiles. - Catch and log failures from the async Home visibility update path.
Move the awaited Home missing-file refresh work into OpenFileAsync and log failures instead of dropping task exceptions. Move the awaited Home missing-file refresh work into OpenFileAsync and log failures instead of dropping task exceptions
…es-from-disk-dynamically
jasonstratton
left a comment
There was a problem hiding this comment.
Thank you for the updated. Approving and merging
|



Purpose
This PR addresses DYN-10516 https://autodesk.atlassian.net/browse/DYN-10516 The changes in the code aim to keep the Home screen Recent files and Templates in sync with disk when the user returns to Home, and to handle stale Home items safely when a file was deleted or moved while Dynamo is still running. Previously, Home only loaded these lists at startup, so deleted files could remain visible, show a confusing warning, and leave Home stuck in a loading state after click.
This pr works with : DynamoDS/DynamoHome#93
Message when selecting a template that doesn't exist anymore :
Changes :
Declarations
Check these if you believe they are true
Release Notes
Home Recent files and Templates now refresh when returning to the Home screen, so the list reflects the current templates folder and recent files. Clicking a deleted or moved Home file now shows a clearer warning and no longer leaves Home stuck in a loading state.
Reviewers
@zeusongit
@DynamoDS/eidos
FYIs
@dnenov
@johnpierson
@jnealb
@jasonstratton