Skip to content

Commit 9a53be9

Browse files
Merge pull request #6 from Stone-Red-Code/develop
Develop
2 parents beb6fce + f0dbf46 commit 9a53be9

File tree

12 files changed

+298
-6
lines changed

12 files changed

+298
-6
lines changed

installer/Installer.iss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
[Setup]
1212
; NOTE: The value of AppId uniquely identifies this application. Do not use the same AppId value in installers for other applications.
1313
; (To generate a new GUID, click Tools | Generate GUID inside the IDE.)
14-
AppId=68d780d4-b946-4154-8815-e4632e5ec5d8
14+
AppId=4B2411E5-1AE9-450C-AF2F-9A515ECBB9DF
1515
AppName={#MyAppName}
1616
AppVersion={#MyAppVersion}
1717
;AppVerName={#MyAppName} {#MyAppVersion}

installer/InvLock-Installer.exe

19.1 KB
Binary file not shown.

src/InvLock/BlurWindow.xaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<Window x:Class="InvLock.BlurWindow"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
5+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
6+
xmlns:local="clr-namespace:InvLock"
7+
mc:Ignorable="d"
8+
Loaded="Window_Loaded"
9+
WindowStyle="None"
10+
MouseDown="Window_MouseDown"
11+
AllowsTransparency="True"
12+
Background="Black"
13+
Opacity="0"
14+
Title="BlurWindow" Height="450" Width="800">
15+
</Window>

src/InvLock/BlurWindow.xaml.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using InvLock.Utilities;
2+
3+
using System.Windows;
4+
5+
namespace InvLock;
6+
7+
/// <summary>
8+
/// Interaction logic for BlurWindow.xaml
9+
/// </summary>
10+
public partial class BlurWindow : Window
11+
{
12+
public BlurWindow()
13+
{
14+
InitializeComponent();
15+
}
16+
17+
private void Window_Loaded(object sender, RoutedEventArgs e)
18+
{
19+
WindowsApi.EnableBlur(this);
20+
}
21+
22+
private void Window_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
23+
{
24+
DragMove();
25+
}
26+
}

src/InvLock/DataContexts/MainWindowDataContext.cs

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
using CommunityToolkit.Mvvm.Input;
22

3+
using InvLock.Utilities;
4+
35
using SharpHook.Native;
46

7+
using System.ComponentModel;
58
using System.Reflection;
9+
using System.Runtime.CompilerServices;
610

711
namespace InvLock.DataContexts;
812

9-
internal partial class MainWindowDataContext(Func<LockWindow?> lockWindowAccessor)
13+
internal partial class MainWindowDataContext(Func<LockWindow?> lockWindowAccessor) : INotifyPropertyChanged
1014
{
15+
public event PropertyChangedEventHandler? PropertyChanged;
16+
1117
#if DEBUG
1218
public string Title => $"{App.AppName} - Dev {AppVersion}";
1319
#else
@@ -16,10 +22,28 @@ internal partial class MainWindowDataContext(Func<LockWindow?> lockWindowAccesso
1622

1723
public string AppName => App.AppName;
1824

19-
public string AppVersion => Assembly.GetExecutingAssembly().GetName().Version?.ToString() ?? "Unknown";
25+
public string AppVersion => Assembly.GetEntryAssembly()?.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion ?? "Unknown";
2026

2127
public Settings Settings { get; } = Settings.Load();
2228

29+
public bool IsAutoStartEnabled
30+
{
31+
get => StartupManager.IsAutoStartEnabled();
32+
set
33+
{
34+
if (value)
35+
{
36+
_ = StartupManager.EnableAutoStart();
37+
}
38+
else
39+
{
40+
_ = StartupManager.DisableAutoStart();
41+
}
42+
43+
OnPropertyChanged();
44+
}
45+
}
46+
2347
[RelayCommand]
2448
public async Task RecordLockShortcut()
2549
{
@@ -55,4 +79,9 @@ public async Task RecordUnlockShortcut()
5579
Settings.UnlockShortcut = unlockShortcut;
5680
}
5781
}
82+
83+
protected void OnPropertyChanged([CallerMemberName] string? name = null)
84+
{
85+
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
86+
}
5887
}

src/InvLock/InvLock.csproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
<UseWPF>true</UseWPF>
99
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
1010
<ApplicationIcon>Assets\logo.ico</ApplicationIcon>
11+
<Version>1.1.0.0</Version>
12+
<AssemblyVersion>1.1.0.0</AssemblyVersion>
13+
<FileVersion>1.1.0.0</FileVersion>
14+
<IncludeSourceRevisionInInformationalVersion>false</IncludeSourceRevisionInInformationalVersion>
1115
</PropertyGroup>
1216

1317
<ItemGroup>
@@ -17,9 +21,11 @@
1721
<ItemGroup>
1822
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.4.0" />
1923
<PackageReference Include="CuteUtils" Version="1.0.0" />
24+
<PackageReference Include="Interop.IWshRuntimeLibrary" Version="1.0.1" />
2025
<PackageReference Include="SharpHook" Version="5.3.8" />
2126
<PackageReference Include="WPF-UI" Version="4.0.0" />
2227
<PackageReference Include="WPF-UI.Tray" Version="4.0.0" />
28+
<PackageReference Include="WpfScreenHelper" Version="2.1.1" />
2329
</ItemGroup>
2430

2531
<ItemGroup>

src/InvLock/LockWindow.xaml.cs

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ public partial class LockWindow : Window
1919
private readonly SimpleGlobalHook hook = new SimpleGlobalHook();
2020
private readonly Dictionary<KeyCode, DateTime> pressedKeys = [];
2121
private readonly Settings settings;
22+
private readonly List<BlurWindow> blurWindows = [];
2223
private List<IntPtr> windows = [];
24+
private Point lastMousePosition;
2325
private bool isOpen = true;
2426
private bool suppressInput = false;
2527

@@ -120,11 +122,32 @@ private void ActivateLockScreen()
120122
MinimizeWindows();
121123
}
122124

123-
isOpen = true;
124-
suppressInput = true;
125-
126125
Dispatcher.Invoke(() =>
127126
{
127+
lastMousePosition = WpfScreenHelper.MouseHelper.MousePosition;
128+
129+
if (settings.BlurScreen)
130+
{
131+
foreach (Rect bounds in WpfScreenHelper.Screen.AllScreens.Select(s => s.WpfBounds))
132+
{
133+
BlurWindow blurWindow = new()
134+
{
135+
Width = bounds.Width,
136+
Height = bounds.Height,
137+
Left = bounds.Left,
138+
Top = bounds.Top,
139+
};
140+
141+
blurWindows.Add(blurWindow);
142+
blurWindow.Show();
143+
}
144+
145+
_ = WindowsApi.SetCursorPosition(new Point(100000, 100000));
146+
}
147+
148+
isOpen = true;
149+
suppressInput = true;
150+
128151
_ = Activate();
129152

130153
textBlock.Text = settings.LockText;
@@ -155,6 +178,9 @@ private void DeactivateLockScreen()
155178

156179
isOpen = true;
157180

181+
_ = WindowsApi.SetCursorPosition(lastMousePosition);
182+
blurWindows.ForEach(w => w.Close());
183+
158184
textBlock.Text = settings.UnlockText;
159185
textBlock.Stroke = (Brush)FindResource("PaletteGreenBrush");
160186

@@ -203,6 +229,9 @@ private async void SystemEvents_SessionSwitch(object sender, Microsoft.Win32.Ses
203229

204230
isOpen = true;
205231

232+
_ = WindowsApi.SetCursorPosition(lastMousePosition);
233+
blurWindows.ForEach(w => w.Close());
234+
206235
_ = Activate();
207236

208237
await Task.Delay(500);

src/InvLock/MainWindow.xaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,34 @@
7979
</ComboBox>
8080
</ui:CardControl>
8181

82+
<ui:CardControl Margin="0,0,0,12" Icon="{ui:SymbolIcon Symbol=Clock24}" Height="75">
83+
<ui:CardControl.Header>
84+
<Grid>
85+
<Grid.RowDefinitions>
86+
<RowDefinition Height="Auto" />
87+
<RowDefinition Height="Auto" />
88+
</Grid.RowDefinitions>
89+
<ui:TextBlock Grid.Row="0" FontTypography="Body" Text="Run at startup" />
90+
<ui:TextBlock Grid.Row="1" Foreground="{ui:ThemeResource TextFillColorTertiaryBrush}" FontSize="12" Text="Start InvLock when you sign in to Windows" />
91+
</Grid>
92+
</ui:CardControl.Header>
93+
<ui:ToggleSwitch Grid.Column="1" IsChecked="{Binding IsAutoStartEnabled}" OffContent="Off" OnContent="On" />
94+
</ui:CardControl>
95+
8296
<ui:CardControl Margin="0,0,0,12" Icon="{ui:SymbolIcon Symbol=Window24}" Height="75">
8397
<ui:CardControl.Header>
8498
<ui:TextBlock Grid.Row="0" FontTypography="Body" Text="Show desktop while locked" />
8599
</ui:CardControl.Header>
86100
<ui:ToggleSwitch Grid.Column="1" IsChecked="{Binding Settings.HideWindows}" OffContent="Off" OnContent="On" />
87101
</ui:CardControl>
88102

103+
<ui:CardControl Margin="0,0,0,12" Icon="{ui:SymbolIcon Symbol=Blur24}" Height="75">
104+
<ui:CardControl.Header>
105+
<ui:TextBlock Grid.Row="0" FontTypography="Body" Text="Blur screen while locked" />
106+
</ui:CardControl.Header>
107+
<ui:ToggleSwitch Grid.Column="1" IsChecked="{Binding Settings.BlurScreen}" OffContent="Off" OnContent="On" />
108+
</ui:CardControl>
109+
89110
<ui:CardControl Margin="0,0,0,12" Icon="{ui:SymbolIcon Symbol=WindowShield24}" Height="75">
90111
<ui:CardControl.Header>
91112
<ui:TextBlock Grid.Row="0" FontTypography="Body" Text="Use windows lock screen to unlock" />

src/InvLock/MainWindow.xaml.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ private void FluentWindow_Closing(object sender, System.ComponentModel.CancelEve
7171
e.Cancel = true;
7272

7373
ShowInTaskbar = false;
74+
WindowState = WindowState.Minimized;
7475
Visibility = Visibility.Collapsed;
7576
}
7677
}

src/InvLock/Settings.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public class Settings : INotifyPropertyChanged
1717
private static readonly string settingsPath = Path.Combine(App.ApplicationDataPath, "settings.json");
1818
private bool useWindowsLockScreen = true;
1919
private bool hideWindows = false;
20+
private bool blurScreen = false;
2021
private string lockText = "Lock Screen Active";
2122
private string theme = "Windows default";
2223
private HashSet<KeyCode> lockShortcut = [KeyCode.VcLeftControl, KeyCode.VcLeftShift, KeyCode.VcL];
@@ -34,6 +35,16 @@ public bool HideWindows
3435
}
3536
}
3637

38+
public bool BlurScreen
39+
{
40+
get => blurScreen;
41+
set
42+
{
43+
blurScreen = value;
44+
OnPropertyChanged();
45+
}
46+
}
47+
3748
public bool UseWindowsLockScreen
3849
{
3950
get => useWindowsLockScreen;

0 commit comments

Comments
 (0)