mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-07 19:57:07 +02:00
Settings backup and restore (#20551)
* Merge and conflict resolution * Messages good, backup/restore algo better. * Start of "GetExportVerion" * fixed spelling * New backup/restore mode working. * Rename a project * Removed test project * Switch to text.json * Renamed BackupAndSync to BackupAndRestore * Added IgnoredPTRunSettings and full merge * Restored "fixed" settings that change for no reason * Various UI updates. * speling * Some cleanup and zip support. * Merge and clean * code clean up * code clean up * code clean up * Smarter settings compare and merge. * config based file include/exclude * Removed some "words" * Code clean up * cleanup * cleanup * cleanup * cleanup * fixed spelling. * Fixed clean up 1 * more clean up * Trying to add ptb as an OK word * Some UI updates. * UI tweaks and PR review items. * UI tweaks * Merge conflicts resolved. * Added CurrentSettingMatchText * PR review updates. * Removed weird file. * Review updates and fixes * More UI tweaks. * UI tweaks * Set default backup location to "%USERPROFILE%\\Documents\\PowerToys\\Backup" * settings ui tweaks * Added ExpanderContentSettingStyle * fix missing config file * fix missing config file, part 2 * update ui, cleanup cope * update ui, cleanup code - Part2 * update method comments * code cleanup and adjust Backup message time * fix changing backup location on empty Regsitry * fix select location - part 2 * location input box min-width * remove lastRestoreDate from ViewModel * Code or backup timing, and error handling. * Should fix file/folder name crash. * Progress to instance class for backup/restore * Persist backup status state, added refresh button. * Better auto check for settings status * Some UI/text updates. * Clean up * Added prefix for "General_Settings" to resources * Code review updates. * Code review changes. * Changed to FolderPicker per review * Fixed issue with early delete of cleanup. * Testing issues with FolderPicker * Removed WinForm req and fixed win10 issue. * Review update. * Review changes. Co-authored-by: htcfreek <61519853+htcfreek@users.noreply.github.com>
This commit is contained in:
@@ -3,12 +3,17 @@
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.PowerToys.Settings.UI.Library;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Utilities;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.ViewModels;
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
using Windows.ApplicationModel.Resources;
|
||||
using Windows.Storage;
|
||||
using Windows.Storage.Pickers;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Views
|
||||
{
|
||||
@@ -17,6 +22,8 @@ namespace Microsoft.PowerToys.Settings.UI.Views
|
||||
/// </summary>
|
||||
public sealed partial class GeneralPage : Page
|
||||
{
|
||||
private static DateTime OkToHideBackupAndRestoreMessageTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets view model.
|
||||
/// </summary>
|
||||
@@ -42,6 +49,25 @@ namespace Microsoft.PowerToys.Settings.UI.Views
|
||||
});
|
||||
};
|
||||
|
||||
Action hideBackupAndRestoreMessageArea = () =>
|
||||
{
|
||||
this.DispatcherQueue.TryEnqueue(async () =>
|
||||
{
|
||||
const int messageShowTimeIs = 10000;
|
||||
|
||||
// in order to keep the message for about 5 seconds after the last call
|
||||
// and not need any lock/thread-synch, use an OK-To-Hide time, and wait just a little longer than that.
|
||||
OkToHideBackupAndRestoreMessageTime = DateTime.UtcNow.AddMilliseconds(messageShowTimeIs - 16);
|
||||
await System.Threading.Tasks.Task.Delay(messageShowTimeIs);
|
||||
if (DateTime.UtcNow > OkToHideBackupAndRestoreMessageTime)
|
||||
{
|
||||
ViewModel.HideBackupAndRestoreMessageArea();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
var doRefreshBackupRestoreStatus = new Action<int>(RefreshBackupRestoreStatus);
|
||||
|
||||
ViewModel = new GeneralViewModel(
|
||||
SettingsRepository<GeneralSettings>.GetInstance(settingsUtils),
|
||||
loader.GetString("GeneralSettings_RunningAsAdminText"),
|
||||
@@ -53,9 +79,15 @@ namespace Microsoft.PowerToys.Settings.UI.Views
|
||||
ShellPage.SendRestartAdminIPCMessage,
|
||||
ShellPage.SendCheckForUpdatesIPCMessage,
|
||||
string.Empty,
|
||||
stateUpdatingAction);
|
||||
stateUpdatingAction,
|
||||
hideBackupAndRestoreMessageArea,
|
||||
doRefreshBackupRestoreStatus,
|
||||
PickSingleFolderDialog,
|
||||
loader);
|
||||
|
||||
DataContext = ViewModel;
|
||||
|
||||
doRefreshBackupRestoreStatus(100);
|
||||
}
|
||||
|
||||
public static int UpdateUIThemeMethod(string themeName)
|
||||
@@ -84,5 +116,38 @@ namespace Microsoft.PowerToys.Settings.UI.Views
|
||||
{
|
||||
Helpers.StartProcessHelper.Start(Helpers.StartProcessHelper.ColorsSettings);
|
||||
}
|
||||
|
||||
private void RefreshBackupRestoreStatus(int delayMs = 0)
|
||||
{
|
||||
Task.Run(() =>
|
||||
{
|
||||
if (delayMs > 0)
|
||||
{
|
||||
Thread.Sleep(delayMs);
|
||||
}
|
||||
|
||||
var settingsBackupAndRestoreUtils = SettingsBackupAndRestoreUtils.Instance;
|
||||
var results = settingsBackupAndRestoreUtils.DryRunBackup();
|
||||
this.DispatcherQueue.TryEnqueue(() =>
|
||||
{
|
||||
ViewModel.NotifyAllBackupAndRestoreProperties();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
private void UpdateBackupAndRestoreStatusText(Microsoft.UI.Xaml.Documents.Hyperlink sender, Microsoft.UI.Xaml.Documents.HyperlinkClickEventArgs args)
|
||||
{
|
||||
RefreshBackupRestoreStatus();
|
||||
}
|
||||
|
||||
private async Task<string> PickSingleFolderDialog()
|
||||
{
|
||||
var openPicker = new FolderPicker();
|
||||
var hwnd = WinRT.Interop.WindowNative.GetWindowHandle(App.GetSettingsWindow());
|
||||
WinRT.Interop.InitializeWithWindow.Initialize(openPicker, hwnd);
|
||||
openPicker.FileTypeFilter.Add("*");
|
||||
var folder = await openPicker.PickSingleFolderAsync();
|
||||
return folder?.Path;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user