OCJvanDijk / Brightness-Sync

Synchronize the brightness of your built-in display with your LG UltraFine display(s)
MIT License
152 stars 17 forks source link

"Launch At Login" does not work when App bundle is located outside of /Applications directory #26

Open gelstudios opened 3 years ago

gelstudios commented 3 years ago

I ran the app (which works great btw!) from the ~/Downloads directory since safari extracted the zip by default, and later noticed some log spam repeating every few seconds:

Dec 10 09:34:36 kintsugi com.apple.xpc.launchd[1] (dev.vandijk.BrightnessSyncLauncher[59549]): Could not find and/or execute program specified by service: 107: Malformed bundle: dev.vandijk.BrightnessSyncLauncher
Dec 10 09:34:36 kintsugi com.apple.xpc.launchd[1] (dev.vandijk.BrightnessSyncLauncher[59549]): Service exited with abnormal code: 78
Dec 10 09:34:36 kintsugi com.apple.xpc.launchd[1] (dev.vandijk.BrightnessSyncLauncher): Service only ran for 0 seconds. Pushing respawn out by 10 seconds.
Dec 10 09:34:46 kintsugi com.apple.xpc.launchd[1] (dev.vandijk.BrightnessSyncLauncher[59553]): Could not find and/or execute program specified by service: 107: Malformed bundle: dev.vandijk.BrightnessSyncLauncher
Dec 10 09:34:46 kintsugi com.apple.xpc.launchd[1] (dev.vandijk.BrightnessSyncLauncher[59553]): Service exited with abnormal code: 78
Dec 10 09:34:46 kintsugi com.apple.xpc.launchd[1] (dev.vandijk.BrightnessSyncLauncher): Service only ran for 0 seconds. Pushing respawn out by 10 seconds.

I disabled "Launch At Login" on a hunch, and the log messages stopped.

Re-enabled "Launch At Login" and moved the App to /Applications and the log messages did not reappear.

I did notice the App does not appear in System Preferences > Login Items, but also dont know if that has fallen out of style with macos apps 🤓

For reference, another app i use (mos) has a "launch at login" option inside it, and appears in syspref Login Items. ex: https://github.com/Caldis/Mos/blob/master/Mos/Utils/LaunchStarter.swift

OCJvanDijk commented 3 years ago

Good catch. I think it's because the Downloads folder is protected these days so the launcher can't access it.

The API to add your app to System Preferences > Login Items has been deprecated for years now. I was also disappointed when I found out about this. The officially sanctioned way of creating a helper application seems obtuse and not transparent to the user and I never really liked it, but I decided to do it the officially supported way anyway.

gelstudios commented 3 years ago

I think you're right about the protected Downloads folder, it works fine if the app is in ~/

OCJvanDijk commented 3 years ago

Not really sure how to solve this actually, maybe I should just start distributing the app as one of those fancy DMGs where you can drag it into the Applications folder.

gelstudios commented 3 years ago

I've seen a number of apps detect when they are running from a path other than /Applications or ~/Applications and offer to move themselves into the main Applications folder.

examples: https://discussions.apple.com/thread/8133756 https://support.swiftify.com/hc/en-us/articles/360013074499-Getting-up-and-started-with-the-Offline-Converter-

possible libraries: https://github.com/potionfactory/LetsMove https://github.com/OskarGroth/AppMover