https://kotlinlang.org logo
#compose-desktop
Title
# compose-desktop
v

Vincent

02/21/2024, 12:19 PM
Hi guys! Is there any way to launch a desktop app on system startup? At least on Windows and macOS?
a

Alexander Maryanovsky

02/21/2024, 2:04 PM
It’s out of scope for Compose itself, but you can look into launching apps on startup in general, or maybe JVM apps in particular.
👍🏻 1
e

eskatos

02/21/2024, 2:42 PM
I had to do this for my app. And it boiled down to do it myself per platform.
On windows it is a registry key away e.g. https://stackoverflow.com/a/385797
On mac, creating a plist file in the right directory was enough https://stackoverflow.com/a/3358472
I intend to do it for linux as well. It should be possible according to this but I'm not sure how well this is supported across DEs https://specifications.freedesktop.org/autostart-spec/autostart-spec-latest.html
v

Vincent

02/21/2024, 3:54 PM
Thank you! I'll look into it
m

mikehearn

02/23/2024, 12:23 PM
It can sometimes be done by packaging tools. If you use Conveyor it's one line of config: https://conveyor.hydraulic.dev/13.1/configs/windows/#appwindowsstart-on-login
👀 1
But only for Windows ... for macOS/Linux it's not done.
e

eskatos

02/23/2024, 12:28 PM
Yep, in my use case it's not the default and users control if the app is started on launch. In any case I prefer to handle this in the app code
a

Alexander Maryanovsky

02/23/2024, 12:29 PM
You can launch it always (with a special flag), and then have the app check whether it should start on launch and shut down if not.
e

eskatos

02/23/2024, 1:00 PM
Yeah I understand but ... meh 🙂
a

Alexander Maryanovsky

02/23/2024, 1:00 PM
It’s an imperfect world 🤷‍♂️
e

eskatos

02/23/2024, 1:01 PM
Indeed, and that's perfectly fine
v

Vincent

02/23/2024, 1:27 PM
I’m building a library (wip) to handle easily launch at login on JVM target: • Windows uses registry
Software\\Microsoft\\Windows\\CurrentVersion\\Run
• MacOS uses .plist file in LaunchAgents folder • Linux to be done And I will add the possibility to add custom flags. If you want to take a look: https://github.com/vinceglb/AutoLaunch
It’s great, but we need to know the location of our app in the system in order to config AutoLaunch properly. • On Windows it’s the MyApp.exe location • On macOS it’s something like MyApp/Contents/MacOS/MyApp location I don't know how to get during runtime the location of this file. In Flutter, they have something like
Platform.resolvedExecutable
for this. Do you know how I can get this?
e

eskatos

02/23/2024, 1:29 PM
I'm using:
Copy code
val ownExecutable = File(ProcessHandle.current().info().command().get())

val isRunningFromDistributable: Boolean =
    ownExecutable.nameWithoutExtension != "java"
v

Vincent

02/23/2024, 1:44 PM
Oh it’s working great! I was struggling on that, thank you 🙏
👍 1
2 Views