Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 72 additions & 36 deletions HeadsetControl@lauinger-clan.de/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Clutter from "gi://Clutter";
import * as Main from "resource:///org/gnome/shell/ui/main.js";
import * as PopupMenu from "resource:///org/gnome/shell/ui/popupMenu.js";
import * as QuickSettings from "resource:///org/gnome/shell/ui/quickSettings.js";
import * as MessageTray from "resource:///org/gnome/shell/ui/messageTray.js";
import { Extension, gettext as _ } from "resource:///org/gnome/shell/extensions/extension.js";
import { PopupAnimation } from "resource:///org/gnome/shell/ui/boxpointer.js";

Expand Down Expand Up @@ -70,15 +71,15 @@ async function invokeCmd(cmd, logger) {

const HeadsetControlMenuToggle = GObject.registerClass(
class HeadsetControlMenuToggle extends QuickSettings.QuickMenuToggle {
constructor(Me) {
const { _settings } = Me;
constructor(extension) {
const { _settings } = extension;
super({
title: _("HeadsetControl"),
iconName: "audio-headset-symbolic",
toggleMode: true,
});
this._logger = Me.getLogger();
this._useLogging = Me._useLogging;
this._logger = extension.getLogger();
this._useLogging = extension._useLogging;
this._settings = _settings;
this._valueBatteryStatus = "";
this._valueBattery = "";
Expand All @@ -91,7 +92,7 @@ const HeadsetControlMenuToggle = GObject.registerClass(
this.setMenuHeader();
this.setMenuTitle();

const quicksettingstoggle = _settings.get_int("quicksettings-toggle");
const quicksettingstoggle = this._settings.get_int("quicksettings-toggle");
let quicksettingstogglekey;
switch (quicksettingstoggle) {
case 1:
Expand All @@ -106,10 +107,10 @@ const HeadsetControlMenuToggle = GObject.registerClass(
default:
quicksettingstogglekey = "show-systemindicator";
}
_settings.bind(quicksettingstogglekey, this, "checked", Gio.SettingsBindFlags.DEFAULT);
this._settings.bind(quicksettingstogglekey, this, "checked", Gio.SettingsBindFlags.DEFAULT);

this._buildMenu();
this._addSettingsAction(Me);
this._addSettingsAction(extension);
}

updateUseLogging(value) {
Expand Down Expand Up @@ -176,17 +177,20 @@ const HeadsetControlMenuToggle = GObject.registerClass(
}
}

refreshMenu(Me) {
refreshMenu(extension) {
this.menu.removeAll();
this._buildMenu();
this._addSettingsAction(Me);
this._addSettingsAction(extension);
}

_addSettingsAction(Me) {
_addSettingsAction(extension) {
this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
const settingsItem = this.menu.addAction(_("Settings"), () => Me._openPreferences());
const settingsItem = this.menu.addAction(_("Settings"), () => {
extension.openPreferences();
QuickSettingsMenu.menu.close(PopupAnimation.FADE);
});
settingsItem.visible = Main.sessionMode.allowSettings;
this.menu._settingsActions[Me.uuid] = settingsItem;
this.menu._settingsActions[extension.uuid] = settingsItem;
}

updateBatteryStatus(strStatus, strBattery, lngBattery) {
Expand Down Expand Up @@ -421,8 +425,8 @@ const HeadsetControlMenuToggle = GObject.registerClass(

const HeadsetControlIndicator = GObject.registerClass(
class HeadsetControlIndicator extends QuickSettings.SystemIndicator {
constructor(Me) {
const { _settings } = Me;
constructor(extension) {
const { _settings } = extension;
super();

// Create the icon for the indicator
Expand All @@ -439,7 +443,7 @@ const HeadsetControlIndicator = GObject.registerClass(

// Create the toggle menu and associate it with the indicator, being
// sure to destroy it along with the indicator
this._headsetControlMenuToggle = new HeadsetControlMenuToggle(Me);
this._headsetControlMenuToggle = new HeadsetControlMenuToggle(extension);
this.quickSettingsItems.push(this._headsetControlMenuToggle);

this.connect("destroy", () => {
Expand Down Expand Up @@ -509,17 +513,7 @@ export default class HeadsetControl extends Extension {
return retval;
}

_notify(strText) {
if (this._useNotifications) {
Main.notify(_("HeadsetControl"), strText);
}
}

_initCmd() {
this._useNotifications = this._settings.get_boolean("use-notifications");
this._useLogging = this._settings.get_boolean("use-logging");
this._headsetControlIndicator.headsetControlMenuToggle.updateUseLogging(this._useLogging);

// Helper function to construct commands
const buildCommand = (executable, option) => `${executable} ${option}`;

Expand Down Expand Up @@ -711,6 +705,10 @@ export default class HeadsetControl extends Extension {
} finally {
this._headsetControlIndicator.updateUIElements();
this._changeIndicatorVisibility();
this._notifyLowBattery(
this._headsetControlIndicator.headsetControlMenuToggle.valueBatteryStatus,
this._headsetControlIndicator.valueBatteryNum
);
}
}

Expand Down Expand Up @@ -818,7 +816,6 @@ export default class HeadsetControl extends Extension {
}

async _refreshIndicator() {
this._notify("_refreshIndicator - " + _("Refreshing..."));
this._logOutput("_refreshIndicator - " + _("Refreshing..."));
if (this._JSONoutputSupported) {
await this._refreshJSON();
Expand All @@ -828,6 +825,10 @@ export default class HeadsetControl extends Extension {
await this._refreshBatteryStatus();
this._headsetControlIndicator.updateUIElements();
this._changeIndicatorVisibility();
this._notifyLowBattery(
this._headsetControlIndicator.headsetControlMenuToggle.valueBatteryStatus,
this._headsetControlIndicator.valueBatteryNum
);
}
}

Expand All @@ -841,7 +842,6 @@ export default class HeadsetControl extends Extension {
this._logOutput(_("Quicksettings not open - do nothing..."));
return;
}
this._notify(_("Refreshing..."));
this._logOutput(_("Refreshing..."));

if (this._JSONoutputSupported) {
Expand All @@ -859,13 +859,23 @@ export default class HeadsetControl extends Extension {
}
this._headsetControlIndicator.updateUIElements();
this._changeIndicatorVisibility();
this._notifyLowBattery(
this._headsetControlIndicator.headsetControlMenuToggle.valueBatteryStatus,
this._headsetControlIndicator.valueBatteryNum
);
}

_onParamChanged() {
this.disable();
this.enable();
}

_onParamChangedLogNot() {
this._notificationLowBattery = this._settings.get_boolean("notification-low-battery");
this._useLogging = this._settings.get_boolean("use-logging");
this._headsetControlIndicator.headsetControlMenuToggle.updateUseLogging(this._useLogging);
}

_onParamChangedMenu() {
if (capabilities.sidetone) {
this._headsetControlIndicator.headsetControlMenuToggle.refreshMenu(this);
Expand Down Expand Up @@ -923,11 +933,6 @@ export default class HeadsetControl extends Extension {
}
}

_openPreferences() {
this.openPreferences();
QuickSettingsMenu.menu.close(PopupAnimation.FADE);
}

async _updateBinaryCapabilities() {
this._logOutput("_updateBinaryCapabilities - calling _refreshJSONupdate");
const ret = await this._refreshJSONupdate(this._showIndicator);
Expand All @@ -937,15 +942,41 @@ export default class HeadsetControl extends Extension {
await this._refreshIndicator();
}

_notifyLowBattery(strStatus, valueBatteryNum) {
this._logOutput("_notifyLowBattery - Battery: " + valueBatteryNum);
this._logOutput("_notifyLowBattery - _notificationLowBattery: " + this._notificationLowBattery);
this._logOutput("_notifyLowBattery - batteryLowNotified: " + this._batteryLowNotified);
if (
strStatus !== "BATTERY_UNAVAILABLE" &&
strStatus !== "BATTERY_CHARGING" &&
valueBatteryNum <= 25 &&
this._notificationLowBattery
) {
if (!this._batteryLowNotified) {
const source = MessageTray.getSystemSource();
const notification = new MessageTray.Notification({
source,
title: _("HeadsetControl"),
body: _("Battery low! Please charge your headset."),
isTransient: false,
});
source.addNotification(notification);
this._batteryLowNotified = true;
}
}
}

enable() {
this._devicecount = 0;
this._visible = false;
this._refreshIndicatorRunning = false;
this._batteryLowNotified = false;
this._settings = this.getSettings();

this._useLogging = this._settings.get_boolean("use-logging");
this._headsetControlIndicator = new HeadsetControlIndicator(this);
this._initCmd();
this._notificationLowBattery = this._settings.get_boolean("notification-low-battery");
this._useLogging = this._settings.get_boolean("use-logging");
this._useColors = this._settings.get_boolean("use-colors");
this._showIndicator = this._settings.get_boolean("show-systemindicator");
this._hideWhenDisconnectedSystemindicator = this._settings.get_boolean("hidewhendisconnected-systemindicator");
Expand All @@ -961,8 +992,12 @@ export default class HeadsetControl extends Extension {
key: "headsetcontrol-executable",
callback: this._initCmd.bind(this),
},
{ key: "use-notifications", callback: this._initCmd.bind(this) },
{ key: "use-logging", callback: this._initCmd.bind(this) },
{
key: "option-output-format",
callback: this._initCmd.bind(this),
},
{ key: "notification-low-battery", callback: this._onParamChangedLogNot.bind(this) },
{ key: "use-logging", callback: this._onParamChangedLogNot.bind(this) },
{
key: "show-systemindicator",
callback: this._onParamChangedIndicator.bind(this),
Expand Down Expand Up @@ -1024,8 +1059,9 @@ export default class HeadsetControl extends Extension {
this._showIndicator = null;
this._hideWhenDisconnectedSystemindicator = null;
this._refreshIndicatorRunning = null;
this._batteryLowNotified = null;
this._refreshIntervalSystemindicator = null;
this._useNotifications = null;
this._notificationLowBattery = null;
this._useLogging = null;
this._useColors = null;
}
Expand Down
2 changes: 1 addition & 1 deletion HeadsetControl@lauinger-clan.de/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
"github": "ChrisLauinger77",
"paypal": "ChrisLauinger"
},
"version-name": "49.6"
"version-name": "49.7"
}
4 changes: 2 additions & 2 deletions HeadsetControl@lauinger-clan.de/prefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,9 @@ export default class AdwPrefs extends ExtensionPreferences {
adwrow = builder.get_object("HeadsetControl_row_showindicator3");
adwrow.set_value(this.getSettings().get_int("refreshinterval-systemindicator"));
adwrow.connect("changed", this._onRIvaluechanged.bind(this, adwrow));
//use notifications
// notification for low battery
adwrow = builder.get_object("HeadsetControl_row_notifications");
window._settings.bind("use-notifications", adwrow, "active", Gio.SettingsBindFlags.DEFAULT);
window._settings.bind("notification-low-battery", adwrow, "active", Gio.SettingsBindFlags.DEFAULT);
//use logging
adwrow = builder.get_object("HeadsetControl_row_logging");
window._settings.bind("use-logging", adwrow, "active", Gio.SettingsBindFlags.DEFAULT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@
headset)</summary>
<description>Shown in equalizer preset menu (when supported)</description>
</key>
<key name="use-notifications" type="b">
<default>false</default>
<summary>Parameter to enable notifications</summary>
<description>Enable / disable notifications</description>
<key name="notification-low-battery" type="b">
<default>true</default>
<summary>Parameter to enable notification when battery is low</summary>
<description>Send a notification when the battery level is low</description>
</key>
<key name="use-logging" type="b">
<default>false</default>
Expand Down
14 changes: 7 additions & 7 deletions HeadsetControl@lauinger-clan.de/ui/prefs.ui
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<object class="AdwExpanderRow" id="HeadsetControl_row_outputformat_new1">
<property name="title" translatable="yes">HeadsetControl Version Option output format</property>
<property name="subtitle" translatable="yes">Used starting with HeadsetControl tool version newer then 2.7.0</property>
<property name="expanded" >true</property>
<property name="expanded">true</property>
<child>
<object class="AdwEntryRow" id="HeadsetControl_row_outputformat_new2">
<property name="title" translatable="yes">Output format</property>
Expand Down Expand Up @@ -68,7 +68,7 @@
<object class="AdwExpanderRow" id="HeadsetControl_row_common1">
<property name="title" translatable="yes">HeadsetControl Common</property>
<property name="subtitle" translatable="yes">Used in all HeadsetControl tool versions</property>
<property name="expanded" >true</property>
<property name="expanded">true</property>
<child>
<object class="AdwEntryRow" id="HeadsetControl_row_common2">
<property name="title" translatable="yes">Sidetone</property>
Expand Down Expand Up @@ -140,7 +140,7 @@
<object class="GtkStringList">
<items>
<item translatable="yes">Show SystemIndicator</item>
<item translatable="yes">Use notifications</item>
<item translatable="yes">Notification on low battery</item>
<item translatable="yes">Use logging</item>
<item translatable="yes">Use colors</item>
</items>
Expand Down Expand Up @@ -179,9 +179,9 @@
</child>
<child>
<object class="AdwSwitchRow" id="HeadsetControl_row_notifications">
<property name="title" translatable="yes">Use notifications</property>
<property name="subtitle" translatable="yes">Enable / disable notifications</property>
<property name="tooltip-text" translatable="yes">Enable / disable notifications</property>
<property name="title" translatable="yes">Notification on low battery</property>
<property name="subtitle" translatable="yes">Send a notification when the battery level is low</property>
<property name="tooltip-text" translatable="yes">Send a notification when the battery level is low</property>
</object>
</child>
<child>
Expand Down Expand Up @@ -386,4 +386,4 @@
</object>
</child>
</object>
</interface>
</interface>
Loading