forked from GnomeSnapExtensions/gSnap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
settings.ts
60 lines (45 loc) · 1.81 KB
/
settings.ts
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
50
51
52
53
54
55
56
57
58
59
60
// GJS import system
declare var imports: any;
import * as SETTINGS from './settings_data';
import { log, setLoggingEnabled } from "./logging";
const ExtensionUtils = imports.misc.extensionUtils;
export const gridSettings = new SETTINGS.ParsedSettings();
export interface SettingsObject {
get_boolean(name: SETTINGS.BoolSettingName): boolean | undefined;
get_string(name: SETTINGS.StringSettingName): string | undefined;
get_int(name: SETTINGS.NumberSettingName): number | undefined;
connect(eventName: string, callback: () => void): any;
disconnect(c: any): void;
};
let settings: SettingsObject;
let settingsConnection: any = null;
export function getBoolSetting(settingName: SETTINGS.BoolSettingName): boolean {
const value = settings.get_boolean(settingName);
if (value === undefined) {
log("Undefined settings " + settingName);
return false;
}
return value;
}
export function getIntSetting(settingsValue: SETTINGS.NumberSettingName) {
let iss = settings.get_int(settingsValue);
if (iss === undefined) {
log("Undefined settings " + settingsValue);
return 0;
} else {
return iss;
}
}
export function initSettings(changed_settings: () => void) {
settings = ExtensionUtils.getSettings();
settingsConnection = settings.connect('changed', changed_settings);
setLoggingEnabled(getBoolSetting(SETTINGS.DEBUG));
log("Init settings");
gridSettings[SETTINGS.SHOW_ICON] = getBoolSetting(SETTINGS.SHOW_ICON);
gridSettings[SETTINGS.SHOW_TABS] = getBoolSetting(SETTINGS.SHOW_TABS);
gridSettings[SETTINGS.WINDOW_MARGIN] = getIntSetting(SETTINGS.WINDOW_MARGIN);
log("Init complete");
}
export function deinitSettings() {
settings.disconnect(settingsConnection);
}