Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

global bypass toggle #21

Merged
merged 5 commits into from
Jul 15, 2024
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
43 changes: 40 additions & 3 deletions eepresetselector@ulville.github.io/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const EEPSIndicator = GObject.registerClass(
this.lastUsedInputPreset = ' ';
this.lastUsedOutputPreset = ' ';
this.lastPresetLoadTime = 0;
this.enableBypass = false;
this.command = [];
this.settings = settings;
this.appDesktopFile = 'com.github.wwmm.easyeffects.desktop';
Expand Down Expand Up @@ -117,6 +118,21 @@ const EEPSIndicator = GObject.registerClass(
}
}

_enableGlobalBypass(state) {
this.enableBypass = state;
const bypassOption = state ? '1' : '2';
const command = this.command.concat(['-b', bypassOption]).join(' ');
try {
GLib.spawn_command_line_async(command);
} catch (error) {
Main.notify(
_('An error occurred while trying to toggle bypass'),
_(`Error:\n\n${error}`)
);
logError(error);
}
}

_addCategoryTitle(categoryName, categoryIconName) {
let _title = new PopupMenu.PopupSeparatorMenuItem(
`${_(categoryName)}:`
Expand Down Expand Up @@ -165,6 +181,7 @@ const EEPSIndicator = GObject.registerClass(
this.menu._getMenuItems().forEach(item => {
item.destroy();
});

// Category Title: "Output Presets" (As how the command did output it)
if (outputCategoryName)
this._addCategoryTitle(outputCategoryName, 'audio-speakers-symbolic');
Expand All @@ -183,9 +200,19 @@ const EEPSIndicator = GObject.registerClass(
let _inputSection = new PopupMenu.PopupMenuSection();
this._addScrollMenuSection(_inputScrollView, _inputSection, this.inputPresets, this.lastUsedInputPreset, command);

// Separator
let _separatorItem = new PopupMenu.PopupSeparatorMenuItem();
this.menu.addMenuItem(_separatorItem);

// Add switch menu item to toggle global bypass
const toggleBypassItem = new PopupMenu.PopupSwitchMenuItem(_('Global Bypass'), this.enableBypass, {});
toggleBypassItem.setOrnament(PopupMenu.Ornament.NONE);
toggleBypassItem.add_style_class_name('bypass-toggle-item');
toggleBypassItem.connect('toggled', (item, state) => {
this._enableGlobalBypass(state);
});
this.menu.addMenuItem(toggleBypassItem);

// Add a menu item to activate (open) the Easy Effects application
let _easyEffectsActivatorItem = new PopupMenu.PopupMenuItem(
_('Launch %s').format(this.easyEffectsApp.get_name())
Expand All @@ -205,17 +232,18 @@ const EEPSIndicator = GObject.registerClass(
let [, _outputNaturH] = _outputSection.actor.get_preferred_height(-1);
let [, _inputNaturH] = _inputSection.actor.get_preferred_height(-1);
let [, _sepNaturH] = _separatorItem.actor.get_preferred_height(-1);
let [, _toggleBypassNaturH] = toggleBypassItem.actor.get_preferred_height(-1);
let [, _eeActNaturH] = _easyEffectsActivatorItem.actor.get_preferred_height(-1);

let _notFillsScreen = _maxHeight >= 0 && _inputNaturH + _outputNaturH + 2 * _titleNaturH <= _maxHeight - _eeActNaturH - _sepNaturH;
let _notFillsScreen = _maxHeight >= 0 && _inputNaturH + _outputNaturH + 2 * _titleNaturH <= _maxHeight - _eeActNaturH - _sepNaturH - _toggleBypassNaturH;
if (_notFillsScreen) {
_inputScrollView.vscrollbar_policy = St.PolicyType.NEVER;
_outputScrollView.vscrollbar_policy = St.PolicyType.NEVER;
} else {
let _outputNeedsScrollbar = _maxHeight >= 0 && _outputNaturH + _titleNaturH >= (_maxHeight - _eeActNaturH - _sepNaturH) / 2;
let _outputNeedsScrollbar = _maxHeight >= 0 && _outputNaturH + _titleNaturH >= (_maxHeight - _eeActNaturH - _sepNaturH - _toggleBypassNaturH) / 2;
_outputScrollView.vscrollbar_policy = _outputNeedsScrollbar ? St.PolicyType.AUTOMATIC : St.PolicyType.NEVER;

let _inputNeedsScrollbar = _maxHeight >= 0 && _inputNaturH + _titleNaturH >= (_maxHeight - _eeActNaturH - _sepNaturH) / 2;
let _inputNeedsScrollbar = _maxHeight >= 0 && _inputNaturH + _titleNaturH >= (_maxHeight - _eeActNaturH - _sepNaturH - _toggleBypassNaturH) / 2;
_inputScrollView.vscrollbar_policy = _inputNeedsScrollbar ? St.PolicyType.AUTOMATIC : St.PolicyType.NEVER;
}
}
Expand Down Expand Up @@ -249,6 +277,15 @@ const EEPSIndicator = GObject.registerClass(
// Build menu with last values
this._buildMenu(this.categoryNames[0], this.categoryNames[1], this.command);

// Get global bypass
try {
const bypassResponse = await this.execCommunicate(this.command.concat(['-b', '3']));
this.enableBypass = bypassResponse.trim() === '1';
} catch (err) {
Main.notify(_('An error occurred while trying to get global bypass'), _(`Error:\n\n${err}`));
logError(err);
}

// Try to get Last used presets
let erMessage = 'An error occurred while trying to get last presets';
try {
Expand Down
6 changes: 5 additions & 1 deletion eepresetselector@ulville.github.io/stylesheet.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@

.easyeffects-activator-item {
font-weight: bold;
}
}

.bypass-toggle-item {
font-weight: bold;
}