Skip to content

Commit e3f22e4

Browse files
authored
Refactor of SettingsViewModel (#8035)
1 parent 614e026 commit e3f22e4

File tree

6 files changed

+51
-70
lines changed

6 files changed

+51
-70
lines changed

src/Files/App.xaml.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
using Windows.ApplicationModel.DataTransfer;
3030
using Windows.Foundation.Metadata;
3131
using Windows.Storage;
32+
using Windows.System;
3233
using Windows.UI.Core;
3334
using Windows.UI.Notifications;
3435
using Windows.UI.ViewManagement;
@@ -466,9 +467,7 @@ async Task PerformNavigation(string payload, string selectItem = null)
466467
var eventArgsForNotification = args as ToastNotificationActivatedEventArgs;
467468
if (eventArgsForNotification.Argument == "report")
468469
{
469-
// Launch the URI and open log files location
470-
//SettingsViewModel.OpenLogLocation();
471-
SettingsViewModel.ReportIssueOnGitHub();
470+
await Launcher.LaunchUriAsync(new Uri(Constants.GitHub.FeedbackUrl));
472471
}
473472
break;
474473

src/Files/Constants.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,5 +169,15 @@ public static class Filesystem
169169

170170
public const string CachedEmptyItemName = "fileicon_cache";
171171
}
172+
173+
public static class GitHub
174+
{
175+
public const string ContributorsUrl = @"https://github.com/files-community/Files/graphs/contributors";
176+
public const string DocumentationUrl = @"https://files.community/docs";
177+
public const string FeedbackUrl = @"https://github.com/files-community/Files/issues/new/choose";
178+
public const string PrivacyPolicyUrl = @"https://github.com/files-community/Files/blob/main/Privacy.md";
179+
public const string ReleaseNotesUrl = @"https://github.com/files-community/Files/releases";
180+
public const string SupportUsUrl = @"https://github.com/sponsors/yaichenbaum";
181+
}
172182
}
173183
}

src/Files/ViewModels/SettingsViewModel.cs

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,11 @@
1111
using System.Reflection;
1212
using System.Runtime.CompilerServices;
1313
using System.Threading.Tasks;
14+
using System.Windows.Input;
1415
using Windows.ApplicationModel.AppService;
15-
using Windows.ApplicationModel.Core;
1616
using Windows.Foundation.Collections;
1717
using Windows.Globalization;
1818
using Windows.Storage;
19-
using Windows.System;
2019

2120
namespace Files.ViewModels
2221
{
@@ -36,25 +35,11 @@ public SettingsViewModel()
3635
{
3736
DefaultLanguages.Add(new DefaultLanguageModel(lang));
3837
}
39-
}
40-
41-
public static async void OpenLogLocation()
42-
{
43-
await Launcher.LaunchFolderAsync(ApplicationData.Current.LocalFolder);
44-
}
4538

46-
public static async void OpenThemesFolder()
47-
{
48-
await CoreApplication.MainView.Dispatcher.YieldAsync();
49-
await NavigationHelpers.OpenPathInNewTab(App.ExternalResourcesHelper.ImportedThemesFolder.Path);
50-
}
51-
52-
public static async void ReportIssueOnGitHub()
53-
{
54-
await Launcher.LaunchUriAsync(new Uri(@"https://github.com/files-community/Files/issues/new/choose"));
55-
}
39+
UpdateThemeElements = new RelayCommand(() => ThemeModeChanged?.Invoke(this, EventArgs.Empty));
40+
}
5641

57-
public bool AreRegistrySettingsMergedToJson
42+
public bool AreRegistrySettingsMergedToJson
5843
{
5944
get => Get(false);
6045
set => Set(value);
@@ -188,10 +173,7 @@ public bool ResumeAfterRestart
188173

189174
public event EventHandler ThemeModeChanged;
190175

191-
public RelayCommand UpdateThemeElements => new RelayCommand(() =>
192-
{
193-
ThemeModeChanged?.Invoke(this, EventArgs.Empty);
194-
});
176+
public ICommand UpdateThemeElements { get; }
195177

196178
#region ReadAndSaveSettings
197179

@@ -208,7 +190,7 @@ public bool Set<TValue>(TValue value, [CallerMemberName] string propertyName = n
208190
originalValue = Get(originalValue, propertyName);
209191

210192
localSettings.Values[propertyName] = value;
211-
if (!base.SetProperty(ref originalValue, value, propertyName))
193+
if (!SetProperty(ref originalValue, value, propertyName))
212194
{
213195
return false;
214196
}
@@ -234,7 +216,7 @@ public TValue Get<TValue>(TValue defaultValue, [CallerMemberName] string propert
234216
{
235217
var value = localSettings.Values[name];
236218

237-
if (!(value is TValue tValue))
219+
if (value is not TValue tValue)
238220
{
239221
if (value is IConvertible)
240222
{

src/Files/ViewModels/SettingsViewModels/AboutViewModel.cs

Lines changed: 24 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,23 @@ public class AboutViewModel : ObservableObject
2626
private IBundlesSettingsService BundlesSettingsService { get; } = Ioc.Default.GetService<IBundlesSettingsService>();
2727
protected IFileTagsSettingsService FileTagsSettingsService { get; } = Ioc.Default.GetService<IFileTagsSettingsService>();
2828

29-
public RelayCommand OpenLogLocationCommand => new RelayCommand(() => SettingsViewModel.OpenLogLocation());
30-
public RelayCommand CopyVersionInfoCommand => new RelayCommand(() => CopyVersionInfo());
29+
public ICommand OpenLogLocationCommand { get; }
30+
public ICommand CopyVersionInfoCommand { get; }
3131

3232
public ICommand ExportSettingsCommand { get; }
33-
3433
public ICommand ImportSettingsCommand { get; }
3534

36-
public RelayCommand<ItemClickEventArgs> ClickAboutFeedbackItemCommand =>
37-
new RelayCommand<ItemClickEventArgs>(ClickAboutFeedbackItem);
35+
public ICommand ClickAboutFeedbackItemCommand { get; }
3836

3937
public AboutViewModel()
4038
{
39+
OpenLogLocationCommand = new AsyncRelayCommand(OpenLogLocation);
40+
CopyVersionInfoCommand = new RelayCommand(CopyVersionInfo);
41+
4142
ExportSettingsCommand = new AsyncRelayCommand(ExportSettings);
4243
ImportSettingsCommand = new AsyncRelayCommand(ImportSettings);
44+
45+
ClickAboutFeedbackItemCommand = new AsyncRelayCommand<ItemClickEventArgs>(ClickAboutFeedbackItem);
4346
}
4447

4548
private async Task ExportSettings()
@@ -148,6 +151,8 @@ public void CopyVersionInfo()
148151
});
149152
}
150153

154+
public static async Task OpenLogLocation() => await Launcher.LaunchFolderAsync(ApplicationData.Current.LocalFolder);
155+
151156
public string Version
152157
{
153158
get
@@ -157,45 +162,24 @@ public string Version
157162
}
158163
}
159164

160-
public string AppName
161-
{
162-
get
163-
{
164-
return Package.Current.DisplayName;
165-
}
166-
}
165+
public string AppName => Package.Current.DisplayName;
167166

168-
private async void ClickAboutFeedbackItem(ItemClickEventArgs e)
167+
private async Task ClickAboutFeedbackItem(ItemClickEventArgs e)
169168
{
170169
var clickedItem = (StackPanel)e.ClickedItem;
171-
switch (clickedItem.Tag)
170+
var uri = clickedItem.Tag switch
172171
{
173-
case "Feedback":
174-
SettingsViewModel.ReportIssueOnGitHub();
175-
break;
176-
177-
case "ReleaseNotes":
178-
await Launcher.LaunchUriAsync(new Uri(@"https://github.com/files-community/Files/releases"));
179-
break;
180-
181-
case "Documentation":
182-
await Launcher.LaunchUriAsync(new Uri(@"https://files.community/docs"));
183-
break;
184-
185-
case "Contributors":
186-
await Launcher.LaunchUriAsync(new Uri(@"https://github.com/files-community/Files/graphs/contributors"));
187-
break;
188-
189-
case "PrivacyPolicy":
190-
await Launcher.LaunchUriAsync(new Uri(@"https://github.com/files-community/Files/blob/main/Privacy.md"));
191-
break;
192-
193-
case "SupportUs":
194-
await Launcher.LaunchUriAsync(new Uri(@"https://github.com/sponsors/yaichenbaum"));
195-
break;
196-
197-
default:
198-
break;
172+
"Contributors" => Constants.GitHub.ContributorsUrl,
173+
"Documentation" => Constants.GitHub.DocumentationUrl,
174+
"Feedback" => Constants.GitHub.FeedbackUrl,
175+
"PrivacyPolicy" => Constants.GitHub.PrivacyPolicyUrl,
176+
"ReleaseNotes" => Constants.GitHub.ReleaseNotesUrl,
177+
"SupportUs" => Constants.GitHub.SupportUsUrl,
178+
_ => null,
179+
};
180+
if (uri is not null)
181+
{
182+
await Launcher.LaunchUriAsync(new Uri(uri));
199183
}
200184
}
201185
}

src/Files/ViewModels/SettingsViewModels/AppearanceViewModel.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System;
77
using System.Collections.Generic;
88
using System.Threading.Tasks;
9+
using Windows.ApplicationModel.Core;
910
using Windows.UI.Xaml;
1011

1112
namespace Files.ViewModels.SettingsViewModels
@@ -202,5 +203,11 @@ public bool ShowWslSection
202203
}
203204
}
204205
}
206+
207+
public async Task OpenThemesFolder()
208+
{
209+
await CoreApplication.MainView.Dispatcher.YieldAsync();
210+
await NavigationHelpers.OpenPathInNewTab(App.ExternalResourcesHelper.ImportedThemesFolder.Path);
211+
}
205212
}
206213
}

src/Files/Views/SettingsPages/Appearance.xaml.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using Files.Dialogs;
22
using Files.Helpers.XamlHelpers;
33
using Files.UserControls.Settings;
4-
using Files.ViewModels;
54
using Microsoft.Toolkit.Uwp.UI;
65
using Windows.UI.Xaml;
76
using Windows.UI.Xaml.Controls;
@@ -36,7 +35,7 @@ private void OpenThemesFolderButton_Click(object sender, Windows.UI.Xaml.RoutedE
3635
{
3736
ThemesTeachingTip.IsOpen = false;
3837
this.FindAscendant<SettingsDialog>()?.Hide();
39-
SettingsViewModel.OpenThemesFolder();
38+
ViewModel.OpenThemesFolder();
4039
}
4140

4241
private async void ViewModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)

0 commit comments

Comments
 (0)