2

I have a bundle with a GUI, service and tray. Note they are three separate processes.

It may sound weird, the tray is a representation of the service and users can open the GUI which would create a tray if none exits.

So in my GUI code I have something like below:

QProcess::startDetached("my-tray");

The whole bundle is configured as the GUI is the main executable.

THE PROBLEM IS: when the GUI starts a tray, I can see two icons in dock. What I want is starting the tray without any extra icon in dock.

I have tried to set QT_MAC_DISABLE_FOREGROUND_APPLICATION_TRANSFORM to true as suggested here.

I have tried to change activation policy programmatically as suggested here.

I don't think set LSUIElement to 1 in plist file is a valid solution for me, because I still want the GUI show an icon in dock.

Currently, I put all processes in the MacOS folder within the bundle. Moving tray into Resources folder caused it failed to load some cocoa library.

This application failed to start because it could not find or load the Qt platform plugin "cocoa" in "".

The whole project is a Qt project written in C++. The tray process is essentially a QSystemTrayIcon.

Jerry
  • 1,704
  • 5
  • 20
  • 40

2 Answers2

1

THE PROBLEM IS: when the GUI starts a tray, I can see two icons in dock.

One possible solution would be to make the "tray" process its own application bundle (and still putting within the bundle of the main application) and setting

<key>NSUIElement</key>
<string>1</string>

in the Info.plist of the tray bundle.

mschmidt
  • 2,740
  • 4
  • 17
  • 31
  • 1
    It is not necessary to make it a bundle. You can embed `Info.plist` in the executable itself using the following linker flag: `-sectcreate __TEXT __info_plist path/to/my/info.plist`. Exact flags will depend on your linking system, it may look like e.g. `-Wl,-sectcreate,__TEXT,__info_plist,path/to/my/info.plist`. – MarSoft Feb 08 '23 at 06:23
0

For this part of the question:

Currently, I put all processes in the MacOS folder within the bundle. Moving tray into Resources folder caused it failed to load some cocoa library.

This application failed to start because it could not find or load the Qt platform plugin "cocoa" in "".

Qt seems to look for its "plugins" in ../PlugIns/ only if the exe is within MacOS directory. In order to workaround this and be able to put your helper executable in Resources folder, you'll need to add the following to your daemon initialization, before constructing your QApplication (the exact lib path determining depends on your language, not sure how it is done in C++):

QApplication::AddLibraryPath(path_to_PlugIns_dir);
MarSoft
  • 3,555
  • 1
  • 33
  • 38