Hide the secondary codex window if it's not supplied
This commit is contained in:
@@ -167,7 +167,7 @@
|
|||||||
"interval": 15,
|
"interval": 15,
|
||||||
"return-type": "json",
|
"return-type": "json",
|
||||||
"exec": "$HOME/.config/waybar/scripts/openai-rate.py --window secondary",
|
"exec": "$HOME/.config/waybar/scripts/openai-rate.py --window secondary",
|
||||||
"exec-if": "test -r ~/.codex/auth.json",
|
"exec-if": "test -r ~/.codex/auth.json && $HOME/.config/waybar/scripts/openai-rate.py --window secondary --check",
|
||||||
"escape": false,
|
"escape": false,
|
||||||
"format": " {}"
|
"format": " {}"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -146,9 +146,14 @@ def format_window(name, window):
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def get_window(data, selector):
|
||||||
|
rate_limit = data.get("rate_limit") or {}
|
||||||
|
return format_window(selector, rate_limit.get(f"{selector}_window"))
|
||||||
|
|
||||||
|
|
||||||
def output_window(data, source, selector):
|
def output_window(data, source, selector):
|
||||||
rate_limit = data.get("rate_limit") or {}
|
rate_limit = data.get("rate_limit") or {}
|
||||||
window = format_window(selector, rate_limit.get(f"{selector}_window"))
|
window = get_window(data, selector)
|
||||||
if not window:
|
if not window:
|
||||||
waybar("n/a", "warning", f"No {selector} usage window returned\nsource: {source}")
|
waybar("n/a", "warning", f"No {selector} usage window returned\nsource: {source}")
|
||||||
|
|
||||||
@@ -165,6 +170,11 @@ def parse_args():
|
|||||||
required=True,
|
required=True,
|
||||||
help="usage window to display",
|
help="usage window to display",
|
||||||
)
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--check",
|
||||||
|
action="store_true",
|
||||||
|
help="exit successfully only when the selected usage window exists",
|
||||||
|
)
|
||||||
return parser.parse_args()
|
return parser.parse_args()
|
||||||
|
|
||||||
|
|
||||||
@@ -172,6 +182,8 @@ def main():
|
|||||||
args = parse_args()
|
args = parse_args()
|
||||||
token, account_id, source = load_auth()
|
token, account_id, source = load_auth()
|
||||||
data = fetch_usage(token, account_id)
|
data = fetch_usage(token, account_id)
|
||||||
|
if args.check:
|
||||||
|
sys.exit(0 if get_window(data, args.window) else 1)
|
||||||
output_window(data, source, args.window)
|
output_window(data, source, args.window)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user