Skip to content

Commit

Permalink
#30 - delinting
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeclayton committed Oct 12, 2023
1 parent 6062600 commit d116f54
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 43 deletions.
30 changes: 30 additions & 0 deletions src/FancyMouse.sln
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,47 @@ EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|ARM64 = Debug|ARM64
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
Release|ARM64 = Release|ARM64
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{EFE2A257-6979-4067-99A7-0C762492A8C7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EFE2A257-6979-4067-99A7-0C762492A8C7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EFE2A257-6979-4067-99A7-0C762492A8C7}.Debug|ARM64.ActiveCfg = Debug|Any CPU
{EFE2A257-6979-4067-99A7-0C762492A8C7}.Debug|ARM64.Build.0 = Debug|Any CPU
{EFE2A257-6979-4067-99A7-0C762492A8C7}.Debug|x64.ActiveCfg = Debug|Any CPU
{EFE2A257-6979-4067-99A7-0C762492A8C7}.Debug|x64.Build.0 = Debug|Any CPU
{EFE2A257-6979-4067-99A7-0C762492A8C7}.Debug|x86.ActiveCfg = Debug|Any CPU
{EFE2A257-6979-4067-99A7-0C762492A8C7}.Debug|x86.Build.0 = Debug|Any CPU
{EFE2A257-6979-4067-99A7-0C762492A8C7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EFE2A257-6979-4067-99A7-0C762492A8C7}.Release|Any CPU.Build.0 = Release|Any CPU
{EFE2A257-6979-4067-99A7-0C762492A8C7}.Release|ARM64.ActiveCfg = Release|Any CPU
{EFE2A257-6979-4067-99A7-0C762492A8C7}.Release|ARM64.Build.0 = Release|Any CPU
{EFE2A257-6979-4067-99A7-0C762492A8C7}.Release|x64.ActiveCfg = Release|Any CPU
{EFE2A257-6979-4067-99A7-0C762492A8C7}.Release|x64.Build.0 = Release|Any CPU
{EFE2A257-6979-4067-99A7-0C762492A8C7}.Release|x86.ActiveCfg = Release|Any CPU
{EFE2A257-6979-4067-99A7-0C762492A8C7}.Release|x86.Build.0 = Release|Any CPU
{9A9E15AF-3E85-4F20-AA23-A14ACA4805B5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9A9E15AF-3E85-4F20-AA23-A14ACA4805B5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9A9E15AF-3E85-4F20-AA23-A14ACA4805B5}.Debug|ARM64.ActiveCfg = Debug|Any CPU
{9A9E15AF-3E85-4F20-AA23-A14ACA4805B5}.Debug|ARM64.Build.0 = Debug|Any CPU
{9A9E15AF-3E85-4F20-AA23-A14ACA4805B5}.Debug|x64.ActiveCfg = Debug|Any CPU
{9A9E15AF-3E85-4F20-AA23-A14ACA4805B5}.Debug|x64.Build.0 = Debug|Any CPU
{9A9E15AF-3E85-4F20-AA23-A14ACA4805B5}.Debug|x86.ActiveCfg = Debug|Any CPU
{9A9E15AF-3E85-4F20-AA23-A14ACA4805B5}.Debug|x86.Build.0 = Debug|Any CPU
{9A9E15AF-3E85-4F20-AA23-A14ACA4805B5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9A9E15AF-3E85-4F20-AA23-A14ACA4805B5}.Release|Any CPU.Build.0 = Release|Any CPU
{9A9E15AF-3E85-4F20-AA23-A14ACA4805B5}.Release|ARM64.ActiveCfg = Release|Any CPU
{9A9E15AF-3E85-4F20-AA23-A14ACA4805B5}.Release|ARM64.Build.0 = Release|Any CPU
{9A9E15AF-3E85-4F20-AA23-A14ACA4805B5}.Release|x64.ActiveCfg = Release|Any CPU
{9A9E15AF-3E85-4F20-AA23-A14ACA4805B5}.Release|x64.Build.0 = Release|Any CPU
{9A9E15AF-3E85-4F20-AA23-A14ACA4805B5}.Release|x86.ActiveCfg = Release|Any CPU
{9A9E15AF-3E85-4F20-AA23-A14ACA4805B5}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
15 changes: 10 additions & 5 deletions src/FancyMouse/Helpers/ConfigHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ internal static class ConfigHelper
{
private static readonly HotKeyManager _hotKeyManager;

private static string? _appSettingsPath;
private static FileSystemWatcher? _appSettingsWatcher;

private static AppSettings? _appSettings;
Expand All @@ -18,6 +17,12 @@ static ConfigHelper()
ConfigHelper._hotKeyManager = new HotKeyManager();
}

