Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable nullable reference types #48

Merged
merged 5 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions FluentAutoClicker/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ namespace FluentAutoClicker;
/// </summary>
public partial class App : Application
{
public static Window Window { get; private set; } = null!;

/// <summary>
/// Initializes the singleton application object. This is the first line of authored code
/// executed, and as such is the logical equivalent of main() or WinMain().
Expand All @@ -45,6 +47,4 @@ protected override void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs ar
Window = new MainWindow();
Window.Activate();
}

public static Window Window { get; private set; }
}
1 change: 1 addition & 0 deletions FluentAutoClicker/FluentAutoClicker.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<RuntimeIdentifiers>win-x86;win-x64;win-arm64</RuntimeIdentifiers>
<PublishProfile>win-$(Platform).pubxml</PublishProfile>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<UseWinUI>true</UseWinUI>
<EnableMsixTooling>true</EnableMsixTooling>
<DefineConstants>DISABLE_XAML_GENERATED_MAIN</DefineConstants>
Expand Down
2 changes: 1 addition & 1 deletion FluentAutoClicker/Helpers/AutoClicker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public static class AutoClicker
[DllImport("user32.dll", SetLastError = true)]
private static extern uint SendInput(uint nInputs, Input[] pInputs, int cbSize);

private static Thread _autoClickerThread;
private static Thread? _autoClickerThread;
private static bool _isAutoClickerRunning;

/// <summary>
Expand Down
12 changes: 6 additions & 6 deletions FluentAutoClicker/Helpers/WindowMessageHook.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class WindowMessageHook : IEquatable<WindowMessageHook>, IDisposable
private static readonly ConcurrentDictionary<nint, WindowMessageHook> Hooks = new();
private static readonly Subclassproc Proc = SubclassProc;

public event EventHandler<MessageEventArgs> Message;
public event EventHandler<MessageEventArgs>? Message;
private nint _hWnd;

public WindowMessageHook(Window window) : this(GetHandle(window)) { }
Expand Down Expand Up @@ -97,7 +97,7 @@ private static nint GetHandle(Window window)

private static nint SubclassProc(nint hWnd, uint uMsg, nint wParam, nint lParam, nint uIdSubclass, uint dwRefData)
{
if (Hooks.TryGetValue(hWnd, out WindowMessageHook hook))
if (Hooks.TryGetValue(hWnd, out WindowMessageHook? hook))
{
MessageEventArgs e = new(hWnd, uMsg, wParam, lParam);
hook.OnMessage(hook, e);
Expand All @@ -114,17 +114,17 @@ public override int GetHashCode()
return _hWnd.GetHashCode();
}

public override string ToString()
public override string? ToString()
{
return _hWnd.ToString();
}

public override bool Equals(object obj)
public override bool Equals(object? obj)
{
return Equals(obj as WindowMessageHook);
}

public virtual bool Equals(WindowMessageHook other)
public virtual bool Equals(WindowMessageHook? other)
{
return other != null && _hWnd.Equals(other._hWnd);
}
Expand All @@ -145,4 +145,4 @@ public MessageEventArgs(nint hWnd, uint uMsg, nint wParam, nint lParam)
public nint WParam { get; }
public nint LParam { get; }
public virtual nint? Result { get; set; }
}
}
6 changes: 3 additions & 3 deletions FluentAutoClicker/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ private static bool DecideRedirection()
bool isRedirect = false;
AppActivationArguments args = AppInstance.GetCurrent().GetActivatedEventArgs();
ExtendedActivationKind kind = args.Kind;
AppInstance keyInstance = AppInstance.FindOrRegisterForKey("MySingleInstanceApp");
AppInstance keyInstance = AppInstance.FindOrRegisterForKey("FluentAutoClickerApp");

if (keyInstance.IsCurrent)
{
Expand All @@ -71,7 +71,7 @@ private static bool DecideRedirection()
[DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
private static extern IntPtr CreateEvent(
IntPtr lpEventAttributes, bool bManualReset,
bool bInitialState, string lpName);
bool bInitialState, string? lpName);

[DllImport("kernel32.dll")]
private static extern bool SetEvent(IntPtr hEvent);
Expand Down Expand Up @@ -109,7 +109,7 @@ public static void RedirectActivationTo(AppActivationArguments args,
_ = SetForegroundWindow(process.MainWindowHandle);
}

private static void OnActivated(object sender, AppActivationArguments args)
private static void OnActivated(object? sender, AppActivationArguments args)
{
_ = args.Kind;
}
Expand Down
Loading