Hi guys! Is there any way to launch a desktop app ...
# compose-desktop
v
Hi guys! Is there any way to launch a desktop app on system startup? At least on Windows and macOS?
a
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
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
Thank you! I'll look into it
m
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
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
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
Yeah I understand but ... meh 🙂
a
It’s an imperfect world 🤷‍♂️
e
Indeed, and that's perfectly fine
v
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
I'm using:
Copy code
val ownExecutable = File(ProcessHandle.current().info().command().get())

val isRunningFromDistributable: Boolean =
    ownExecutable.nameWithoutExtension != "java"
v
Oh it’s working great! I was struggling on that, thank you 🙏
👍 1