Last active
December 12, 2018 18:41
-
-
Save aguynamedben/1266d6dac3fffcc333a29126db44682f to your computer and use it in GitHub Desktop.
Get friendly OS values in Node.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import log from 'electron-log'; | |
import macosVersion from 'macos-version'; | |
export function humanOSName() { | |
const platform = os.platform(); | |
if (platform === 'darwin') { | |
return 'macOS'; | |
} else if (platform === 'win') { | |
return 'Windows'; | |
} else if (platform === 'linux') { | |
return 'Linux'; | |
} else { | |
log.warn(`Unexpected OS platform '${platform}'`); | |
return platform; | |
} | |
} | |
/** | |
* Convert Dawrin kernel version to macOS version. | |
*/ | |
export function humanOSVersion() { | |
const platform = os.platform(); | |
if (platform === 'darwin') { | |
return macosVersion(); | |
} else { | |
return os.release(); | |
} | |
} | |
export function humanOSString() { | |
return `${humanOSName()} ${humanOSVersion()}`; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
analytics.identify({ | |
userId: id, | |
traits: { | |
email: email, | |
accountsStats: getAccountsStats(accounts), | |
providerIds: getAccountsProviderIds(accounts), | |
// App version | |
// TODO: Should we use context? | |
// https://github.com/segmentio/analytics-node/issues/193 | |
version: remote.app.getVersion(), | |
// Operating system version | |
// TODO: Should we use context? | |
// https://github.com/segmentio/analytics-node/issues/197#issuecomment-446402914 | |
osName: humanOSName(), | |
osVersion: humanOSVersion(), | |
os: humanOSString(), | |
}, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment