Nuitka / Nuitka

Nuitka is a Python compiler written in Python. It's fully compatible with Python 2.6, 2.7, 3.4-3.12. You feed it your Python app, it does a lot of clever things, and spits out an executable or extension module.
http://nuitka.net
Apache License 2.0
11.8k stars 639 forks source link

Question:does LSUIElement(agent app that runs in the background) entitlement(plist) nuitka option exist? #1915

Closed emre84 closed 1 year ago

emre84 commented 1 year ago

does LSUIElement(agent app that runs in the background) entitlement(plist) nuitka compilation option exist for macOS? My aim is that my icon does not appear in Dock.

I could not find such an option in "nuitka --help" and https://nuitka.net/doc/user-manual.html

PS:This Issue is related with #1911.

Thanks a lot in advance.

kayhayen commented 1 year ago

This might be something to use --macos-app-protected-resource for, can you check that? Also I agree, this is not listed in the user manual at all, is not good, and help probably needs to mention that work. Protected resource is the proper term, but entitlement is what is used frequently. That word should be in the help output indeed.

I have a suspect, that the new option, will be on develop now, --macos-app-windowless is what you are looking for. It's not really a right I guess, or is it. I cannot find your value on the page linked, https://developer.apple.com/documentation/bundleresources/information_property_list/protected_resources from help. How did you find that value to begin with?

emre84 commented 1 year ago

Hi Kay,

Thanks for the fast response.

I am looking for following feature: https://developer.apple.com/documentation/bundleresources/information_property_list/lsuielement

How I used it: I added following item into my info.plist file :

    <key>LSUIElement</key>
    <true/>

Thereby when I started my application, my app icon did not appear in dock. (Although even my app GUI was shown on the screen.)

I had a look into https://developer.apple.com/documentation/bundleresources/information_property_list/protected_resources but I do not think that it is relevant with LSUIElement.

If you need more info, please do not hesitate to ask.

PS:--macos-app-windowless sounds like my app should be necessarily a background service. To prevent misunderstanding:I want to have also an app GUI which controls my background service. The only thing which required is that my application icon should not appear in dock.

Thanks a lot in advance.

kayhayen commented 1 year ago

I guess, that is a third mode, right now we have full GUI, and background with no GUI. I will add something for it too.

I think the windowsless identified is going away too. I failed to remember that name on different occasions, and it actually sounds like something you would mean too now. Luckily it hasn't been part of a release yet.

kayhayen commented 1 year ago

I am working on something like this now:

    --macos-app-mode=MODE
                        Mode of application for the application bundle. When
                        launching a Window, and appearing in Docker is
                        desired, default value "gui" is a good fit. Without a
                        Window ever, the application is a "background"
                        application. For UI elements that get to display
                        later, "ui-element" is between, will not appear in
                        dock, but get full access to desktop when it does open
                        a Window later.

Let me know if it makes sense.

kayhayen commented 1 year ago

Thanks for your report, this is fixed on the factory branch, which is a development version under rapid development. You can try it out by going here: https://nuitka.net/doc/factory.html

Feedback if this is working is very welcome, just please do not share plans of doing it, but rather confirmations or denials of it working.

emre84 commented 1 year ago

Hi Kay,

I tested it, and unfortunately I got a compilation error.

With following command: python3.7 -m nuitka --run --standalone --enable-plugin=numpy,pyside6 --noinclude-pytest-mode=nofollow --noinclude-setuptools-mode=nofollow --python-flag=no_site --include-data-dir=/Users/models=models --include-data-dir=/Users/icons=icons --macos-app-icon=/Users/icons/license_lock_photo.png --macos-create-app-bundle --macos-disable-console --macos-app-protected-resource="NSCameraUsageDescription:xxx." --macos-app-protected-resource="NSPhotoLibraryUsageDescription:xxx." --macos-app-mode=ui-element test_copy.py

Code:

from Foundation import NSUserNotification
from Foundation import NSUserNotificationCenter
from PySide6.QtWidgets import QWidget, QApplication, QLineEdit

_title = "title"
_message = "message"
notification = NSUserNotification.alloc().init()
notification.setTitle_(_title)
notification.setInformativeText_(_message)
notification.setSoundName_("Ping")
try:
    center = NSUserNotificationCenter.defaultUserNotificationCenter()
    center.deliverNotification_(notification)
except Exception as e:
    print("test")
class ButtonExample(QWidget):

    def __init__(self):
        # Call parent constructor
        super().__init__()
        self.btn = QLineEdit('Click Me', self)
        self.show()

app = QApplication([])
button = ButtonExample()
app.exec()

Error: Nuitka-Postprocessing:INFO: File '/Users/emre/Documents/Tensorflow1/models/research/object_detection/object_detection/icons/license_lock_photo.png' is not in macOS icon format, converting to it. Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/nuitka/main.py", line 151, in main() File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/nuitka/main.py", line 137, in main MainControl.main() File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/nuitka/MainControl.py", line 955, in main executePostProcessing() File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/nuitka/PostProcessing.py", line 359, in executePostProcessing createPlistInfoFile(logger=postprocessing_logger, onefile=False) File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/nuitka/utils/MacOSApp.py", line 99, in createPlistInfoFile if Options.isMacOSBackgroundApp(): File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/nuitka/Options.py", line 1633, in isMacOSBackgroundApp return options.mac_app_mode == "background" AttributeError: 'Values' object has no attribute 'mac_app_mode'

My Version: Nuitka-Options:INFO: Used command line options: --version 1.3rc5 Commercial: None Python: 3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 16:52:21) Flavor: CPython Official Executable: /Library/Frameworks/Python.framework/Versions/3.7/bin/python3.7 OS: Darwin Arch: x86_64 Version C compiler: /usr/bin/clang (clang). AttributeError: 'SConsEnvironment' object has no attribute 'macos_min_version': File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/nuitka/build/CCompilerVersion.scons", line 276: job_count=job_count, File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/nuitka/build/SconsCompilerSettings.py", line 528: setEnvironmentVariable(env, "MACOSX_DEPLOYMENT_TARGET", env.macos_min_version)

PS: My version shows somehow a clang error.

kayhayen commented 1 year ago

Both issues should be fixed now.

kayhayen commented 1 year ago

This is now on the develop branch and will be part of 1.3 release.

emre84 commented 1 year ago

Thanks Kay, it works fine with a small code peace. I want to try it on my project but it is blocked because of #1928. please do not close the issue till i test it on my project. Thanks a lot in advance.

kayhayen commented 1 year ago

This is part of the stable release 1.3 that I just made.