Add a preference to temporarily disable Nightscout readings, for example if connectivity goes down

This commit is contained in:
Timothy Allen 2024-05-23 13:16:01 +02:00
parent 3f4b473c25
commit de85d1867f
3 changed files with 26 additions and 4 deletions

View File

@ -36,6 +36,7 @@ export default class NightscoutExtension extends Extension {
this._httpSession = new Soup.Session(); this._httpSession = new Soup.Session();
this._indicator = new PanelMenu.Button(0.0, this.metadata.name, false); this._indicator = new PanelMenu.Button(0.0, this.metadata.name, false);
this._systemSource = MessageTray.getSystemSource(); this._systemSource = MessageTray.getSystemSource();
this._active = this._settings.get_boolean('update-data');
this._label = new St.Label({ this._label = new St.Label({
text: "Loading...", text: "Loading...",
@ -44,8 +45,8 @@ export default class NightscoutExtension extends Extension {
}); });
this._indicator.add_child(this._label); this._indicator.add_child(this._label);
//this._indicator.menu.addAction(_('Preferences'), this._indicator.menu.addAction(_('Preferences'),
// () => this.openPreferences()); () => this.openPreferences());
Main.panel.addToStatusArea(this.uuid, this._indicator); Main.panel.addToStatusArea(this.uuid, this._indicator);
@ -61,6 +62,9 @@ export default class NightscoutExtension extends Extension {
return GLib.SOURCE_CONTINUE; return GLib.SOURCE_CONTINUE;
}); });
this._settings.connect('changed::update-data', (settings, key) => {
this._active = settings.get_boolean(key);
});
this._settings.connect('changed::url', () => { this._settings.connect('changed::url', () => {
this._update(); this._update();
}); });
@ -85,6 +89,11 @@ export default class NightscoutExtension extends Extension {
}; };
_update() { _update() {
if (!this._active) {
this._label.set_text("Disabled");
return;
}
//console.log("nightscout-follower: updating...") //console.log("nightscout-follower: updating...")
// Watch for changes to a specific setting // Watch for changes to a specific setting
this._fetch((status, data) => { this._fetch((status, data) => {

View File

@ -19,6 +19,16 @@ export default class NightscoutPreferences extends ExtensionPreferences {
page.add(group); page.add(group);
const update_row = new Adw.SwitchRow({
title: _('Connect to Nightscout'),
subtitle: _('Update current data from Nightscout'),
});
group.add(update_row);
window._settings.bind('update-data', update_row, 'active',
Gio.SettingsBindFlags.DEFAULT);
const url_row = new Adw.EntryRow({ const url_row = new Adw.EntryRow({
title: _('Nightscout URL'), title: _('Nightscout URL'),
}); });
@ -26,8 +36,6 @@ export default class NightscoutPreferences extends ExtensionPreferences {
url_row.set_show_apply_button(true); url_row.set_show_apply_button(true);
group.add(url_row); group.add(url_row);
//window._settings.bind('url', url_row, 'text',
// Gio.SettingsBindFlags.DEFAULT);
url_row.set_text(window._settings.get_string('url')); url_row.set_text(window._settings.get_string('url'));
url_row.connect('apply', () => { url_row.connect('apply', () => {
window._settings.set_string('url', url_row.text); window._settings.set_string('url', url_row.text);

View File

@ -1,6 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<schemalist> <schemalist>
<schema id="org.gnome.shell.extensions.nightscout-follower" path="/org/gnome/shell/extensions/nightscout-follower/"> <schema id="org.gnome.shell.extensions.nightscout-follower" path="/org/gnome/shell/extensions/nightscout-follower/">
<key name="update-data" type="b">
<default>false</default>
<summary>Connect to Nightscout</summary>
<description>Update current data</description>
</key>
<key name="url" type="s"> <key name="url" type="s">
<default>"https://API_SECRET@sitename.yourprovider.com"</default> <default>"https://API_SECRET@sitename.yourprovider.com"</default>
<summary>Nightscout URL</summary> <summary>Nightscout URL</summary>