-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from FaithBeam/startup
Add Run at Startup Feature
- Loading branch information
Showing
56 changed files
with
927 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,5 +5,5 @@ public enum ButtonMappings | |
Nothing, | ||
Disabled, | ||
SimulatedKeystrokes, | ||
RightClick | ||
RightClick, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
YMouseButtonControl.Core/DataAccess/Models/Implementations/Setting.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,5 +3,5 @@ | |
public enum MouseButtonState | ||
{ | ||
Pressed, | ||
Released | ||
Released, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
YMouseButtonControl.Core/Profiles/Implementations/SettingsService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
13
YMouseButtonControl.Core/Profiles/Interfaces/ISettingsService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
YMouseButtonControl.Core/Services/IStartupInstallerService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |
Oops, something went wrong.