-
Notifications
You must be signed in to change notification settings - Fork 675
DYN-10516 refresh templates and recent files from disk dynamically #17161
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
e301645
c26666e
8f7dd6d
dd0a232
3cec116
a36667b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -124,11 +124,28 @@ private void OnDataContextChanged(object sender, DependencyPropertyChangedEventA | |
| } | ||
| } | ||
|
|
||
| private void DynamoViewModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) | ||
| 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}')"); | ||
| try | ||
| { | ||
| if (startPage.DynamoViewModel.ShowStartPage) | ||
| { | ||
| await startPage.RefreshTemplateFilesAsync(); | ||
| startPage.RefreshRecentFiles(); | ||
|
|
||
| await SendTemplateData(); | ||
| await SendRecentGraphsData(); | ||
| } | ||
|
|
||
| await dynWebView.CoreWebView2.ExecuteScriptAsync(@$"window.setShowStartPageChanged('{startPage.DynamoViewModel.ShowStartPage}')"); | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| startPage?.DynamoViewModel?.Model?.Logger?.Log("Failed to update Dynamo Home visibility state."); | ||
| startPage?.DynamoViewModel?.Model?.Logger?.Log(ex); | ||
| } | ||
| } | ||
| } | ||
|
Comment on lines
+127
to
150
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a valid concern that should be addressed.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
|
|
||
|
|
@@ -338,11 +355,8 @@ private async Task SendSamplesData() | |
| /// </summary> | ||
| private async Task SendTemplateData() | ||
| { | ||
| var items = startPage.TemplateFiles?.DistinctBy(x => x.ContextData).ToList(); | ||
| if (items != null && items.Any()) | ||
| { | ||
| await LoadTemplates(items); | ||
| } | ||
| var items = startPage.TemplateFiles?.DistinctBy(x => x.ContextData).ToList() ?? new List<StartPageListItem>(); | ||
| await LoadTemplates(items); | ||
| } | ||
|
|
||
| private async Task SendRecentGraphsData() | ||
|
|
@@ -361,14 +375,12 @@ private async Task SendRecentGraphsData() | |
| } | ||
|
|
||
| // Load recent files | ||
| var recentFiles = startPage.RecentFiles?.DistinctBy(x => x.ContextData).ToList(); | ||
| if (recentFiles != null && recentFiles.Any()) | ||
| { | ||
| await LoadGraphs(recentFiles); | ||
| } | ||
| var recentFiles = startPage.RecentFiles?.DistinctBy(x => x.ContextData).ToList() ?? new List<StartPageListItem>(); | ||
| await LoadGraphs(recentFiles); | ||
|
|
||
| if (startPage.DynamoViewModel != null && startPage.DynamoViewModel.RecentFiles != null) | ||
| { | ||
| startPage.DynamoViewModel.RecentFiles.CollectionChanged -= RecentFiles_CollectionChanged; | ||
| startPage.DynamoViewModel.RecentFiles.CollectionChanged += RecentFiles_CollectionChanged; | ||
| } | ||
| } | ||
|
|
@@ -534,6 +546,11 @@ private void ShowPackagesGuidedTour() | |
|
|
||
| #region Relay Commands | ||
| internal void OpenFile(string path) | ||
| { | ||
| _ = OpenFileAsync(path); | ||
| } | ||
|
|
||
| private async Task OpenFileAsync(string path) | ||
| { | ||
| if (String.IsNullOrEmpty(path)) return; | ||
| if (DynamoModel.IsTestMode) | ||
|
|
@@ -542,13 +559,31 @@ internal void OpenFile(string path) | |
| return; | ||
| } | ||
|
|
||
| var dvm = this.startPage.DynamoViewModel; | ||
| var openArg = IsListedHomePageTemplate(path) | ||
| ? (object)Tuple.Create(path, false, true) | ||
| : path; | ||
| if (dvm.OpenCommand.CanExecute(openArg)) | ||
| try | ||
| { | ||
| if (startPage.HandleMissingFilePath(path)) | ||
| { | ||
| var recentFiles = startPage.RecentFiles?.DistinctBy(x => x.ContextData).ToList() ?? new List<StartPageListItem>(); | ||
| var templateFiles = startPage.TemplateFiles?.DistinctBy(x => x.ContextData).ToList() ?? new List<StartPageListItem>(); | ||
|
|
||
| await LoadGraphs(recentFiles); | ||
| await LoadTemplates(templateFiles); | ||
| return; | ||
| } | ||
|
|
||
| var dvm = this.startPage.DynamoViewModel; | ||
| var openArg = IsListedHomePageTemplate(path) | ||
| ? (object)Tuple.Create(path, false, true) | ||
| : path; | ||
| if (dvm.OpenCommand.CanExecute(openArg)) | ||
| { | ||
| dvm.OpenCommand.Execute(openArg); | ||
| } | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| dvm.OpenCommand.Execute(openArg); | ||
| startPage?.DynamoViewModel?.Model?.Logger?.Log("Failed to open file from Dynamo Home."); | ||
| startPage?.DynamoViewModel?.Model?.Logger?.Log(ex); | ||
| } | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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