Skip to content

Commit c70be14

Browse files
fix: retarget to .NET 10, rename namespace to Controller2Mouse, cleanup dead code and empty catch blocks
1 parent 16f5b87 commit c70be14

8 files changed

Lines changed: 47 additions & 54 deletions

File tree

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
- name: Setup .NET
1919
uses: actions/setup-dotnet@v4
2020
with:
21-
dotnet-version: '11.0.x'
21+
dotnet-version: '10.0.x'
2222
include-prerelease: true
2323

2424
- name: Restore dependencies

Controller2Mouse/App.xaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
<Application x:Class="GameController_Helper.App"
1+
<Application x:Class="Controller2Mouse.App"
22
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
33
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4-
xmlns:local="clr-namespace:GameController_Helper"
4+
xmlns:local="clr-namespace:Controller2Mouse"
55
StartupUri="MainWindow.xaml"
66
ThemeMode="System">
77
<Application.Resources>

Controller2Mouse/App.xaml.cs

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

5-
namespace GameController_Helper;
3+
namespace Controller2Mouse;
64

7-
/// <summary>
8-
/// Interaction logic for App.xaml
9-
/// </summary>
10-
#pragma warning disable WPF0001
115
public partial class App : Application
126
{
137
}

Controller2Mouse/Controller2Mouse.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
<PropertyGroup>
44
<OutputType>WinExe</OutputType>
5-
<TargetFramework>net11.0-windows10.0.26100.0</TargetFramework>
6-
<RootNamespace>GameController_Helper</RootNamespace>
5+
<TargetFramework>net10.0-windows10.0.26100.0</TargetFramework>
6+
<RootNamespace>Controller2Mouse</RootNamespace>
77
<Nullable>enable</Nullable>
88
<ImplicitUsings>enable</ImplicitUsings>
99
<UseWPF>true</UseWPF>

Controller2Mouse/ControllerToMouseMapper.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
using System.Windows.Threading;
33
using System.Diagnostics;
44

5-
namespace GameController_Helper;
5+
namespace Controller2Mouse;
66

77
public class ControllerToMouseMapper
88
{
@@ -191,7 +191,10 @@ private void Timer_Tick(object? sender, EventArgs e)
191191
{
192192
Process.Start(new ProcessStartInfo("osk.exe") { UseShellExecute = true });
193193
}
194-
catch { }
194+
catch (Exception ex)
195+
{
196+
System.Diagnostics.Debug.WriteLine($"Failed to launch osk.exe: {ex.Message}");
197+
}
195198
_bothThumbsDown = true;
196199

197200
// 如果之前有单按下的状态,先释放

Controller2Mouse/MainWindow.xaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
<Window x:Class="GameController_Helper.MainWindow"
1+
<Window x:Class="Controller2Mouse.MainWindow"
22
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
33
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
44
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
55
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
6-
xmlns:local="clr-namespace:GameController_Helper"
6+
xmlns:local="clr-namespace:Controller2Mouse"
77
mc:Ignorable="d"
88
Title="GameController Helper" Height="500" Width="700"
99
Background="Transparent"

Controller2Mouse/MainWindow.xaml.cs

Lines changed: 32 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,10 @@
11
using System.Runtime.InteropServices;
2-
using System.Text;
32
using System.Windows;
43
using System.Windows.Controls;
5-
using System.Windows.Data;
6-
using System.Windows.Documents;
7-
using System.Windows.Input;
84
using System.Windows.Interop;
95
using System.Windows.Media;
10-
using System.Windows.Media.Imaging;
11-
using System.Windows.Navigation;
12-
using System.Windows.Shapes;
136

14-
namespace GameController_Helper;
7+
namespace Controller2Mouse;
158

169
/// <summary>
1710
/// Interaction logic for MainWindow.xaml
@@ -40,12 +33,6 @@ public MainWindow()
4033

4134
if (Application.Current != null)
4235
{
43-
#pragma warning disable WPF0001
44-
// 尝试监听主题变化 (如果支持)
45-
try {
46-
// Application.Current.ActualThemeModeChanged += (s, e) => { UpdateThemeResources(); ApplyThemeToTitleBar(); };
47-
} catch {}
48-
#pragma warning restore WPF0001
4936
UpdateThemeResources();
5037
}
5138

@@ -62,41 +49,47 @@ public MainWindow()
6249
private void MainWindow_SourceInitialized(object? sender, EventArgs e)
6350
{
6451
var hwnd = new WindowInteropHelper(this).Handle;
65-
66-
// 启用 Mica
67-
int micaValue = DWMSBT_MICA;
68-
DwmSetWindowAttribute(hwnd, DWMWA_SYSTEMBACKDROP_TYPE, ref micaValue, Marshal.SizeOf(typeof(int)));
69-
70-
// 标题栏主题
52+
53+
try
54+
{
55+
int micaValue = DWMSBT_MICA;
56+
DwmSetWindowAttribute(hwnd, DWMWA_SYSTEMBACKDROP_TYPE, ref micaValue, Marshal.SizeOf(typeof(int)));
57+
}
58+
catch (Exception ex)
59+
{
60+
System.Diagnostics.Debug.WriteLine($"Failed to set Mica backdrop: {ex.Message}");
61+
}
62+
7163
ApplyThemeToTitleBar();
7264
}
7365

7466
private void ApplyThemeToTitleBar()
7567
{
7668
var hwnd = new WindowInteropHelper(this).Handle;
77-
bool isDark = false;
78-
79-
try {
80-
#pragma warning disable WPF0001
81-
// 尝试获取实际主题
82-
var theme = Application.Current.ThemeMode;
83-
#pragma warning restore WPF0001
84-
isDark = IsCurrentlyDarkMode();
85-
} catch { }
86-
87-
int darkValue = isDark ? 1 : 0;
88-
DwmSetWindowAttribute(hwnd, DWMWA_USE_IMMERSIVE_DARK_MODE, ref darkValue, Marshal.SizeOf(typeof(int)));
69+
bool isDark = IsCurrentlyDarkMode();
70+
71+
try
72+
{
73+
int darkValue = isDark ? 1 : 0;
74+
DwmSetWindowAttribute(hwnd, DWMWA_USE_IMMERSIVE_DARK_MODE, ref darkValue, Marshal.SizeOf(typeof(int)));
75+
}
76+
catch (Exception ex)
77+
{
78+
System.Diagnostics.Debug.WriteLine($"Failed to set title bar theme: {ex.Message}");
79+
}
8980
}
9081

91-
private bool IsCurrentlyDarkMode()
82+
private static bool IsCurrentlyDarkMode()
9283
{
93-
// 简单的深色模式检测逻辑
9484
try
9585
{
9686
var res = Microsoft.Win32.Registry.GetValue(@"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize", "AppsUseLightTheme", 1);
9787
if (res != null && (int)res == 0) return true;
9888
}
99-
catch { }
89+
catch (Exception ex)
90+
{
91+
System.Diagnostics.Debug.WriteLine($"Failed to detect dark mode: {ex.Message}");
92+
}
10093
return false;
10194
}
10295

@@ -178,7 +171,10 @@ private void SetLanguage(string cultureCode)
178171
}
179172
}
180173
}
181-
catch { }
174+
catch (Exception ex)
175+
{
176+
System.Diagnostics.Debug.WriteLine($"Failed to set language: {ex.Message}");
177+
}
182178
}
183179

184180
private void LanguageComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)

Controller2Mouse/MouseSimulator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using System.Runtime.InteropServices;
22

3-
namespace GameController_Helper;
3+
namespace Controller2Mouse;
44

55
public static class MouseSimulator
66
{

0 commit comments

Comments
 (0)