Fix not manually disposing of resources when the app window is closed

This commit is contained in:
chylex 2022-03-05 13:35:11 +01:00
parent 4bc9626013
commit 6d3db23f80
No known key found for this signature in database
GPG Key ID: 4DE42C8F19A80548
3 changed files with 15 additions and 2 deletions

View File

@ -9,7 +9,8 @@
Icon="avares://DiscordHistoryTracker/Resources/icon.ico"
Width="800" Height="500"
MinWidth="480" MinHeight="240"
WindowStartupLocation="CenterScreen">
WindowStartupLocation="CenterScreen"
Closed="OnClosed">
<Design.DataContext>
<main:MainWindowModel />

View File

@ -1,3 +1,4 @@
using System;
using System.Diagnostics.CodeAnalysis;
using Avalonia;
using Avalonia.Controls;
@ -24,5 +25,11 @@ namespace DHT.Desktop.Main {
this.AttachDevTools();
#endif
}
public void OnClosed(object? sender, EventArgs e) {
if (DataContext is IDisposable disposable) {
disposable.Dispose();
}
}
}
}

View File

@ -10,7 +10,7 @@ using DHT.Server.Database;
using DHT.Utils.Models;
namespace DHT.Desktop.Main {
sealed class MainWindowModel : BaseModel {
sealed class MainWindowModel : BaseModel, IDisposable {
private const string DefaultTitle = "Discord History Tracker";
public string Title { get; private set; } = DefaultTitle;
@ -104,5 +104,10 @@ namespace DHT.Desktop.Main {
private void MainContentScreenModelOnDatabaseClosed(object? sender, EventArgs e) {
WelcomeScreenModel.CloseDatabase();
}
public void Dispose() {
MainContentScreenModel?.Dispose();
db?.Dispose();
}
}
}