3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Electronで多重起動させない方法

Last updated at Posted at 2022-09-12

メインプロセス(Nodejs)

const { app } = require('electron');

// メインプロセス(Nodejs)の多重起動防止
const gotTheLock = app.requestSingleInstanceLock();
if (!gotTheLock) {
  console.log('メインプロセスが多重起動しました。終了します。');
  app.quit();
}

レンダラープロセス(画面)

例えば、設定画面なんかは同じ画面をいくつも表示したくないです。なので、プロセスの存在をチェックして、カーソルを合わせるだけの実装をします。

if (settingWindow && !settingWindow.isDestroyed()) {
  settingWindow.show();
  settingWindow.focus();
  return;
}
3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?