-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainWindow.xaml.cs
More file actions
98 lines (82 loc) · 2.67 KB
/
MainWindow.xaml.cs
File metadata and controls
98 lines (82 loc) · 2.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
using System;
using System.ComponentModel;
using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Interop;
using ClaudeAutoResponse.ViewModels;
namespace ClaudeAutoResponse
{
public partial class MainWindow : Window
{
[DllImport("dwmapi.dll")]
private static extern int DwmSetWindowAttribute(IntPtr hwnd, int attr, ref int attrValue, int attrSize);
private const int DWMWA_USE_IMMERSIVE_DARK_MODE = 20;
private MainViewModel _viewModel;
public MainWindow()
{
InitializeComponent();
_viewModel = new MainViewModel();
DataContext = _viewModel;
Loaded += MainWindow_Loaded;
Closing += MainWindow_Closing;
}
private void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
// Set dark title bar
SetDarkTitleBar();
// Restore window position
var settings = _viewModel.Settings;
if (settings.WindowLeft >= 0 && settings.WindowTop >= 0)
{
Left = settings.WindowLeft;
Top = settings.WindowTop;
}
else
{
WindowStartupLocation = WindowStartupLocation.CenterScreen;
}
}
private void SetDarkTitleBar()
{
try
{
var windowHelper = new WindowInteropHelper(this);
IntPtr hwnd = windowHelper.Handle;
if (hwnd != IntPtr.Zero)
{
int useDarkMode = 1;
DwmSetWindowAttribute(hwnd, DWMWA_USE_IMMERSIVE_DARK_MODE, ref useDarkMode, sizeof(int));
}
}
catch
{
// Silently fail on older Windows versions
}
}
private void MainWindow_Closing(object? sender, CancelEventArgs e)
{
// Save window position
_viewModel.Settings.WindowLeft = Left;
_viewModel.Settings.WindowTop = Top;
_viewModel.Settings.Save();
// Hide instead of close (minimize to tray)
e.Cancel = true;
Hide();
}
private void PinButton_Click(object sender, RoutedEventArgs e)
{
Topmost = !Topmost;
PinIcon.Opacity = Topmost ? 1.0 : 0.6;
}
private void RefreshButton_Click(object sender, RoutedEventArgs e)
{
_viewModel.RefreshWindows();
}
public void ForceClose()
{
Closing -= MainWindow_Closing;
Close();
}
public MainViewModel ViewModel => _viewModel;
}
}