Check for new songs
This commit is contained in:
parent
1b4bb16c29
commit
0fbf4aa619
1 changed files with 43 additions and 1 deletions
|
@ -1,4 +1,5 @@
|
||||||
using Gio;
|
using Gio;
|
||||||
|
using GLib;
|
||||||
using Gtk;
|
using Gtk;
|
||||||
using ZwlrLayerShell;
|
using ZwlrLayerShell;
|
||||||
using Application = Gtk.Application;
|
using Application = Gtk.Application;
|
||||||
|
@ -9,11 +10,31 @@ if (!LayerShell.IsSupported())
|
||||||
return 255;
|
return 255;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ApplicationWindow? window = null;
|
||||||
|
|
||||||
var application = Application.New("gay.pancakes.deltatune_wls", Gio.ApplicationFlags.FlagsNone);
|
var application = Application.New("gay.pancakes.deltatune_wls", Gio.ApplicationFlags.FlagsNone);
|
||||||
|
|
||||||
|
GLib.Functions.TimeoutAdd(GLib.Constants.PRIORITY_DEFAULT, 500, () =>
|
||||||
|
{
|
||||||
|
if (window == null) return true;
|
||||||
|
|
||||||
|
var playerctl = Subprocess.New(["playerctl", "metadata", "--format", "{{ title }}"],
|
||||||
|
SubprocessFlags.StdoutPipe | SubprocessFlags.StderrSilence);
|
||||||
|
|
||||||
|
var pipe = playerctl.GetStdoutPipe();
|
||||||
|
if (pipe == null) return true;
|
||||||
|
|
||||||
|
var stdout = DataInputStream.New(pipe);
|
||||||
|
var line = stdout.ReadLineUtf8(out UIntPtr length, null);
|
||||||
|
|
||||||
|
window.ActivateAction("new_song", Variant.NewString(line?.Trim() ?? ""));
|
||||||
|
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
application.OnActivate += (sender, eventArgs) =>
|
application.OnActivate += (sender, eventArgs) =>
|
||||||
{
|
{
|
||||||
var window = ApplicationWindow.New((Application)sender);
|
window = ApplicationWindow.New((Application)sender);
|
||||||
|
|
||||||
LayerShell.InitForWindow(window);
|
LayerShell.InitForWindow(window);
|
||||||
LayerShell.SetNamespace(window, "deltatune-wls");
|
LayerShell.SetNamespace(window, "deltatune-wls");
|
||||||
|
@ -22,6 +43,27 @@ application.OnActivate += (sender, eventArgs) =>
|
||||||
LayerShell.SetAnchor(window, Edge.Top, true);
|
LayerShell.SetAnchor(window, Edge.Top, true);
|
||||||
LayerShell.SetMargin(window, 15);
|
LayerShell.SetMargin(window, 15);
|
||||||
|
|
||||||
|
var label = Label.New(null);
|
||||||
|
label.Halign = Align.Start;
|
||||||
|
|
||||||
|
window.SetChild(label);
|
||||||
|
|
||||||
|
window.OnDestroy += (widget, args1) => application.Quit();
|
||||||
|
|
||||||
|
var action = SimpleAction.NewStateful("new_song", VariantType.String, Variant.NewString(""));
|
||||||
|
action.OnActivate += (simpleAction, signalArgs) =>
|
||||||
|
{
|
||||||
|
var title = simpleAction.GetState()!.GetString(out _);
|
||||||
|
var newTitle = signalArgs.Parameter!.GetString(out _);
|
||||||
|
|
||||||
|
if (newTitle != title)
|
||||||
|
{
|
||||||
|
simpleAction.SetState(signalArgs.Parameter);
|
||||||
|
label.SetLabel($"♪ - {newTitle}");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
window.AddAction(action);
|
||||||
|
|
||||||
window.Present();
|
window.Present();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue