Skip to content

Commit

Permalink
Merge branch 'devel'
Browse files Browse the repository at this point in the history
  • Loading branch information
johnhoran committed Mar 21, 2016
2 parents ed2858b + 7e05303 commit 8947e90
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 71 deletions.
93 changes: 54 additions & 39 deletions src/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,46 +21,56 @@ const SourceMenu = Me.imports.sourceMenu;
const Convenience = Me.imports.convenience;

function connectToPADBus(callback){
let dbus = Gio.DBus.session;

dbus.call('org.PulseAudio1', '/org/pulseaudio/server_lookup1', "org.freedesktop.DBus.Properties", "Get",
GLib.Variant.new('(ss)', ['org.PulseAudio.ServerLookup1', 'Address']), GLib.VariantType.new("(v)"),
Gio.DBusCallFlags.NONE, -1, null, Lang.bind(this, function(conn, query){
let resp = conn.call_finish(query);
resp = resp.get_child_value(0).unpack();
let paAddr = resp.get_string()[0];

Gio.DBusConnection.new_for_address(paAddr, Gio.DBusConnectionFlags.AUTHENTICATION_CLIENT, null, null,
Lang.bind(this, function(conn, query){
let f_connectToPABus = function(paAddr, callback, moduleLoaded){
Gio.DBusConnection.new_for_address(paAddr,
Gio.DBusConnectionFlags.AUTHENTICATION_CLIENT, null, null, Lang.bind(this,
function(conn, query){
try{
let paConn = Gio.DBusConnection.new_for_address_finish(query);
callback(paConn, false);
callback(paConn, moduleLoaded);
} catch(e) {
log('EXCEPTION:: '+e);
//Couldn't connect to PADBus, try manually loading the module and reconnecting
let [, pid] = GLib.spawn_async(null, ['pactl','load-module','module-dbus-protocol'], null,
GLib.SpawnFlags.SEARCH_PATH | GLib.SpawnFlags.STDOUT_TO_DEV_NULL | GLib.SpawnFlags.STDERR_TO_DEV_NULL | GLib.SpawnFlags.DO_NOT_REAP_CHILD,
null, null);

this._childWatch = GLib.child_watch_add(GLib.PRIORITY_DEFAULT, pid, Lang.bind(this, function(pid, status, requestObj) {
GLib.source_remove(this._childWatch);

Gio.DBusConnection.new_for_address(paAddr, Gio.DBusConnectionFlags.AUTHENTICATION_CLIENT, null, null,
Lang.bind(this, function(conn, query){
try{
let paConn = Gio.DBusConnection.new_for_address_finish(query);
callback(paConn, true);
} catch(e) {
log('Laine: Cannot connect to pulseaudio over dbus');
throw e;
}
})
);
}));
if(!moduleLoaded){
//If the module wasn't loaded, try loading it and reconnecting
f_loadModule(Lang.bind(this, function(){
f_connectToPABus(paAddr, callback, true);
}));
} else {
log('Laine: Cannot connect to pulseaudio over dbus');
}
}
})
);
})
}
));
};

let f_loadModule = function(callback){
let [, pid] = GLib.spawn_async(null,
['pactl','load-module','module-dbus-protocol'], null,
GLib.SpawnFlags.SEARCH_PATH | GLib.SpawnFlags.STDOUT_TO_DEV_NULL |
GLib.SpawnFlags.STDERR_TO_DEV_NULL | GLib.SpawnFlags.DO_NOT_REAP_CHILD,
null, null
);

this._childWatch = GLib.child_watch_add(GLib.PRIORITY_DEFAULT, pid,
Lang.bind(this, function(pid, status, requestObj){
GLib.source_remove(this._childWatch);
callback();
})
);
};


let dbus = Gio.DBus.session;
dbus.call('org.PulseAudio1', '/org/pulseaudio/server_lookup1',
"org.freedesktop.DBus.Properties",
"Get", GLib.Variant.new('(ss)', ['org.PulseAudio.ServerLookup1', 'Address']),
GLib.VariantType.new("(v)"), Gio.DBusCallFlags.NONE, -1, null, Lang.bind(this,
function(conn, query){
let resp = conn.call_finish(query).get_child_value(0).unpack();
let paAddr = resp.get_string()[0];

f_connectToPABus(paAddr, callback, false);
}
)
);
}

Expand All @@ -71,8 +81,7 @@ const LaineCore = new Lang.Class({
_init: function(container){
this.parent();
this._icon = new St.Icon({ icon_name: 'system-run-symbolic', style_class: 'system-status-icon' });

connectToPADBus(Lang.bind(this, function(conn, manual){
let build_cb = function(conn, manual){
this._paDBus = conn;
this._moduleLoad = manual;

Expand All @@ -93,8 +102,14 @@ const LaineCore = new Lang.Class({
this.addMenuItem(this._streamMenu);

container.layout();
}));
};

try{
connectToPADBus(Lang.bind(this, build_cb));
}
catch(e){
log("EXCEPTION:Laine "+e);
}
},

_addPulseAudioListeners: function(){
Expand Down
86 changes: 54 additions & 32 deletions src/prefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ const KEY_MERGE_CONTROLS = "merge-controls";

function init(){
Convenience.initTranslations();


}

const LainePrefsWidget = new GObject.Class({
Expand All @@ -25,45 +23,69 @@ const LainePrefsWidget = new GObject.Class({
_init:function(params){
this.parent(params);
this.margin = this.row_spacing = this.column_spacing = 10;
this.set_hexpand(true);

this._settings = Convenience.getSettings();
//-----------------------------------------------------------
let volumeOverdrive = Gtk.Scale.new_with_range(Gtk.Orientation.HORIZONTAL, 80, 150, 5);
volumeOverdrive.set_value(this._settings.get_int(KEY_PA_OVER));
volumeOverdrive.connect('value-changed', Lang.bind(this, function(src){
this._settings.set_int(KEY_PA_OVER, src.get_value());
}));

this.attach(new Gtk.Label({
//Labels
let lbl_volumeOverdrive = new Gtk.Label({
label: _("Volume overdrive"),
halign: Gtk.Align.START
}), 0, 0, 1, 1);
halign: Gtk.Align.END}
);
let lbl_showPortLabel = new Gtk.Label({
label: _("Show active port label"),
halign: Gtk.Align.END
});
let lbl_mergeAggregate = new Gtk.Label({
label: _("Merge controls into aggregate menu"),
halign: Gtk.Align.END
});

this.attach(volumeOverdrive, 20, 0, 40, 1);
this.attach(lbl_volumeOverdrive, 0, 0, 1, 1);
this.attach_next_to(lbl_showPortLabel, lbl_volumeOverdrive,
Gtk.PositionType.BOTTOM, 1, 1);
this.attach_next_to(lbl_mergeAggregate, lbl_showPortLabel,
Gtk.PositionType.BOTTOM, 1, 1);

//-----------------------------------------------------------
this.attach(new Gtk.Label({
label: _("Show active port label"),
halign: Gtk.Align.START
}), 0, 1, 1, 1);
//Controls

this._showLabelSwitch = new Gtk.Switch({active: this._settings.get_boolean(KEY_PORT_LABEL)});
this._showLabelSwitch.connect('notify::active', Lang.bind(this, function(src){
this._settings.set_boolean(KEY_PORT_LABEL, src.active);
}));
this.attach(this._showLabelSwitch, 20, 1, 1, 1);

//-----------------------------------------------------------
let volumeOverdrive = Gtk.Scale.new_with_range(
Gtk.Orientation.HORIZONTAL, 80, 150, 5);
volumeOverdrive.set_value(this._settings.get_int(KEY_PA_OVER));
volumeOverdrive.connect('value-changed', Lang.bind(this,
function(src){ this._settings.set_int(KEY_PA_OVER, src.get_value()); }
));

this.attach(new Gtk.Label({
label: _("Merge controls into aggregate menu"),
halign: Gtk.Align.START
}), 0, 2, 1, 1);
this._mergeAggregateSwitch = new Gtk.Switch({active: this._settings.get_boolean(KEY_MERGE_CONTROLS)});
this._mergeAggregateSwitch.connect('notify::active', Lang.bind(this, function(src){
this._settings.set_boolean(KEY_MERGE_CONTROLS, src.active);
}));
this.attach(this._mergeAggregateSwitch, 20, 2, 1, 1);
this._showLabelSwitch = new Gtk.Switch({
active: this._settings.get_boolean(KEY_PORT_LABEL)
});
this._showLabelSwitch.connect('notify::active', Lang.bind(this,
function(src){ this._settings.set_boolean(KEY_PORT_LABEL, src.active); }
));

this._mergeAggregateSwitch = new Gtk.Switch({
active: this._settings.get_boolean(KEY_MERGE_CONTROLS)
});
this._mergeAggregateSwitch.connect('notify::active', Lang.bind(this,
function(src){this._settings.set_boolean(KEY_MERGE_CONTROLS, src.active);}
));

this.attach_next_to(volumeOverdrive, lbl_volumeOverdrive,
Gtk.PositionType.RIGHT, 2, 1);
this.attach_next_to(this._showLabelSwitch, lbl_showPortLabel,
Gtk.PositionType.RIGHT, 1, 1);
this.attach_next_to(this._mergeAggregateSwitch, lbl_mergeAggregate,
Gtk.PositionType.RIGHT, 1, 1);
volumeOverdrive.set_hexpand(true);
volumeOverdrive.add_mark(100, Gtk.PositionType.BOTTOM, null);

//Just for spacing to expand column three
this.attach_next_to(new Gtk.Label({
visible:false,
hexpand:true
}),this._showLabelSwitch, Gtk.PositionType.RIGHT, 1, 1);

}
});
Expand All @@ -73,4 +95,4 @@ function buildPrefsWidget() {
widget.show_all();

return widget;
}
}

0 comments on commit 8947e90

Please sign in to comment.