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 () => {
const environment = await system.getEnvironment()
console.log(environment.osVersion)
console.log(environment.oliveHelpsVersion)
console.log(environment.loopVersion)
});
import { filesystem, network, system } from '@oliveai/ldk';
const CONFIG_FILE = {
windows: './windows.json',
darwin: './darwin.json',
};
const SUPPORTED_OS = Object.keys(CONFIG_FILE);
function validateOS(os) {
if (!SUPPORTED_OS.includes(os)) {
throw new Error(`This example does not support ${os}.`);
}
return os;
}
function getConfig(os) {
return CONFIG_FILE[os];
}
function buildNetworkRequest(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.
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 aptitude, aptitude, and aptitude.