electron-vite-vue icon indicating copy to clipboard operation
electron-vite-vue copied to clipboard

[Help] how to run the built application and `npm run dev` at the same time?

Open DenniLa2 opened this issue 1 year ago • 6 comments

On macos unable to run built app and npm run dev at the same time. If built app is running, then npm run dev returns image otherwise nothing happens.

DenniLa2 avatar Apr 24 '23 06:04 DenniLa2

Need comment this:

if (!app.requestSingleInstanceLock()) {
  app.quit()
  process.exit(0)
}

)

DenniLa2 avatar Apr 24 '23 07:04 DenniLa2

Maybe the following code is better.

- if (!app.requestSingleInstanceLock()) {
-   app.quit()
-   process.exit(0)
- }

caoxiemeihao avatar Apr 24 '23 08:04 caoxiemeihao

Maybe the following code is better.

- if (!app.requestSingleInstanceLock()) {
-   app.quit()
-   process.exit(0)
- }

Indeed, allowing many instances if it is not required is a bad idea. So I decided to do this:

if (isDevMode()) {
  app.setName(`${app.name}-dev`)
}

if (!app.requestSingleInstanceLock()) {
  app.quit()
  process.exit(0)
}

@caoxiemeihao thanks

DenniLa2 avatar Apr 25 '23 07:04 DenniLa2

The compiled application and launched through npm run dev get one pid. Because of this, I cannot run both the built and developed applications at the same time. @caoxiemeihao How to make the assembled application get a name not from package.json.name?

DenniLa2 avatar Apr 29 '23 10:04 DenniLa2

import { app } from 'electron'

app.getName()

caoxiemeihao avatar May 01 '23 00:05 caoxiemeihao

If I understand correctly, then the OS generates a PID based on the application name. When assembled, the name is taken from package.json.name. When I run the built app and when I run the app from npm run dev they have the same PID. Because of this, I can't run a built app and a development app at the same time. But if I specify a different name when building in package.json.name, then the assembled application gets a different name. And, as a result, another PID. But it's not convenient. I want to substitute a name during assembly that is different from what is in package.json.name. How to do it?

DenniLa2 avatar May 02 '23 03:05 DenniLa2