This repository has been archived by the owner on Sep 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
prefs.js
190 lines (166 loc) · 6.77 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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
'use strict';
const { Gio, Gtk, Gdk, GLib, GObject } = imports.gi;
const Params = imports.misc.params;
const ExtensionUtils = imports.misc.extensionUtils;
const Me = ExtensionUtils.getCurrentExtension();
const Config = imports.misc.config;
const [major, minor] = Config.PACKAGE_VERSION.split('.').map(s => Number(s));
let Adw;
function init() {
}
function fillPreferencesWindow(window) {
Adw = imports.gi.Adw;
let prefs = new PrefsWindow(window);
prefs.fillPrefsWindow();
}
function buildPrefsWidget() {
let widget = new prefsWidget();
(major < 40) ? widget.show_all(): widget.show();
return widget;
}
const prefsWidget = GObject.registerClass(
class prefsWidget extends Gtk.Notebook {
_init(params) {
super._init(params);
this._settings = ExtensionUtils.getSettings('org.gnome.shell.extensions.visualizer');
this.margin = 20;
let grid = new Gtk.Grid();
attachItems(grid, new Gtk.Label({ label: 'Flip the Visualizer' }), getSwitch('flip-visualizer', this._settings), 0);
attachItems(grid, new Gtk.Label({ label: 'Visualizer Height' }), getSpinButton(false, 'visualizer-height', 1, 200, 1, this._settings), 1);
attachItems(grid, new Gtk.Label({ label: 'Visualizer Width' }), getSpinButton(false, 'visualizer-width', 1, 1920, 1, this._settings), 2);
attachItems(grid, new Gtk.Label({ label: 'Spects Line Width' }), getSpinButton(false, 'spects-line-width', 1, 20, 1, this._settings), 3);
attachItems(grid, new Gtk.Label({ label: 'Change Spects Band to Get' }), getSpinButton(false, 'total-spects-band', 1, 256, 1, this._settings), 4);
this.attachHybridRow(grid, new Gtk.Label({ label: 'Override Spect Value' }), new Gtk.Label({ label: 'Set Spects Value' }), getSwitch('spect-over-ride-bool', this._settings), getSpinButton(false, 'spect-over-ride', 1, 256, 1, this._settings), 5);
this.append_page(grid, new Gtk.Label({ label: 'Visualizer' }));
let aboutBox = new Gtk.Box({ orientation: Gtk.Orientation.VERTICAL });
if (major < 40) {
aboutBox.add(new Gtk.Label({ label: Me.metadata.name }));
aboutBox.add(new Gtk.Label({ label: 'Version: ' + Me.metadata.version.toString() }));
} else {
aboutBox.append(new Gtk.Label({ label: Me.metadata.name }));
aboutBox.append(new Gtk.Label({ label: 'Version: ' + Me.metadata.version.toString() }));
}
this.append_page(aboutBox, new Gtk.Label({ label: 'About' }));
}
attachHybridRow(grid, label, label1, button, button1, row) {
grid.attach(label, 0, row, 1, 1);
grid.attach(button, 1, row, 1, 1);
grid.attach(label1, 0, row + 1, 1, 1);
grid.attach(button1, 1, row + 1, 1, 1);
}
});
class PrefsWindow {
constructor(window) {
this._window = window;
this._settings = ExtensionUtils.getSettings('org.gnome.shell.extensions.visualizer');
}
create_page(title) {
let page = new Adw.PreferencesPage({
title: title,
//icon_name: icon,
});
this._window.add(page);
// get the headerbar
if (!this.headerbar) {
let pages_stack = page.get_parent(); // AdwViewStack
let content_stack = pages_stack.get_parent().get_parent(); // GtkStack
let preferences = content_stack.get_parent(); // GtkBox
this.headerbar = preferences.get_first_child(); // AdwHeaderBar
}
return page;
}
// create a new Adw.PreferencesGroup and add it to a prefsPage
create_group(page, title) {
let group;
if (title !== undefined) {
group = new Adw.PreferencesGroup({
title: title,
//margin_top: 5,
//margin_bottom: 5,
});
} else {
group = new Adw.PreferencesGroup();
}
page.add(group);
return group;
}
append_row(group, title, widget) {
let row = new Adw.ActionRow({
title: title,
});
group.add(row);
row.add_suffix(widget);
row.activatable_widget = widget;
}
append_expander_row(group, titleEx, title, key, key1) {
let expand_row = new Adw.ExpanderRow({
title: titleEx,
show_enable_switch: true,
expanded: this._settings.get_boolean(key),
enable_expansion: this._settings.get_boolean(key)
});
let row = new Adw.ActionRow({
title: title,
});
expand_row.connect("notify::enable-expansion", (widget) => {
let settingArray = this._settings.get_boolean(key);
settingArray = widget.enable_expansion;
this._settings.set_value(key, new GLib.Variant('b', settingArray));
});
row.add_suffix(key1);
expand_row.add_row(row);
group.add(expand_row);
};
append_info_group(group, name, title) {
let adw_group = new Adw.PreferencesGroup();
let infoBox = new Gtk.Box({
orientation: Gtk.Orientation.VERTICAL,
hexpand: false,
vexpand: false
});
let name_label = new Gtk.Label({
label: name,
});
let version = new Gtk.Label({
label: 'Version: ' + title,
});
infoBox.append(name_label);
infoBox.append(version);
adw_group.add(infoBox);
group.add(adw_group);
}
fillPrefsWindow() {
let visualWidget = this.create_page('Visualizer'); {
let groupVisual = this.create_group(visualWidget);
this.append_row(groupVisual, 'Flip the Visualizer', getSwitch('flip-visualizer', this._settings));
this.append_row(groupVisual, 'Visualizer Height', getSpinButton(false, 'visualizer-height', 1, 200, 1, this._settings));
this.append_row(groupVisual, 'Visualizer Width', getSpinButton(false, 'visualizer-width', 1, 1920, 1, this._settings));
this.append_row(groupVisual, 'Spects Line Width', getSpinButton(false, 'spects-line-width', 1, 20, 1, this._settings));
this.append_row(groupVisual, 'Change Spects Band to Get', getSpinButton(false, 'total-spects-band', 1, 256, 1, this._settings));
this.append_expander_row(groupVisual, 'Override Spect Value', 'Set Spects Value', 'spect-over-ride-bool', getSpinButton(false, 'spect-over-ride', 1, 256, 1, this._settings));
}
let aboutPage = this.create_page('About'); {
let groupAbout = this.create_group(aboutPage);
this.append_info_group(groupAbout, Me.metadata.name, Me.metadata.version.toString());
}
}
}
function attachItems(grid, label, widget, row) {
grid.set_column_spacing(200);
grid.set_row_spacing(25);
grid.attach(label, 0, row, 1, 1);
grid.attach(widget, 1, row, 1, 1);
}
function getSwitch(key, settings) {
let button = new Gtk.Switch({ active: key, valign: Gtk.Align.CENTER });
settings.bind(key, button, 'active', Gio.SettingsBindFlags.DEFAULT);
return button
}
function getSpinButton(is_double, key, min, max, step, settings) {
let v = 0;
(is_double) ? v = settings.get_double(key) : v = settings.get_int(key);
let spin = Gtk.SpinButton.new_with_range(min, max, step);
spin.set_value(v);
settings.bind(key, spin, 'value', Gio.SettingsBindFlags.DEFAULT);
return spin;
}