Status menus

Mac OSX specific forum
mrbungle
Enthusiast
Enthusiast
Posts: 143
Joined: Wed Dec 30, 2020 3:18 am

Status menus

Post by mrbungle »

Were there other changes made to the 6.03 Beta 5? I created an Status bar app using code posted on the forum and even with the proper entry in the Info.plist (the <key>LSUIElement</key>, the compiled code doesn't hide the app in the menu bar. This code works on 6.02 LTS and previous versions.
User avatar
Piero
Addict
Addict
Posts: 885
Joined: Sat Apr 29, 2023 6:04 pm
Location: Italy

Re: Status menus

Post by Piero »

I wish I could help you, but I'm avoiding Betas (and Ventura) for now…
I see Magic Fred is now doing a lot of work on Mac stuff... poor Fred... Thanks!
I heard about many UI problems on apps made "for Ventura but compatible with previous OSs" on Monterey...
Tell Fred your OS
Fred
Administrator
Administrator
Posts: 18164
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Status menus

Post by Fred »

Can you post a small code showing the issue ?
mrbungle
Enthusiast
Enthusiast
Posts: 143
Joined: Wed Dec 30, 2020 3:18 am

Re: Status menus

Post by mrbungle »

Code: Select all

EnableExplicit

#NSSquareStatusBarItemLength = -2

Define ItemLength.CGFloat = 32
Define StatusBar.I
Define StatusItem.I

UsePNGImageDecoder()

OpenWindow(0, 270, 100, 300, 100, "SysTray Menu Example")

If LoadImage(0, #PB_Compiler_Home + "Examples/Sources/Data/World.png")
  StatusBar = CocoaMessage(0, 0, "NSStatusBar systemStatusBar")
 
  If StatusBar
    ; ----- Create icon in system status bar (SysTray)
    StatusItem = CocoaMessage(0, CocoaMessage(0, StatusBar,
      "statusItemWithLength:", #NSSquareStatusBarItemLength), "retain")

    If StatusItem
      CocoaMessage(0, StatusItem, "setLength:@", @ItemLength)
      CocoaMessage(0, StatusItem, "setImage:", ImageID(0))
     
      ; ----- Create menu with entries for click on SysTray icon
      CreatePopupMenu(0)
      MenuItem(0, "Show computer name")
      MenuItem(1, "Show user name")
      CocoaMessage(0, StatusItem, "setMenu:",
        CocoaMessage(0, MenuID(0), "firstObject"))
     
      Repeat
        Select WaitWindowEvent()
          Case #PB_Event_CloseWindow
            Break
          Case #PB_Event_Menu
            Select EventMenu()
              Case 0
                MessageRequester("Info", "Computer name: " + ComputerName())
              Case 1
                MessageRequester("Info", "User name: " + UserName())
            EndSelect
        EndSelect
      ForEver
    EndIf
  EndIf
EndIf
If you compile this code on PB 6.03 Beta 5 and insert the following key in its Info.plist file, the app's icon will appear on the Dock when run:
<key>LSUIElement</key>
<true/>
This is incorrect behavior as the app's icon should be hidden not shown.

However, this same code compiled on PB 6.02 and earlier will not show the app icon in the Dock (correct behavior) if the LSUIElement key is added to the Info.plist. I have tested this on an Apple M1 computer using the latest Mac OS
User avatar
Piero
Addict
Addict
Posts: 885
Joined: Sat Apr 29, 2023 6:04 pm
Location: Italy

Re: Status menus

Post by Piero »

mrbungle wrote: Sat Aug 19, 2023 8:49 pm <key>LSUIElement</key>
<true/>
Did you try this?

<key>LSUIElement</key>
<integer>1</integer>

Edit/PS: It works here, and even if they say <true/> is the way to go for a boolean, it seems malformed to my old eyes :x
mrbungle
Enthusiast
Enthusiast
Posts: 143
Joined: Wed Dec 30, 2020 3:18 am

Re: Status menus

Post by mrbungle »

Doesn't work here but appreciate your feedback.
User avatar
deseven
Enthusiast
Enthusiast
Posts: 367
Joined: Wed Jan 12, 2011 3:48 pm
Location: Serbia
Contact:

Re: Status menus

Post by deseven »

I haven't tried 6.03 yet, but I think it could be related to the fix introduced in viewtopic.php?t=77852
The (temporary?) solution would be to explicitly set NSApplicationActivationPolicy after application starts (I provided an example in that topic). Changes in the plist are not needed if you're going to control it in the runtime.
Piero wrote: Sat Aug 19, 2023 10:11 pm It works here, and even if they say <true/> is the way to go for a boolean, it seems malformed to my old eyes :x
Oh, that's just a self-closing syntax from XML standard. Technically this is just a short way of writing <true></true>
mrbungle
Enthusiast
Enthusiast
Posts: 143
Joined: Wed Dec 30, 2020 3:18 am

Re: Status menus

Post by mrbungle »

Dseven,

I added the following to the start of the program:

Code: Select all

application = CocoaMessage(0,0,"NSApplication sharedApplication")
CocoaMessage(0,application,"setActivationPolicy:",#NSApplicationActivationPolicyAccessory)
And it worked! Thank you!
Post Reply