This repository has been archived by the owner on May 10, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
/
extension.js
182 lines (152 loc) · 5.07 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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
const Main = imports.ui.main;
const PopupMenu = imports.ui.popupMenu;
const GObject = imports.gi.GObject;
const AudioOutputSubMenu = GObject.registerClass({
GTypeName: 'ASAudioOutputSubMenu',
}, class AudioOutputSubMenu extends PopupMenu.PopupSubMenuMenuItem {
_init() {
super._init('Audio Output: Connecting...', true);
this._control = Main.panel.statusArea.aggregateMenu._volume._control;
this._controlSignal = this._control.connect('default-sink-changed', () => {
this._updateDefaultSink();
});
this._updateDefaultSink();
this.menu.connect('open-state-changed', (menu, isOpen) => {
if (isOpen)
this._updateSinkList();
});
//Unless there is at least one item here, no 'open' will be emitted...
let item = new PopupMenu.PopupMenuItem('Connecting...');
this.menu.addMenuItem(item);
}
_updateDefaultSink() {
let defsink = this._control.get_default_sink();
//Unfortunately, Gvc neglects some pulse-devices, such as all "Monitor of ..."
if (defsink == null)
this.label.set_text("Other");
else
this.label.set_text(defsink.get_description());
}
_updateSinkList() {
this.menu.removeAll();
let defsink = this._control.get_default_sink();
let sinklist = this._control.get_sinks();
let control = this._control;
let item;
for (let i=0; i<sinklist.length; i++) {
let sink = sinklist[i];
if (sink === defsink)
continue;
item = new PopupMenu.PopupMenuItem(sink.get_description());
item.connect('activate', () => {
control.set_default_sink(sink);
});
this.menu.addMenuItem(item);
}
if (sinklist.length == 0 ||
(sinklist.length == 1 && sinklist[0] === defsink)) {
item = new PopupMenu.PopupMenuItem("No more Devices");
this.menu.addMenuItem(item);
}
}
destroy() {
this._control.disconnect(this._controlSignal);
super.destroy();
}
});
const AudioInputSubMenu = GObject.registerClass({
GTypeName: 'ASAudioInputSubMenu',
}, class AudioInputSubMenu extends PopupMenu.PopupSubMenuMenuItem {
_init() {
super._init('Audio Input: Connecting...', true);
this._control = Main.panel.statusArea.aggregateMenu._volume._control;
this._controlSignal = this._control.connect('default-source-changed', () => {
this._updateDefaultSource();
});
this._updateDefaultSource();
this.menu.connect('open-state-changed', (menu, isOpen) => {
if (isOpen)
this._updateSourceList();
});
//Unless there is at least one item here, no 'open' will be emitted...
let item = new PopupMenu.PopupMenuItem('Connecting...');
this.menu.addMenuItem(item);
}
_updateDefaultSource() {
let defsource = this._control.get_default_source();
//Unfortunately, Gvc neglects some pulse-devices, such as all "Monitor of ..."
if (defsource == null)
this.label.set_text("Other");
else
this.label.set_text(defsource.get_description());
}
_updateSourceList() {
this.menu.removeAll();
let defsource = this._control.get_default_source();
let sourcelist = this._control.get_sources();
let control = this._control;
let item;
for (var i = 0; i < sourcelist.length; i++) {
let source = sourcelist[i];
if (source === defsource) {
continue;
}
item = new PopupMenu.PopupMenuItem(source.get_description());
item.connect('activate', () => {
control.set_default_source(source);
});
this.menu.addMenuItem(item);
}
if (sourcelist.length == 0 ||
(sourcelist.length == 1 && sourcelist[0] === defsource)) {
item = new PopupMenu.PopupMenuItem("No more Devices");
this.menu.addMenuItem(item);
}
}
destroy() {
this._control.disconnect(this._controlSignal);
super.destroy();
}
});
var audioOutputSubMenu = null;
var audioInputSubMenu = null;
var savedUpdateVisibility = null;
function init() {
}
function enable() {
if ((audioInputSubMenu != null) || (audioOutputSubMenu != null))
return;
audioInputSubMenu = new AudioInputSubMenu();
audioOutputSubMenu = new AudioOutputSubMenu();
//Try to add the switchers right below the sliders...
let volMen = Main.panel.statusArea.aggregateMenu._volume._volumeMenu;
let items = volMen._getMenuItems();
let i = 0;
let addedInput, addedOutput = false;
while (i < items.length){
if (items[i] === volMen._output.item){
volMen.addMenuItem(audioOutputSubMenu, i+1);
addedOutput = true;
} else if (items[i] === volMen._input.item){
volMen.addMenuItem(audioInputSubMenu, i+2);
addedInput = true;
}
if (addedOutput && addedInput){
break;
}
i++;
}
//Make input-slider allways visible.
savedUpdateVisibility = Main.panel.statusArea.aggregateMenu._volume._volumeMenu._input._updateVisibility;
Main.panel.statusArea.aggregateMenu._volume._volumeMenu._input._updateVisibility = function () {};
Main.panel.statusArea.aggregateMenu._volume._volumeMenu._input.item.actor.visible = true;
}
function disable() {
audioInputSubMenu.destroy();
audioInputSubMenu = null;
audioOutputSubMenu.destroy();
audioOutputSubMenu = null;
Main.panel.statusArea.aggregateMenu._volume._volumeMenu._input._updateVisibility = savedUpdateVisibility;
savedUpdateVisibility = null;
Main.panel.statusArea.aggregateMenu._volume._volumeMenu._input._updateVisibility();
}