Skip to content
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

Get response back from single instance event when using app.requestSingleInstanceLock(); ? #20942

Closed
3 tasks done
paul-marechal opened this issue Nov 4, 2019 · 6 comments
Closed
3 tasks done

Comments

@paul-marechal
Copy link

paul-marechal commented Nov 4, 2019

Preflight Checklist

  • I have read the Contributing Guidelines for this project.
  • I agree to follow the Code of Conduct that this project adheres to.
  • I have searched the issue tracker for a feature request that matches the one I want to file, without success.

Problem Description

IIUC, when using the app.requestSingleInstanceLock(); function in our electron main process, when it returns false we would usually exit the second created process, since the event will be forwarded to the first instance. My issue here is that when exiting the second process, I may want to get feedback from the main instance to know what exit code to return with. Say I wanted to open a resource but it failed, I would like my second process to exit with code != 0. Maybe a CLI argument passed was bogus as well, which case I'd like to exit with code != 0 again.

Proposed Solution

Since it would be weird to change the return type of app.requestSingleInstanceLock(), maybe add a new app.waitSingleInstanceResponse() that would return a promise with the value set from a new callback function in the second-instance event: event.setResponse(data). Data type is left to implementers to decide what is easier/better. String is fine with me, or serialization could be done by the framework, I don't know what's best.

Alternatives Considered

I would have liked to tap into any already involved IPC mechanism used for that feature, but I don't know where to look for that, and it feels a bit hacky IMO.

Additional Information

This new flow would allow to put most argument parsing into the main single instance process, and avoid thinking about how to break the processing in the temporary second process and then maybe duplicate parsing again in the main instance. Please tell me if I just approach the issue from the wrong angle as well.

@LuminescentMoon
Copy link

Can you provide a concrete and realistic example of why this feature would be needed?

@paul-marechal
Copy link
Author

paul-marechal commented Nov 4, 2019

Make my second process exit with an exit code = 1 if the main process failed to process the 'second-instance' event. Else exit with code = 0.

@paul-marechal
Copy link
Author

Another concrete example I have is argument parsing: I want to do it in my single instance process on second-instance, but if I want the second process to display help, I have to parse argv there as well.

@nornagon
Copy link
Member

nornagon commented Mar 9, 2022

I think this is doable now that #30891 has been merged.

@nornagon nornagon closed this as completed Mar 9, 2022
@paul-marechal
Copy link
Author

@nornagon IIUC #30891 allows passing data from the second-instance to the main-instance. I opened this issue with the idea of communicating data back from the main-instance to the second-instance.

@paul-marechal
Copy link
Author

Actually this issue is fixed by #31460! Nice :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants