From daf75dd3755c994fdfba3f70686e75f4e4c4a2a2 Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Mon, 7 May 2018 23:15:31 -0700 Subject: [PATCH] add app.isPackaged (#12656) * add isPackaged method * add false test case for app.isPackaged() * document add.isPackaged() * check isPackaged() without fs call * convert to non-method property * document app.isPackaged as a property * update tests for app.isPackaged * remove unused fs require * clarify docs for isPackaged() --- docs/api/app.md | 6 ++++++ lib/browser/api/app.js | 9 +++++++++ spec/api-app-spec.js | 6 ++++++ 3 files changed, 21 insertions(+) diff --git a/docs/api/app.md b/docs/api/app.md index 48a4632d96..4661c9e409 100644 --- a/docs/api/app.md +++ b/docs/api/app.md @@ -1131,6 +1131,12 @@ Sets the application's [dock menu][dock-menu]. Sets the `image` associated with this dock icon. +## Properties + +### `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. + [dock-menu]:https://developer.apple.com/library/mac/documentation/Carbon/Conceptual/customizing_docktile/concepts/dockconcepts.html#//apple_ref/doc/uid/TP30000986-CH2-TPXREF103 [tasks]:https://msdn.microsoft.com/en-us/library/windows/desktop/dd378460(v=vs.85).aspx#tasks [app-user-model-id]: https://msdn.microsoft.com/en-us/library/windows/desktop/dd378459(v=vs.85).aspx diff --git a/lib/browser/api/app.js b/lib/browser/api/app.js index 789419a082..0db77baecb 100644 --- a/lib/browser/api/app.js +++ b/lib/browser/api/app.js @@ -1,6 +1,7 @@ 'use strict' const bindings = process.atomBinding('app') +const path = require('path') const {app, App} = bindings // Only one app object permitted. @@ -57,6 +58,14 @@ Object.assign(app, { } }) +app.isPackaged = (() => { + const execFile = path.basename(process.execPath).toLowerCase() + if (process.platform === 'win32') { + return execFile !== 'electron.exe' + } + return execFile !== 'electron' +})() + if (process.platform === 'darwin') { app.dock = { bounce (type = 'informational') { diff --git a/spec/api-app-spec.js b/spec/api-app-spec.js index 6a13543717..311c4dbcde 100644 --- a/spec/api-app-spec.js +++ b/spec/api-app-spec.js @@ -118,6 +118,12 @@ describe('app module', () => { }) }) + describe('app.isPackaged', () => { + it('should be false durings tests', () => { + assert.equal(app.isPackaged, false) + }) + }) + describe('app.isInApplicationsFolder()', () => { before(function () { if (process.platform !== 'darwin') {