Skip to content

Commit

Permalink
Fix: Fixed duplicate initialization when resuming (#13261)
Browse files Browse the repository at this point in the history
  • Loading branch information
hishitetsu authored Aug 27, 2023
1 parent 2b1b7c5 commit 7dbd806
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
10 changes: 9 additions & 1 deletion src/Files.App/Helpers/UI/ThemeHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public static class ThemeHelper
private const string selectedAppThemeKey = "theme";
private static Window? currentApplicationWindow;
private static AppWindowTitleBar? titleBar;
private static bool isInitialized = false;

// Keep reference so it does not get optimized/garbage collected
public static UISettings UiSettings;
Expand All @@ -42,8 +43,13 @@ public static ElementTheme RootTheme
}
}

public static void Initialize()
public static bool Initialize()
{
if (isInitialized)
return false;

isInitialized = true;

// Save reference as this might be null when the user is in another app
currentApplicationWindow = MainWindow.Instance;

Expand All @@ -57,6 +63,8 @@ public static void Initialize()
// Registering to color changes, thus we notice when user changes theme system wide
UiSettings = new UISettings();
UiSettings.ColorValuesChanged += UiSettings_ColorValuesChanged;

return true;
}

public static void ApplyResources()
Expand Down
15 changes: 9 additions & 6 deletions src/Files.App/ViewModels/MainPageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ public async Task OnNavigatedTo(NavigationEventArgs e)

//Initialize the static theme helper to capture a reference to this window
//to handle theme changes without restarting the app
ThemeHelper.Initialize();
var isInitialized = ThemeHelper.Initialize();

var parameter = e.Parameter;
var ignoreStartupSettings = false;
Expand Down Expand Up @@ -378,12 +378,15 @@ public async Task OnNavigatedTo(NavigationEventArgs e)
await AddNewTabByParam(tabArgs.InitialPageType, tabArgs.NavigationArg);
}

// Load the app theme resources
resourcesService.LoadAppResources(appearanceSettingsService);
if (isInitialized)
{
// Load the app theme resources
resourcesService.LoadAppResources(appearanceSettingsService);

await Task.WhenAll(
drivesViewModel.UpdateDrivesAsync(),
networkDrivesViewModel.UpdateDrivesAsync());
await Task.WhenAll(
drivesViewModel.UpdateDrivesAsync(),
networkDrivesViewModel.UpdateDrivesAsync());
}
}

public Task AddNewTabAsync()
Expand Down

0 comments on commit 7dbd806

Please sign in to comment.