Skip to content

DYN-10516 refresh templates and recent files from disk dynamically#17161

Merged
jasonstratton merged 6 commits into
DynamoDS:masterfrom
Chloepeg:DYN-10516-Refresh-Templates-and-Recent-Files-from-disk-dynamically
Jun 23, 2026
Merged

DYN-10516 refresh templates and recent files from disk dynamically#17161
jasonstratton merged 6 commits into
DynamoDS:masterfrom
Chloepeg:DYN-10516-Refresh-Templates-and-Recent-Files-from-disk-dynamically

Conversation

@Chloepeg

@Chloepeg Chloepeg commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

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

Gif refresh home

Message when selecting a template that doesn't exist anymore :

Error message after template delete

Changes :

  • Added missing-file handling before opening Home Recent files or Templates.
  • Added refresh methods to rebuild RecentFiles and TemplateFiles from the current source.
  • Uses the same missing-file guard for the WebView Home page and sends refreshed data back to DynamoHome.
  • Refreshes Recent files and Templates when ShowStartPage becomes true.
  • Sends empty lists too, so deleted items are cleared from Home.
  • Added MessageHomeFileMissing for a clearer missing-file warning.

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

Chloepeg added 2 commits June 2, 2026 12:47
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.
@github-actions github-actions Bot changed the title Dyn 10516 refresh templates and recent files from disk dynamically DYN-: Dyn 10516 refresh templates and recent files from disk dynamically Jun 16, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

See the ticket for this pull request: https://jira.autodesk.com/browse/DYN-10516

…-Templates-and-Recent-Files-from-disk-dynamically
@Chloepeg Chloepeg marked this pull request as ready for review June 17, 2026 14:48
@jasonstratton jasonstratton requested a review from Copilot June 17, 2026 18:28

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 RecentFiles and TemplateFiles when ShowStartPage becomes true, 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

Comment on lines +127 to 142
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}')");
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is a valid concern that should be addressed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

Comment on lines +705 to +709
RemoveMissingFilePath(RecentFiles, path);
RemoveMissingFilePath(TemplateFiles, path);

return true;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please add a test for this scenario.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

Comment on lines +283 to +287
internal void RefreshTemplateFiles()
{
TemplateFiles.Clear();
LoadTemplates();
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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

Comment on lines +691 to +709
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;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think this can be testable without using WebView

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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 jasonstratton left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

_ = 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

@Chloepeg Chloepeg Jun 22, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

@johnpierson johnpierson changed the title DYN-: Dyn 10516 refresh templates and recent files from disk dynamically DYN-10516 refresh templates and recent files from disk dynamically Jun 17, 2026
Chloepeg and others added 3 commits June 22, 2026 12:43
- 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

@jasonstratton jasonstratton left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you for the updated. Approving and merging

@jasonstratton jasonstratton merged commit b535587 into DynamoDS:master Jun 23, 2026
28 of 30 checks passed
@sonarqubecloud

Copy link
Copy Markdown

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.

4 participants