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

Don't error if DB is already open #125

Open
simonw opened this issue Sep 23, 2021 · 1 comment
Open

Don't error if DB is already open #125

simonw opened this issue Sep 23, 2021 · 1 comment
Labels
electron-wrapper Features that go in the Node.js/Electron code enhancement New feature or request

Comments

@simonw
Copy link
Owner

simonw commented Sep 23, 2021

I found out today that running this opens the database in Datasette Desktop, which is really cool!

open vaccinate.db

But... if you then run the same command a second time you get the following error:

vaccinate__location__80_842_rows

It would be better if it ignored the error and instead opened a window for that database - or re-focused a window if one was already open somewhere.

@simonw simonw added enhancement New feature or request electron-wrapper Features that go in the Node.js/Electron code labels Sep 23, 2021
@mnckapilan
Copy link
Contributor

mnckapilan commented Oct 3, 2021

Some preliminary research tells me that the electron API provides us a way to deal with this:

When open vaccinate.db is called, a new app instance will launch – one of the initial steps should be to call app.requestSingleInstanceLock() which:

  • returns true if your process is the primary instance of your application and your app should continue loading.
  • returns false if your process should immediately quit as it has sent its parameters to another instance that has already acquired the lock.

Our scenario where an instance of the app is already open should return false, and the second-instance event should be fired (and the primary instance of the app should handle the event accordingly):

app.on('second-instance', (event, commandLine, workingDirectory) => {
    // handle event here to re-focus existing open window
  })

If the file is already open, we can simply re-focus the window – if a new file is being called using open (rather than within the app), then we can open a new window accordingly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
electron-wrapper Features that go in the Node.js/Electron code enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants