Skip to content

Commit

Permalink
Merge pull request #28 from XanatosX/feature/toggle-application-via-icon
Browse files Browse the repository at this point in the history
Add functionality to toggle app via icon
  • Loading branch information
XanatosX authored Dec 11, 2022
2 parents 14ecdc9 + 430537f commit c0c819a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using CommunityToolkit.Mvvm.Messaging.Messages;

namespace ModularToolManager.Models.Messages;

/// <summary>
/// Get the current visiblilty for the application
/// </summary>
internal class RequestApplicationVisiblity : RequestMessage<bool> { }
8 changes: 7 additions & 1 deletion src/ModularToolManager/ViewModels/AppViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,13 @@ public class AppViewModel : ObservableObject
/// </summary>
public AppViewModel()
{
ShowApplicationCommand = new RelayCommand(() => WeakReferenceMessenger.Default.Send(new ToggleApplicationVisibilityMessage(false)));
ShowApplicationCommand = new RelayCommand(() =>
{
var response = WeakReferenceMessenger.Default.Send(new RequestApplicationVisiblity());
bool toggleMode = response.HasReceivedResponse ? response.Response : false;
WeakReferenceMessenger.Default.Send(new ToggleApplicationVisibilityMessage(toggleMode));

});
ExitApplicationCommand = new RelayCommand(() => WeakReferenceMessenger.Default.Send(new CloseApplicationMessage()));
}
}
2 changes: 1 addition & 1 deletion src/ModularToolManager/Views/MainWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ public MainWindow(IWindowManagementService? modalService, ISettingsService? sett
{
Topmost = false;
}

});
WeakReferenceMessenger.Default.Register<RequestApplicationVisiblity>(this, (_, e) => e.Reply(IsVisible));
WeakReferenceMessenger.Default.Register<ValueChangedMessage<ApplicationSettings>>(this, (_, settings) =>
{
Topmost = settings.Value.AlwaysOnTop;
Expand Down

0 comments on commit c0c819a

Please sign in to comment.