Check for new songs

This commit is contained in:
pancakes 2025-08-26 13:34:11 +10:00
parent 1b4bb16c29
commit 0fbf4aa619
Signed by: pancakes
SSH key fingerprint: SHA256:yrp4c4hhaPoPG07fb4QyQIgAdlbUdsJvUAydJEWnfTw

View file

@ -1,4 +1,5 @@
using Gio;
using GLib;
using Gtk;
using ZwlrLayerShell;
using Application = Gtk.Application;
@ -9,11 +10,31 @@ if (!LayerShell.IsSupported())
return 255;
}
ApplicationWindow? window = null;
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) =>
{
var window = ApplicationWindow.New((Application)sender);
window = ApplicationWindow.New((Application)sender);
LayerShell.InitForWindow(window);
LayerShell.SetNamespace(window, "deltatune-wls");
@ -22,6 +43,27 @@ application.OnActivate += (sender, eventArgs) =>
LayerShell.SetAnchor(window, Edge.Top, true);
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();
};