-
Notifications
You must be signed in to change notification settings - Fork 0
/
extension.js
executable file
·146 lines (139 loc) · 4.9 KB
/
extension.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
/*******************************************************************************
* This program is free software: you can redistribute it and/or modify it under
* 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/>.
*
* Orignal Author: Gopi Sankar Karmegam
******************************************************************************/
/* jshint moz:true */
const Lang = imports.lang;
const ExtensionUtils = imports.misc.extensionUtils;
const Me = ExtensionUtils.getCurrentExtension();
const Base = Me.imports.base;
const Lib = Me.imports.convenience;
const SignalManager = Lib.SignalManager;
const Prefs = Me.imports.prefs;
const Main = imports.ui.main;
const SoundOutputDeviceChooser = new Lang.Class({
Name : 'SoundOutputDeviceChooser',
Extends : Base.SoundDeviceChooserBase,
_init : function() {
this.parent("output");
},
lookupDeviceById : function(id) {
return this._control.lookup_output_id(id);
},
changeDevice : function(uidevice) {
this._control.change_output(uidevice);
},
getDefaultDevice : function() {
return this._control.get_default_sink();
},
getDefaultIcon : function() {
return "audio-card";
}
});
const SoundInputDeviceChooser = new Lang.Class({
Name : 'SoundInputDeviceChooser',
Extends : Base.SoundDeviceChooserBase,
_init : function() {
this.parent("input");
},
lookupDeviceById : function(id) {
return this._control.lookup_input_id(id);
},
changeDevice : function(uidevice) {
this._control.change_input(uidevice);
},
getDefaultDevice : function() {
return this._control.get_default_source();
},
getDefaultIcon : function() {
return "audio-input-microphone";
}
});
const InputSliderInstance = new Lang.Class({
Name : 'InputSliderInstance',
_init : function(volumeMenu) {
this._input = volumeMenu._input;
this._settings = Lib.getSettings(Prefs.SETTINGS_SCHEMA);
this._signalManager = new SignalManager();
this._signalManager.addSignal(this._settings, "changed::"
+ Prefs.SHOW_INPUT_SLIDER, Lang.bind(this,
this._setSliderVisiblity));
this._overrideFunction();
this._setSliderVisiblity();
},
_overrideFunction : function() {
this._input._shouldBeVisibleOriginal = this._input._shouldBeVisible;
this._input._shouldBeVisibleCustom = function() {
return this._stream != null;
};
},
_setSliderVisiblity : function() {
if (this._settings.get_boolean(Prefs.SHOW_INPUT_SLIDER)) {
this._input._shouldBeVisible = this._input._shouldBeVisibleCustom;
} else {
this._input._shouldBeVisible = this._input._shouldBeVisibleOriginal;
}
this._input._maybeShowInput();
},
destroy : function() {
this._signalManager.disconnectAll();
this._input._shouldBeVisible = this._input._shouldBeVisibleOriginal;
this._input._maybeShowInput();
delete this._input['_shouldBeVisibleOriginal'];
delete this._input['_shouldBeVisibleCustom'];
}
});
var _outputInstance = null;
var _inputInstance = null;
var _inputSliderInstance = null;
function init(extensionMeta) {
let theme = imports.gi.Gtk.IconTheme.get_default();
theme.append_search_path(extensionMeta.path + "/icons");
}
function enable() {
if (_outputInstance == null) {
_outputInstance = new SoundOutputDeviceChooser();
}
if (_inputInstance == null) {
_inputInstance = new SoundInputDeviceChooser();
}
let _volumeMenu = Main.panel.statusArea.aggregateMenu._volume._volumeMenu;
if (_inputSliderInstance == null) {
_inputSliderInstance = new InputSliderInstance(_volumeMenu);
}
let menuItems = _volumeMenu._getMenuItems();
let i = 0;
for (; i < menuItems.length; i++) {
if (menuItems[i] === _volumeMenu._output.item) {
break;
}
}
_volumeMenu.addMenuItem(_outputInstance, ++i);
menuItems = _volumeMenu._getMenuItems();
for (i = 0; i < menuItems.length; i++) {
if (menuItems[i] === _volumeMenu._input.item) {
break;
}
}
_volumeMenu.addMenuItem(_inputInstance, ++i);
}
function disable() {
_outputInstance.destroy();
_outputInstance = null;
_inputInstance.destroy();
_inputInstance = null;
_inputSliderInstance.destroy();
_inputSliderInstance = null;
}