Skip to content

Commit 6bb5e9e

Browse files
authored
Merge pull request #3 from immichFrame/dev.3rob3.touchExit
Added nativeoverlay to capture input events
2 parents 386b233 + 689f9bb commit 6bb5e9e

File tree

11 files changed

+970
-837
lines changed

11 files changed

+970
-837
lines changed

App.xaml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@
22
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
33
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
44
xmlns:local="clr-namespace:ImmichFrame_Screensaver"
5-
StartupUri="MainWindow.xaml">
5+
ThemeMode="System">
66
<Application.Resources>
7-
7+
<ResourceDictionary>
8+
<ResourceDictionary.MergedDictionaries>
9+
<ResourceDictionary Source="pack://application:,,,/PresentationFramework.Fluent;component/Themes/Fluent.xaml" />
10+
</ResourceDictionary.MergedDictionaries>
11+
</ResourceDictionary>
812
</Application.Resources>
913
</Application>

App.xaml.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
using System.Configuration;
2-
using System.Data;
3-
using System.Windows;
1+
using System.Windows;
42

53

64
namespace ImmichFrame_Screensaver
@@ -24,7 +22,7 @@ protected override void OnStartup(StartupEventArgs e)
2422
}
2523
else if (arg.StartsWith("/c"))
2624
{
27-
var settings = new Settings();
25+
var settings = new SettingsWindow();
2826
settings.ShowDialog();
2927
Shutdown();
3028
}

ImmichFrame_Screensaver.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<PublishSingleFile>true</PublishSingleFile>
1313
<IncludeNativeLibrariesInSingleFile>true</IncludeNativeLibrariesInSingleFile>
1414
<ApplicationIcon>AppIcon.ico</ApplicationIcon>
15-
<FileVersion>1.0.2.0</FileVersion>
15+
<FileVersion>1.0.3.0</FileVersion>
1616
</PropertyGroup>
1717

1818
<ItemGroup>
@@ -25,7 +25,7 @@
2525
</ItemGroup>
2626

2727
<ItemGroup>
28-
<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.3240.44" />
28+
<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.3537.50" />
29+
<FrameworkReference Include="Microsoft.WindowsDesktop.App.WindowsForms" />
2930
</ItemGroup>
30-
3131
</Project>

LICENSE

100644100755
Lines changed: 674 additions & 674 deletions
Large diffs are not rendered by default.

MainWindow.xaml.cs

Lines changed: 25 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -2,102 +2,56 @@
22
using System.IO;
33
using System.Runtime.InteropServices;
44
using System.Windows;
5+
using System.Windows.Interop;
56

67
namespace ImmichFrame_Screensaver
78
{
89
public partial class MainWindow : Window
910
{
10-
//public static string settingsPath = @"C:\ProgramData\ImmichFrame_Screensaver\Settings.json";
11-
public static string settingsPath = Path.Combine(Path.GetTempPath(), "ImmichFrame_Screensaver");
12-
private const int WH_KEYBOARD_LL = 13;
13-
private const int WH_MOUSE_LL = 14;
14-
15-
// Declare the hook procedure delegate with the correct signature and make it public
16-
public delegate IntPtr HookProc(int nCode, IntPtr wParam, IntPtr lParam);
17-
18-
// Hook handles
19-
private IntPtr _keyboardHookHandle = IntPtr.Zero;
20-
private IntPtr _mouseHookHandle = IntPtr.Zero;
21-
22-
// Delegate instances
23-
private HookProc _keyboardProc;
24-
private HookProc _mouseProc;
25-
26-
private bool _inputDetectionEnabled = false;
11+
private NativeOverlayWindow _nativeOverlay;
2712
public MainWindow()
2813
{
2914
InitializeComponent();
3015
Cursor = System.Windows.Input.Cursors.None;
3116
LoadWebView();
32-
StartInputDelayAsync();
33-
_keyboardProc = new HookProc(KeyboardHookProc);
34-
_mouseProc = new HookProc(MouseHookProc);
35-
}
36-
private async void StartInputDelayAsync()
37-
{
38-
_inputDetectionEnabled = false; // Disable input detection initially
39-
await Task.Delay(3000); // Delay for 2 seconds
40-
_inputDetectionEnabled = true; // Enable input detection
41-
SetUpHooks();
42-
}
43-
private void OpenSettings()
44-
{
45-
var settings = new Settings();
46-
settings.ShowDialog();
17+
Loaded += async (s, e) =>
18+
{
19+
await Task.Delay(3000); // 3 second delay
20+
// Start the native overlay in a new thread so it doesn't block the UI
21+
_ = Task.Run(() =>
22+
{
23+
using (_nativeOverlay = new NativeOverlayWindow())
24+
{
25+
_nativeOverlay.RunMessageLoop();
26+
}
27+
});
28+
};
4729
}
48-
//private void LoadWebView()
49-
//{
50-
// if (File.Exists(Path.Combine(MainWindow.settingsPath, "Settings.json")))
51-
// {
52-
// var strUrl = File.ReadAllText(Path.Combine(MainWindow.settingsPath, "Settings.json"));
53-
// if (!string.IsNullOrWhiteSpace(strUrl))
54-
// {
55-
// WebView.Source = new Uri(strUrl);
56-
// }
57-
// else
58-
// {
59-
// MessageBox.Show("Please configure settings!");
60-
// CloseScreensaver();
61-
// }
62-
// }
63-
// else
64-
// {
65-
// WebView.Source = new Uri("https://github.com/immichFrame/ImmichFrame/raw/main/design/16x9%20frame.svg");
66-
// }
67-
//}
6830
private async void LoadWebView()
6931
{
7032
try
7133
{
72-
string userDataFolder = Path.Combine(settingsPath, "WebView2");
73-
74-
// Ensure directory exists
34+
string userDataFolder = Path.Combine(Settings.appDataFolder, "WebView2");
7535
Directory.CreateDirectory(userDataFolder);
7636

7737
var options = new CoreWebView2EnvironmentOptions("--allow-insecure-localhost --allow-running-insecure-content");
7838
var env = await CoreWebView2Environment.CreateAsync(null, userDataFolder, options);
7939
await WebView.EnsureCoreWebView2Async(env);
8040

81-
// Determine URL
82-
string url = "https://github.com/immichFrame/ImmichFrame/raw/main/design/16x9%20frame.svg";
41+
// Use SavedUrl if valid, else fallback to default
42+
string defaultUrl = "https://github.com/immichFrame/ImmichFrame/raw/main/design/16x9%20frame.svg";
43+
string url = !string.IsNullOrWhiteSpace(Settings.CurrentSettings.SavedUrl)
44+
? Settings.CurrentSettings.SavedUrl
45+
: defaultUrl;
8346

84-
string settingsFile = Path.Combine(MainWindow.settingsPath, "Settings.json");
85-
if (File.Exists(settingsFile))
47+
// Validate URL
48+
if (!Uri.TryCreate(url, UriKind.Absolute, out var uriResult))
8649
{
87-
string strUrl = File.ReadAllText(settingsFile);
88-
if (!string.IsNullOrWhiteSpace(strUrl))
89-
{
90-
url = strUrl.Trim();
91-
}
92-
else
93-
{
94-
MessageBox.Show("Please configure settings!");
95-
CloseScreensaver();
96-
return;
97-
}
50+
MessageBox.Show("Invalid URL in settings. Using placeholder.");
51+
uriResult = new Uri(defaultUrl);
9852
}
9953

100-
WebView.Source = new Uri(url);
54+
WebView.Source = uriResult;
10155
}
10256
catch (Exception ex)
10357
{
@@ -106,55 +60,9 @@ private async void LoadWebView()
10660
}
10761
}
10862

109-
private void SetUpHooks()
110-
{
111-
// Set the keyboard hook
112-
_keyboardHookHandle = SetWindowsHookEx(WH_KEYBOARD_LL, _keyboardProc, IntPtr.Zero, 0);
113-
// Set the mouse hook
114-
_mouseHookHandle = SetWindowsHookEx(WH_MOUSE_LL, _mouseProc, IntPtr.Zero, 0);
115-
}
116-
117-
private IntPtr KeyboardHookProc(int nCode, IntPtr wParam, IntPtr lParam)
118-
{
119-
if (_inputDetectionEnabled && nCode >= 0)
120-
{
121-
CloseScreensaver();
122-
}
123-
return CallNextHookEx(_keyboardHookHandle, nCode, wParam, lParam);
124-
}
125-
126-
private IntPtr MouseHookProc(int nCode, IntPtr wParam, IntPtr lParam)
127-
{
128-
if (_inputDetectionEnabled && nCode >= 0)
129-
{
130-
CloseScreensaver();
131-
}
132-
return CallNextHookEx(_mouseHookHandle, nCode, wParam, lParam);
133-
}
134-
135-
13663
private void CloseScreensaver()
13764
{
13865
Application.Current.Shutdown();
13966
}
140-
[DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
141-
public static extern IntPtr SetWindowsHookEx(int idHook, HookProc lpfn, IntPtr hmod, uint dwThreadId);
142-
143-
[DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
144-
public static extern IntPtr CallNextHookEx(IntPtr idHook, int nCode, IntPtr wParam, IntPtr lParam);
145-
146-
[DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
147-
public static extern bool UnhookWindowsHookEx(IntPtr idHook);
148-
149-
[DllImport("kernel32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
150-
public static extern IntPtr GetModuleHandle(string lpModuleName);
151-
152-
// Ensure hooks are removed when the window is closed
153-
protected override void OnClosed(EventArgs e)
154-
{
155-
base.OnClosed(e);
156-
UnhookWindowsHookEx(_keyboardHookHandle);
157-
UnhookWindowsHookEx(_mouseHookHandle);
158-
}
15967
}
16068
}

0 commit comments

Comments
 (0)