Skip to content

Instantly share code, notes, and snippets.

@aguynamedben
Last active December 12, 2018 18:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aguynamedben/1266d6dac3fffcc333a29126db44682f to your computer and use it in GitHub Desktop.
Save aguynamedben/1266d6dac3fffcc333a29126db44682f to your computer and use it in GitHub Desktop.
Get friendly OS values in Node.js
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()}`;
}
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