using AcDream.UI.Abstractions.Input; namespace AcDream.App.Settings; internal interface IRuntimeKeyBindingTarget { void Apply(KeyBindings bindings); } /// /// 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. /// internal sealed class RuntimeKeyBindingTarget : IRuntimeKeyBindingTarget { private readonly InputDispatcher _dispatcher; private readonly string _path; private readonly Action _log; public RuntimeKeyBindingTarget( InputDispatcher dispatcher, string? path = null, Action? 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}"); } } }