Skip to content

Commit

Permalink
Code reorganization and formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
kgshank committed Sep 20, 2019
1 parent cabb5b5 commit 886a85a
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 72 deletions.
23 changes: 10 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
A simple selector to enabled selection of sound source and sink based on Gnome Control Center

### Dependency
Python 2 or 3. New version needs python as optional dependency. Use option to turn off new profile identification logic, if python is to be avoided. But the old logic has language dependecy and works only with English display language
Python 2 or 3. New version needs Python as optional dependency. Use option to turn off new profile identification logic, if Python is to be avoided. But the old logic has language dependency and works only with English display language

### Installation Instructions

The official method to install this extension is from [extensions.gnome.org](https://extensions.gnome.org/extension/906/sound-output-device-chooser).

To install the extension from source, clone the repository and place it in the `gnome-shell/extensions` directory
To install the extension from source, clone the repository and place it in the `$HOME/.local/share/gnome-shell/extensions` directory
```
git clone https://github.com/kgshank/gse-sound-output-device-chooser.git
cp --recursive gse-sound-output-device-chooser/[email protected] $HOME/.local/share/gnome-shell/extensions/[email protected]
Expand All @@ -26,24 +26,24 @@ Enable the extensions from [GNOME Tweaks](https://wiki.gnome.org/Apps/Tweaks).
* May conflict with extensions which modify volume menu.
* Extension works with Volume Mixer extension. Restart shell, if errors encountered.

### Changelog
### Change log
-----------------------
#### 24 (Not released)
* Remove Mainloop timeout
* Remove Mainloop timeout
* New option to expand volume menu based on length of device names

#### 23
* Updates for Gnome Shell 3.34 compatibility
* Minor UI changes

#### 22
* Failback to old method of profile identification incase of Python
errors.
* Fallback to old method of profile identification in case of Python errors.

#### 21
* Remove unsupported shell versions from compatibility

#### 20
* Use python for identifying profiles available
* Use Python for identifying profiles available
* Option to control new profile identification logic
* Turn off/on log message in options

Expand All @@ -52,9 +52,9 @@ errors.
* Lots of bug fixes, thanks @HarlemSquirrel and @mdmower for the support

#### 16
* Redesinged preferences dialog, credits @eliandoran
* Rewritten and restructed code
* gnome shell 3.22 compatibility
* Redesigned preferences dialog, credits @eliandoran
* Rewritten and restructured code
* Gnome shell 3.22 compatibility

#### 15
* New option to show/hide input devices
Expand All @@ -68,6 +68,3 @@ errors.
* Option to show input volume control slider
* Bug fixes to hide sound devices without a valid card (network devices etc)
* Remove unnecessary code



105 changes: 55 additions & 50 deletions [email protected]/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,63 +97,68 @@ var InputSliderInstance = class InputSliderInstance {
};

var SDCInstance = class SDCInstance {
constructor(){
this._settings = Lib.getSettings(Prefs.SETTINGS_SCHEMA);
this._aggregateMenu = Main.panel.statusArea.aggregateMenu;
this._volumeMenu = this._aggregateMenu._volume._volumeMenu;
this._aggregateLayout = this._aggregateMenu.menu.box.get_layout_manager();
}
constructor(){
this._settings = Lib.getSettings(Prefs.SETTINGS_SCHEMA);
this._aggregateMenu = Main.panel.statusArea.aggregateMenu;
this._volumeMenu = this._aggregateMenu._volume._volumeMenu;
this._aggregateLayout = this._aggregateMenu.menu.box.get_layout_manager();
}

enable(){
if (this._outputInstance == null) {
this._outputInstance = new SoundOutputDeviceChooser();
}
if (this._inputInstance == null) {
this._inputInstance = new SoundInputDeviceChooser();
}

if (this._inputSliderInstance == null) {
this._inputSliderInstance = new InputSliderInstance(this._volumeMenu, this._settings);
}

this._addMenuItem(this._volumeMenu, this._volumeMenu._output.item, this._outputInstance.menuItem);
this._addMenuItem(this._volumeMenu, this._volumeMenu._input.item, this._inputInstance.menuItem);

this._expSignalId = this._settings.connect("changed::" + Prefs.EXPAND_VOL_MENU, this._expandVolMenu.bind(this));
}

enable(){
if (this._outputInstance == null) {
this._outputInstance = new SoundOutputDeviceChooser();
}
if (this._inputInstance == null) {
this._inputInstance = new SoundInputDeviceChooser();
}
_addMenuItem(_volumeMenu, checkItem, menuItem){
let menuItems = _volumeMenu._getMenuItems();
let i = 0;
for (; i < menuItems.length; i++) {
if (menuItems[i] === checkItem) {
break;
}
}
_volumeMenu.addMenuItem(menuItem, ++i);
}

if (this._inputSliderInstance == null) {
this._inputSliderInstance = new InputSliderInstance(this._volumeMenu, this._settings);
}

this._addMenuItem(this._volumeMenu, this._volumeMenu._output.item, this._outputInstance.menuItem);
this._addMenuItem(this._volumeMenu, this._volumeMenu._input.item, this._inputInstance.menuItem);

this._expSignalId = this._settings.connect("changed::" + Prefs.EXPAND_VOL_MENU, this._expandVolMenu.bind(this));
_expandVolMenu() {
if (this._settings.get_boolean(Prefs.EXPAND_VOL_MENU)) {
this._aggregateLayout.addSizeChild(this._volumeMenu.actor);
} else {
this._revertVolMenuChanges();
}
}

_addMenuItem(_volumeMenu, checkItem, menuItem){
let menuItems = _volumeMenu._getMenuItems();
let i = 0;
for (; i < menuItems.length; i++) {
if (menuItems[i] === checkItem) {
break;
}
}
_volumeMenu.addMenuItem(menuItem, ++i);
}

_expandVolMenu() {
if (this._settings.get_boolean(Prefs.EXPAND_VOL_MENU)) {
this._aggregateLayout.addSizeChild(this._volumeMenu.actor);
} else {
this._aggregateLayout._sizeChildren = this._aggregateLayout._sizeChildren.filter(item => item !== this._volumeMenu.actor);
this._aggregateLayout.layout_changed();
}
}
_revertVolMenuChanges() {
this._aggregateLayout._sizeChildren = this._aggregateLayout._sizeChildren.filter(item => item !== this._volumeMenu.actor);
this._aggregateLayout.layout_changed();
}

disable(){
this._outputInstance.destroy();
this._outputInstance = null;
this._inputInstance.destroy();
this._inputInstance = null;
this._inputSliderInstance.destroy();
this._inputSliderInstance = null;
if(this._expSignalId) {
disable(){
this._revertVolMenuChanges();
this._outputInstance.destroy();
this._outputInstance = null;
this._inputInstance.destroy();
this._inputInstance = null;
this._inputSliderInstance.destroy();
this._inputSliderInstance = null;
if(this._expSignalId) {
this._settings.disconnect(this._expSignalId);
this._expSignalId = null;
}
}
}
}
};

function init(extensionMeta) {
Expand Down
18 changes: 9 additions & 9 deletions [email protected]/prefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,24 @@
* the terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later
* version.
*
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*
*
* Original Author: Gopi Sankar Karmegam
******************************************************************************/
/* jshint moz:true */
/* jshint moz:true */

const GLib = imports.gi.GLib;
const GObject = imports.gi.GObject;
const Gio = imports.gi.Gio;
const Gtk = imports.gi.Gtk;
//const Lang = imports.lang;
// const Lang = imports.lang;

const ExtensionUtils = imports.misc.extensionUtils;
const Me = ExtensionUtils.getCurrentExtension();
Expand Down Expand Up @@ -57,9 +57,9 @@ const SDCSettingsWidget = new GObject.Class({
this.orientation = Gtk.Orientation.VERTICAL;
this.spacing = 0;

// creates the settings
// creates the settings
this._settings = Lib.getSettings(SETTINGS_SCHEMA);

Lib.setLog(this._settings.get_boolean(ENABLE_LOG));

// creates the ui builder and add the main resource file
Expand Down Expand Up @@ -94,7 +94,7 @@ const SDCSettingsWidget = new GObject.Class({
let iconThemeCombo = builder.get_object("icon-theme");
let logSwitch = builder.get_object("enable-log");
let newProfileIdSwitch = builder.get_object("new-profile-identification");

this._settings.bind(HIDE_ON_SINGLE_DEVICE, singleDeviceSwitch, "active", Gio.SettingsBindFlags.DEFAULT);
this._settings.bind(SHOW_PROFILES, showProfileSwitch, "active", Gio.SettingsBindFlags.DEFAULT);
this._settings.bind(EXPAND_VOL_MENU, volMenuSwitch, "active", Gio.SettingsBindFlags.DEFAULT);
Expand All @@ -105,7 +105,7 @@ const SDCSettingsWidget = new GObject.Class({
this._settings.bind(ENABLE_LOG, logSwitch, "active", Gio.SettingsBindFlags.DEFAULT);
this._settings.bind(NEW_PROFILE_ID, newProfileIdSwitch, "active", Gio.SettingsBindFlags.DEFAULT);
this._settings.bind(ICON_THEME, iconThemeCombo, "active-id", Gio.SettingsBindFlags.DEFAULT);


let showAlwaysToggleRender = builder.get_object("ShowAlwaysToggleRender");
let hideAlwaysToggleRender = builder.get_object("HideAlwaysToggleRender");
Expand Down

0 comments on commit 886a85a

Please sign in to comment.