Skip to content

Commit

Permalink
Use JSON for settings
Browse files Browse the repository at this point in the history
  • Loading branch information
TolikPylypchuk committed Feb 3, 2024
1 parent 577616d commit 1b4b6a9
Show file tree
Hide file tree
Showing 29 changed files with 189 additions and 252 deletions.
4 changes: 0 additions & 4 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@
<FileVersion>$(Version)</FileVersion>
</PropertyGroup>

<PropertyGroup>
<NoWarn>$(NoWarn);NETSDK1206</NoWarn>
</PropertyGroup>

<PropertyGroup Condition="'$(TargetOS)' == '' And $([MSBuild]::IsOSPlatform('Windows'))">
<TargetOS>Windows</TargetOS>
</PropertyGroup>
Expand Down
10 changes: 0 additions & 10 deletions build/KeyboardSwitch.Build/Build.Files.Pkg.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ public partial class Build
private const string AppInfoFile = "Info.plist";
private const string KeyboardSwitchUninstaller = nameof(KeyboardSwitchUninstaller);

private const string LibSqLite = "libe_sqlite3.dylib";
private const string LibUioHook = "libuiohook.dylib";
private const string LibAvaloniaNative = "libAvaloniaNative.dylib";
private const string LibHarfBuzzSharp = "libHarfBuzzSharp.dylib";
Expand Down Expand Up @@ -48,9 +47,6 @@ public partial class Build
private static AbsolutePath KeyboardSwitchSettingsExecutableFile =>
PublishOutputDirectory / KeyboardSwitchSettings;

private static AbsolutePath LibSqLiteFile =>
PublishOutputDirectory / LibSqLite;

private static AbsolutePath LibUioHookFile =>
PublishOutputDirectory / LibUioHook;

Expand All @@ -66,18 +62,12 @@ public partial class Build
private static AbsolutePath KeyboardSwitchAppExecutableFile =>
KeyboardSwitchAppMacOSDirectory / KeyboardSwitch;

private static AbsolutePath KeyboardSwitchAppLibSqLiteFile =>
KeyboardSwitchAppMacOSDirectory / LibSqLite;

private static AbsolutePath KeyboardSwitchAppLibUioHookFile =>
KeyboardSwitchAppMacOSDirectory / LibUioHook;

private static AbsolutePath KeyboardSwitchSettingsAppExecutableFile =>
KeyboardSwitchSettingsAppMacOSDirectory / KeyboardSwitchSettings;

private static AbsolutePath KeyboardSwitchSettingsAppLibSqLiteFile =>
KeyboardSwitchSettingsAppMacOSDirectory / LibSqLite;

private static AbsolutePath KeyboardSwitchSettingsAppLibAvaloniaNativeFile =>
KeyboardSwitchSettingsAppMacOSDirectory / LibAvaloniaNative;

Expand Down
4 changes: 0 additions & 4 deletions build/KeyboardSwitch.Build/Build.Targets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,6 @@ public partial class Build
KeyboardSwitchAppMacOSDirectory.CreateOrCleanDirectory();
CopyFileToDirectory(KeyboardSwitchExecutableFile, KeyboardSwitchAppMacOSDirectory);
CopyFileToDirectory(LibSqLiteFile, KeyboardSwitchAppMacOSDirectory);
CopyFileToDirectory(LibUioHookFile, KeyboardSwitchAppMacOSDirectory);
KeyboardSwitchAppResourcesDirectory.CreateOrCleanDirectory();
Expand All @@ -233,7 +232,6 @@ public partial class Build
CopyFileToDirectory(KeyboardSwitchSettingsExecutableFile, KeyboardSwitchSettingsAppMacOSDirectory);
CopyFileToDirectory(LibAvaloniaNativeFile, KeyboardSwitchSettingsAppMacOSDirectory);
CopyFileToDirectory(LibSqLiteFile, KeyboardSwitchSettingsAppMacOSDirectory);
CopyFileToDirectory(LibHarfBuzzSharpFile, KeyboardSwitchSettingsAppMacOSDirectory);
CopyFileToDirectory(LibSkiaSharpFile, KeyboardSwitchSettingsAppMacOSDirectory);
Expand Down Expand Up @@ -263,12 +261,10 @@ public partial class Build
{
Log.Information("Creating a macOS package containing the published project");
this.Sign(KeyboardSwitchAppLibSqLiteFile);
this.Sign(KeyboardSwitchAppLibUioHookFile);
this.Sign(KeyboardSwitchAppExecutableFile, hardenedRuntime: true);
this.Sign(KeyboardSwitchSettingsAppLibAvaloniaNativeFile);
this.Sign(KeyboardSwitchSettingsAppLibSqLiteFile);
this.Sign(KeyboardSwitchSettingsAppLibHarfBuzzSharpFile);
this.Sign(KeyboardSwitchSettingsAppLibSkiaSharpFile);
this.Sign(KeyboardSwitchSettingsAppExecutableFile, hardenedRuntime: true);
Expand Down
4 changes: 2 additions & 2 deletions build/KeyboardSwitch.Build/linux/keyboard-switch.spec
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ $INSTALL_DIR/KeyboardSwitch --stop

awk -F: '($3 >= 1000) && ($3 < 60000) && ($1 != "nobody") { print $1 }' /etc/passwd | while read -r CURRENT_USER
do
if [ -f "$(eval echo ~$CURRENT_USER)/.keyboard-switch/.setup-configured" ]
if [ -f "$(eval echo ~$CURRENT_USER)/.config/keyboard-switch/.setup-configured" ]
then
rm "$(eval echo ~$CURRENT_USER)/.keyboard-switch/.setup-configured"
rm "$(eval echo ~$CURRENT_USER)/.config/keyboard-switch/.setup-configured"
fi

if [ -f "$(eval echo ~$CURRENT_USER)/$SERVICE_DESKTOP_FILE" ]
Expand Down
4 changes: 2 additions & 2 deletions build/KeyboardSwitch.Build/linux/prerm
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ $INSTALL_DIR/KeyboardSwitch --stop

awk -F: '($3 >= 1000) && ($3 < 60000) && ($1 != "nobody") { print $1 }' /etc/passwd | while read -r CURRENT_USER
do
if [ -f "$(eval echo ~$CURRENT_USER)/.keyboard-switch/.setup-configured" ]
if [ -f "$(eval echo ~$CURRENT_USER)/.config/keyboard-switch/.setup-configured" ]
then
rm "$(eval echo ~$CURRENT_USER)/.keyboard-switch/.setup-configured"
rm "$(eval echo ~$CURRENT_USER)/.config/keyboard-switch/.setup-configured"
fi

if [ -f "$(eval echo ~$CURRENT_USER)/$SERVICE_DESKTOP_FILE" ]
Expand Down
4 changes: 2 additions & 2 deletions build/KeyboardSwitch.Build/linux/uninstall.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ GNOME_EXTENSION_DIR=$HOME/.local/share/gnome-shell/extensions/switch-layout@toli

$INSTALL_DIR/KeyboardSwitch --stop

if [ -f "$HOME/.keyboard-switch/.setup-configured" ]
if [ -f "$HOME/.config/keyboard-switch/.setup-configured" ]
then
rm "$HOME/.keyboard-switch/.setup-configured"
rm "$HOME/.config/keyboard-switch/.setup-configured"
fi

if [ -f "$SERVICE_DESKTOP_FILE" ]
Expand Down
28 changes: 0 additions & 28 deletions src/KeyboardSwitch.Core/BlobCacheFactory.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace KeyboardSwitch.Core;
namespace KeyboardSwitch.Core.Exceptions;

public sealed class IncompatibleAppVersionException : Exception
{
Expand Down
15 changes: 15 additions & 0 deletions src/KeyboardSwitch.Core/Exceptions/SettingsException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace KeyboardSwitch.Core.Exceptions;

public sealed class SettingsException : Exception
{
public SettingsException()
{ }

public SettingsException(string? message)
: base(message)
{ }

public SettingsException(string? message, Exception? innerException)
: base(message, innerException)
{ }
}
2 changes: 1 addition & 1 deletion src/KeyboardSwitch.Core/KeyboardSwitch.Core.csproj
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<ItemGroup>
<PackageReference Include="akavache" Version="9.1.20" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="SharpHook" Version="5.2.3" />
<PackageReference Include="SharpHook.Reactive" Version="5.2.3" />
<PackageReference Include="System.Interactive" Version="6.0.1" />
<PackageReference Include="System.Interactive.Async" Version="6.0.1" />
<PackageReference Include="System.Reactive" Version="6.0.0" />
<PackageReference Include="System.Text.Json" Version="8.0.1" />
</ItemGroup>
</Project>
13 changes: 0 additions & 13 deletions src/KeyboardSwitch.Core/ObservableExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
namespace KeyboardSwitch.Core;

using Akavache;

public static class ObservableExtensions
{
public static IObservable<Unit> Discard<T>(this IObservable<T> observable) =>
Expand Down Expand Up @@ -36,15 +34,4 @@ public static IObservable<T> WhereValueNotNull<T>(this IObservable<T?> observabl
await observer();
return Unit.Default;
}).Subscribe();

public static Task<bool> ContainsKey(this IBlobCache cache, string key)
{
var completionSource = new TaskCompletionSource<bool>();

cache.Get(key).Subscribe(
x => completionSource.SetResult(true),
ex => completionSource.SetResult(false));

return completionSource.Task;
}
}
4 changes: 1 addition & 3 deletions src/KeyboardSwitch.Core/ServiceExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ public static class ServiceExtensions
.AddSingleton<IEventSimulator, EventSimulator>()
.AddSingleton<IKeyboardHookService, SharpHookService>()
.AddSingleton<ITextService, ClipboardTextService>()
.AddSingleton(BlobCacheFactory.CreateBlobCache)
.AddSingleton<BlobCacheSettingsService>()
.AddSingleton<IAppSettingsService, BlobCacheSettingsService>()
.AddSingleton<IAppSettingsService, JsonSettingsService>()
.AddSingleton<ISwitchService, SwitchService>()
.AddSingleton<INamedPipeService, NamedPipeService>()
.AddSingleton<ISingleInstanceService, SingleInstanceService>();
Expand Down
135 changes: 0 additions & 135 deletions src/KeyboardSwitch.Core/Services/Settings/BlobCacheSettingsService.cs

This file was deleted.

0 comments on commit 1b4b6a9

Please sign in to comment.