Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

app.name() #5

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 36 additions & 3 deletions src/api/name.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,50 @@

/*
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;
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');
} 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;