From 198071300a555d4da1e8976738c157adeaa84b98 Mon Sep 17 00:00:00 2001 From: Spike Curtis Date: Fri, 7 Feb 2025 12:03:58 +0400 Subject: [PATCH] feat: Sign in Window views & view models --- App/App.csproj | 18 ++++++ App/App.xaml.cs | 5 +- App/DisplayScale.cs | 26 +++++++++ App/SignInTokenPage.xaml | 93 +++++++++++++++++++++++++++++++ App/SignInTokenPage.xaml.cs | 37 ++++++++++++ App/SignInURLPage.xaml | 53 ++++++++++++++++++ App/SignInURLPage.xaml.cs | 33 +++++++++++ App/SignInWindow.xaml | 15 +++++ App/SignInWindow.xaml.cs | 60 ++++++++++++++++++++ App/TrayWindow.xaml | 5 +- App/TrayWindow.xaml.cs | 26 ++++----- App/ViewModels/SignInViewModel.cs | 45 +++++++++++++++ 12 files changed, 400 insertions(+), 16 deletions(-) create mode 100644 App/DisplayScale.cs create mode 100644 App/SignInTokenPage.xaml create mode 100644 App/SignInTokenPage.xaml.cs create mode 100644 App/SignInURLPage.xaml create mode 100644 App/SignInURLPage.xaml.cs create mode 100644 App/SignInWindow.xaml create mode 100644 App/SignInWindow.xaml.cs create mode 100644 App/ViewModels/SignInViewModel.cs diff --git a/App/App.csproj b/App/App.csproj index cae1812..5f06f25 100644 --- a/App/App.csproj +++ b/App/App.csproj @@ -41,6 +41,24 @@ + + + MSBuild:Compile + + + + + + MSBuild:Compile + + + + + + MSBuild:Compile + + + MSBuild:Compile diff --git a/App/App.xaml.cs b/App/App.xaml.cs index 4fbde75..6081d69 100644 --- a/App/App.xaml.cs +++ b/App/App.xaml.cs @@ -1,3 +1,4 @@ +using Coder.Desktop.App.ViewModels; using Microsoft.UI.Xaml; namespace Coder.Desktop.App; @@ -5,9 +6,11 @@ namespace Coder.Desktop.App; public partial class App : Application { private TrayWindow? TrayWindow; + public SignInViewModel SignInViewModel { get; } public App() { + SignInViewModel = new SignInViewModel(); InitializeComponent(); } @@ -15,7 +18,7 @@ public App() protected override void OnLaunched(LaunchActivatedEventArgs args) { - TrayWindow = new TrayWindow(); + TrayWindow = new TrayWindow(SignInViewModel); TrayWindow.Closed += (sender, args) => { // TODO: wire up HandleClosedEvents properly diff --git a/App/DisplayScale.cs b/App/DisplayScale.cs new file mode 100644 index 0000000..3712351 --- /dev/null +++ b/App/DisplayScale.cs @@ -0,0 +1,26 @@ +using System; +using Microsoft.UI.Xaml; +using WinRT.Interop; +using System.Runtime.InteropServices; + +namespace Coder.Desktop.App; + +/// +/// A static utility class to house methods related to the visual scale of the display monitor. +/// +public static class DisplayScale +{ + public static double WindowScale(Window win) + { + var hwnd = WindowNative.GetWindowHandle(win); + var dpi = NativeApi.GetDpiForWindow(hwnd); + if (dpi == 0) return 1; // assume scale of 1 + return dpi / 96.0; // 96 DPI == 1 + } + + public class NativeApi + { + [DllImport("user32.dll")] + public static extern int GetDpiForWindow(IntPtr hwnd); + } +} diff --git a/App/SignInTokenPage.xaml b/App/SignInTokenPage.xaml new file mode 100644 index 0000000..97194ae --- /dev/null +++ b/App/SignInTokenPage.xaml @@ -0,0 +1,93 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +