Skip to content
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

Feature: Auto restore tabs if the app crashes #12005

Merged
merged 11 commits into from
Apr 16, 2023
29 changes: 26 additions & 3 deletions src/Files.App/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
using Windows.ApplicationModel;
using Windows.ApplicationModel.DataTransfer;
using Windows.Storage;
using Windows.System;
using Windows.UI.Notifications;

namespace Files.App
Expand Down Expand Up @@ -445,19 +446,41 @@ private static void AppUnhandledException(Exception ex, bool shouldShowNotificat
{
Buttons =
{
new ToastButton("ExceptionNotificationReportButton".GetLocalizedResource(), "report")
new ToastButton("ExceptionNotificationReportButton".GetLocalizedResource(), Constants.GitHub.BugReportUrl)
{
ActivationType = ToastActivationType.Foreground
ActivationType = ToastActivationType.Protocol
}
}
}
},
ActivationType = ToastActivationType.Protocol
};

// Create the toast notification
var toastNotif = new ToastNotification(toastContent.GetXml());

// And send the notification
ToastNotificationManager.CreateToastNotifier().Show(toastNotif);

// Restart the app
var userSettingsService = Ioc.Default.GetRequiredService<IUserSettingsService>();
QuaintMako marked this conversation as resolved.
Show resolved Hide resolved
var lastSessionTabList = userSettingsService.GeneralSettingsService.LastSessionTabList;

if (userSettingsService.GeneralSettingsService.LastCrashedTabList?.SequenceEqual(lastSessionTabList) ?? false)
{
// Avoid infinite restart loop
hishitetsu marked this conversation as resolved.
Show resolved Hide resolved
userSettingsService.GeneralSettingsService.LastSessionTabList = null;
}
else
{
userSettingsService.AppSettingsService.RestoreTabsOnStartup = true;
userSettingsService.GeneralSettingsService.LastCrashedTabList = lastSessionTabList;
}

Window.DispatcherQueue.EnqueueAsync(async () =>
{
await Launcher.LaunchUriAsync(new Uri("files-uwp:"));
}).Wait(1000);
Process.GetCurrentProcess().Kill();
}

public static void CloseApp()
Expand Down
10 changes: 0 additions & 10 deletions src/Files.App/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,16 +139,6 @@ public async Task InitializeApplication(object activatedEventArgs)
}
break;

case IToastNotificationActivatedEventArgs eventArgsForNotification:
if (eventArgsForNotification.Argument == "report")
{
await Windows.System.Launcher.LaunchUriAsync(new Uri(Constants.GitHub.BugReportUrl));
}
break;

case IStartupTaskActivatedEventArgs:
break;

case IFileActivatedEventArgs fileArgs:
var index = 0;
if (rootFrame.Content is null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ public List<string> LastSessionTabList
set => Set(value);
}

public List<string> LastCrashedTabList
{
get => Get<List<string>>(null);
set => Set(value);
}

public DateTimeFormats DateTimeFormat
{
get => Get(DateTimeFormats.Application);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public override object ExportSettings()

// Remove session settings
export.Remove(nameof(GeneralSettingsService.LastSessionTabList));
export.Remove(nameof(GeneralSettingsService.LastCrashedTabList));

return JsonSettingsSerializer.SerializeToJson(export);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ public interface IGeneralSettingsService : IBaseSettingsService, INotifyProperty
/// </summary>
List<string> LastSessionTabList { get; set; }

/// <summary>
/// A list containing paths of the tabs from the previous session that crashed.
/// </summary>
List<string> LastCrashedTabList { get; set; }

/// <summary>
/// Gets or sets a value indicating which date and time format to use.
/// </summary>
Expand Down