From 1f64109472765e68c7e70f30dca01b22b82d8a23 Mon Sep 17 00:00:00 2001
From: Kristen Schau <47155823+krschau@users.noreply.github.com>
Date: Tue, 23 Apr 2024 11:50:53 -0400
Subject: [PATCH] Cancelling file picker shouldn't send info
---
common/Renderers/FilePickerAction.cs | 7 ++++++-
.../DevHome.Dashboard/ViewModels/WidgetViewModel.cs | 7 ++++++-
2 files changed, 12 insertions(+), 2 deletions(-)
diff --git a/common/Renderers/FilePickerAction.cs b/common/Renderers/FilePickerAction.cs
index e42103d407..da0f99be2e 100644
--- a/common/Renderers/FilePickerAction.cs
+++ b/common/Renderers/FilePickerAction.cs
@@ -71,7 +71,9 @@ public JsonObject ToJson()
return json;
}
- public void LaunchFilePicker()
+ /// Launches the file picker dialog to select a file.
+ /// true if a file was selected, false otherwise.
+ public bool LaunchFilePicker()
{
var filePicker = new FileOpenPicker();
filePicker.FileTypeFilter.Add("*");
@@ -87,7 +89,10 @@ public void LaunchFilePicker()
if (file != null)
{
FilePath = file.Path;
+ return true;
}
+
+ return false;
}
}
diff --git a/tools/Dashboard/DevHome.Dashboard/ViewModels/WidgetViewModel.cs b/tools/Dashboard/DevHome.Dashboard/ViewModels/WidgetViewModel.cs
index 09ea68c43c..ba13f2604c 100644
--- a/tools/Dashboard/DevHome.Dashboard/ViewModels/WidgetViewModel.cs
+++ b/tools/Dashboard/DevHome.Dashboard/ViewModels/WidgetViewModel.cs
@@ -325,7 +325,12 @@ private async void HandleAdaptiveAction(RenderedAdaptiveCard sender, AdaptiveAct
else if (args.Action is FilePickerAction filePickerAction)
{
var dataToSend = string.Empty;
- filePickerAction.LaunchFilePicker();
+ if (!filePickerAction.LaunchFilePicker())
+ {
+ // Don't send data if the user canceled the file picker.
+ return;
+ }
+
var dataType = filePickerAction.ToJson().ValueType;
if (dataType != Windows.Data.Json.JsonValueType.Null)
{