Fix show UI when opening Station twice. Closes #266#274
Conversation
|
Converted to a draft because CI is failing |
bajtos
left a comment
There was a problem hiding this comment.
Great UX improvement 👏🏻
Let's make the implementation easier to reason about and more robust in edge cases 👇🏻
| app.on('second-instance', () => { | ||
| ctx.showUI() | ||
| }) | ||
|
|
There was a problem hiding this comment.
Nice! I did not know about this event.
Here is the link to API docs: https://www.electronjs.org/docs/latest/api/app#event-second-instance
I think it would be better to have app.on('second-instance') and app.requestSingleInstanceLock() closer together. Can you perhaps move these new four lines to the top of the file, insert it at line 74?
I think we should also change the condition !app.requestSingleInstanceLock() && !inTest to skip requesting single instance lock when running in the test environment. Otherwise we request the lock just to ignore it, while still triggering second-instance event in the other running instance.
if (!inTest && !app.requestSingleInstanceLock()) { Thoughts?
There was a problem hiding this comment.
These are really great suggestions! I implemented both :)
| app.quit() | ||
| } | ||
|
|
||
| app.on('second-instance', () => { |
There was a problem hiding this comment.
Nitpick: feel free to ignore.
I would add a comment to explain the UX flow we are implementing here. E.g.
// When the user attempts to start the app from the menu because
// they don't notice the Station icon in the tray, then help
// them finding the Station by showing our main window.
app.on('second-instance', () => {After I wrote this comment, I realised it would be even nicer if the main window could also show a dialog explaining to the user that the Station has been running in the background and that they can always find it in the Tray (macOS menu bar). That's probably out of the scope of this PR, though.
There was a problem hiding this comment.
great suggestions, added docs and opened #282
In #266, @walkerlj0 thought Station didn't open when she opened it, although it was already open (and hidden in the tray).
This change makes it so the app show its UI when you open it a second time, to try to recover from that situation.
Closes #266.