Skip to content

feat: add the ability to check if the app is autostart #2650

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

Open
wants to merge 2 commits into
base: v2
Choose a base branch
from

Conversation

ayangweb
Copy link
Contributor

@ayangweb ayangweb commented Apr 21, 2025

Resolved #2568

Copy link
Contributor

Package Changes Through 92ce8e4

There are 7 changes which include single-instance with patch, fs with minor, fs-js with minor, http with patch, http-js with patch, opener with patch, opener-js with patch

Planned Package Versions

The following package releases are the planned based on the context of changes in this pull request.

package current next
api-example 2.0.25 2.0.26
api-example-js 2.0.21 2.0.22
fs 2.2.1 2.3.0
fs-js 2.2.1 2.3.0
dialog 2.2.1 2.2.2
dialog-js 2.2.1 2.2.2
opener 2.2.6 2.2.7
opener-js 2.2.6 2.2.7
http 2.4.3 2.4.4
http-js 2.4.3 2.4.4
persisted-scope 2.2.1 2.2.2
single-instance 2.2.3 2.2.4

Add another change file through the GitHub UI by following this link.


Read about change files or the docs at github.com/jbolda/covector

Comment on lines +102 to +110
async fn is_autostart(manager: State<'_, AutoLaunchManager>) -> Result<bool> {
let process_args: Vec<String> = std::env::args().collect();

let passed_args = manager.0.get_args();

let is_autostart = passed_args.iter().all(|arg| process_args.contains(arg));

Ok(is_autostart)
}
Copy link
Contributor

@Legend-Master Legend-Master Apr 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just checking if all the args used to launch the program match the ones we passed into the plugin builder, this wouldn't work if we didn't pass in anything or if we changed the args

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be used to determine whether the app was launched automatically or manually during its first startup. In the case of a manual launch, these parameters are usually not present.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, you can pass in nothing in the builder, and this wouldn't work in that case, also when you relaunch/restart your app with app.restart, it will include all the args you previously set and that's going to be another false positive

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I really didn't think about that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there any other approaches to determine whether an application is set to launch automatically at startup?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's fine to use command line args for this purpose, maybe a function in the builder that adds in a special cli arg to the args and we can detect if that cli arg is present or not, about the restart, that one would probably be a bit more involved since we don't have a way to change the restart cli args right now

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If that's an opt-in, I'm fine with that 🙃, or we could provide some docs for people to do it in their own apps for now

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

Successfully merging this pull request may close these issues.

[feat][autostart] added is_autostart method
2 participants