Skip to content

Commit

Permalink
Construct app from SinkInputInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
leolost2605 committed Aug 26, 2023
1 parent 44b0402 commit 441d346
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 17 deletions.
35 changes: 22 additions & 13 deletions src/App.vala
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,40 @@
*/

public class Sound.App : Object {
public uint32 index { get; construct; }
public string name { get; construct; }
public string display_name { get; construct; }
public Icon icon { get; construct; }
public uint32 index { get; private set; }
public string name { get; private set; }
public string display_name { get; private set; }
public Icon icon { get; private set; }

public string media_name { get; set; }
public double volume { get; set; }
public bool muted { get; set; }
public PulseAudio.ChannelMap channel_map { get; set; }

public App (uint32 index, string name) {
Object (
index: index,
name: name
);
}
public App.from_sink_input_info (PulseAudio.SinkInputInfo sink_input) {
index = sink_input.index;
name = sink_input.proplist.gets (PulseAudio.Proplist.PROP_APPLICATION_NAME);

construct {
var app_info = new GLib.DesktopAppInfo (name + ".desktop");
string app_id;
if (sink_input.proplist.contains (PulseAudio.Proplist.PROP_APPLICATION_ID) == 1) {
app_id = sink_input.proplist.gets (PulseAudio.Proplist.PROP_APPLICATION_ID);
} else {
app_id = name;
}

var app_info = new DesktopAppInfo (app_id + ".desktop");

if (app_info != null) {
display_name = app_info.get_name ();
icon = app_info.get_icon ();
} else {
display_name = name;
icon = new ThemedIcon ("application-default-icon");

if (sink_input.proplist.contains (PulseAudio.Proplist.PROP_APPLICATION_ICON_NAME) == 1) {
icon = new ThemedIcon (sink_input.proplist.gets (PulseAudio.Proplist.PROP_APPLICATION_ICON_NAME));
} else {
icon = new ThemedIcon ("application-default-icon");
}
}
}
}
5 changes: 1 addition & 4 deletions src/PulseAudioManager.vala
Original file line number Diff line number Diff line change
Expand Up @@ -613,10 +613,7 @@ public class Sound.PulseAudioManager : GLib.Object {
}

if (app == null) {
app = new App (
sink_input.index,
sink_input.proplist.gets ("application.name")
);
app = new App.from_sink_input_info (sink_input);
apps.append (app);
}

Expand Down

0 comments on commit 441d346

Please sign in to comment.