public static string? AppSettingsPath
{
get;
private set;
}

public static AppSettings? AppSettings
{
get
Expand All @@ -33,7 +38,7 @@ public static AppSettings? AppSettings

public static void SetAppSettingsPath(string appSettingsPath)
{
_appSettingsPath = appSettingsPath;
ConfigHelper.AppSettingsPath = appSettingsPath;
}

public static void SetHotKeyEventHandler(EventHandler<HotKeyEventArgs> eventHandler)
Expand All @@ -51,7 +56,7 @@ public static void SetHotKeyEventHandler(EventHandler<HotKeyEventArgs> eventHand
public static void LoadAppSettings()
{
_hotKeyManager.SetHoKey(null);
_appSettings = AppSettingsReader.ReadFile(_appSettingsPath
_appSettings = AppSettingsReader.ReadFile(ConfigHelper.AppSettingsPath
?? throw new InvalidOperationException("AppSettings cannot be null"));
_hotKeyManager.SetHoKey(_appSettings?.Hotkey
?? throw new InvalidOperationException($"{nameof(_appSettings.Hotkey)} cannot be null"));
Expand All @@ -60,8 +65,8 @@ public static void LoadAppSettings()
public static void StartWatcher()
{
// set up the filesystem watcher
var path = Path.GetDirectoryName(_appSettingsPath) ?? throw new InvalidOperationException();
var filter = Path.GetFileName(_appSettingsPath) ?? throw new InvalidOperationException();
var path = Path.GetDirectoryName(ConfigHelper.AppSettingsPath) ?? throw new InvalidOperationException();
var filter = Path.GetFileName(ConfigHelper.AppSettingsPath) ?? throw new InvalidOperationException();
_appSettingsWatcher = new FileSystemWatcher(path, filter)
{
NotifyFilter = NotifyFilters.LastWrite,
Expand Down
21 changes: 0 additions & 21 deletions src/FancyMouse/Helpers/MouseHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,27 +44,6 @@ public static PointInfo GetCursorPosition()
point.x, point.y);
}

public static PointInfo GetCursorPosition(PointInfo location)
{
var pos = new POINT(0, 0);
var lpPoint = new LPPOINT(pos);

if (!User32.GetCursorPos(lpPoint))
{
throw new InvalidOperationException();
}

if (lpPoint.IsNull)
{
throw new InvalidOperationException();
}

pos = lpPoint.ToStructure();
lpPoint.Free();

return new PointInfo(pos.x, pos.y);
}

/// <summary>
/// Moves the cursor to the specified location.
/// </summary>
Expand Down
2 changes: 0 additions & 2 deletions src/FancyMouse/Hotkeys/HotKeyManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ public void SetHoKey(Keystroke? hotKey)
// do we need to unregister the existing hotkey first?
if ((this.HotKey is not null) && hwnd.HasValue)
{
// HotKeyHelper.PostPrivateThreadMessage(this.MessageLoop.NativeThreadId, HotKeyHelper.WM_PRIV_UNREGISTER_HOTKEY);
HotKeyHelper.PostPrivateMessage(hwnd.Value, HotKeyHelper.WM_PRIV_UNREGISTER_HOTKEY);
this.MessageSemaphore.Wait();
}
Expand All @@ -84,7 +83,6 @@ public void SetHoKey(Keystroke? hotKey)
// register the new hotkey
if ((this.HotKey is not null) && hwnd.HasValue)
{
// HotKeyHelper.PostPrivateThreadMessage(this.MessageLoop.NativeThreadId, HotKeyHelper.WM_PRIV_REGISTER_HOTKEY);
HotKeyHelper.PostPrivateMessage(hwnd.Value, HotKeyHelper.WM_PRIV_REGISTER_HOTKEY);
this.MessageSemaphore.Wait();
}
Expand Down
4 changes: 1 addition & 3 deletions src/FancyMouse/Hotkeys/MessageLoop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ internal sealed class MessageLoop
public MessageLoop(string name, Func<HWND> hwndCallback)
{
this.Name = name ?? throw new ArgumentNullException(nameof(name));

this.HwndCallback = hwndCallback ?? throw new ArgumentNullException(nameof(hwndCallback));

this.RunningSemaphore = new SemaphoreSlim(1);
Expand Down Expand Up @@ -159,8 +158,7 @@ public void Stop()
}

// signal to the internal message loop that it should stop
(this.CancellationTokenSource ?? throw new InvalidOperationException())
.Cancel();
this.CancellationTokenSource.Cancel();

// post a null message just in case GetMessageW needs a nudge to stop blocking the
// message loop - the loop will then notice that we've set the cancellation token,
Expand Down
6 changes: 3 additions & 3 deletions src/FancyMouse/Models/Settings/V1/AppConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
internal sealed class AppConfig
{
public AppConfig(
FancyMouseSettings? fancymouse)
FancyMouse? fancyMouse)
{
this.FancyMouse = fancymouse;
this.FancyMouse = fancyMouse;
}

public FancyMouseSettings? FancyMouse
public FancyMouse? FancyMouse
{
get;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

namespace FancyMouse.Models.Settings.V1;

public sealed class FancyMouseSettings
/// <summary>
/// Represents the "fancymouse"' node in the V1 config file
/// </summary>
public sealed class FancyMouse
{
public FancyMouseSettings(
public FancyMouse(
string? hotkey,
string? previewSize)
{
Expand Down
12 changes: 6 additions & 6 deletions src/FancyMouse/Models/Settings/V2/ScreenshotStyleSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,29 @@ namespace FancyMouse.Models.Settings.V2;
public sealed class ScreenshotStyleSettings
{
public ScreenshotStyleSettings(
MarginStyleSettings marginStyle,
BorderStyleSettings borderStyle,
BackgroundStyleSettings backgroundStyle)
MarginStyleSettings? marginStyle,
BorderStyleSettings? borderStyle,
BackgroundStyleSettings? backgroundStyle)
{
this.MarginStyle = marginStyle ?? throw new ArgumentNullException(nameof(marginStyle));
this.BorderStyle = borderStyle ?? throw new ArgumentNullException(nameof(borderStyle));
this.BackgroundStyle = backgroundStyle ?? throw new ArgumentNullException(nameof(backgroundStyle));
}

[JsonPropertyName("margin")]
public MarginStyleSettings MarginStyle
public MarginStyleSettings? MarginStyle
{
get;
}

[JsonPropertyName("border")]
public BorderStyleSettings BorderStyle
public BorderStyleSettings? BorderStyle
{
get;
}

[JsonPropertyName("background")]
public BackgroundStyleSettings BackgroundStyle
public BackgroundStyleSettings? BackgroundStyle
{
get;
}
Expand Down
2 changes: 1 addition & 1 deletion src/FancyMouse/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace FancyMouse;
internal static class Program
{
/// <summary>
/// The main entry point for the application.
/// The main entry point for the application.
/// </summary>
[STAThread]
private static void Main()
Expand Down

0 comments on commit d116f54

Please sign in to comment.