Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minimize to tray and Context Menu support on Tray Icon Windows MacOS #351

Open
vadimffe opened this issue May 22, 2023 · 4 comments
Open

Comments

@vadimffe
Copy link

vadimffe commented May 22, 2023

It would be great if you could extend your example for WeatherTwentyOne to support:

  1. Minimize net maui app to tray
  2. Context Menu support on Tray Icon right click

Windows MacOS

https://github.com/dotnet/maui-samples/tree/main/7.0/Apps/WeatherTwentyOne/src/WeatherTwentyOne/Platforms/Windows

@vadimffe vadimffe changed the title Minimize to tray and Context Menu support on Tray Icon support Windows MacOS Minimize to tray and Context Menu support on Tray Icon Windows MacOS May 22, 2023
@ITaluone
Copy link

ITaluone commented Jun 5, 2023

Finally I got this working:

 builder.ConfigureLifecycleEvents(lifecycle =>
        {
            lifecycle.AddWindows(lifecycleBuilder => lifecycleBuilder.OnWindowCreated(window =>
            {
                window.ExtendsContentIntoTitleBar = true;
                var handle = WinRT.Interop.WindowNative.GetWindowHandle(window);
                var id = Microsoft.UI.Win32Interop.GetWindowIdFromWindow(handle);
                var appWindow = Microsoft.UI.Windowing.AppWindow.GetFromWindowId(id);

                appWindow.Closing += async (s, e) =>
                {
                    e.Cancel = true;
                    var result = await Application.Current?.MainPage?.DisplayAlert(
                        "App close",
                        "Do you really want to quit?",
                        "Close",
                        "Minimize to system tray")!;

                    if (result)
                    {
                        Application.Current?.Quit();
                    }
                    WindowExtensions.MinimizeToTray();
                };
            }));
        });

https://stackoverflow.com/questions/74129182/how-to-edit-the-function-of-the-close-button-on-maui-blazor-hybrid

@Irasil
Copy link

Irasil commented Sep 20, 2023

And for MacOS? I've been looking for an implementation option for a long time, unfortunately I can't find any information and I'm dreaming of examples like the one for Windows. I'm starting to think that I'll have to wait until MAUI supports MacOS and not just the stripped-down Mac Catalyst version like it currently does.

@vadimffe
Copy link
Author

And for MacOS? I've been looking for an implementation option for a long time, unfortunately I can't find any information and I'm dreaming of examples like the one for Windows. I'm starting to think that I'll have to wait until MAUI supports MacOS and not just the stripped-down Mac Catalyst version like it currently does.

Have you tried this? I don't know about MacOS, but it seems to be supporting it as well. It may need some custom code, but in general has necessary functions.

https://github.com/HavenDV/H.NotifyIcon

@ITaluone
Copy link

Have you tried this? I don't know about MacOS, but it seems to be supporting it as well. It may need some custom code, but > in general has necessary functions.

https://github.com/HavenDV/H.NotifyIcon

This was actually a very useful hint :)

Thank you! @vadimffe

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants