Skip to content

Commit 7070266

Browse files
committed
Fix crash: consentDialogUI shown before CoreWindow ready
1 parent ba6b68a commit 7070266

File tree

2 files changed

+31
-35
lines changed

2 files changed

+31
-35
lines changed

Files/App.xaml.cs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,9 @@
1919
using System.IO;
2020
using System.Linq;
2121
using System.Collections.ObjectModel;
22-
using System.Threading.Tasks;
23-
using Windows.Devices.Enumeration;
24-
using Windows.Devices.Portable;
25-
using Windows.ApplicationModel.Core;
2622
using Windows.UI.Core;
2723
using Windows.UI.Xaml.Controls.Primitives;
28-
using Files.Enums;
29-
using Windows.UI.Xaml.Media.Imaging;
30-
using Windows.Management.Deployment;
31-
using Windows.Storage.Streams;
3224
using Windows.System;
33-
using Microsoft.UI.Xaml.Controls;
3425
using Files.View_Models;
3526

3627
namespace Files
@@ -60,7 +51,7 @@ public static ProHome OccupiedInstance
6051
public static Dialogs.AddItemDialog addItemDialog { get; set; }
6152
public static ObservableCollection<SidebarItem> sideBarItems = new ObservableCollection<SidebarItem>();
6253
public static ObservableCollection<WSLDistroItem> linuxDistroItems = new ObservableCollection<WSLDistroItem>();
63-
public static SettingsViewModel AppSettings = new SettingsViewModel();
54+
public static SettingsViewModel AppSettings { get; set; }
6455

6556
public App()
6657
{
@@ -76,6 +67,8 @@ public App()
7667
Clipboard_ContentChanged(null, null);
7768
AppCenter.Start("682666d1-51d3-4e4a-93d0-d028d43baaa0", typeof(Analytics), typeof(Crashes));
7869

70+
AppSettings = new SettingsViewModel();
71+
7972
SetPropertiesFromLocalSettings();
8073

8174
PopulatePinnedSidebarItems();

Files/View Models/SettingsViewModel.cs

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -99,31 +99,34 @@ private async void DetectCustomLocations()
9999

100100
private void DetectApplicationTheme()
101101
{
102-
if (localSettings.Values["theme"].ToString() == "Light")
103-
{
104-
ThemeValue = ThemeStyle.Light;
105-
App.Current.RequestedTheme = ApplicationTheme.Light;
106-
}
107-
else if (localSettings.Values["theme"].ToString() == "Dark")
108-
{
109-
ThemeValue = ThemeStyle.Dark;
110-
App.Current.RequestedTheme = ApplicationTheme.Dark;
111-
}
112-
else
113-
{
114-
var uiSettings = new UISettings();
115-
var color = uiSettings.GetColorValue(UIColorType.Background);
116-
if (color == Colors.White)
117-
{
118-
ThemeValue = ThemeStyle.System;
119-
App.Current.RequestedTheme = ApplicationTheme.Light;
120-
}
121-
else
122-
{
123-
ThemeValue = ThemeStyle.System;
124-
App.Current.RequestedTheme = ApplicationTheme.Dark;
125-
}
126-
}
102+
if (localSettings.Values["theme"] != null)
103+
{
104+
if (localSettings.Values["theme"].ToString() == "Light")
105+
{
106+
ThemeValue = ThemeStyle.Light;
107+
App.Current.RequestedTheme = ApplicationTheme.Light;
108+
return;
109+
}
110+
else if (localSettings.Values["theme"].ToString() == "Dark")
111+
{
112+
ThemeValue = ThemeStyle.Dark;
113+
App.Current.RequestedTheme = ApplicationTheme.Dark;
114+
return;
115+
}
116+
}
117+
118+
var uiSettings = new UISettings();
119+
var color = uiSettings.GetColorValue(UIColorType.Background);
120+
if (color == Colors.White)
121+
{
122+
ThemeValue = ThemeStyle.System;
123+
App.Current.RequestedTheme = ApplicationTheme.Light;
124+
}
125+
else
126+
{
127+
ThemeValue = ThemeStyle.System;
128+
App.Current.RequestedTheme = ApplicationTheme.Dark;
129+
}
127130
}
128131

129132
private FormFactorMode _FormFactor = FormFactorMode.Regular;

0 commit comments

Comments
 (0)