From d5e00c29ef8ffdf0f7ce6075a956ac2c8b13f5c4 Mon Sep 17 00:00:00 2001 From: Stone_Red <56473591+Stone-Red-Code@users.noreply.github.com> Date: Mon, 29 Dec 2025 14:02:59 +0100 Subject: [PATCH] Fix startup behavior and properly focus blur windows --- .../DataContexts/MainWindowDataContext.cs | 11 ++++++++++- src/InvLock/LockWindow.xaml.cs | 6 ++++-- src/InvLock/MainWindow.xaml | 2 -- src/InvLock/MainWindow.xaml.cs | 16 ++++++++++++++-- src/InvLock/Settings.cs | 11 +++++++++++ 5 files changed, 39 insertions(+), 7 deletions(-) diff --git a/src/InvLock/DataContexts/MainWindowDataContext.cs b/src/InvLock/DataContexts/MainWindowDataContext.cs index 9910baa..cc61b66 100644 --- a/src/InvLock/DataContexts/MainWindowDataContext.cs +++ b/src/InvLock/DataContexts/MainWindowDataContext.cs @@ -5,6 +5,7 @@ using InvLock.Utilities; using SharpHook.Native; using System.ComponentModel; +using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; @@ -22,7 +23,15 @@ internal partial class MainWindowDataContext(Func lockWindowAccesso public string AppName => App.AppName; - public string AppVersion => Assembly.GetEntryAssembly()?.GetCustomAttribute()?.InformationalVersion ?? "Unknown"; + public string AppVersion + { + get + { + Assembly assembly = Assembly.GetExecutingAssembly(); + FileVersionInfo fileVersionInfo = FileVersionInfo.GetVersionInfo(assembly.Location); + return fileVersionInfo.ProductVersion ?? "Unknown"; + } + } public Settings Settings { get; } = Settings.Load(); diff --git a/src/InvLock/LockWindow.xaml.cs b/src/InvLock/LockWindow.xaml.cs index 8da10a1..133100c 100644 --- a/src/InvLock/LockWindow.xaml.cs +++ b/src/InvLock/LockWindow.xaml.cs @@ -122,7 +122,7 @@ public partial class LockWindow : Window MinimizeWindows(); } - Dispatcher.Invoke(() => + _ = Dispatcher.Invoke(async () => { lastMousePosition = WpfScreenHelper.MouseHelper.MousePosition; @@ -136,11 +136,13 @@ public partial class LockWindow : Window Height = bounds.Height, Left = bounds.Left, Top = bounds.Top, + Topmost = true }; blurWindows.Add(blurWindow); blurWindow.Show(); - _ = blurWindow.Activate(); + + blurWindow.Topmost = false; } _ = WindowsApi.SetCursorPosition(new Point(100000, 100000)); diff --git a/src/InvLock/MainWindow.xaml b/src/InvLock/MainWindow.xaml index ae3c409..942d352 100644 --- a/src/InvLock/MainWindow.xaml +++ b/src/InvLock/MainWindow.xaml @@ -18,8 +18,6 @@ WindowBackdropType="Mica" WindowCornerPreference="Round" WindowStartupLocation="CenterScreen" - WindowState="Minimized" - ShowInTaskbar="False" Loaded="Window_Loaded" Closing="FluentWindow_Closing" Closed="FluentWindow_Closed" diff --git a/src/InvLock/MainWindow.xaml.cs b/src/InvLock/MainWindow.xaml.cs index aca9690..944f798 100644 --- a/src/InvLock/MainWindow.xaml.cs +++ b/src/InvLock/MainWindow.xaml.cs @@ -18,12 +18,12 @@ public partial class MainWindow : FluentWindow public MainWindow() { + SystemThemeWatcher.Watch(this); + mainWindowDataContext = new MainWindowDataContext(() => lockWindow); DataContext = mainWindowDataContext; InitializeComponent(); - - SystemThemeWatcher.Watch(this); } internal void RestoreWindow() @@ -53,6 +53,18 @@ public partial class MainWindow : FluentWindow { lockWindow = new LockWindow(mainWindowDataContext.Settings); lockWindow.Show(); + + if (mainWindowDataContext.Settings.FirstRun) + { + mainWindowDataContext.Settings.FirstRun = false; + RestoreWindow(); + } + else + { + ShowInTaskbar = false; + WindowState = WindowState.Minimized; + Visibility = Visibility.Collapsed; + } } private void NotifyIcon_LeftClick(Wpf.Ui.Tray.Controls.NotifyIcon sender, RoutedEventArgs e) diff --git a/src/InvLock/Settings.cs b/src/InvLock/Settings.cs index 4a057d6..073e939 100644 --- a/src/InvLock/Settings.cs +++ b/src/InvLock/Settings.cs @@ -20,6 +20,7 @@ public class Settings : INotifyPropertyChanged private bool blurScreen = false; private string lockText = "Lock Screen Active"; private string theme = "Windows default"; + private bool firstRun = true; private HashSet lockShortcut = [KeyCode.VcLeftControl, KeyCode.VcLeftShift, KeyCode.VcL]; private HashSet unlockShortcut = [KeyCode.VcLeftControl, KeyCode.VcLeftShift, KeyCode.VcL]; @@ -76,6 +77,16 @@ public class Settings : INotifyPropertyChanged } } + public bool FirstRun + { + get => firstRun; + set + { + firstRun = value; + OnPropertyChanged(); + } + } + [JsonIgnore] public string LockShortcutText => string.Join(" + ", LockShortcut.Select(key => key.ToString()[2..]));