Skip to content

Commit 4ef6aeb

Browse files
jaigakyaira2tsvietOK
authored
Added a push notification asking for feedback when the app crashes (#1666)
Co-authored-by: Yair Aichenbaum <[email protected]> Co-authored-by: Vladyslav Tsvietkov <[email protected]>
1 parent 6ab9c30 commit 4ef6aeb

26 files changed

+503
-28
lines changed

.github/ISSUE_TEMPLATE/bug_report.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,6 @@ If applicable, add screenshots to help explain your problem.
4242

4343
**Additional context**
4444
Add any other context about the problem here. Does this problem occur again after restarting the app?
45+
46+
**Log file**
47+
Please post the log file here so that we can understand your problem better. You can access it from Settings->About->Open log location.

.github/ISSUE_TEMPLATE/critical-high-priority-bug-report.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,6 @@ If applicable, add screenshots to help explain your problem.
4343

4444
**Additional context**
4545
Add any other context about the problem here. For instance, are you building from source or using a precompiled build/snapshot?
46+
47+
**Log file**
48+
Please post the log file here so that we can understand your problem better. You can access it from Settings->About->Open log location.

Files.Package/Package.appxmanifest

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,4 @@
6666
<uap:Capability Name="removableStorage" />
6767
<Capability Name="internetClient"/>
6868
</Capabilities>
69-
</Package>
69+
</Package>

Files/App.xaml.cs

Lines changed: 57 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,19 @@
2828
using Windows.UI.Xaml.Controls;
2929
using Windows.UI.Xaml.Media.Animation;
3030
using Windows.UI.Xaml.Navigation;
31+
using System.Threading.Tasks;
32+
using Microsoft.Toolkit.Uwp.Notifications;
33+
using Windows.UI.Notifications;
34+
using System.Linq;
35+
using Newtonsoft.Json;
36+
using Files.Common;
3137

3238
namespace Files
3339
{
3440
sealed partial class App : Application
3541
{
3642
private static IShellPage currentInstance;
43+
private static bool ShowErrorNotification = false;
3744

3845
public static IShellPage CurrentInstance
3946
{
@@ -49,7 +56,6 @@ public static IShellPage CurrentInstance
4956
}
5057
}
5158
}
52-
5359
public static SettingsViewModel AppSettings { get; set; }
5460
public static InteractionViewModel InteractionViewModel { get; set; }
5561
public static JumpListManager JumpList { get; } = new JumpListManager();
@@ -243,6 +249,7 @@ private void CoreWindow_Activated(CoreWindow sender, WindowActivatedEventArgs ar
243249
if (args.WindowActivationState == CoreWindowActivationState.CodeActivated ||
244250
args.WindowActivationState == CoreWindowActivationState.PointerActivated)
245251
{
252+
ShowErrorNotification = true;
246253
ApplicationData.Current.LocalSettings.Values["INSTANCE_ACTIVE"] = Process.GetCurrentProcess().Id;
247254
}
248255
}
@@ -412,16 +419,58 @@ private void SaveSessionTabs() // Enumerates through all tabs and gets the Path
412419
}
413420

414421
// Occurs when an exception is not handled on the UI thread.
415-
private static void OnUnhandledException(object sender, Windows.UI.Xaml.UnhandledExceptionEventArgs e)
416-
{
417-
Logger.Error(e.Exception, e.Message);
418-
}
422+
private static void OnUnhandledException(object sender, Windows.UI.Xaml.UnhandledExceptionEventArgs e) => AppUnhandledException(e.Exception);
419423

420424
// Occurs when an exception is not handled on a background thread.
421425
// ie. A task is fired and forgotten Task.Run(() => {...})
422-
private static void OnUnobservedException(object sender, UnobservedTaskExceptionEventArgs e)
426+
private static void OnUnobservedException(object sender, UnobservedTaskExceptionEventArgs e) => AppUnhandledException(e.Exception);
427+
428+
private static void AppUnhandledException(Exception ex)
423429
{
424-
Logger.Error(e.Exception, e.Exception.Message);
430+
Logger.Error(ex, ex.Message);
431+
if (ShowErrorNotification)
432+
{
433+
var toastContent = new ToastContent()
434+
{
435+
Visual = new ToastVisual()
436+
{
437+
BindingGeneric = new ToastBindingGeneric()
438+
{
439+
Children =
440+
{
441+
new AdaptiveText()
442+
{
443+
Text = ResourceController.GetTranslation("ExceptionNotificationHeader")
444+
},
445+
new AdaptiveText()
446+
{
447+
Text = ResourceController.GetTranslation("ExceptionNotificationBody")
448+
}
449+
},
450+
AppLogoOverride = new ToastGenericAppLogo()
451+
{
452+
Source = "ms-appx:///Assets/error.png"
453+
}
454+
}
455+
},
456+
Actions = new ToastActionsCustom()
457+
{
458+
Buttons =
459+
{
460+
new ToastButton(ResourceController.GetTranslation("ExceptionNotificationReportButton"), "report")
461+
{
462+
ActivationType = ToastActivationType.Foreground
463+
}
464+
}
465+
}
466+
};
467+
468+
// Create the toast notification
469+
var toastNotif = new ToastNotification(toastContent.GetXml());
470+
471+
// And send the notification
472+
ToastNotificationManager.CreateToastNotifier().Show(toastNotif);
473+
}
425474
}
426475

427476
public static async void CloseApp()
@@ -438,4 +487,4 @@ public class WSLDistroItem : INavigationControlItem
438487
public NavigationControlItemType ItemType => NavigationControlItemType.LinuxDistro;
439488
public Uri Logo { get; set; }
440489
}
441-
}
490+
}

Files/Assets/error.png

9.35 KB
Loading

Files/Files.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,7 @@
320320
</Compile>
321321
</ItemGroup>
322322
<ItemGroup>
323+
<Content Include="Assets\error.png" />
323324
<Content Include="Assets\Files UWP Beta Icon.png" />
324325
<Content Include="Assets\Files UWP Icon.png" />
325326
<Content Include="Assets\FilesHome.png" />
@@ -600,6 +601,9 @@
600601
<PackageReference Include="Microsoft.Toolkit.Uwp.DeveloperTools">
601602
<Version>6.1.1</Version>
602603
</PackageReference>
604+
<PackageReference Include="Microsoft.Toolkit.Uwp.Notifications">
605+
<Version>6.1.1</Version>
606+
</PackageReference>
603607
<PackageReference Include="Microsoft.Toolkit.Uwp.UI">
604608
<Version>6.1.1</Version>
605609
</PackageReference>

Files/Filesystem/DriveItem.cs

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,20 +49,27 @@ public DriveItem(StorageFolder root, DriveType type)
4949
return await root.Properties.RetrievePropertiesAsync(new[] { "System.FreeSpace", "System.Capacity" });
5050
}).Result;
5151

52-
try
52+
if (properties.ContainsKey("System.Capacity") && properties.ContainsKey("System.FreeSpace"))
5353
{
54-
MaxSpace = ByteSize.FromBytes((ulong)properties["System.Capacity"]);
55-
FreeSpace = ByteSize.FromBytes((ulong)properties["System.FreeSpace"]);
56-
57-
SpaceUsed = MaxSpace - FreeSpace;
58-
SpaceText = string.Format(
59-
ResourceController.GetTranslation("DriveFreeSpaceAndCapacity"),
60-
FreeSpace.ToBinaryString().ConvertSizeAbbreviation(),
61-
MaxSpace.ToBinaryString().ConvertSizeAbbreviation());
54+
try
55+
{
56+
MaxSpace = ByteSize.FromBytes((ulong)properties["System.Capacity"]);
57+
FreeSpace = ByteSize.FromBytes((ulong)properties["System.FreeSpace"]);
58+
59+
SpaceUsed = MaxSpace - FreeSpace;
60+
SpaceText = string.Format(
61+
ResourceController.GetTranslation("DriveFreeSpaceAndCapacity"),
62+
FreeSpace.ToBinaryString().ConvertSizeAbbreviation(),
63+
MaxSpace.ToBinaryString().ConvertSizeAbbreviation());
64+
}
65+
catch (NullReferenceException)
66+
{
67+
SpaceText = ResourceController.GetTranslation("DriveCapacityUnknown");
68+
}
6269
}
63-
catch (NullReferenceException)
70+
else
6471
{
65-
SpaceText = "Unknown";
72+
SpaceText = ResourceController.GetTranslation("DriveCapacityUnknown");
6673
}
6774
}
6875

Files/MultilingualResources/Files.de-DE.xlf

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1111,6 +1111,26 @@
11111111
<source>Show a horizontal tab strip on the title bar</source>
11121112
<target state="new">Show a horizontal tab strip on the title bar</target>
11131113
</trans-unit>
1114+
<trans-unit id="DriveCapacityUnknown" translate="yes" xml:space="preserve">
1115+
<source>Unknown</source>
1116+
<target state="new">Unknown</target>
1117+
</trans-unit>
1118+
<trans-unit id="ExceptionNotificationAccessLogFileButton" translate="yes" xml:space="preserve">
1119+
<source>Open log location</source>
1120+
<target state="new">Open log location</target>
1121+
</trans-unit>
1122+
<trans-unit id="ExceptionNotificationBody" translate="yes" xml:space="preserve">
1123+
<source>Files ran into a problem that the developers didn't prepare for yet.</source>
1124+
<target state="new">Files ran into a problem that the developers didn't prepare for yet.</target>
1125+
</trans-unit>
1126+
<trans-unit id="ExceptionNotificationHeader" translate="yes" xml:space="preserve">
1127+
<source>Something went wrong!</source>
1128+
<target state="new">Something went wrong!</target>
1129+
</trans-unit>
1130+
<trans-unit id="ExceptionNotificationReportButton" translate="yes" xml:space="preserve">
1131+
<source>Report this issue</source>
1132+
<target state="new">Report this issue</target>
1133+
</trans-unit>
11141134
<trans-unit id="SettingsAboutContributors.Text" translate="yes" xml:space="preserve">
11151135
<source>Contributors</source>
11161136
<target state="new">Contributors</target>
@@ -1139,6 +1159,10 @@
11391159
<source>Invalid item</source>
11401160
<target state="new">Invalid item</target>
11411161
</trans-unit>
1162+
<trans-unit id="SettingsAboutVersionTitle" translate="yes" xml:space="preserve">
1163+
<source>Version:</source>
1164+
<target state="new">Version:</target>
1165+
</trans-unit>
11421166
<trans-unit id="ShareDialogFailMessage" translate="yes" xml:space="preserve">
11431167
<source>There's nothing to share right now</source>
11441168
<target state="new">There's nothing to share right now</target>

Files/MultilingualResources/Files.es-ES.xlf

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1126,6 +1126,30 @@
11261126
<source>Invalid item</source>
11271127
<target state="new">Invalid item</target>
11281128
</trans-unit>
1129+
<trans-unit id="DriveCapacityUnknown" translate="yes" xml:space="preserve">
1130+
<source>Unknown</source>
1131+
<target state="new">Unknown</target>
1132+
</trans-unit>
1133+
<trans-unit id="ExceptionNotificationAccessLogFileButton" translate="yes" xml:space="preserve">
1134+
<source>Open log location</source>
1135+
<target state="new">Open log location</target>
1136+
</trans-unit>
1137+
<trans-unit id="ExceptionNotificationBody" translate="yes" xml:space="preserve">
1138+
<source>Files ran into a problem that the developers didn't prepare for yet.</source>
1139+
<target state="new">Files ran into a problem that the developers didn't prepare for yet.</target>
1140+
</trans-unit>
1141+
<trans-unit id="ExceptionNotificationHeader" translate="yes" xml:space="preserve">
1142+
<source>Something went wrong!</source>
1143+
<target state="new">Something went wrong!</target>
1144+
</trans-unit>
1145+
<trans-unit id="ExceptionNotificationReportButton" translate="yes" xml:space="preserve">
1146+
<source>Report this issue</source>
1147+
<target state="new">Report this issue</target>
1148+
</trans-unit>
1149+
<trans-unit id="SettingsAboutVersionTitle" translate="yes" xml:space="preserve">
1150+
<source>Version:</source>
1151+
<target state="new">Version:</target>
1152+
</trans-unit>
11291153
<trans-unit id="ShareDialogFailMessage" translate="yes" xml:space="preserve">
11301154
<source>There's nothing to share right now</source>
11311155
<target state="new">There's nothing to share right now</target>

Files/MultilingualResources/Files.fr-FR.xlf

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,6 +1104,26 @@
11041104
<source>Show a horizontal tab strip on the title bar</source>
11051105
<target state="new">Show a horizontal tab strip on the title bar</target>
11061106
</trans-unit>
1107+
<trans-unit id="DriveCapacityUnknown" translate="yes" xml:space="preserve">
1108+
<source>Unknown</source>
1109+
<target state="new">Unknown</target>
1110+
</trans-unit>
1111+
<trans-unit id="ExceptionNotificationAccessLogFileButton" translate="yes" xml:space="preserve">
1112+
<source>Open log location</source>
1113+
<target state="new">Open log location</target>
1114+
</trans-unit>
1115+
<trans-unit id="ExceptionNotificationBody" translate="yes" xml:space="preserve">
1116+
<source>Files ran into a problem that the developers didn't prepare for yet.</source>
1117+
<target state="new">Files ran into a problem that the developers didn't prepare for yet.</target>
1118+
</trans-unit>
1119+
<trans-unit id="ExceptionNotificationHeader" translate="yes" xml:space="preserve">
1120+
<source>Something went wrong!</source>
1121+
<target state="new">Something went wrong!</target>
1122+
</trans-unit>
1123+
<trans-unit id="ExceptionNotificationReportButton" translate="yes" xml:space="preserve">
1124+
<source>Report this issue</source>
1125+
<target state="new">Report this issue</target>
1126+
</trans-unit>
11071127
<trans-unit id="SettingsAboutContributors.Text" translate="yes" xml:space="preserve">
11081128
<source>Contributors</source>
11091129
<target state="new">Contributors</target>
@@ -1132,6 +1152,10 @@
11321152
<source>Invalid item</source>
11331153
<target state="new">Invalid item</target>
11341154
</trans-unit>
1155+
<trans-unit id="SettingsAboutVersionTitle" translate="yes" xml:space="preserve">
1156+
<source>Version:</source>
1157+
<target state="new">Version:</target>
1158+
</trans-unit>
11351159
<trans-unit id="ShareDialogFailMessage" translate="yes" xml:space="preserve">
11361160
<source>There's nothing to share right now</source>
11371161
<target state="new">There's nothing to share right now</target>

0 commit comments

Comments
 (0)