From 2b7f89d69ae35c75b064f1bdcc3aae7da51a3f6d Mon Sep 17 00:00:00 2001 From: Daniel Olsen Date: Tue, 3 May 2022 17:59:55 +0200 Subject: [PATCH] Fix left click action on minecraft player count --- profiles/xsession/polybar.nix | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/profiles/xsession/polybar.nix b/profiles/xsession/polybar.nix index 763a841..8c83e2b 100644 --- a/profiles/xsession/polybar.nix +++ b/profiles/xsession/polybar.nix @@ -202,13 +202,16 @@ in pass print(result) ''; - click-left = "" + pkgs.writers.writePython3 "minecraft_status" { libraries = [ pkgs.python3.pkgs.mcstatus ]; flakeIgnore = [ "E722" ]; } '' + click-left = "" + pkgs.writers.writePython3 "minecraft_status" { libraries = with pkgs.python3.pkgs; [ mcstatus notify2 ]; flakeIgnore = [ "E722" ]; } '' from mcstatus import MinecraftServer as JavaServer - import os + import notify2 pvv = JavaServer.lookup("minecraft.pvv.ntnu.no") dods = JavaServer.lookup("mc.dodsorf.as") + pvv_status = None + dods_status = None + try: pvv_status = pvv.status() dods_status = dods.status() @@ -216,15 +219,23 @@ in pass result = "" - if pvv_status.players.sample is not None: - result += "PVV\n" + if pvv_status is not None: + result += "PVV: " for player in pvv_status.players.sample: - result += player - os.exec("notify-send", "Minecraft Server Status", result) + result += player.name + result += "\n" + if dods_status is not None: + result += "DODS: " + for player in dods_status.players.sample: + result += player.name + result += "\n" + + notify2.init('Minecraft Server Status') + n = notify2.Notification("Minecraft Server Status", result) + n.show() ''; interval = 10; format = "