mirror of
https://github.com/Stone-Red-Code/InvLock.git
synced 2026-09-04 09:06:13 +02:00
Implement settings and add icon
This commit is contained in:
Binary file not shown.
|
After Width: | Height: | Size: 259 KiB |
@@ -1,16 +1,22 @@
|
|||||||
using System.Reflection;
|
using System.ComponentModel;
|
||||||
|
using System.Reflection;
|
||||||
|
|
||||||
namespace InvLock.DataContexts;
|
namespace InvLock.DataContexts;
|
||||||
|
|
||||||
internal class MainWindowDataContext
|
internal class MainWindowDataContext : INotifyPropertyChanged
|
||||||
{
|
{
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
public string Title => $"{App.AppName} - Dev {AppVersion}";
|
public string Title => $"{App.AppName} - Dev {AppVersion}";
|
||||||
#else
|
#else
|
||||||
|
|
||||||
|
public event PropertyChangedEventHandler? PropertyChanged;
|
||||||
|
|
||||||
public string Title => $"{App.AppName} - {AppVersion}";
|
public string Title => $"{App.AppName} - {AppVersion}";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
public string AppName => App.AppName;
|
public string AppName => App.AppName;
|
||||||
|
|
||||||
public string AppVersion => Assembly.GetExecutingAssembly().GetName().Version?.ToString() ?? "Unknown";
|
public string AppVersion => Assembly.GetExecutingAssembly().GetName().Version?.ToString() ?? "Unknown";
|
||||||
|
|
||||||
|
public Settings Settings { get; } = Settings.Load();
|
||||||
}
|
}
|
||||||
@@ -7,8 +7,13 @@
|
|||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<UseWPF>true</UseWPF>
|
<UseWPF>true</UseWPF>
|
||||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||||
|
<ApplicationIcon>Assets\logo.ico</ApplicationIcon>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<None Remove="icon.ico" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="CuteUtils" Version="1.0.0" />
|
<PackageReference Include="CuteUtils" Version="1.0.0" />
|
||||||
<PackageReference Include="SharpHook" Version="5.3.8" />
|
<PackageReference Include="SharpHook" Version="5.3.8" />
|
||||||
@@ -16,4 +21,8 @@
|
|||||||
<PackageReference Include="WPF-UI.Tray" Version="3.0.5" />
|
<PackageReference Include="WPF-UI.Tray" Version="3.0.5" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Resource Include="Assets\logo.ico" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -15,14 +15,14 @@ namespace InvLock;
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public partial class LockWindow : Window
|
public partial class LockWindow : Window
|
||||||
{
|
{
|
||||||
private const bool HideWindows = false;
|
|
||||||
private readonly SimpleGlobalHook hook = new SimpleGlobalHook();
|
private readonly SimpleGlobalHook hook = new SimpleGlobalHook();
|
||||||
private readonly Dictionary<KeyCode, DateTime> pressedKeys = [];
|
private readonly Dictionary<KeyCode, DateTime> pressedKeys = [];
|
||||||
|
private readonly Settings settings;
|
||||||
private List<IntPtr> windows = [];
|
private List<IntPtr> windows = [];
|
||||||
private bool isOpen = true;
|
private bool isOpen = true;
|
||||||
private bool suppressInput = false;
|
private bool suppressInput = false;
|
||||||
|
|
||||||
public LockWindow()
|
public LockWindow(Settings settings)
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
|
||||||
@@ -42,6 +42,8 @@ public partial class LockWindow : Window
|
|||||||
|
|
||||||
Owner = w;
|
Owner = w;
|
||||||
|
|
||||||
|
this.settings = settings;
|
||||||
|
|
||||||
hook.MouseMoved += Hook_Mouse;
|
hook.MouseMoved += Hook_Mouse;
|
||||||
hook.MouseDragged += Hook_Mouse;
|
hook.MouseDragged += Hook_Mouse;
|
||||||
hook.MousePressed += Hook_Mouse;
|
hook.MousePressed += Hook_Mouse;
|
||||||
@@ -59,7 +61,7 @@ public partial class LockWindow : Window
|
|||||||
|
|
||||||
private void ActivateLockScreen()
|
private void ActivateLockScreen()
|
||||||
{
|
{
|
||||||
if (HideWindows)
|
if (settings.HideWindows)
|
||||||
{
|
{
|
||||||
MinimizeWindows();
|
MinimizeWindows();
|
||||||
}
|
}
|
||||||
@@ -71,7 +73,7 @@ public partial class LockWindow : Window
|
|||||||
{
|
{
|
||||||
_ = Activate();
|
_ = Activate();
|
||||||
|
|
||||||
textBlock.Text = "Lock Screen Active";
|
textBlock.Text = settings.LockText;
|
||||||
textBlock.Stroke = (Brush)FindResource("PaletteRedBrush");
|
textBlock.Stroke = (Brush)FindResource("PaletteRedBrush");
|
||||||
|
|
||||||
Animation();
|
Animation();
|
||||||
@@ -120,7 +122,7 @@ public partial class LockWindow : Window
|
|||||||
{
|
{
|
||||||
if (e.Reason == Microsoft.Win32.SessionSwitchReason.SessionUnlock)
|
if (e.Reason == Microsoft.Win32.SessionSwitchReason.SessionUnlock)
|
||||||
{
|
{
|
||||||
if (HideWindows)
|
if (settings.HideWindows)
|
||||||
{
|
{
|
||||||
RestoreWindows();
|
RestoreWindows();
|
||||||
}
|
}
|
||||||
@@ -131,7 +133,7 @@ public partial class LockWindow : Window
|
|||||||
|
|
||||||
await Task.Delay(500);
|
await Task.Delay(500);
|
||||||
|
|
||||||
textBlock.Text = "Lock Screen Inactive";
|
textBlock.Text = settings.UnlockText;
|
||||||
textBlock.Stroke = (Brush)FindResource("PaletteGreenBrush");
|
textBlock.Stroke = (Brush)FindResource("PaletteGreenBrush");
|
||||||
|
|
||||||
Animation();
|
Animation();
|
||||||
|
|||||||
+12
-5
@@ -31,15 +31,22 @@
|
|||||||
<RowDefinition Height="*" />
|
<RowDefinition Height="*" />
|
||||||
</Grid.RowDefinitions>
|
</Grid.RowDefinitions>
|
||||||
|
|
||||||
<ui:TitleBar Title="{Binding Title}" Grid.Row="0" />
|
<ui:TitleBar Title="{Binding Title}">
|
||||||
|
<ui:TitleBar.Icon>
|
||||||
|
<ui:ImageIcon Source="pack://application:,,,/Assets/logo.ico" />
|
||||||
|
</ui:TitleBar.Icon>
|
||||||
|
</ui:TitleBar>
|
||||||
|
|
||||||
<tray:NotifyIcon Grid.Row="0" FocusOnLeftClick="True" MenuOnRightClick="True" LeftClick="NotifyIcon_LeftClick" TooltipText="Wpf.Ui.Demo.Simple">
|
<tray:NotifyIcon Grid.Row="0" FocusOnLeftClick="True" MenuOnRightClick="True" LeftClick="NotifyIcon_LeftClick" TooltipText="{Binding AppName}">
|
||||||
<tray:NotifyIcon.Menu>
|
<tray:NotifyIcon.Menu>
|
||||||
<ContextMenu>
|
<ContextMenu>
|
||||||
<MenuItem Header="Settings" Click="SettingsMenuItem_Click" />
|
<MenuItem Header="Settings" Click="SettingsMenuItem_Click" />
|
||||||
<MenuItem Header="Quit" Click="QuitMenuItem_Click" />
|
<MenuItem Header="Quit" Click="QuitMenuItem_Click" />
|
||||||
</ContextMenu>
|
</ContextMenu>
|
||||||
</tray:NotifyIcon.Menu>
|
</tray:NotifyIcon.Menu>
|
||||||
|
<tray:NotifyIcon.Icon>
|
||||||
|
<BitmapImage UriSource="pack://application:,,,/Assets/logo.ico" />
|
||||||
|
</tray:NotifyIcon.Icon>
|
||||||
</tray:NotifyIcon>
|
</tray:NotifyIcon>
|
||||||
|
|
||||||
<ui:DynamicScrollViewer Grid.Row="1" VirtualizingPanel.ScrollUnit="Pixel">
|
<ui:DynamicScrollViewer Grid.Row="1" VirtualizingPanel.ScrollUnit="Pixel">
|
||||||
@@ -80,21 +87,21 @@
|
|||||||
<ui:CardControl.Header>
|
<ui:CardControl.Header>
|
||||||
<ui:TextBlock Grid.Row="0" FontTypography="Body" Text="Show desktop while locked" />
|
<ui:TextBlock Grid.Row="0" FontTypography="Body" Text="Show desktop while locked" />
|
||||||
</ui:CardControl.Header>
|
</ui:CardControl.Header>
|
||||||
<ui:ToggleSwitch Grid.Column="1" IsChecked="False" OffContent="Off" OnContent="On" />
|
<ui:ToggleSwitch Grid.Column="1" IsChecked="{Binding Settings.HideWindows}" OffContent="Off" OnContent="On" />
|
||||||
</ui:CardControl>
|
</ui:CardControl>
|
||||||
|
|
||||||
<ui:CardControl Margin="0,0,0,12" Icon="{ui:SymbolIcon Symbol=LockClosed24}" Height="75">
|
<ui:CardControl Margin="0,0,0,12" Icon="{ui:SymbolIcon Symbol=LockClosed24}" Height="75">
|
||||||
<ui:CardControl.Header>
|
<ui:CardControl.Header>
|
||||||
<ui:TextBlock Grid.Row="0" FontTypography="Body" Text="Lock text" />
|
<ui:TextBlock Grid.Row="0" FontTypography="Body" Text="Lock text" />
|
||||||
</ui:CardControl.Header>
|
</ui:CardControl.Header>
|
||||||
<ui:TextBox Grid.Column="1" MinWidth="200" PlaceholderText="Lock screen active" />
|
<ui:TextBox Grid.Column="1" MinWidth="200" Text="{Binding Settings.LockText, UpdateSourceTrigger=PropertyChanged}" PlaceholderText="Type your lock text here" />
|
||||||
</ui:CardControl>
|
</ui:CardControl>
|
||||||
|
|
||||||
<ui:CardControl Margin="0,0,0,12" Icon="{ui:SymbolIcon Symbol=LockOpen24}" Height="75">
|
<ui:CardControl Margin="0,0,0,12" Icon="{ui:SymbolIcon Symbol=LockOpen24}" Height="75">
|
||||||
<ui:CardControl.Header>
|
<ui:CardControl.Header>
|
||||||
<ui:TextBlock Grid.Row="0" FontTypography="Body" Text="Unlock text" />
|
<ui:TextBlock Grid.Row="0" FontTypography="Body" Text="Unlock text" />
|
||||||
</ui:CardControl.Header>
|
</ui:CardControl.Header>
|
||||||
<ui:TextBox Grid.Column="1" MinWidth="200" PlaceholderText="Lock screen inactive" />
|
<ui:TextBox Grid.Column="1" MinWidth="200" Text="{Binding Settings.UnlockText, UpdateSourceTrigger=PropertyChanged}" PlaceholderText="Type your unlock text here" />
|
||||||
</ui:CardControl>
|
</ui:CardControl>
|
||||||
|
|
||||||
<ui:TextBlock Margin="0,24,0,8" FontTypography="BodyStrong" Text="About" />
|
<ui:TextBlock Margin="0,24,0,8" FontTypography="BodyStrong" Text="About" />
|
||||||
|
|||||||
@@ -12,12 +12,13 @@ namespace InvLock;
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public partial class MainWindow : FluentWindow
|
public partial class MainWindow : FluentWindow
|
||||||
{
|
{
|
||||||
|
private readonly MainWindowDataContext mainWindowDataContext = new MainWindowDataContext();
|
||||||
private LockWindow? lockWindow;
|
private LockWindow? lockWindow;
|
||||||
private bool blockWindowClosing = true;
|
private bool blockWindowClosing = true;
|
||||||
|
|
||||||
public MainWindow()
|
public MainWindow()
|
||||||
{
|
{
|
||||||
DataContext = new MainWindowDataContext();
|
DataContext = mainWindowDataContext;
|
||||||
|
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
|
||||||
@@ -51,7 +52,7 @@ public partial class MainWindow : FluentWindow
|
|||||||
{
|
{
|
||||||
Close();
|
Close();
|
||||||
|
|
||||||
lockWindow = new LockWindow();
|
lockWindow = new LockWindow(mainWindowDataContext.Settings);
|
||||||
lockWindow.Show();
|
lockWindow.Show();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -62,6 +63,8 @@ public partial class MainWindow : FluentWindow
|
|||||||
|
|
||||||
private void FluentWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e)
|
private void FluentWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e)
|
||||||
{
|
{
|
||||||
|
mainWindowDataContext.Settings.Save();
|
||||||
|
|
||||||
if (blockWindowClosing)
|
if (blockWindowClosing)
|
||||||
{
|
{
|
||||||
e.Cancel = true;
|
e.Cancel = true;
|
||||||
|
|||||||
+66
-5
@@ -1,8 +1,69 @@
|
|||||||
namespace InvLock;
|
using System.ComponentModel;
|
||||||
|
using System.IO;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
using System.Text.Json;
|
||||||
|
|
||||||
internal class Settings
|
namespace InvLock;
|
||||||
|
|
||||||
|
public class Settings : INotifyPropertyChanged
|
||||||
{
|
{
|
||||||
public bool HideWindows { get; set; } = false;
|
public event PropertyChangedEventHandler? PropertyChanged;
|
||||||
public string LockText { get; set; } = "Lock Screen Active";
|
|
||||||
public string UnlockText { get; set; } = "Lock Screen Inactive";
|
private static readonly string settingsPath = Path.Combine(App.ApplicationDataPath, "settings.json");
|
||||||
|
private bool hideWindows = false;
|
||||||
|
private string lockText = "Lock Screen Active";
|
||||||
|
|
||||||
|
private string unlockText = "Lock Screen Inactive";
|
||||||
|
|
||||||
|
public bool HideWindows
|
||||||
|
{
|
||||||
|
get => hideWindows;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
hideWindows = value;
|
||||||
|
OnPropertyChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public string LockText
|
||||||
|
{
|
||||||
|
get => lockText;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
lockText = value;
|
||||||
|
OnPropertyChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public string UnlockText
|
||||||
|
{
|
||||||
|
get => unlockText;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
unlockText = value;
|
||||||
|
OnPropertyChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Settings Load()
|
||||||
|
{
|
||||||
|
if (File.Exists(settingsPath))
|
||||||
|
{
|
||||||
|
string json = File.ReadAllText(settingsPath);
|
||||||
|
return JsonSerializer.Deserialize<Settings>(json) ?? new Settings();
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Settings();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Save()
|
||||||
|
{
|
||||||
|
string json = JsonSerializer.Serialize(this);
|
||||||
|
File.WriteAllText(settingsPath, json);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void OnPropertyChanged([CallerMemberName] string? name = null)
|
||||||
|
{
|
||||||
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user