Skip to content

Commit

Permalink
Merge pull request #28 from mikeclayton/feature/refactor
Browse files Browse the repository at this point in the history
Released in v0.0.16-preview
  • Loading branch information
mikeclayton authored Jul 25, 2023
2 parents 5a5175d + 5e26818 commit 5dfae19
Show file tree
Hide file tree
Showing 44 changed files with 645 additions and 228 deletions.
49 changes: 23 additions & 26 deletions .github/workflows/01_build_test_publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:

defaults:
run:
shell: bash
shell: powershell

env:

Expand All @@ -36,49 +36,46 @@ jobs:
with:
dotnet-version: 7.0.x

- name: dotnet version
- name: dotnet info
working-directory: ${{ env.BUILD_PATH }}
run: dotnet --version
run: dotnet --info

- name: dotnet restore
working-directory: ${{ env.BUILD_PATH }}
run: dotnet restore

- name: dotnet build
working-directory: ${{ env.BUILD_PATH }}
run: dotnet build --configuration "$CONFIG_NAME" --no-restore
run: dotnet build --configuration "${{ env.CONFIG_NAME }}" --no-restore

- name: dotnet test
working-directory: ${{ env.BUILD_PATH }}
run: dotnet test --configuration "$CONFIG_NAME" --no-build --filter "TestCategory!=Performance"
run: dotnet test --configuration "${{ env.CONFIG_NAME }}" --no-build --filter "TestCategory!=Performance"

- name: dotnet publish
working-directory: ${{ env.BUILD_PATH }}
run: dotnet publish "./FancyMouse/FancyMouse.csproj" --configuration "$CONFIG_NAME" --no-build --output "$PUBLISH_PATH"
run: dotnet publish "./FancyMouse/FancyMouse.csproj" --configuration "${{ env.CONFIG_NAME }}" --no-build --output "${{ env.PUBLISH_PATH }}/net7.0-windows"

- name: upload binaries
uses: actions/upload-artifact@v3
with:
name: app
path: .build/app

- name: dotnet tool jb inspectcode
working-directory: ${{ env.BUILD_PATH }}
run: |
dotnet new tool-manifest
dotnet tool install jetbrains.resharper.globaltools
dotnet tool run jb inspectcode "./FancyMouse.sln" -output="../.build/out/jb-inspectcode.xml" --no-build
#- name: zip release
# working-directory: ${{ env.BUILD_PATH }}
# run: |
# & "C:\Program Files\7-Zip\7z.exe" a "FancyMouse-preview-v0.0.0.zip" "${{ env.PUBLISH_PATH }}"

- name: upload jb-inspectcode.xml
- name: upload release
uses: actions/upload-artifact@v3
with:
name: jb-inspectcode.xml
path: .build/out/jb-inspectcode.xml
name: FancyMouse-v0.0.0-preview
path: .build/app

#- name: zip
#- name: dotnet tool jb inspectcode
# working-directory: ${{ env.BUILD_PATH }}
# run: |
# sudo apt-get update
# sudo apt-get install -y zip
# echo "version = ${{ github.ref_name }}"
# zip -r "$PUBLISH_PATH" FancyMouse-${{ github.ref_name }}.zip
# dotnet new tool-manifest
# dotnet tool install jetbrains.resharper.globaltools
# dotnet tool run jb inspectcode "./FancyMouse.sln" -output="../.build/out/jb-inspectcode.xml" --no-build

#- name: upload jb-inspectcode.xml
# uses: actions/upload-artifact@v3
# with:
# name: jb-inspectcode.xml
# path: .build/out/jb-inspectcode.xml
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

