forked from lukearran/GNOME-Cast-Control
-
Notifications
You must be signed in to change notification settings - Fork 0
/
prefs.js
164 lines (130 loc) · 4.29 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
'use strict'
const Gio = imports.gi.Gio;
const Gtk = imports.gi.Gtk;
const GLib = imports.gi.GLib;
const Lang = imports.lang;
const GObject = imports.gi.GObject;
const ExtensionUtils = imports.misc.extensionUtils;
const Me = ExtensionUtils.getCurrentExtension();
const compat = Me.imports.helpers.compatibility;
function init(){
}
function buildPrefsWidget(){
// Load the schema values
this.settings = this.compat.getExtensionUtilsSettings().getSettings('castcontrol.hello.lukearran.com');
// Create a parent widget that we'll return from this function
let layout = new Gtk.Grid({
margin: 50,
column_spacing: 12,
row_spacing: 18,
visible: true
});
// Add a simple title and add it to the layout
let title = new Gtk.Label({
label: `<b>${Me.metadata.name} Settings</b>`,
halign: Gtk.Align.START,
use_markup: true,
visible: true
});
layout.attach(title, 0, 0, 2, 1);
// Auto Start Control
let autoStartLabel = new Gtk.Label({
label: ' Automatic Start Cast API ',
halign: Gtk.Align.START,
visible: true
});
layout.attach(autoStartLabel, 0, 1, 1, 1);
let autoStartSwitchControl = new Gtk.Switch({
visible: true,
margin_right: 100
});
var isAuto = this.settings.get_boolean("auto-castapi");
autoStartSwitchControl.set_state(isAuto);
layout.attach(autoStartSwitchControl, 1, 1, 1, 1);
// API Hostname
let hostnameLabel = new Gtk.Label({
label: ' API Hostname Custom Endpoint',
halign: Gtk.Align.START,
visible: true
});
layout.attach(hostnameLabel, 0, 2, 1, 2);
let hostnameTextbox = new Gtk.Entry({
visible: true
});
var hostnameValue = this.settings.get_string("castapi-hostname");
hostnameTextbox.set_text(hostnameValue);
layout.attach(hostnameTextbox, 1, 2, 2, 2);
// API Port
let portLabel = new Gtk.Label({
label: ' API Port Custom Endpoint ',
halign: Gtk.Align.START,
visible: true
});
layout.attach(portLabel, 0, 4, 1, 3);
let portTextbox = new Gtk.SpinButton({
visible: true,
numeric: true,
snap_to_ticks: true,
climb_rate: 1
});
var serverPortValue = this.settings.get_int("castapi-port");
portTextbox.set_range(1000, 9999);
portTextbox.set_increments(1, 1);
portTextbox.set_value(serverPortValue);
layout.attach(portTextbox, 1, 4, 1, 3);
// Refresh Interval
let refreshIntervalLabel = new Gtk.Label({
label: ' Refresh Interval (Sec) ',
halign: Gtk.Align.START,
visible: true
});
layout.attach(refreshIntervalLabel, 0, 7, 1, 3);
let refreshIntervalTextbox = new Gtk.SpinButton({
visible: true,
numeric: true,
climb_rate: 1
});
var serverRefreshIntervalValue = this.settings.get_int("refresh-interval-ms") / 1000;
refreshIntervalTextbox.set_range(1, 9999);
refreshIntervalTextbox.set_increments(1, 1);
refreshIntervalTextbox.set_value(serverRefreshIntervalValue);
layout.attach(refreshIntervalTextbox, 1, 7, 1, 3);
// Save Button
let saveButton = new Gtk.Button({
label: ' Save Changes ',
visible: true
});
// On the Save Button clicked, apply settings
saveButton.connect('clicked', (button) => {
// Auto Start API
this.settings.set_boolean(
'auto-castapi',
autoStartSwitchControl.get_state()
);
// Hostname
this.settings.set_string(
'castapi-hostname',
hostnameTextbox.get_text()
);
// Port
this.settings.set_int(
'castapi-port',
portTextbox.get_value()
);
// Refresh Interval
this.settings.set_int(
'refresh-interval-ms',
refreshIntervalTextbox.get_value() * 1000
);
});
layout.attach(saveButton, 1, 50, 1, 1);
// Get Cast API Button
let getApiButton = new Gtk.LinkButton({
label: " Don't have Cast API installed? ",
halign: Gtk.Align.START,
visible: true,
uri: 'https://github.com/lukearran/GNOME-Cast-Control'
});
layout.attach_next_to(getApiButton, saveButton, Gtk.PositionType.LEFT, 1, 1);
return layout;
}