Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix inconsistent theme on first launch and restart #30

Merged
merged 3 commits into from
Sep 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion GenshinLyreMidiPlayer.WPF/GenshinLyreMidiPlayer.WPF.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<UseWPF>true</UseWPF>
<StartupObject>GenshinLyreMidiPlayer.WPF.App</StartupObject>
<ApplicationManifest>app.manifest</ApplicationManifest>
<Version>4.0.2</Version>
<Version>4.0.3</Version>
<ApplicationIcon>item_windsong_lyre.ico</ApplicationIcon>
<Nullable>enable</Nullable>
<RepositoryUrl>https://github.com/sabihoshi/GenshinLyreMidiPlayer</RepositoryUrl>
Expand Down
8 changes: 7 additions & 1 deletion GenshinLyreMidiPlayer.WPF/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,13 @@ public void SearchSong(AutoSuggestBox sender, TextChangedEventArgs e)
protected override async void OnViewLoaded()
{
Navigation = ((MainWindowView) View).RootNavigation;
_theme.SetTheme(_theme.GetSystemTheme());

_theme.SetTheme(ThemeManager.Current.ApplicationTheme switch
{
ApplicationTheme.Light => ThemeType.Light,
ApplicationTheme.Dark => ThemeType.Dark,
_ => SettingsView.GetSystemTheme()
});

if (!await SettingsView.TryGetLocationAsync()) _ = SettingsView.LocationMissing();
if (SettingsView.AutoCheckUpdates)
Expand Down
12 changes: 10 additions & 2 deletions GenshinLyreMidiPlayer.WPF/ViewModels/SettingsPageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -316,14 +316,21 @@ await Task.Delay(start, PlayTimerToken.Token)
PlayTimerToken = null;
}

public ThemeType GetSystemTheme()
{
var SystemThemeColor = new Windows.UI.ViewManagement.UISettings().GetColorValue(Windows.UI.ViewManagement.UIColorType.Background).ToString();
var SystemTheme = SystemThemeColor == "#FFFFFFFF" ? ThemeType.Light : ThemeType.Dark;
return SystemTheme;
}

[UsedImplicitly]
public void OnThemeChanged()
{
_theme.SetTheme(ThemeManager.Current.ApplicationTheme switch
{
ApplicationTheme.Light => ThemeType.Light,
ApplicationTheme.Dark => ThemeType.Dark,
_ => _theme.GetSystemTheme()
_ => GetSystemTheme()
});

Settings.Modify(s => s.AppTheme = (int?) ThemeManager.Current.ApplicationTheme ?? -1);
Expand All @@ -348,8 +355,9 @@ private async Task<bool> TrySetLocationAsync(string? location)
Title = "Incorrect Location",
Content = "launcher.exe is not the game, please find GenshinImpact.exe",

CloseButtonText = "Ok"
CloseButtonText = "Ok",
};


await dialog.ShowAsync();
return false;
Expand Down
12 changes: 6 additions & 6 deletions GenshinLyreMidiPlayer.WPF/Views/LyrePlayerView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

<modern:SimpleStackPanel Orientation="Horizontal" Grid.Row="0">
<Button Command="{s:Action OpenFile}" Background="Transparent">
<modern:FontIcon Glyph="&#xE8E5;" />
<modern:FontIcon Glyph="&#xE8E5;" />
</Button>
<TextBlock VerticalAlignment="Center" Text="{Binding Playlist.OpenedFile.Title, Mode=OneWay, FallbackValue=Open...}" />
</modern:SimpleStackPanel>
Expand All @@ -41,19 +41,19 @@

<Button Command="{s:Action Previous}"
IsHitTestVisible="{Binding CanHitPrevious}">
<modern:FontIcon Glyph="&#xE892;" />
<modern:FontIcon Glyph="&#xE892;" />
</Button>
<Button Command="{s:Action PlayPause}"
IsHitTestVisible="{Binding CanHitPlayPause}">
<modern:FontIcon Glyph="{Binding PlayPauseIcon}" />
<modern:FontIcon Glyph="{Binding PlayPauseIcon}" />
</Button>
<Button Command="{s:Action Next}"
IsHitTestVisible="{Binding CanHitNext}">
<modern:FontIcon Glyph="&#xE893;" />
<modern:FontIcon Glyph="&#xE893;" />
</Button>

<Button s:View.ActionTarget="{Binding Playlist}" Command="{s:Action ToggleLoop}">
<modern:FontIcon Glyph="{Binding Playlist.LoopStateString}" />
<modern:FontIcon Glyph="{Binding Playlist.LoopStateString}" />
</Button>
</modern:SimpleStackPanel>

Expand Down Expand Up @@ -120,7 +120,7 @@
SelectedItem="{Binding SelectedMidiInput}"
DisplayMemberPath="DeviceName" />
<Button Command="{s:Action RefreshDevices}">
<modern:FontIcon Glyph="&#xE72C;" />
<modern:FontIcon Glyph="&#xE72C;" />
</Button>
</modern:SimpleStackPanel>
</GroupBox>
Expand Down