From 4bea53a6676fd29711c215d3d525f4d4d2d1d4fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Burak=20Kaan=20K=C3=B6se?= Date: Tue, 14 Apr 2026 00:59:30 +0200 Subject: [PATCH] Add custom theme deletion flow --- .../Interfaces/INewThemeService.cs | 1 + .../Translations/en_US/resources.json | 4 ++ .../PersonalizationPageViewModel.cs | 38 +++++++++++ Wino.Mail.WinUI/Services/NewThemeService.cs | 35 ++++++++++ .../Views/Settings/PersonalizationPage.xaml | 64 ++++++++++++++++++- 5 files changed, 141 insertions(+), 1 deletion(-) diff --git a/Wino.Core.Domain/Interfaces/INewThemeService.cs b/Wino.Core.Domain/Interfaces/INewThemeService.cs index 037b4bee..b3d596bc 100644 --- a/Wino.Core.Domain/Interfaces/INewThemeService.cs +++ b/Wino.Core.Domain/Interfaces/INewThemeService.cs @@ -15,6 +15,7 @@ public interface INewThemeService : IInitializeAsync Task> GetAvailableThemesAsync(); Task CreateNewCustomThemeAsync(string themeName, string accentColor, byte[] wallpaperData); Task> GetCurrentCustomThemesAsync(); + Task DeleteCustomThemeAsync(Guid themeId); List GetAvailableAccountColors(); Task ApplyCustomThemeAsync(bool isInitializing); diff --git a/Wino.Core.Domain/Translations/en_US/resources.json b/Wino.Core.Domain/Translations/en_US/resources.json index 6b62a911..5f97615f 100644 --- a/Wino.Core.Domain/Translations/en_US/resources.json +++ b/Wino.Core.Domain/Translations/en_US/resources.json @@ -807,6 +807,10 @@ "SettingsConfigureSpecialFolders_Description": "Set folders with special functions. Folders such as Archive, Inbox, and Drafts are essential for Wino to function properly.", "SettingsConfigureSpecialFolders_Title": "Configure System Folders", "SettingsCustomTheme_Description": "Create your own custom theme with custom wallpaper and accent color.", + "SettingsCustomTheme_DeleteConfirm_Message": "Delete custom theme \"{0}\"? Its saved wallpaper will also be removed from disk.", + "SettingsCustomTheme_DeleteConfirm_Title": "Delete Theme", + "SettingsCustomTheme_DeleteMissing": "This custom theme no longer exists.", + "SettingsCustomTheme_DeleteSuccess": "Custom theme \"{0}\" was deleted.", "SettingsCustomTheme_Title": "Custom Theme", "SettingsDeleteAccount_Description": "Delete all e-mails and credentials associated with this account.", "SettingsDeleteAccount_Title": "Delete this account", diff --git a/Wino.Core.ViewModels/PersonalizationPageViewModel.cs b/Wino.Core.ViewModels/PersonalizationPageViewModel.cs index 7e2e805e..bde4b56a 100644 --- a/Wino.Core.ViewModels/PersonalizationPageViewModel.cs +++ b/Wino.Core.ViewModels/PersonalizationPageViewModel.cs @@ -174,8 +174,46 @@ public partial class PersonalizationPageViewModel : CoreBaseViewModel } } + [RelayCommand] + private async Task DeleteCustomThemeAsync(AppThemeBase theme) + { + if (theme == null || theme.AppThemeType != AppThemeType.Custom) + { + return; + } + + var shouldDelete = await _dialogService.ShowConfirmationDialogAsync( + string.Format(Translator.SettingsCustomTheme_DeleteConfirm_Message, theme.ThemeName), + Translator.SettingsCustomTheme_DeleteConfirm_Title, + Translator.Buttons_Delete); + + if (!shouldDelete) + { + return; + } + + var isDeleted = await _newThemeService.DeleteCustomThemeAsync(theme.Id); + + if (!isDeleted) + { + _dialogService.InfoBarMessage( + Translator.GeneralTitle_Warning, + Translator.SettingsCustomTheme_DeleteMissing, + InfoBarMessageType.Warning); + return; + } + + await InitializeSettingsAsync(); + + _dialogService.InfoBarMessage( + Translator.GeneralTitle_Info, + string.Format(Translator.SettingsCustomTheme_DeleteSuccess, theme.ThemeName), + InfoBarMessageType.Success); + } + private void InitializeColors() { + Colors.Clear(); Colors.Add(new AppColorViewModel("#0078d7")); Colors.Add(new AppColorViewModel("#00838c")); Colors.Add(new AppColorViewModel("#e3008c")); diff --git a/Wino.Mail.WinUI/Services/NewThemeService.cs b/Wino.Mail.WinUI/Services/NewThemeService.cs index 589dd30a..41766936 100644 --- a/Wino.Mail.WinUI/Services/NewThemeService.cs +++ b/Wino.Mail.WinUI/Services/NewThemeService.cs @@ -587,6 +587,31 @@ public class NewThemeService : INewThemeService return results; } + public async Task DeleteCustomThemeAsync(Guid themeId) + { + var themeFolder = await ApplicationData.Current.LocalFolder.CreateFolderAsync(CustomThemeFolderName, CreationCollisionOption.OpenIfExists); + var metadataFileName = $"{themeId}.json"; + var themeItem = await themeFolder.TryGetItemAsync(metadataFileName); + + if (themeItem == null) + { + return false; + } + + if (currentApplicationThemeId == themeId) + { + currentApplicationThemeId = preDefinedThemes[0].Id; + _configurationService.Set(CurrentApplicationThemeKey, currentApplicationThemeId); + await ApplyCustomThemeAsync(false); + } + + await DeleteThemeAssetIfExistsAsync(themeFolder, metadataFileName); + await DeleteThemeAssetIfExistsAsync(themeFolder, $"{themeId}.jpg"); + await DeleteThemeAssetIfExistsAsync(themeFolder, $"{themeId}_preview.jpg"); + + return true; + } + private async Task GetCustomMetadataAsync(IStorageFile file) { var fileContent = await FileIO.ReadTextAsync(file); @@ -594,6 +619,16 @@ public class NewThemeService : INewThemeService return JsonSerializer.Deserialize(fileContent, DomainModelsJsonContext.Default.CustomThemeMetadata); } + private static async Task DeleteThemeAssetIfExistsAsync(StorageFolder themeFolder, string fileName) + { + var item = await themeFolder.TryGetItemAsync(fileName); + + if (item != null) + { + await item.DeleteAsync(); + } + } + public string GetSystemAccentColorHex() => uiSettings.GetColorValue(UIColorType.Accent).ToHex(); diff --git a/Wino.Mail.WinUI/Views/Settings/PersonalizationPage.xaml b/Wino.Mail.WinUI/Views/Settings/PersonalizationPage.xaml index 1c93662a..fd7d1a77 100644 --- a/Wino.Mail.WinUI/Views/Settings/PersonalizationPage.xaml +++ b/Wino.Mail.WinUI/Views/Settings/PersonalizationPage.xaml @@ -49,6 +49,68 @@ CompactTemplate="{StaticResource CompactDisplayModePreviewTemplate}" MediumTemplate="{StaticResource MediumDisplayModePreviewTemplate}" SpaciousTemplate="{StaticResource SpaciousDisplayModePreviewTemplate}" /> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -147,7 +209,7 @@