You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I would like to use MacCatalyst to display the status bar.(The status bar refers to the area in the image below.)
I also understand that there is sample code that can be used as a reference(sample code).
However, the code is esoteric, including the use of objective-c libraries. (There is no documentation on the web for reference.)
Based on the sample code, I was able to achieve up to the display of the icon, but I am unable to implement the menu that appears when the icon is clicked. If you have technical knowledge, I would appreciate your help.
The execution environment is
mac: intel cpu
os: Ventura 13.6.1
account: admin user
.net: .net8.0.201
maui(vscode): v0.10.61
Sample code excerpts from the link
using System.Runtime.InteropServices;
using Foundation;
using ObjCRuntime;
using WeatherTwentyOne.Services;
namespace WeatherTwentyOne.MacCatalyst;
public class TrayService : NSObject, ITrayService
{
[DllImport("/usr/lib/libobjc.dylib", EntryPoint = "objc_msgSend")]
public static extern IntPtr IntPtr_objc_msgSend_nfloat(IntPtr receiver, IntPtr selector, nfloat arg1);
[DllImport("/usr/lib/libobjc.dylib", EntryPoint = "objc_msgSend")]
public static extern IntPtr IntPtr_objc_msgSend_IntPtr(IntPtr receiver, IntPtr selector, IntPtr arg1);
[DllImport("/usr/lib/libobjc.dylib", EntryPoint = "objc_msgSend")]
public static extern IntPtr IntPtr_objc_msgSend(IntPtr receiver, IntPtr selector);
[DllImport("/usr/lib/libobjc.dylib", EntryPoint = "objc_msgSend")]
public static extern void void_objc_msgSend_IntPtr(IntPtr receiver, IntPtr selector, IntPtr arg1);
[DllImport("/usr/lib/libobjc.dylib", EntryPoint = "objc_msgSend")]
public static extern void void_objc_msgSend_bool(IntPtr receiver, IntPtr selector, bool arg1);
NSObject systemStatusBarObj;
NSObject statusBarObj;
NSObject statusBarItem;
NSObject statusBarButton;
NSObject statusBarImage;
public Action ClickHandler { get; set; }
public void Initialize()
{
statusBarObj = Runtime.GetNSObject(Class.GetHandle("NSStatusBar"));
systemStatusBarObj = statusBarObj.PerformSelector(new Selector("systemStatusBar"));
statusBarItem = Runtime.GetNSObject(IntPtr_objc_msgSend_nfloat(systemStatusBarObj.Handle, Selector.GetHandle("statusItemWithLength:"), -1));
statusBarButton = Runtime.GetNSObject(IntPtr_objc_msgSend(statusBarItem.Handle, Selector.GetHandle("button")));
statusBarImage = Runtime.GetNSObject(IntPtr_objc_msgSend(ObjCRuntime.Class.GetHandle("NSImage"), Selector.GetHandle("alloc")));
var imgPath = System.IO.Path.Combine(NSBundle.MainBundle.BundlePath, "Contents", "Resources", "Platforms", "MacCatalyst", "trayicon.png");
var imageFileStr = NSString.CreateNative(imgPath);
var nsImagePtr = IntPtr_objc_msgSend_IntPtr(statusBarImage.Handle, Selector.GetHandle("initWithContentsOfFile:"), imageFileStr);
void_objc_msgSend_IntPtr(statusBarButton.Handle, Selector.GetHandle("setImage:"), statusBarImage.Handle);
void_objc_msgSend_bool(nsImagePtr, Selector.GetHandle("setTemplate:"), true);
// Handle click
void_objc_msgSend_IntPtr(statusBarButton.Handle, Selector.GetHandle("setTarget:"), this.Handle);
void_objc_msgSend_IntPtr(statusBarButton.Handle, Selector.GetHandle("setAction:"), new Selector("handleButtonClick:").Handle);
}
[Export("handleButtonClick:")]
void HandleClick(NSObject senderStatusBarButton)
{
var nsapp = Runtime.GetNSObject(Class.GetHandle("NSApplication"));
var sharedApp = nsapp.PerformSelector(new Selector("sharedApplication"));
void_objc_msgSend_bool(sharedApp.Handle, Selector.GetHandle("activateIgnoringOtherApps:"), true);
ClickHandler?.Invoke();
}
}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Description
I would like to use MacCatalyst to display the status bar.(The status bar refers to the area in the image below.)

I also understand that there is sample code that can be used as a reference(sample code).
However, the code is esoteric, including the use of objective-c libraries. (There is no documentation on the web for reference.)
Based on the sample code, I was able to achieve up to the display of the icon, but I am unable to implement the menu that appears when the icon is clicked. If you have technical knowledge, I would appreciate your help.
The execution environment is
mac: intel cpu
os: Ventura 13.6.1
account: admin user
.net: .net8.0.201
maui(vscode): v0.10.61
Sample code excerpts from the link
Beta Was this translation helpful? Give feedback.
All reactions