The System Aptitude provides the ability to access information about the user's system.
operatingSystem
operatingSystem returns a promise with a string that describes which operating system the Loop is running on.
import { system } from'@oliveai/ldk';system.operatingSystem().then((os) => {console.log(os);});/* * This will print out one of: * windows * darwin (This will be returned for macOS) * linux */
getEnvironment
getEnvironment returns a promise with an object that contains the osVersion, oliveHelpsVersion, and the loopVersion.
import { system } from'@oliveai/ldk';(async () => {constenvironment=awaitsystem.getEnvironment()console.log(environment.osVersion)console.log(environment.oliveHelpsVersion)console.log(environment.loopVersion)});
In some cases you may need to do something specific to the operating system, whether it's loading a specific configuration file or retrieving data from an API. Here's a quick example on how to do both using the System aptitude, Filesystem aptitude, and Network aptitude.
import { filesystem, network, system } from'@oliveai/ldk';constCONFIG_FILE= { windows:'./windows.json', darwin:'./darwin.json',};constSUPPORTED_OS=Object.keys(CONFIG_FILE);functionvalidateOS(os) {if (!SUPPORTED_OS.includes(os)) {thrownewError(`This example does not support ${os}.`); }return os;}functiongetConfig(os) {returnCONFIG_FILE[os];}functionbuildNetworkRequest(config) {return { url: config['url'], method:'GET', };}system.operatingSystem().then(validateOS).then(getConfig).then(filesystem.readFile).then(network.decode).then(JSON.parse).then(buildNetworkRequest).then(network.httpRequest).then( /* Do something with the request */ ).catch((e) =>console.log(e));
To use the System Aptitude, simply set the following permissions in your package.json under the ldk object.
Please see our Permissions page for more information.