Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue: darkdetect listener cannot work under sudo #37

Open
LorenEteval opened this issue Sep 6, 2023 · 2 comments
Open

Issue: darkdetect listener cannot work under sudo #37

LorenEteval opened this issue Sep 6, 2023 · 2 comments

Comments

@LorenEteval
Copy link

Hi. Recently I found that darkdetect listener cannot work under sudo mode. This is how I reproduce:

Environment: macOS 13.5.1 Apple Silicon, Python 3.11

Create a new venv, and install darkdetect by pip install "darkdetect[macos-listener]"

Test sample.py as follows:

import threading
import darkdetect


def printCurrentTheme(theme):
    print(f'System theme is {theme}')


if __name__ == '__main__':
    thread = threading.Thread(
        target=darkdetect.listener, args=(printCurrentTheme,), daemon=True
    )

    thread.start()
    thread.join()

When running with python sample.py, the theme is printed correctly when changing system theme in the settings manually.

However, if running with sudo python sample.py, the callback never called when switching system theme.

There are some cases that I want to launch my application as sudo, and found that darkdetect failed to behave as expected.

Is this a bug related to darkdetect, or related to macos-listener implementation under the hood? Will darkdetect fix this in the future? Thanks.

@LorenEteval
Copy link
Author

Just tested on Ubuntu 22.04, same steps except for installing darkdetect using pip install darkdetect. It still fails to print under sudo mode.

@LorenEteval
Copy link
Author

darkdetect.theme() also fails under sudo mode, but it seems that on Ubuntu 22.04 the result is caused by gsettings and sudo gsettings giving different output.

I took a quick glance on the implemetation of macOS side, not sure why it would fail because it's just interacting with pyobjc.

Also, because of issue #33 , I have to fall back to combination of darkdetect.theme + timer to achieve the same "listener" feature on macOS (non-sudo, packed application).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant