piradoiv / countdown-desktop-app

Countdown App for macOS
2 stars 0 forks source link

Tray Icon on Windows #1

Open LwRed opened 1 year ago

LwRed commented 1 year ago

I know this example is for MacOs platform and it works great. Any idea to make it working with trayicon on Windows Platform or Windows App Icon ? I saw "SetWindowIcon" or Trayicon.mask

Thanks a lot

piradoiv commented 1 year ago

Hi @LwRed, I don't know how to do this on Windows, but maybe DesktopApplication.AddTrayItem with a DesktopTrayItem can help. It supports a picture in the Icon property, so that should help I guess.

LwRed commented 11 months ago

Hello and thanks for this, Do you know how I can make on MacOs an icon on top right menu for this app ? Must i look to NS... cocoa ?

piradoiv commented 11 months ago

That's definitely possible!

On macOS you'll have to use the NSStatusBar class. It has a systemStatusBar "shared method" that will return the NSStatusBar instance you're looking for.

With that instance you'll be able to add a new NSMenuItem, which can be either an icon or plain text. Then, you will have to attach your NSMenu, with all the options inside.

The hard work, which is creating the menu contents and creating the event handlers, can be done entirely using the Xojo Menu Bar editor. Using declares and the Handle property, you can just attach them to your NSMenu instance.

If you want to create a macOS app without visible windows and without appearing in the Dock (what people call "Menu Bar App"), create a Info.plist file with this content:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>LSBackgroundOnly</key>
    <integer>1</integer>
</dict>
</plist>

I'm sure there will be something in the https://github.com/macoslib/macoslib project for doing this. But if you want to learn and create your own, it's a fun exercise. Let me know if you need any help.