Skip to content
This repository has been archived by the owner on Aug 30, 2023. It is now read-only.

Two instances are opened when I try to open a single file #258

Closed
rudolfvesely opened this issue Apr 23, 2019 · 6 comments
Closed

Two instances are opened when I try to open a single file #258

rudolfvesely opened this issue Apr 23, 2019 · 6 comments
Labels

Comments

@rudolfvesely
Copy link

Hi all,

Fantastic Markdown editor. Thank you for the great work.

The only issue I have is that when I click on another (second, third...) markdown file the editor is opened twice. I recorded a short GIF to explain:

vokoscreen-2019-04-23_09-37-36

My environment:

Abricotine: 7.0.0
Linux with KDE Plasma 5.14 desktop

Kind regards,
Rudolf

@brrd brrd added the bug label Apr 29, 2019
@GitSquared
Copy link

@brrd
Copy link
Owner

brrd commented Oct 21, 2019

This might be related?

Probably yes. Obviously the document is redirected to the first instance as expected, but it is still opened in the new instance, which makes a duplicate.

@GitSquared
Copy link

@brrd It seems that the second instance continue its startup process even though it failed to acquire the lock.
From the docs, you should add this:

const { app } = require('electron')
let myWindow = null

const gotTheLock = app.requestSingleInstanceLock()

if (!gotTheLock) {
  app.quit()
} else {
  app.on('second-instance', (event, commandLine, workingDirectory) => {
    // Someone tried to run a second instance, we should focus our window.
    if (myWindow) {
      if (myWindow.isMinimized()) myWindow.restore()
      myWindow.focus()
    }
  })

  // Create myWindow, load the rest of the app, etc...
  app.on('ready', () => {
  })
}

Or you could simply do this at line 18:

app.requestSingleInstanceLock() || app.quit();

@brrd
Copy link
Owner

brrd commented Oct 21, 2019

@GitSquared Yes, you're right. It should use app.requestSingleInstanceLock() return value. I obviously forgot this point when I moved from the previous API.

@GitSquared
Copy link

@brrd I suppose you won't need a PR for this, but ping me if needed.

tsonne added a commit to tsonne/Abricotine that referenced this issue Feb 18, 2020
@tsonne
Copy link

tsonne commented Feb 24, 2020

Sorry if I'm polluting your Issues board here with my fork commit. I just wanted to fix it for myself.
One thing: I couldn't build Abricotine with the latest Node.js 13.8.0 due to the spellchecker module, but it works fine with node version 12.14.1

@brrd brrd closed this as completed in efd6d27 Apr 16, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants