xmedeko
xmedeko

Reputation: 7802

Electron: difference between process.defaultApp and app.isPackaged

What is a the difference between Electron flags process.defaultApp and app.isPackaged? Both are used to distinguish dev and production environment. My observation is that Boolean(process.defaultApp) == !app.isPackaged always. Are there any cases, when both are true or both are false?

From doc and code:

process.defaultApp

A Boolean. When app is started by being passed as parameter to the default app, this property is true in the main process, otherwise it is undefined.

app.isPackaged

A Boolean property that returns true if the app is packaged, false otherwise. For many apps, this property can be used to distinguish development and production environments.

From the code - app.isPackaged is set when exec file is not electron or electron.exe.

Note: I know a minor difference is that process.defaultApp may be used in the main process only.

Upvotes: 5

Views: 3367

Answers (1)

Alex Rich
Alex Rich

Reputation: 71

Both can yield the same result, but some extra care has to be taken for the process.defaultApp property:

  • handle the case where it is undefined (by using the ! operator for instance)
  • make use of remote.process instead of process in a renderer process

Main process

var isPackaged = !process.defaultApp;

is equivalent to:

var isPackaged = require('electron').app.isPackaged;

Renderer process

var isPackaged = !require('electron').remote.process.defaultApp;

is equivalent to:

var isPackaged = require('electron').remote.app.isPackaged;

Edit:

Some extra information, although not 100% crystal clear, about why the app.isPackaged property had to be added can be found in the related pull request's conversation: add app.isPackaged #12656

Upvotes: 7

Related Questions