Skip to content

Commit

Permalink
Fix #209
Browse files Browse the repository at this point in the history
  • Loading branch information
natsurainko committed Feb 15, 2024
1 parent e33d102 commit e828e95
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public partial class SettingsService : SettingsContainer, IFluentCoreSettingsSer

[SettingItem(typeof(double), "AppWindowHeight", Default = 500, Converter = typeof(JsonStringConverter<double>))]
[SettingItem(typeof(double), "AppWindowWidth", Default = 950, Converter = typeof(JsonStringConverter<double>))]
[SettingItem(typeof(WinUIEx.WindowState), "AppWindowState", Default = WinUIEx.WindowState.Normal, Converter = typeof(JsonStringConverter<WinUIEx.WindowState>))]
[SettingItem(typeof(bool), "FinishGuide", Default = false, Converter = typeof(JsonStringConverter<bool>))]

[SettingItem(typeof(int), "CoresSortByIndex", Default = 0, Converter = typeof(JsonStringConverter<int>))]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
using Microsoft.UI.Xaml;
using Microsoft.Windows.AppNotifications;
using Microsoft.Windows.AppNotifications;
using Microsoft.Windows.AppNotifications.Builder;
using Natsurainko.FluentLauncher.Components.Launch;
using Natsurainko.FluentLauncher.Services.Launch;
using Natsurainko.FluentLauncher.Services.UI.Windows;
using Natsurainko.FluentLauncher.Utils;
using Natsurainko.FluentLauncher.Utils.Xaml;
using Natsurainko.FluentLauncher.ViewModels.Activities;
using Nrk.FluentCore.Launch;
using Nrk.FluentCore.Utils;
Expand Down
1 change: 0 additions & 1 deletion Natsurainko.FluentLauncher/Views/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
xmlns:local="using:Natsurainko.FluentLauncher.Views"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:winuiex="using:WinUIEx"
Activated="WindowEx_Activated"
mc:Ignorable="d">
<Grid>
<Grid x:Name="BackgroundGrid" Background="Transparent" />
Expand Down
53 changes: 34 additions & 19 deletions Natsurainko.FluentLauncher/Views/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using Natsurainko.FluentLauncher.Services.UI.Navigation;
using Natsurainko.FluentLauncher.Utils;
using System.IO;
using System.Windows.Navigation;
using Windows.ApplicationModel;
using Windows.Globalization;
using WinUIEx;
Expand All @@ -22,10 +21,14 @@ public sealed partial class MainWindow : WindowEx, INavigationProvider
private readonly INavigationService _navService;
private readonly SettingsService _settings = App.GetService<SettingsService>();
private readonly NotificationService _notificationService = App.GetService<NotificationService>();
private bool _firstActivated = true;

public MainWindow(INavigationService navService)
{
_navService = navService;
App.MainWindow = this;
var hoverColor = App.Current.RequestedTheme == ApplicationTheme.Light ? Colors.Black : Colors.White;
hoverColor.A = 35;

if (string.IsNullOrEmpty(ApplicationLanguages.PrimaryLanguageOverride))
ResourceUtils.ApplyLanguage(_settings.CurrentLanguage);
Expand All @@ -40,19 +43,42 @@ public MainWindow(INavigationService navService)
AppWindow.TitleBar.ButtonBackgroundColor = AppWindow.TitleBar.ButtonInactiveBackgroundColor = Colors.Transparent;
AppWindow.TitleBar.ButtonForegroundColor = App.Current.RequestedTheme == ApplicationTheme.Light ? Colors.Black : Colors.White;
AppWindow.TitleBar.ButtonHoverForegroundColor = App.Current.RequestedTheme == ApplicationTheme.Light ? Colors.Black : Colors.White;

var hoverColor = App.Current.RequestedTheme == ApplicationTheme.Light ? Colors.Black : Colors.White;
hoverColor.A = 35;

AppWindow.TitleBar.ButtonHoverBackgroundColor = hoverColor;

(MinWidth, MinHeight) = _settings.FinishGuide ? (516, 328) : (_settings.AppWindowWidth, _settings.AppWindowHeight);
(Width, Height) = (_settings.AppWindowWidth, _settings.AppWindowHeight);

App.GetService<AppearanceService>().ApplyBackgroundAtWindowCreated(this);
App.MainWindow = this;

((FrameworkElement)this.Content).ActualThemeChanged += MainWindow_ActualThemeChanged;
this.WindowStateChanged += MainWindow_WindowStateChanged;
this.SizeChanged += MainWindow_SizeChanged;
this.Activated += MainWindow_Activated;
}

#region Window Event

private void MainWindow_Activated(object sender, WindowActivatedEventArgs args)
{
if (_firstActivated)
{
_navService.NavigateTo(_settings.FinishGuide ? "ShellPage" : "OOBENavigationPage");
this.CenterOnScreen();
if (_settings.AppWindowState == WindowState.Maximized) this.Maximize();
}

_firstActivated = false;
}

private void MainWindow_SizeChanged(object sender, WindowSizeChangedEventArgs args)
{
_settings.AppWindowWidth = App.MainWindow.Width;
_settings.AppWindowHeight = App.MainWindow.Height;
}

private void MainWindow_WindowStateChanged(object? sender, WindowState e)
{
_settings.AppWindowState = e;
}

private void MainWindow_ActualThemeChanged(FrameworkElement sender, object args)
Expand All @@ -66,18 +92,7 @@ private void MainWindow_ActualThemeChanged(FrameworkElement sender, object args)

AppWindow.TitleBar.ButtonHoverBackgroundColor = hoverColor;
}
#endregion

private bool _firstActivated = true;
private void WindowEx_Activated(object sender, WindowActivatedEventArgs args)
{
if (_firstActivated)
_navService.NavigateTo(_settings.FinishGuide ? "ShellPage" : "OOBENavigationPage");

_firstActivated = false;
}

public void NavigateToLaunchTasksPage()
{
_navService.NavigateTo("ShellPage", "ActivitiesNavigationPage");
}
public void NavigateToLaunchTasksPage() => _navService.NavigateTo("ShellPage", "ActivitiesNavigationPage");
}
37 changes: 15 additions & 22 deletions Natsurainko.FluentLauncher/Views/ShellPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,10 @@ public ShellPage()
_appearanceService.RegisterNavigationView(NavigationViewControl);
}

private void UpdateAppTitleMargin(NavigationView sender)
{
AppTitle.TranslationTransition = new Vector3Transition();
AppTitle.Translation = ((sender.DisplayMode == NavigationViewDisplayMode.Expanded && sender.IsPaneOpen) ||
sender.DisplayMode == NavigationViewDisplayMode.Minimal)
? new System.Numerics.Vector3(8, 0, 0)
: new System.Numerics.Vector3(28, 0, 0);
}

private void NavigationViewControl_PaneClosing(NavigationView sender, object _)
=> UpdateAppTitleMargin(sender);
#region NavigationView Events
private void NavigationViewControl_PaneClosing(NavigationView sender, object _) => UpdateAppTitleMargin(sender);

private void NavigationViewControl_PaneOpening(NavigationView sender, object _)
=> UpdateAppTitleMargin(sender);
private void NavigationViewControl_PaneOpening(NavigationView sender, object _) => UpdateAppTitleMargin(sender);

private void NavigationViewControl_ItemInvoked(NavigationView _, NavigationViewItemInvokedEventArgs args)
{
Expand All @@ -62,8 +52,7 @@ private void NavigationViewControl_ItemInvoked(NavigationView _, NavigationViewI
VM.NavigationService.NavigateTo(pageTag);
}

private void NavigationViewControl_BackRequested(NavigationView sender, NavigationViewBackRequestedEventArgs args)
=> VM.NavigationService.GoBack();
private void NavigationViewControl_BackRequested(NavigationView sender, NavigationViewBackRequestedEventArgs args) => VM.NavigationService.GoBack();

private void NavigationViewControl_DisplayModeChanged(NavigationView sender, NavigationViewDisplayModeChangedEventArgs args)
{
Expand All @@ -72,6 +61,7 @@ private void NavigationViewControl_DisplayModeChanged(NavigationView sender, Nav
UpdateAppTitleMargin(sender);
RefreshDragArea();
}
#endregion

private async void Page_Loaded(object sender, RoutedEventArgs e)
{
Expand All @@ -92,13 +82,7 @@ private async void Page_Loaded(object sender, RoutedEventArgs e)
RefreshDragArea();
}

private void Page_SizeChanged(object sender, SizeChangedEventArgs e)
{
RefreshDragArea();

_settings.AppWindowWidth = App.MainWindow.Width;
_settings.AppWindowHeight = App.MainWindow.Height;
}
private void Page_SizeChanged(object sender, SizeChangedEventArgs e) => RefreshDragArea();

private void ContentFrame_Navigated(object sender, NavigationEventArgs e)
{
Expand Down Expand Up @@ -132,6 +116,15 @@ private void RefreshDragArea()
App.MainWindow.AppWindow.TitleBar.SetDragRectangles(new[] { dragRect });
}

private void UpdateAppTitleMargin(NavigationView sender)
{
AppTitle.TranslationTransition = new Vector3Transition();
AppTitle.Translation = ((sender.DisplayMode == NavigationViewDisplayMode.Expanded && sender.IsPaneOpen) ||
sender.DisplayMode == NavigationViewDisplayMode.Minimal)
? new System.Numerics.Vector3(8, 0, 0)
: new System.Numerics.Vector3(28, 0, 0);
}

internal async void BlurAnimation(int from, int to)
{
var sprite = await PipelineBuilder
Expand Down

0 comments on commit e828e95

Please sign in to comment.