-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsettingsParser.js
More file actions
49 lines (44 loc) · 1.87 KB
/
settingsParser.js
File metadata and controls
49 lines (44 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
"use strict";
import { ServerSetting } from "./serverSetting.js";
/**
* Convert `Gio.Settings` into `ServerSetting`s.
*/
export class SettingsParser {
/**
* Parse a `Gio.Settings` instance.
*
* @param {Gio.Settings} gioSettings the persisted settings
* @returns {ServerSetting} array of `ServerSetting`s
*/
static parseGioSettings(gioSettings) {
const variant = gioSettings.get_value("server-settings");
const savedSettings = variant.deep_unpack();
const settings = [];
for (const savedSetting of savedSettings) {
const name =
savedSetting["name"] !== undefined ? savedSetting["name"] : "";
const url =
savedSetting["url"] !== undefined ? savedSetting["url"] : "";
const frequency =
savedSetting["frequency"] !== undefined
? Number(savedSetting["frequency"])
: 120;
const timeout =
savedSetting["timeout"] !== undefined
? Number(savedSetting["timeout"])
: 10;
// migrate old key
let isGet = false;
if (savedSetting["is_get"] !== undefined) {
isGet = savedSetting["is_get"] === "true";
} else if (savedSetting["isGet"] !== undefined) {
isGet = savedSetting["isGet"] === "true";
}
const notifies = savedSetting["notifies"] !== undefined ? savedSetting["notifies"] === "true" : false; // defaults to false
const visible = savedSetting["visible"] !== undefined ? savedSetting["visible"] === "true" : true; // defaults to true for backward compatibility
const setting = new ServerSetting(name, url, frequency, timeout, isGet, notifies, visible);
settings.push(setting);
}
return settings;
}
}