Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ public IWindowHandle ShowChatWindow(ChatViewModel viewModel)
{
DataContext = viewModel
};
window.ShowAndActivate();
window.Show();
window.Activate();
return new WindowHandle(window);
});
}
Expand Down
37 changes: 4 additions & 33 deletions src/RemoteViewer.Client/Views/Chat/ChatView.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ namespace RemoteViewer.Client.Views.Chat;
public partial class ChatView : Window
{
private ChatViewModel? _viewModel;
private bool _forceClose;

public ChatView()
{
Expand All @@ -18,23 +17,6 @@ public ChatView()
this.Deactivated += this.OnDeactivated;
}

public void ForceClose()
{
this._forceClose = true;
this.Close();
}

public void ShowAndActivate()
{
this.Show();

// Restore from minimized state if needed
if (this.WindowState == WindowState.Minimized)
this.WindowState = WindowState.Normal;

this.Activate();
}

private void OnDataContextChanged(object? sender, EventArgs e)
{
if (this._viewModel is not null)
Expand Down Expand Up @@ -77,23 +59,12 @@ protected override void OnClosing(WindowClosingEventArgs e)
{
base.OnClosing(e);

if (this._forceClose)
if (this._viewModel is { } vm)
{
// Dispose ViewModel and cleanup
if (this._viewModel is { } vm)
{
vm.Messages.CollectionChanged -= this.Messages_CollectionChanged;
vm.Dispose();
}
return;
vm.Messages.CollectionChanged -= this.Messages_CollectionChanged;
vm.IsOpen = false;
vm.Dispose();
}

// Hide instead of close to preserve state
e.Cancel = true;
this.Hide();

if (this._viewModel is { } vm2)
vm2.IsOpen = false;
}

private void Messages_CollectionChanged(object? sender, NotifyCollectionChangedEventArgs e)
Expand Down