refactor(app): compose settings and developer tools
This commit is contained in:
parent
60a1698ce7
commit
cd7b519f78
24 changed files with 2073 additions and 333 deletions
45
src/AcDream.App/Settings/RuntimeKeyBindingTarget.cs
Normal file
45
src/AcDream.App/Settings/RuntimeKeyBindingTarget.cs
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
using AcDream.UI.Abstractions.Input;
|
||||
|
||||
namespace AcDream.App.Settings;
|
||||
|
||||
internal interface IRuntimeKeyBindingTarget
|
||||
{
|
||||
void Apply(KeyBindings bindings);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Applies a settings-panel keymap to the live dispatcher and then persists
|
||||
/// that exact map. Persistence failure is reported without rolling back the
|
||||
/// already accepted live binding, matching the former startup-root callback.
|
||||
/// </summary>
|
||||
internal sealed class RuntimeKeyBindingTarget : IRuntimeKeyBindingTarget
|
||||
{
|
||||
private readonly InputDispatcher _dispatcher;
|
||||
private readonly string _path;
|
||||
private readonly Action<string> _log;
|
||||
|
||||
public RuntimeKeyBindingTarget(
|
||||
InputDispatcher dispatcher,
|
||||
string? path = null,
|
||||
Action<string>? log = null)
|
||||
{
|
||||
_dispatcher = dispatcher ?? throw new ArgumentNullException(nameof(dispatcher));
|
||||
_path = path ?? KeyBindings.DefaultPath();
|
||||
_log = log ?? Console.WriteLine;
|
||||
}
|
||||
|
||||
public void Apply(KeyBindings bindings)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(bindings);
|
||||
_dispatcher.SetBindings(bindings);
|
||||
try
|
||||
{
|
||||
bindings.SaveToFile(_path);
|
||||
_log($"keybinds: saved to {_path}");
|
||||
}
|
||||
catch (Exception failure)
|
||||
{
|
||||
_log($"keybinds: save failed: {failure.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue