From b37065a81ec5cc1f92fd968075dedc9eb7f30082 Mon Sep 17 00:00:00 2001 From: The Jared Wilcurt Date: Thu, 26 Nov 2020 21:44:34 -0500 Subject: [PATCH 1/3] app.Name --- src/api/name.js | 47 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 44 insertions(+), 3 deletions(-) diff --git a/src/api/name.js b/src/api/name.js index a3097a1..f5b6815 100644 --- a/src/api/name.js +++ b/src/api/name.js @@ -1,17 +1,58 @@ /* - Electron Docs v10.1.1 + Electron Docs v11.0.3 https://www.electronjs.org/docs/api/app#appname `app.name()` + + A String property that indicates the current application's name, which is the name in + the application's package.json file. + + Usually the name field of package.json is a short lowercase name, according to the npm + modules spec. You should usually also specify a productName field, which is your + application's full capitalized name, and which will be preferred over name by Electron. */ /** - * [Description] + * Returns the value of "productName" in the package.json, or + * the value of "name" if there is no "productName". * - * @return {undefined} [Description] + * @return String The name of the application */ const name = function () { + let fs; + let appName; + if (window && window.nw && window.nw.App && window.nw.App.manifest && window.nw.App.manifest.name) { + appName = window.nw.App.manifest.name; + } + if (global && global.nw && global.nw.App && global.nw.App.manifest && global.nw.App.manifest.name) { + appName = global.nw.App.manifest.name; + } + if (window && window.nw && window.nw.App && window.nw.App.manifest && window.nw.App.manifest.productName) { + appName = window.nw.App.manifest.productName; + } + if (global && global.nw && global.nw.App && global.nw.App.manifest && global.nw.App.manifest.productName) { + appName = global.nw.App.manifest.productName; + } + if (!appName) { + if (global && global.require && global.require('fs')) { + fs = global.require('fs'); + } else if (window && window.require && window.require('fs')) { + fs = window.require('fs'); + } + if (fs && fs.existsSync('./package.json')) { + try { + let manifest = fs.readFileSync('./package.json'); + manifest = JSON.parse(manifest); + appName = manifest.productName || manifest.name; + } catch (err) { + console.log('Could not find appName. Failed to read or parse package.json'); + console.log(err); + } + } + } + + return appName; }; module.exports = name; From 3be2f23ed9f4c76d2beec5efae8dd128dd1584e1 Mon Sep 17 00:00:00 2001 From: The Jared Wilcurt Date: Tue, 8 Dec 2020 13:17:25 -0600 Subject: [PATCH 2/3] Update src/api/name.js --- src/api/name.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api/name.js b/src/api/name.js index f5b6815..06c652e 100644 --- a/src/api/name.js +++ b/src/api/name.js @@ -17,7 +17,7 @@ * Returns the value of "productName" in the package.json, or * the value of "name" if there is no "productName". * - * @return String The name of the application + * @return {string} The name of the application */ const name = function () { let fs; From 9c297509ec8afc239be636a896a8b959f67d9bd6 Mon Sep 17 00:00:00 2001 From: The Jared Wilcurt Date: Tue, 23 Mar 2021 20:56:39 -0400 Subject: [PATCH 3/3] Update src/api/name.js --- src/api/name.js | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/src/api/name.js b/src/api/name.js index 06c652e..2e976fd 100644 --- a/src/api/name.js +++ b/src/api/name.js @@ -22,18 +22,10 @@ const name = function () { let fs; let appName; - if (window && window.nw && window.nw.App && window.nw.App.manifest && window.nw.App.manifest.name) { - appName = window.nw.App.manifest.name; - } - if (global && global.nw && global.nw.App && global.nw.App.manifest && global.nw.App.manifest.name) { - appName = global.nw.App.manifest.name; - } - if (window && window.nw && window.nw.App && window.nw.App.manifest && window.nw.App.manifest.productName) { - appName = window.nw.App.manifest.productName; - } - if (global && global.nw && global.nw.App && global.nw.App.manifest && global.nw.App.manifest.productName) { - appName = global.nw.App.manifest.productName; - } + appName = window && window.nw && window.nw.App && window.nw.App.manifest && window.nw.App.manifest.name || appName; + appName = global && global.nw && global.nw.App && global.nw.App.manifest && global.nw.App.manifest.name || appName; + appName = window && window.nw && window.nw.App && window.nw.App.manifest && window.nw.App.manifest.productName || appName; + appName = global && global.nw && global.nw.App && global.nw.App.manifest && global.nw.App.manifest.productName || appName; if (!appName) { if (global && global.require && global.require('fs')) { fs = global.require('fs');