Skip to content

Commit 69902d4

Browse files
committed
Start Settings ViewModel
1 parent 5a0744a commit 69902d4

File tree

7 files changed

+327
-151
lines changed

7 files changed

+327
-151
lines changed

Files.Launcher/Program.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,18 @@ static void Main(string[] args)
1515
var arguments = (string)localSettings.Values["Arguments"];
1616
if (!string.IsNullOrWhiteSpace(arguments))
1717
{
18-
if (arguments.Equals("DetectUserPaths"))
18+
if (arguments.Equals("StartupTasks"))
1919
{
20+
// Detect User Paths
2021
ApplicationData.Current.LocalSettings.Values["DetectedDesktopLocation"] = Microsoft.Win32.Registry.GetValue(@"HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders", "Desktop", null);
2122
ApplicationData.Current.LocalSettings.Values["DetectedDownloadsLocation"] = Microsoft.Win32.Registry.GetValue(@"HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders", "{374DE290-123F-4565-9164-39C4925E467B}", null);
2223
ApplicationData.Current.LocalSettings.Values["DetectedDocumentsLocation"] = Microsoft.Win32.Registry.GetValue(@"HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders", "Personal", null);
2324
ApplicationData.Current.LocalSettings.Values["DetectedPicturesLocation"] = Microsoft.Win32.Registry.GetValue(@"HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders", "My Pictures", null);
2425
ApplicationData.Current.LocalSettings.Values["DetectedMusicLocation"] = Microsoft.Win32.Registry.GetValue(@"HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders", "My Music", null);
2526
ApplicationData.Current.LocalSettings.Values["DetectedVideosLocation"] = Microsoft.Win32.Registry.GetValue(@"HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders", "My Video", null);
2627
ApplicationData.Current.LocalSettings.Values["DetectedOneDriveLocation"] = Microsoft.Win32.Registry.GetValue(@"HKEY_CURRENT_USER\Software\Microsoft\OneDrive", "UserFolder", null);
27-
}
28-
else if (arguments.Equals("CheckQuickLookAvailability"))
29-
{
28+
29+
// Check QuickLook Availability
3030
QuickLook.CheckQuickLookAvailability(localSettings);
3131
}
3232
else if (arguments.Equals("ToggleQuickLook"))

Files/App.xaml.cs

Lines changed: 16 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,13 @@
3030
using Windows.Storage.Streams;
3131
using Windows.System;
3232
using Microsoft.UI.Xaml.Controls;
33+
using Files.View_Models;
3334

3435
namespace Files
3536
{
3637
sealed partial class App : Application
3738
{
38-
public static bool areLinuxFilesSupported { get; set; } = false;
39-
public static string DesktopPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
40-
public static string DocumentsPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
41-
public static string DownloadsPath = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + @"\Downloads";
42-
public static string OneDrivePath = Environment.GetEnvironmentVariable("OneDrive");
43-
public static string PicturesPath = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures);
44-
public static string MusicPath = Environment.GetFolderPath(Environment.SpecialFolder.MyMusic);
45-
public static string VideosPath = Environment.GetFolderPath(Environment.SpecialFolder.MyVideos);
39+
4640
private static ProHome occupiedInstance;
4741
public static ProHome OccupiedInstance
4842
{
@@ -66,8 +60,7 @@ public static ProHome OccupiedInstance
6660
private DeviceWatcher watcher;
6761
public static ObservableCollection<SidebarItem> sideBarItems = new ObservableCollection<SidebarItem>();
6862
public static ObservableCollection<WSLDistroItem> linuxDistroItems = new ObservableCollection<WSLDistroItem>();
69-
public static FormFactorMode FormFactor { get; set; } = FormFactorMode.Regular;
70-
ApplicationDataContainer localSettings;
63+
public static SettingsViewModel AppSettings = new SettingsViewModel();
7164

7265
public App()
7366
{
@@ -82,12 +75,11 @@ public App()
8275
Clipboard.ContentChanged += Clipboard_ContentChanged;
8376
Clipboard_ContentChanged(null, null);
8477
AppCenter.Start("682666d1-51d3-4e4a-93d0-d028d43baaa0", typeof(Analytics), typeof(Crashes));
85-
localSettings = ApplicationData.Current.LocalSettings;
78+
8679
SetPropertiesFromLocalSettings();
87-
DetectCustomLocations();
80+
8881
PopulatePinnedSidebarItems();
8982
DetectWSLDistros();
90-
QuickLookIntegration();
9183
}
9284

9385
public void CloseOpenPopups()
@@ -226,7 +218,7 @@ private async void DetectWSLDistros()
226218
var distroFolder = await StorageFolder.GetFolderFromPathAsync(@"\\wsl$\");
227219
if ((await distroFolder.GetFoldersAsync()).Count > 0)
228220
{
229-
areLinuxFilesSupported = false;
221+
AppSettings.AreLinuxFilesSupported = false;
230222
}
231223

232224
foreach (StorageFolder folder in await distroFolder.GetFoldersAsync())
@@ -264,86 +256,21 @@ private async void DetectWSLDistros()
264256
catch (Exception)
265257
{
266258
// WSL Not Supported/Enabled
267-
areLinuxFilesSupported = false;
259+
AppSettings.AreLinuxFilesSupported = false;
268260
}
269261
}
270262

271-
private async void QuickLookIntegration()
272-
{
273-
localSettings.Values["Arguments"] = "CheckQuickLookAvailability";
274-
await FullTrustProcessLauncher.LaunchFullTrustProcessForCurrentAppAsync();
275-
}
276-
277263
private void SetPropertiesFromLocalSettings()
278264
{
279-
if (localSettings.Values["theme"] == null)
280-
{
281-
localSettings.Values["theme"] = "Default";
282-
}
283265

284-
if (localSettings.Values["datetimeformat"] == null)
285-
{
286-
localSettings.Values["datetimeformat"] = "Application";
287-
}
288266

289-
if (localSettings.Values["theme"] != null)
290-
{
291-
if (localSettings.Values["theme"].ToString() == "Light")
292-
{
293-
SettingsPages.Personalization.TV.ThemeValue = ApplicationTheme.Light;
294-
}
295-
else if (localSettings.Values["theme"].ToString() == "Dark")
296-
{
297-
SettingsPages.Personalization.TV.ThemeValue = ApplicationTheme.Dark;
298-
}
299-
else
300-
{
301-
var uiSettings = new Windows.UI.ViewManagement.UISettings();
302-
var color = uiSettings.GetColorValue(Windows.UI.ViewManagement.UIColorType.Background);
303-
if (color == Colors.White)
304-
{
305-
SettingsPages.Personalization.TV.ThemeValue = ApplicationTheme.Light;
306-
}
307-
else
308-
{
309-
SettingsPages.Personalization.TV.ThemeValue = ApplicationTheme.Dark;
310-
}
311-
}
312-
}
313267

314-
this.RequestedTheme = SettingsPages.Personalization.TV.ThemeValue;
315-
}
268+
316269

317-
private async void DetectCustomLocations()
318-
{
319-
// Detect custom locations set from Windows
320-
localSettings.Values["Arguments"] = "DetectUserPaths";
321-
await FullTrustProcessLauncher.LaunchFullTrustProcessForCurrentAppAsync("UserFolderPathsGroup");
322-
323-
App.DesktopPath = localSettings.Values["DetectedDesktopLocation"] as string;
324-
App.DownloadsPath = localSettings.Values["DetectedDownloadsLocation"] as string;
325-
App.DocumentsPath = localSettings.Values["DetectedDocumentsLocation"] as string;
326-
App.PicturesPath = localSettings.Values["DetectedPicturesLocation"] as string;
327-
App.MusicPath = localSettings.Values["DetectedMusicLocation"] as string;
328-
App.VideosPath = localSettings.Values["DetectedVideosLocation"] as string;
329-
App.OneDrivePath = localSettings.Values["DetectedOneDriveLocation"] as string;
330-
331-
// Overwrite paths for common locations if Custom Locations setting is enabled
332-
if (localSettings.Values["customLocationsSetting"] != null)
333-
{
334-
if (localSettings.Values["customLocationsSetting"].Equals(true))
335-
{
336-
App.DesktopPath = localSettings.Values["DesktopLocation"] as string;
337-
App.DownloadsPath = localSettings.Values["DownloadsLocation"] as string;
338-
App.DocumentsPath = localSettings.Values["DocumentsLocation"] as string;
339-
App.PicturesPath = localSettings.Values["PicturesLocation"] as string;
340-
App.MusicPath = localSettings.Values["MusicLocation"] as string;
341-
App.VideosPath = localSettings.Values["VideosLocation"] as string;
342-
App.OneDrivePath = localSettings.Values["DetectedOneDriveLocation"] as string;
343-
}
344-
}
345270
}
346271

272+
273+
347274
public void PopulateDrivesListWithLocalDisks()
348275
{
349276
var driveLetters = DriveInfo.GetDrives().Select(x => x.RootDirectory.Root).ToList().OrderBy(x => x.Root.FullName).ToList();
@@ -616,12 +543,12 @@ public async void PopulatePinnedSidebarItems()
616543
private void AddDefaultLocations()
617544
{
618545
sideBarItems.Add(new SidebarItem() { Text = "Home", IconGlyph = "\uE737", isDefaultLocation = true, Path = "Home" });
619-
sideBarItems.Add(new SidebarItem() { Text = "Desktop", IconGlyph = "\uE8FC", isDefaultLocation = true, Path = DesktopPath });
620-
sideBarItems.Add(new SidebarItem() { Text = "Downloads", IconGlyph = "\uE896", isDefaultLocation = true, Path = DownloadsPath });
621-
sideBarItems.Add(new SidebarItem() { Text = "Documents", IconGlyph = "\uE8A5", isDefaultLocation = true, Path = DocumentsPath });
622-
sideBarItems.Add(new SidebarItem() { Text = "Pictures", IconGlyph = "\uEB9F", isDefaultLocation = true, Path = PicturesPath });
623-
sideBarItems.Add(new SidebarItem() { Text = "Music", IconGlyph = "\uEC4F", isDefaultLocation = true, Path = MusicPath });
624-
sideBarItems.Add(new SidebarItem() { Text = "Videos", IconGlyph = "\uE8B2", isDefaultLocation = true, Path = VideosPath });
546+
sideBarItems.Add(new SidebarItem() { Text = "Desktop", IconGlyph = "\uE8FC", isDefaultLocation = true, Path = AppSettings.DesktopPath });
547+
sideBarItems.Add(new SidebarItem() { Text = "Downloads", IconGlyph = "\uE896", isDefaultLocation = true, Path = AppSettings.DownloadsPath });
548+
sideBarItems.Add(new SidebarItem() { Text = "Documents", IconGlyph = "\uE8A5", isDefaultLocation = true, Path = AppSettings.DocumentsPath });
549+
sideBarItems.Add(new SidebarItem() { Text = "Pictures", IconGlyph = "\uEB9F", isDefaultLocation = true, Path = AppSettings.PicturesPath });
550+
sideBarItems.Add(new SidebarItem() { Text = "Music", IconGlyph = "\uEC4F", isDefaultLocation = true, Path = AppSettings.MusicPath });
551+
sideBarItems.Add(new SidebarItem() { Text = "Videos", IconGlyph = "\uE8B2", isDefaultLocation = true, Path = AppSettings.VideosPath });
625552
}
626553

627554
public static async void RemoveStaleSidebarItems()

Files/Enums/SidebarOpacity.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace Files.Enums
8+
{
9+
public enum SidebarOpacity
10+
{
11+
Opaque = 0,
12+
AcrylicEnabled = 1
13+
}
14+
}

Files/Files.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@
167167
<DependentUpon>RenameDialog.xaml</DependentUpon>
168168
</Compile>
169169
<Compile Include="Enums\FormFactorMode.cs" />
170+
<Compile Include="Enums\SidebarOpacity.cs" />
170171
<Compile Include="Enums\SortOption.cs" />
171172
<Compile Include="Enums\ThemeStyle.cs" />
172173
<Compile Include="Enums\TimeStyle.cs" />
@@ -221,6 +222,7 @@
221222
<DependentUpon>StartPageWidgets.xaml</DependentUpon>
222223
</Compile>
223224
<Compile Include="View Models\RibbonViewModel.cs" />
225+
<Compile Include="View Models\SettingsViewModel.cs" />
224226
<Compile Include="WindowDisplayInfo.cs" />
225227
<Compile Include="WindowDisplayMode.cs" />
226228
<Compile Include="YourHome.xaml.cs">

Files/SettingsPages/Personalization.xaml.cs

Lines changed: 46 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -19,86 +19,76 @@ public Personalization()
1919
//Load Theme Style
2020
var _themeval = Enum.GetValues(typeof(ThemeStyle)).Cast<ThemeStyle>();
2121
ThemeChooser.ItemsSource = _themeval.ToList();
22+
ThemeStyle _selectedTheme = App.AppSettings.ThemeValue;
2223

23-
Windows.Storage.ApplicationDataContainer localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
24-
if (localSettings.Values["theme"] != null)
24+
ThemeChooser.SelectedIndex = _themeval.ToList().IndexOf(_selectedTheme);
25+
ThemeChooser.Loaded += (s, e) =>
2526
{
26-
ThemeStyle _selectedTheme = localSettings.Values["theme"].ToString().Equals("Default") ? ThemeStyle.System : Enum.Parse<ThemeStyle>(localSettings.Values["theme"].ToString());
27-
ThemeChooser.SelectedIndex = _themeval.ToList().IndexOf(_selectedTheme);
28-
ThemeChooser.Loaded += (s, e) =>
27+
ThemeChooser.SelectionChanged += async (s1, e1) =>
2928
{
30-
ThemeChooser.SelectionChanged += async (s1, e1) =>
29+
switch (e1.AddedItems[0].ToString())
3130
{
32-
localSettings.Values["theme"] = e1.AddedItems[0].Equals("System") ? "Default" : e1.AddedItems[0].ToString();
33-
await RestartReminder.Fade(value: 1.0f, duration: 1500, delay: 0).StartAsync();
34-
await RestartReminder.Fade(value: 0.0f, duration: 1500, delay: 0).StartAsync();
35-
};
31+
case "System":
32+
App.AppSettings.ThemeValue = ThemeStyle.System;
33+
break;
34+
case "Light":
35+
App.AppSettings.ThemeValue = ThemeStyle.Light;
36+
break;
37+
case "Dark":
38+
App.AppSettings.ThemeValue = ThemeStyle.Dark;
39+
break;
40+
}
41+
42+
await RestartReminder.Fade(value: 1.0f, duration: 1500, delay: 0).StartAsync();
43+
await RestartReminder.Fade(value: 0.0f, duration: 1500, delay: 0).StartAsync();
3644
};
37-
}
45+
};
3846

3947
//Load App Time Style
4048
var _dateformatval = Enum.GetValues(typeof(TimeStyle)).Cast<TimeStyle>();
4149
DateFormatChooser.ItemsSource = _dateformatval.ToList();
4250

43-
if (localSettings.Values["datetimeformat"] != null)
51+
TimeStyle _selectedFormat = App.AppSettings.DisplayedTimeStyle;
52+
DateFormatChooser.SelectedIndex = _dateformatval.ToList().IndexOf(_selectedFormat);
53+
DateFormatChooser.Loaded += (s, e) =>
4454
{
45-
TimeStyle _selectedFormat = Enum.Parse<TimeStyle>(localSettings.Values["datetimeformat"].ToString());
46-
DateFormatChooser.SelectedIndex = _dateformatval.ToList().IndexOf(_selectedFormat);
47-
DateFormatChooser.Loaded += (s, e) =>
55+
DateFormatChooser.SelectionChanged += async (s1, e1) =>
4856
{
49-
DateFormatChooser.SelectionChanged += async (s1, e1) =>
57+
switch (e1.AddedItems[0].ToString())
5058
{
51-
localSettings.Values["datetimeformat"] = e1.AddedItems[0].ToString();
52-
await TimeFormatReminder.Fade(value: 1.0f, duration: 1500, delay: 0).StartAsync();
53-
await TimeFormatReminder.Fade(value: 0.0f, duration: 1500, delay: 0).StartAsync();
54-
};
59+
case "Application":
60+
App.AppSettings.DisplayedTimeStyle = TimeStyle.Application;
61+
break;
62+
case "System":
63+
App.AppSettings.DisplayedTimeStyle = TimeStyle.System;
64+
break;
65+
}
66+
67+
await TimeFormatReminder.Fade(value: 1.0f, duration: 1500, delay: 0).StartAsync();
68+
await TimeFormatReminder.Fade(value: 0.0f, duration: 1500, delay: 0).StartAsync();
5569
};
56-
}
70+
};
5771

58-
// Acrylic Sidebar
59-
if (localSettings.Values["acrylicSidebar"] != null)
60-
{
61-
var isAcrylicSidebarEnabled = bool.Parse(localSettings.Values["acrylicSidebar"].ToString());
62-
AcrylicSidebarSwitch.IsOn = isAcrylicSidebarEnabled;
63-
}
72+
73+
AcrylicSidebarSwitch.IsOn = App.AppSettings.SidebarThemeMode.Equals(SidebarOpacity.Opaque) ? false : true;
6474

6575
AcrylicSidebarSwitch.Loaded += (sender, args) =>
6676
{
6777
AcrylicSidebarSwitch.Toggled += (o, eventArgs) =>
6878
{
69-
localSettings.Values["acrylicSidebar"] = ((ToggleSwitch)o).IsOn;
79+
if (((ToggleSwitch)o).IsOn)
80+
{
81+
App.AppSettings.SidebarThemeMode = SidebarOpacity.AcrylicEnabled;
82+
}
83+
else
84+
{
85+
App.AppSettings.SidebarThemeMode = SidebarOpacity.Opaque;
86+
}
7087
};
7188
};
7289
}
7390

74-
private static ThemeValueClass tv = new ThemeValueClass();
75-
public static ThemeValueClass TV { get { return tv; } }
76-
7791
}
7892

79-
public class ThemeValueClass : INotifyPropertyChanged
80-
{
81-
public ApplicationTheme _ThemeValue;
82-
public ApplicationTheme ThemeValue
83-
{
84-
get
85-
{
86-
return _ThemeValue;
87-
}
88-
set
89-
{
90-
if(value != _ThemeValue)
91-
{
92-
_ThemeValue = value;
93-
NotifyPropertyChanged("ThemeValue");
94-
}
95-
}
96-
}
97-
98-
public event PropertyChangedEventHandler PropertyChanged;
99-
private void NotifyPropertyChanged([CallerMemberName] string propertyName = "")
100-
{
101-
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
102-
}
103-
}
93+
10494
}

Files/SettingsPages/Preferences.xaml.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,12 @@ namespace Files.SettingsPages
1111

1212
public sealed partial class Preferences : Page
1313
{
14-
ApplicationDataContainer localSettings = ApplicationData.Current.LocalSettings;
1514
StorageFolder localFolder = ApplicationData.Current.LocalFolder;
1615
public Preferences()
1716
{
1817
this.InitializeComponent();
1918

20-
if (localSettings.Values["customLocationsSetting"] != null)
19+
if (App.AppSettings != null)
2120
{
2221
if (localSettings.Values["customLocationsSetting"].Equals(true))
2322
{

0 commit comments

Comments
 (0)