Skip to content

Commit

Permalink
Merge pull request #14 from FaithBeam/startup
Browse files Browse the repository at this point in the history
Add Run at Startup Feature
  • Loading branch information
FaithBeam authored Sep 11, 2024
2 parents 906052d + 085d8c7 commit 3fc2cb5
Show file tree
Hide file tree
Showing 56 changed files with 927 additions and 113 deletions.
2 changes: 1 addition & 1 deletion .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"isRoot": true,
"tools": {
"csharpier": {
"version": "0.28.0",
"version": "0.29.1",
"commands": [
"dotnet-csharpier"
]
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/dotnet-desktop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ jobs:
-c ${{ env.CONFIGURATION }} \
-r ${{ matrix.rid }} \
-p:PublishSingleFile=true \
-p:SelfContained=true \
-p:IncludeNativeLibrariesForSelfExtract=true \
-p:IncludeAllContentForSelfExtract=true \
-p:SelfContained=true \
-p:EnableCompressionInSingleFile=true \
-p:DebugType=embedded \
-p:Version=${{ steps.gitversion.outputs.SemVer }} \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public void DefaultProfileSendsKeys()
{
SimulatedKeystrokesType = new MouseButtonPressedActionType(),
BlockOriginalMouseInput = true,
Keys = "wee"
Keys = "wee",
};
var testProvider = new TestProvider();
using var hook = new SimpleReactiveGlobalHook(globalHookProvider: testProvider);
Expand All @@ -51,7 +51,7 @@ public void DefaultProfileSendsKeys()
var evtDn = new UioHookEvent
{
Type = EventType.MousePressed,
Mouse = new MouseEventData { Button = MouseButton.Button3, }
Mouse = new MouseEventData { Button = MouseButton.Button3 },
};
// var evtUp = new UioHookEvent
// {
Expand All @@ -78,7 +78,7 @@ public void NonDefaultProfileSendsKeys()
{
SimulatedKeystrokesType = new MouseButtonPressedActionType(),
BlockOriginalMouseInput = true,
Keys = "wee"
Keys = "wee",
};
var testProvider = new TestProvider();
using var hook = new SimpleReactiveGlobalHook(globalHookProvider: testProvider);
Expand All @@ -103,7 +103,7 @@ public void NonDefaultProfileSendsKeys()
var evtDn = new UioHookEvent
{
Type = EventType.MousePressed,
Mouse = new MouseEventData { Button = MouseButton.Button3, }
Mouse = new MouseEventData { Button = MouseButton.Button3 },
};
// var evtUp = new UioHookEvent
// {
Expand All @@ -130,7 +130,7 @@ public void NonDefaultProfileNotSendKeys()
{
SimulatedKeystrokesType = new MouseButtonPressedActionType(),
BlockOriginalMouseInput = true,
Keys = "wee"
Keys = "wee",
};
var testProvider = new TestProvider();
using var hook = new SimpleReactiveGlobalHook(globalHookProvider: testProvider);
Expand All @@ -156,7 +156,7 @@ public void NonDefaultProfileNotSendKeys()
var evtDn = new UioHookEvent
{
Type = EventType.MousePressed,
Mouse = new MouseEventData { Button = MouseButton.Button3, }
Mouse = new MouseEventData { Button = MouseButton.Button3 },
};
// var evtUp = new UioHookEvent
// {
Expand All @@ -181,7 +181,7 @@ public void DefaultProfileSendsKeysReleased()
{
SimulatedKeystrokesType = new MouseButtonReleasedActionType(),
BlockOriginalMouseInput = true,
Keys = "wee"
Keys = "wee",
};
var testProvider = new TestProvider();
using var hook = new SimpleReactiveGlobalHook(globalHookProvider: testProvider);
Expand All @@ -206,7 +206,7 @@ public void DefaultProfileSendsKeysReleased()
var evtUp = new UioHookEvent
{
Type = EventType.MouseReleased,
Mouse = new MouseEventData { Button = MouseButton.Button3, }
Mouse = new MouseEventData { Button = MouseButton.Button3 },
};
RunHookAndWaitForStart(hook, testProvider);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using YMouseButtonControl.Core.ViewModels.Implementations.Dialogs;
using YMouseButtonControl.Core.ViewModels.Interfaces;
using YMouseButtonControl.Core.ViewModels.Interfaces.Dialogs;
using YMouseButtonControl.Core.ViewModels.ProfilesList;
using YMouseButtonControl.Core.ViewModels.ProfilesList.Features.Add;
using YMouseButtonControl.DataAccess.LiteDb;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ public enum ButtonMappings
Nothing,
Disabled,
SimulatedKeystrokes,
RightClick
RightClick,
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ public enum YMouseButton : ushort
MouseWheelUp,
MouseWheelDown,
MouseWheelLeft,
MouseWheelRight
MouseWheelRight,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using System;
using ReactiveUI;

namespace YMouseButtonControl.Core.DataAccess.Models.Implementations;

public class Setting : ReactiveObject, IEquatable<Setting>
{
private string? _value;

public int Id { get; set; }
public required string Name { get; set; }

public string? Value
{
get => _value;
set => this.RaiseAndSetIfChanged(ref _value, value);
}

public bool Equals(Setting? other)
{
if (ReferenceEquals(null, other))
return false;
if (ReferenceEquals(this, other))
return true;
return Id == other.Id && Name == other.Name && Value == other.Value;
}

public override bool Equals(object? obj)
{
if (ReferenceEquals(null, obj))
return false;
if (ReferenceEquals(this, obj))
return true;
if (obj.GetType() != this.GetType())
return false;
return Equals((Setting)obj);
}

public override int GetHashCode()
{
return HashCode.Combine(Id, Name, Value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace YMouseButtonControl.Core.DataAccess.Repositories;
public interface IRepository<T>
{
T GetById(string id);
T GetById(int id);
IEnumerable<T> GetAll();
void Add(T entity);
void Update(string id, T entity);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
public enum MouseButtonState
{
Pressed,
Released
Released,
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,12 @@ public ProfilesService(IUnitOfWorkFactory unitOfWorkFactory)
CurrentProfile = change.Reason switch
{
ChangeReason.Add => change.Current,
ChangeReason.Remove
=> _profiles
.Items.Where(x => x.DisplayPriority < change.Current.DisplayPriority)
.MaxBy(x => x.DisplayPriority)
?? throw new Exception("Unable to get next lower priority on remove"),
ChangeReason.Remove => _profiles
.Items.Where(x => x.DisplayPriority < change.Current.DisplayPriority)
.MaxBy(x => x.DisplayPriority)
?? throw new Exception("Unable to get next lower priority on remove"),
ChangeReason.Update => change.Current,
_ => throw new Exception("Unhandled change reason")
_ => throw new Exception("Unhandled change reason"),
};
});

Expand Down Expand Up @@ -90,7 +89,9 @@ private void CheckDefaultProfile()
var repository = unitOfWork.GetRepository<Profile>();
var model = repository.GetAll();
if (model.Any(x => x.Name == "Default"))
{
return;
}
var defaultProfile = new Profile
{
Checked = true,
Expand All @@ -111,7 +112,7 @@ private void CheckDefaultProfile()
MouseWheelUp = new NothingMapping(),
MouseWheelDown = new NothingMapping(),
MouseWheelLeft = new NothingMapping(),
MouseWheelRight = new NothingMapping()
MouseWheelRight = new NothingMapping(),
};
repository.Add(defaultProfile);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
using System;
using System.Linq;
using System.Xml.Linq;
using DynamicData;
using ReactiveUI;
using YMouseButtonControl.Core.DataAccess.Models.Implementations;
using YMouseButtonControl.Core.DataAccess.UnitOfWork;
using YMouseButtonControl.Core.Profiles.Interfaces;

namespace YMouseButtonControl.Core.Profiles.Implementations;

public class SettingsService : ReactiveObject, ISettingsService
{
private readonly IUnitOfWorkFactory _unitOfWorkFactory;
private readonly SourceCache<Setting, int> _settings;

public SettingsService(IUnitOfWorkFactory unitOfWorkFactory)
{
_unitOfWorkFactory = unitOfWorkFactory;
_settings = new SourceCache<Setting, int>(x => x.Id);
CheckDefaultSettings();
LoadSettingsFromDb();
}

public IObservable<IChangeSet<Setting, int>> Connect() => _settings.Connect();

public bool IsUnsavedChanges()
{
using var unitOfWork = _unitOfWorkFactory.Create();
var repository = unitOfWork.GetRepository<Setting>();
var dbSettings = repository.GetAll().ToList();
return _settings.Items.Count() != dbSettings.Count
|| _settings.Items.Where((p, i) => !p.Equals(dbSettings[i])).Any();
}

public Setting? GetSetting(string name)
{
using var unitOfWork = _unitOfWorkFactory.Create();
var repository = unitOfWork.GetRepository<Setting>();
return repository.GetAll().ToList().FirstOrDefault(x => x.Name == name);
}

public Setting UpdateSetting(int id, string value)
{
using var unitOfWork = _unitOfWorkFactory.Create();
var repository = unitOfWork.GetRepository<Setting>();
var dbSetting = repository.GetById(id);
dbSetting.Value = value;
repository.ApplyAction([dbSetting]);
return dbSetting;
}

private void LoadSettingsFromDb()
{
using var unitOfWork = _unitOfWorkFactory.Create();
var repository = unitOfWork.GetRepository<Setting>();
var model = repository.GetAll();
_settings.AddOrUpdate(model);
}

private void CheckDefaultSettings()
{
using var uow = _unitOfWorkFactory.Create();
var repo = uow.GetRepository<Setting>();
var model = repo.GetAll();
if (model.Any(x => x.Name == "StartMinimized"))
{
return;
}

var startMinimizedSetting = new Setting { Name = "StartMinimized", Value = "false" };
repo.Add(startMinimizedSetting);

uow.SaveChanges();
}
}
13 changes: 13 additions & 0 deletions YMouseButtonControl.Core/Profiles/Interfaces/ISettingsService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using DynamicData;
using YMouseButtonControl.Core.DataAccess.Models.Implementations;

namespace YMouseButtonControl.Core.Profiles.Interfaces;

public interface ISettingsService
{
IObservable<IChangeSet<Setting, int>> Connect();
bool IsUnsavedChanges();
Setting? GetSetting(string name);
Setting UpdateSetting(int id, string value);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ public enum WheelScrollDirection
VerticalUp = 1,
VerticalDown = 2,
HorizontalRight = 3,
HorizontalLeft = 4
HorizontalLeft = 4,
}
9 changes: 9 additions & 0 deletions YMouseButtonControl.Core/Services/IStartupInstallerService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace YMouseButtonControl.Core.Services;

public interface IStartupInstallerService
{
public bool ButtonEnabled();
public bool InstallStatus();
public void Install();
public void Uninstall();
}
Loading

0 comments on commit 3fc2cb5

Please sign in to comment.