From 7c1a183ae9e8dba730e9c31177023752938ee4e3 Mon Sep 17 00:00:00 2001 From: vddCore Date: Sat, 1 Jul 2023 10:56:48 +0200 Subject: [PATCH] port to avalonia 11 rc1 --- Slate/App.axaml | 3 +-- Slate/App.axaml.cs | 6 ++---- .../Services/IApplicationExecutionService.cs | 9 +++++++++ .../ApplicationExecutionService.cs | 19 +++++++++++++++++++ Slate/Slate.csproj | 11 +++++------ Slate/View/Window/MainWindow.axaml.cs | 9 ++++++--- .../Control/AuraColorControlViewModel.cs | 4 +--- Slate/ViewModel/Page/FansPageViewModel.cs | 4 +--- 8 files changed, 44 insertions(+), 21 deletions(-) create mode 100644 Slate/Infrastructure/Services/IApplicationExecutionService.cs create mode 100644 Slate/Infrastructure/Services/Implementations/ApplicationExecutionService.cs diff --git a/Slate/App.axaml b/Slate/App.axaml index 9633a24..323197d 100644 --- a/Slate/App.axaml +++ b/Slate/App.axaml @@ -42,8 +42,7 @@ + UseSystemFontOnWindows="True" /> diff --git a/Slate/App.axaml.cs b/Slate/App.axaml.cs index 7103cba..172392b 100644 --- a/Slate/App.axaml.cs +++ b/Slate/App.axaml.cs @@ -48,10 +48,8 @@ public override void OnFrameworkInitializationCompleted() base.OnFrameworkInitializationCompleted(); - TrayIcon.GetIcons(this)[0].IsVisible = true; - - _platformSettings = AvaloniaLocator.Current.GetRequiredService(); - _platformSettings.ColorValuesChanged += PlatformSettings_ColorValuesChanged; + TrayIcon.GetIcons(this)![0].IsVisible = true; + PlatformSettings!.ColorValuesChanged += PlatformSettings_ColorValuesChanged; } private void OnMainWindowTransitionFinished(MainWindowTransitionFinishedMessage msg) diff --git a/Slate/Infrastructure/Services/IApplicationExecutionService.cs b/Slate/Infrastructure/Services/IApplicationExecutionService.cs new file mode 100644 index 0000000..c29be15 --- /dev/null +++ b/Slate/Infrastructure/Services/IApplicationExecutionService.cs @@ -0,0 +1,9 @@ +using Glitonea.Mvvm; + +namespace Slate.Infrastructure.Services +{ + public interface IApplicationExecutionService : IService + { + void RunElevatedProcess(string path); + } +} \ No newline at end of file diff --git a/Slate/Infrastructure/Services/Implementations/ApplicationExecutionService.cs b/Slate/Infrastructure/Services/Implementations/ApplicationExecutionService.cs new file mode 100644 index 0000000..6a6fe35 --- /dev/null +++ b/Slate/Infrastructure/Services/Implementations/ApplicationExecutionService.cs @@ -0,0 +1,19 @@ +using System.Diagnostics; +using System.IO; + +namespace Slate.Infrastructure.Services.Implementations +{ + public class ApplicationExecutionService : IApplicationExecutionService + { + public void RunElevatedProcess(string path) + { + Process.Start(new ProcessStartInfo + { + UseShellExecute = true, + WorkingDirectory = Path.GetDirectoryName(path), + FileName = path, + Verb = "runas" + }); + } + } +} \ No newline at end of file diff --git a/Slate/Slate.csproj b/Slate/Slate.csproj index e6544c7..bb87977 100644 --- a/Slate/Slate.csproj +++ b/Slate/Slate.csproj @@ -15,15 +15,14 @@ - - + + - - - + + + - diff --git a/Slate/View/Window/MainWindow.axaml.cs b/Slate/View/Window/MainWindow.axaml.cs index ac8f669..1ca3c5f 100644 --- a/Slate/View/Window/MainWindow.axaml.cs +++ b/Slate/View/Window/MainWindow.axaml.cs @@ -57,10 +57,13 @@ private void UpdateVisualState(PageMarker page) protected override void OnLoaded() { - var hwnd = PlatformImpl!.Handle.Handle; - - ConfigureAsToolWindow(hwnd); + var hwnd = TryGetPlatformHandle()?.Handle ?? IntPtr.Zero; + if (hwnd != IntPtr.Zero) + { + ConfigureAsToolWindow(hwnd); + } + IsVisible = false; Position = HiddenDesktopPosition; diff --git a/Slate/ViewModel/Control/AuraColorControlViewModel.cs b/Slate/ViewModel/Control/AuraColorControlViewModel.cs index 6e6a935..05a05df 100644 --- a/Slate/ViewModel/Control/AuraColorControlViewModel.cs +++ b/Slate/ViewModel/Control/AuraColorControlViewModel.cs @@ -77,9 +77,7 @@ public bool FollowSystemAccentColor if (value) { - var color = AvaloniaLocator - .Current - .GetRequiredService() + var color = Application.Current!.PlatformSettings! .GetColorValues() .AccentColor1; diff --git a/Slate/ViewModel/Page/FansPageViewModel.cs b/Slate/ViewModel/Page/FansPageViewModel.cs index e43185f..03de698 100644 --- a/Slate/ViewModel/Page/FansPageViewModel.cs +++ b/Slate/ViewModel/Page/FansPageViewModel.cs @@ -64,9 +64,7 @@ public FansPageViewModel( _asusHalService = asusHalService; HardwareMonitor = hardwareMonitor; - var primaryColor = AvaloniaLocator - .Current - .GetRequiredService() + var primaryColor = Application.Current!.PlatformSettings! .GetColorValues() .AccentColor1 .ToSKColor();