System
The System Aptitude provides the ability to access information about the user's system.
API
Example
Permissions

operatingSystem

operatingSystem returns a promise with a string that describes which operating system the Loop is running on.
1
import { system } from '@oliveai/ldk';
2
3
system.operatingSystem().then((os) => {
4
console.log(os);
5
});
6
7
/*
8
* This will print out one of:
9
* windows
10
* darwin (This will be returned for macOS)
11
* linux
12
*/
Copied!

getEnvironment

getEnvironment returns a promise with an object that contains the osVersion, oliveHelpsVersion, and the loopVersion.
1
import { system } from '@oliveai/ldk';
2
3
(async () => {
4
const environment = await system.getEnvironment()
5
console.log(environment.osVersion)
6
console.log(environment.oliveHelpsVersion)
7
console.log(environment.loopVersion)
8
});
9
Copied!
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.
1
import { filesystem, network, system } from '@oliveai/ldk';
2
3
const CONFIG_FILE = {
4
windows: './windows.json',
5
darwin: './darwin.json',
6
};
7
8
const SUPPORTED_OS = Object.keys(CONFIG_FILE);
9
10
function validateOS(os) {
11
if (!SUPPORTED_OS.includes(os)) {
12
throw new Error(`This example does not support ${os}.`);
13
}
14
15
return os;
16
}
17
18
function getConfig(os) {
19
return CONFIG_FILE[os];
20
}
21
22
function buildNetworkRequest(config) {
23
return {
24
url: config['url'],
25
method: 'GET',
26
};
27
}
28
29
system.operatingSystem()
30
.then(validateOS)
31
.then(getConfig)
32
.then(filesystem.readFile)
33
.then(network.decode)
34
.then(JSON.parse)
35
.then(buildNetworkRequest)
36
.then(network.httpRequest)
37
.then( /* Do something with the request */ )
38
.catch((e) => console.log(e));
Copied!
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.
1
...
2
"ldk": {
3
"permissions": {
4
"system": {},
5
...
6
}
7
},
8
...
Copied!

Last modified 1mo ago
Copy link
Contents