-
Notifications
You must be signed in to change notification settings - Fork 1
/
utils.js
99 lines (78 loc) · 3.09 KB
/
utils.js
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/usr/bin/gjs
'use strict';
const ExtensionUtils = imports.misc.extensionUtils;
var wallpaperMode = {
DAY: 1,
NIGHT: 2
};
function getDesktopBackgroundSettings() {
return ExtensionUtils.getSettings('org.gnome.desktop.background');
}
function getAvailablePictureOptions() {
const backgroundSettings = getDesktopBackgroundSettings();
return backgroundSettings.settings_schema.get_key('picture-options').get_range().get_child_value(1).get_child_value(0).deep_unpack();
}
function isWallpaperOptionSelected(extensionSettings, wallpaperKey) {
return extensionSettings.get_string(wallpaperKey) != '';
}
function fallbackToSystemWallpaper(extensionSettings, wallpaperKey) {
const backgroundSettings = getDesktopBackgroundSettings();
const systemBackgroundUri = backgroundSettings.get_string('picture-uri');
extensionSettings.set_string(wallpaperKey, systemBackgroundUri);
}
function fallbackToSystemWallpaperAdjustment(extensionSettings, wallpaperAdjustmentKey) {
const backgroundSettings = getDesktopBackgroundSettings();
const systemBackgroundAdjustment = backgroundSettings.get_string('picture-options');
extensionSettings.set_string(wallpaperAdjustmentKey, systemBackgroundAdjustment);
}
function checkExtensionSettings() {
const extensionSettings = ExtensionUtils.getSettings();
if (!isWallpaperOptionSelected(extensionSettings, 'day-wallpaper')) {
fallbackToSystemWallpaper(extensionSettings, 'day-wallpaper');
}
if (!isWallpaperOptionSelected(extensionSettings, 'day-wallpaper-adjustment')) {
fallbackToSystemWallpaperAdjustment(extensionSettings, 'day-wallpaper-adjustment');
}
if (!isWallpaperOptionSelected(extensionSettings, 'night-wallpaper')) {
fallbackToSystemWallpaper(extensionSettings, 'night-wallpaper');
}
if (!isWallpaperOptionSelected(extensionSettings, 'night-wallpaper-adjustment')) {
fallbackToSystemWallpaperAdjustment(extensionSettings, 'night-wallpaper-adjustment');
}
}
var SwitchTime = class SwitchTime {
constructor(switchHour, switchMinute) {
this._switchHour = switchHour;
this._switchMinute = switchMinute;
}
get switchHour() {
return this._switchHour;
}
get switchMinute() {
return this._switchMinute;
}
toSettingsFormat() {
let decimal = this._switchMinute / 60;
decimal = parseFloat(decimal.toFixed(2));
return this._switchHour + decimal;
}
static newFromSettings(switchTimeFromSettings) {
let switchHour = parseInt(switchTimeFromSettings);
let decimal = switchTimeFromSettings - switchHour;
decimal = parseFloat(decimal.toFixed(2));
let switchMinute = Math.round(decimal * 60);
return new SwitchTime(switchHour, switchMinute);
}
}
var NextWallpaperSwitch = class NextWallpaperSwitch {
constructor(mode, secondsLeftForSwitch) {
this._mode = mode;
this._secondsLeftForSwitch = secondsLeftForSwitch;
}
get mode() {
return this._mode;
}
get secondsLeftForSwitch() {
return this._secondsLeftForSwitch;
}
}