A modified version of FancyMouse is now incorporated into Microsoft [PowerToys](https://github.com/microsoft/PowerToys) and renamed "Mouse Jump".

I'll continue to maintain the FancyMouse repo as an incubator for new features going forward.
I'll continue to maintain the FancyMouse repo as an incubator, and new features will arrive here first before being submitted to PowerToys into their review process.

----

Expand Down
17 changes: 14 additions & 3 deletions src/FancyMouse.UnitTests/FancyMouse.UnitTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,24 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.0.2" />
<PackageReference Include="MSTest.TestFramework" Version="3.0.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.0-preview-23364-03" />
<PackageReference Include="MSTest.TestAdapter" Version="3.1.1" />
<PackageReference Include="MSTest.TestFramework" Version="3.1.1" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\FancyMouse\FancyMouse.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Update="Microsoft.CodeAnalysis.NetAnalyzers" Version="8.0.0-preview1.23165.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Update="StyleCop.Analyzers" Version="1.2.0-beta.507">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

</Project>
2 changes: 2 additions & 0 deletions src/FancyMouse.UnitTests/TestUtils/SerializationUtils.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Text.Json;

namespace FancyMouse.UnitTests.TestUtils;

internal static class SerializationUtils
{
public static string SerializeAnonymousType<T>(T value)
Expand All @@ -9,6 +10,7 @@ public static string SerializeAnonymousType<T>(T value)
{
WriteIndented = true,
};

return JsonSerializer.Serialize(value, options);
}
}
21 changes: 16 additions & 5 deletions src/FancyMouse/FancyMouse.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="8.0.0-preview.4.23259.5" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0" />
<PackageReference Include="NLog" Version="5.1.3" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0-preview.6.23329.7" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="8.0.0-preview.6.23329.7" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0-preview.6.23329.7" />
<PackageReference Include="NLog" Version="5.2.2" />
<PackageReference Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
<PackageReference Include="System.Drawing.Common" Version="7.0.0" />
<PackageReference Include="System.Drawing.Common" Version="8.0.0-preview.5.23280.5" />
</ItemGroup>

<ItemGroup>
Expand All @@ -50,4 +50,15 @@
</EmbeddedResource>
</ItemGroup>

<ItemGroup>
<PackageReference Update="Microsoft.CodeAnalysis.NetAnalyzers" Version="8.0.0-preview1.23165.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Update="StyleCop.Analyzers" Version="1.2.0-beta.507">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

</Project>
97 changes: 97 additions & 0 deletions src/FancyMouse/Helpers/ConfigHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
using FancyMouse.HotKeys;
using FancyMouse.Models.Settings;

namespace FancyMouse.Helpers;

internal static class ConfigHelper
{
private static readonly HotKeyManager _hotKeyManager;

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

private static AppSettings? _appSettings;
private static EventHandler<HotKeyEventArgs>? _hotKeyPressed;

static ConfigHelper()
{
ConfigHelper._hotKeyManager = new HotKeyManager();
}

public static AppSettings? AppSettings
{
get
{
if (_appSettings is null)
{
ConfigHelper.LoadAppSettings();
}

return _appSettings;
}
}

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

public static void SetHotKeyEventHandler(EventHandler<HotKeyEventArgs> eventHandler)
{
var evt = _hotKeyPressed;
if (evt is not null)
{
_hotKeyManager.HotKeyPressed -= evt;
}

_hotKeyPressed = eventHandler;
_hotKeyManager.HotKeyPressed += eventHandler;
}

public static void LoadAppSettings()
{
_hotKeyManager.SetHoKey(null);
_appSettings = AppSettingsReader.ReadFile(_appSettingsPath
?? throw new InvalidOperationException("AppSettings cannot be null"));
_hotKeyManager.SetHoKey(_appSettings?.Hotkey
?? throw new InvalidOperationException($"{nameof(_appSettings.Hotkey)} cannot be null"));
}

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();
_appSettingsWatcher = new FileSystemWatcher(path, filter)
{
NotifyFilter = NotifyFilters.LastWrite,
EnableRaisingEvents = true,
};
_appSettingsWatcher.Changed += ConfigHelper.OnAppSettingsChanged;
}

private static void OnAppSettingsChanged(object sender, FileSystemEventArgs e)
{
if (e.ChangeType != WatcherChangeTypes.Changed)
{
return;
}

// the file might not have been released yet by the application that saved it
// and caused the file system event (e.g. notepad) so we need to do a couple
// of retries to give it a change to release the lock so we can load the file contents.
for (var i = 0; i < 3; i++)
{
try
{
ConfigHelper.LoadAppSettings();
break;
}
catch (IOException ex)
{
Console.WriteLine(ex.ToString());
Thread.Sleep(250);
}
}
}
}
Loading

0 comments on commit 5dfae19

Please sign in to comment.