fix: Implement IDisposable on ShortcutService and dispose on app exit#78
Conversation
Agent-Logs-Url: https://github.com/murapadev/NeuralDeck/sessions/178e34aa-541d-4c95-b62f-63e9a782a496 Co-authored-by: murapadev <10557163+murapadev@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Adds a guaranteed cleanup path for ShortcutService on application shutdown by formally implementing IDisposable and invoking disposal from the Avalonia desktop lifetime exit hook.
Changes:
- Declared
ShortcutService : IDisposable(theDispose()method already existed). - Hooked
ShortcutServicedisposal intoIClassicDesktopStyleApplicationLifetime.Exit.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| Services/ShortcutService.cs | Declares IDisposable on ShortcutService to match its existing Dispose() implementation. |
| App.axaml.cs | Disposes ShortcutService on desktop app exit to ensure keybindings/window references are cleared during shutdown. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| desktop.MainWindow = mainWindow; | ||
|
|
||
| desktop.Exit += (_, _) => ShortcutService.Instance?.Dispose(); |
There was a problem hiding this comment.
ShortcutService.Instance is non-nullable and lazily creates the singleton (_instance ??= new ShortcutService()). Using ShortcutService.Instance?.Dispose() will still instantiate the service during shutdown even if it was never used, and the null-conditional is redundant. If the intent is to dispose only when already created, consider adding a static DisposeInstance()/TryGetInstance() (or exposing a Current/MaybeInstance that returns _instance) and call that from desktop.Exit.
, #79) - MainWindowViewModel: implement IDisposable, dispose ChatViewModel - ShortcutService: add IDisposable interface declaration - App.OnExit: dispose TrayService, ShortcutService, MainWindowViewModel Cherry-picked from copilot branches: 8be25e3 (TrayService), b353ef1 (ShortcutService), 0f80c4d (ChatViewModel)
ShortcutServiceheld aWindowreference and accumulatedKeyBindingregistrations with no cleanup path, leaking resources on app shutdown.Changes
ShortcutService: Added: IDisposableto the class declaration — theDispose()method already existed (callsUnregisterAll()+ nulls_window) but the interface was never declared.App.axaml.cs: WiredShortcutService.Instance?.Dispose()intoIClassicDesktopStyleApplicationLifetime.Exitto guarantee cleanup on shutdown.Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
av-build-tel-api-v1.avaloniaui.net/usr/share/dotnet/dotnet dotnet exec --runtimeconfig /home/REDACTED/.nuget/packages/avalonia.buildservices/0.0.29/tools/netstandard2.0/runtimeconfig.json /home/REDACTED/.nuget/packages/avalonia.buildservices/0.0.29/tools/netstandard2.0/Avalonia.BuildServices.Collector.dll 20' --output-dircredential.username(dns block)If you need me to access, download, or install something from one of these locations, you can either: