-
Notifications
You must be signed in to change notification settings - Fork 113
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
Check if app launched as hidden at login or manually by the user #93
Comments
Here's a workaround I'm using: After initialising the AutoLauncher, overwrite the appPath with something like this: AutoLauncher.opts.appPath += '" --autostart "' Notice the double quotes inside the single quotes. auto-launch automatically encloses the appPath with double quotes when writing to the registry, so what this does is closing the double quotes behind the path, adding an
You end up having a set of double quotes as an additional command line argument as well, but that shouldn't hurt. Now you can check in your app if the argument is set and react to it accordingly. I only tested this under Windows and it's a bit hack-ish, but as long as adding command line arguments is not natively supported by this package, it works. |
Please see that we're looking for contributors / maintainers: #64. I'm happy to give access to people who are willing to help improve things, merge pull-requests, close issues, etc. |
@Connum can you share more code please. I don't understand what you mean by after initializing the autolauncher. |
|
Thank you! I will test on mac and let you know how it goes. |
There seems to be an option to
So if we set this to true we can detect if it was auto-launched by looking for the "hidden" argument. I haven't tried this yet, just peeked at the source and am theorizing. |
@Noitidart , @Connum , did you find a solution for this? I am on Mac, and I can't use the solution proposed by @Connum , also the --hidden argument is not present in Electron's main entry file (process.argv) |
I didn't find a solution. :( |
A year and a half later and not having worked much with Electon since, all I can say is that I had it working with my workaround. But I can't say if this still works with more recent versions of Electon. |
@Noitidart , @Connum thank you for your quick reply. Well for anyone looking for a solution, here is what I did. I used the Electron's built in For windows users, they can make use of NodeJS built-in (process.argv) to check if '--startup' is present at Electron Main process entry file, and then do the same processes accordingly. |
Thanks for sharing your learnings!
…On Sat, Oct 31, 2020 at 12:31 AM newCodeRunner ***@***.***> wrote:
@Noitidart <https://github.com/Noitidart> , @Connum
<https://github.com/Connum> thank you for your quick reply.
Well for anyone looking for a solution, here is what I did.
Electron-v10.1.5
OS- Mac
I used the Electron's built in
app.setLoginItemSettings({ openAtLogin: true, args: ['--startup'])
and
app.getLoginItemSettings().wasOpenedAtLogin // for mac only
to check if the app was opened at startup, and then used my Electron Main
process entry file to open main window or use NodeJs child-proc to execute
another binary. Hacky, but this is all I got after 2 days searching.
For windows users, they can make use of NodeJS built-in (process.argv) to
check if '--startup' is present at Electron Main process entry file, and
then do the same processes accordingly.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#93 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABQTZCK55P5C7RVZE4K73LTSNO4OTANCNFSM4GT2ETSQ>
.
|
To summarize the comment from @newCodeRunner, this snipped works on Windows\Linux\macOS (Electron v12.0.0).
|
This is the way to go, at least for now. Auto-launch could have dealt with extra arguments uniformly without this specific use case. Since we handle this one specifically ("hidden"), maybe we could explore what could be improved in auto-launch to make things even easier. I'm opening an issue to track some ideas: #128 |
I have integrated auto-launch in my Electron app. I would like not to open the main window of the app when the app is auto-launched at startup. Is there a way to determine if the app was launched by the user, or if it has been auto-launched at system startup?
The text was updated successfully, but these errors were encountered: