updates + waybar update notification
This commit is contained in:
@@ -225,6 +225,10 @@
|
||||
"workspace name:steam silent, class:^([Ss]team)$, title:^([Ss]team)$"
|
||||
"tile, class:^([Ss]team)$, title:^([Ss]team)$"
|
||||
|
||||
# Code
|
||||
# "pin, class:^(code)$,title:^(Save As)$"
|
||||
"float, class:^(code)$,title:^(Save As)$"
|
||||
|
||||
# Game Tearing??? https://wiki.hyprland.org/Configuring/Tearing/
|
||||
"immediate, class:gamescope"
|
||||
];
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
|
||||
modules-right = [
|
||||
"tray"
|
||||
# "custom/updates"
|
||||
"custom/updates"
|
||||
"keyboard-state#capslock"
|
||||
"keyboard-state#numlock"
|
||||
"pulseaudio"
|
||||
@@ -54,6 +54,14 @@
|
||||
return-type = "json";
|
||||
};
|
||||
|
||||
"custom/updates" = {
|
||||
tooltip = true;
|
||||
format = {};
|
||||
interval = 60;
|
||||
exec = "sudo waybar-updates";
|
||||
return-type = "json";
|
||||
};
|
||||
|
||||
tray = {
|
||||
icon-size = 16;
|
||||
spacing = 10;
|
||||
@@ -246,7 +254,6 @@
|
||||
color: #91d7e3;
|
||||
border-left: 0px;
|
||||
border-right: 0px;
|
||||
border-radius: 10px 0px 0px 10px;
|
||||
}
|
||||
|
||||
#keyboard-state.numlock {
|
||||
|
||||
82
hosts/desktop/hyprland/config/waybar/scripts/waybar-updates.py
Executable file
82
hosts/desktop/hyprland/config/waybar/scripts/waybar-updates.py
Executable file
@@ -0,0 +1,82 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import os
|
||||
import json
|
||||
import subprocess
|
||||
import re
|
||||
from datetime import datetime
|
||||
import time
|
||||
|
||||
tmp_path = '/tmp/waybar-scripts/updates'
|
||||
json_cache = tmp_path + "/data.json"
|
||||
git_repo = 'git@github.com:mjallen18/nix-config.git'
|
||||
|
||||
def cache_json(data):
|
||||
with open(json_cache, mode="w") as cache:
|
||||
json.dump(data, cache)
|
||||
|
||||
def create_folders():
|
||||
if not os.path.exists(tmp_path):
|
||||
os.makedirs(tmp_path)
|
||||
os.chdir(tmp_path)
|
||||
|
||||
def clone_repo():
|
||||
reset_repo()
|
||||
if os.path.exists(tmp_path) and len(os.listdir(tmp_path)) == 0:
|
||||
subprocess.run(["git", "clone", git_repo, tmp_path])
|
||||
|
||||
def check_for_flake_updates():
|
||||
return subprocess.run(["sudo", "nix", "flake", "update", "-I", tmp_path, tmp_path], capture_output=True, text=True)
|
||||
|
||||
def reset_repo():
|
||||
if os.path.exists(tmp_path) and not len(os.listdir(tmp_path)) == 0:
|
||||
subprocess.run(["git", "reset", "--hard"])
|
||||
subprocess.run(["git", "pull"])
|
||||
|
||||
def parse_output(output):
|
||||
updates_dict = {}
|
||||
updates = re.findall(r"(• Updated input '(.+)':((\n|\r|\n)(.+\((\d\d\d\d-\d\d-\d\d\)))){2})", output)
|
||||
for update in updates:
|
||||
input = re.findall(r"'(.+)':", update[0])[0].strip()
|
||||
dates = re.findall(r"(\d{4}-\d{2}-\d{2})", update[0])
|
||||
updates_dict[input] = dates
|
||||
return updates_dict
|
||||
|
||||
def check():
|
||||
data = {}
|
||||
# print("create folders")
|
||||
create_folders()
|
||||
# print("clone repo")
|
||||
clone_repo()
|
||||
# print("checking for updates")
|
||||
updates = check_for_flake_updates()
|
||||
updates_dict = parse_output(updates.stderr)
|
||||
|
||||
data["text"] = (str(len(updates_dict.keys())))
|
||||
if len(updates_dict.keys()) <= 0:
|
||||
data["tooltip"] = ("flake inputs up to date")
|
||||
else:
|
||||
data["tooltip"] = ("flake input updates:\n\n")
|
||||
|
||||
for input in updates_dict.keys():
|
||||
data["tooltip"] += "<b>{}</b>\n".format(input)
|
||||
data["tooltip"] += "Old Ref: {0} → {1}\n\n".format(updates_dict[input][0].strip(), updates_dict[input][1].strip())
|
||||
|
||||
cache_json(data)
|
||||
|
||||
print(json.dumps(data))
|
||||
|
||||
def read_cache():
|
||||
with open(json_cache, mode="r") as cache:
|
||||
print(json.dumps(json.load(cache)))
|
||||
|
||||
def main():
|
||||
now = int(datetime.now().strftime("%H"))
|
||||
mtime = int(time.localtime(os.stat(json_cache).st_ctime).tm_hour)
|
||||
|
||||
if (now % 2 == 0 and mtime < now) or not os.path.exists(json_cache):
|
||||
check()
|
||||
else:
|
||||
read_cache()
|
||||
|
||||
main()
|
||||
@@ -59,6 +59,10 @@ in
|
||||
command = "/run/current-system/sw/bin/waybar-weather";
|
||||
options = [ "NOPASSWD" ];
|
||||
}
|
||||
{
|
||||
command = "/run/current-system/sw/bin/waybar-updates";
|
||||
options = [ "NOPASSWD" ];
|
||||
}
|
||||
];
|
||||
groups = [ "wheel" ];
|
||||
}
|
||||
|
||||
@@ -6,6 +6,10 @@ let
|
||||
#! nix-shell -i bash --packages python3 python3Packages.requests
|
||||
python /home/matt/.config/waybar/scripts/waybar-wttr.py
|
||||
'';
|
||||
|
||||
waybarUpdatesScript = pkgs.writeScriptBin "waybar-updates" ''
|
||||
/home/matt/.config/waybar/scripts/waybar-updates.py
|
||||
'';
|
||||
in
|
||||
{
|
||||
environment.systemPackages = with pkgs; [
|
||||
@@ -40,6 +44,7 @@ in
|
||||
qt6.qtwayland
|
||||
rofi-wayland
|
||||
waybar
|
||||
waybarUpdatesScript
|
||||
waybarWeatherScript
|
||||
wayland-protocols
|
||||
wayland-utils
|
||||
|
||||
Reference in New Issue
Block a user