forked from RedSoftwareSystems/easy_docker_containers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
prefs.js
136 lines (112 loc) · 3.22 KB
/
prefs.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
"use strict";
const { Gio, Gtk, GObject } = imports.gi;
const Config = imports.misc.config;
const ExtensionUtils = imports.misc.extensionUtils;
const Me = ExtensionUtils.getCurrentExtension();
const [major] = Config.PACKAGE_VERSION.split(".");
const shellVersion = Number.parseInt(major);
const BOX_PADDING = 8;
const MARGIN_BOTTOM = 8;
const WIDGET_PADDING = 16;
const getMarginAll = (value) => ({
margin_start: value,
margin_top: value,
margin_end: value,
margin_bottom: value,
});
const addToBox = (box, element) => {
if (shellVersion < 40) {
box.add(element);
} else {
box.append(element);
}
};
const getIntervalSpinButton = () => {
const settings = ExtensionUtils.getSettings(
"red.software.systems.easy_docker_containers"
);
const spin = new Gtk.SpinButton({
valign: Gtk.Align.CENTER,
climb_rate: 10,
digits: 0,
snap_to_ticks: true,
adjustment: new Gtk.Adjustment({
lower: 0,
upper: 3600,
step_increment: 1,
page_size: 0,
}),
});
settings.bind("refresh-delay", spin, "value", Gio.SettingsBindFlags.DEFAULT);
return spin;
};
// Heavily inspired by https://github.com/MichalW/gnome-bluetooth-battery-indicator/blob/6b769eacd5b58eaef9d4fd7160cbd5fef9723731/settingsWidget.js
const SettingsWidget = GObject.registerClass(
class SettingsWidget extends Gtk.Box {
_init(params) {
super._init(params);
this.set_orientation(Gtk.Orientation.VERTICAL);
if (shellVersion < 40) {
this.set_border_width(WIDGET_PADDING);
}
addToBox(this, this._getIndicatorSettingsFrame());
}
_getIndicatorSettingsFrame() {
const hBox1 = new Gtk.Box({
orientation: Gtk.Orientation.HORIZONTAL,
...getMarginAll(BOX_PADDING),
});
addToBox(hBox1, this._getIntervalLabel());
addToBox(hBox1, getIntervalSpinButton());
const vBox = new Gtk.Box({
orientation: Gtk.Orientation.VERTICAL,
...getMarginAll(BOX_PADDING),
});
addToBox(vBox, hBox1);
const frame = new Gtk.Frame({
margin_bottom: MARGIN_BOTTOM,
});
if (shellVersion < 40) {
frame.add(vBox);
} else {
frame.set_child(vBox);
}
return frame;
}
_getIntervalLabel() {
return new Gtk.Label({
label:
"Container count refresh interval (seconds). Set to 0 to disable",
xalign: 0,
hexpand: true,
});
}
}
);
function init() {}
// Used on GNOME < 42 only, uses classical GTK4 Window and widgets
function buildPrefsWidget() {
const prefsWidget = new SettingsWidget();
if (shellVersion < 40) {
prefsWidget.show_all();
} else {
prefsWidget.show();
}
return prefsWidget;
}
// // Takes precedence over buildPrefsWidget in GNOME 42+, uses Adw.PreferencesWindow
function fillPreferencesWindow(window) {
const { Adw } = imports.gi;
const page = new Adw.PreferencesPage();
const group = new Adw.PreferencesGroup();
page.add(group);
const row = new Adw.ActionRow({
title: "Container count refresh interval. Set to 0 to disable",
});
group.add(row);
const delayInput = getIntervalSpinButton();
row.add_suffix(delayInput);
row.activatable_widget = delayInput;
window.add(page);
return window;
}