openhop

srcSource code

Source code

Every file of openhop's latest version, exactly as published. Read anything, or download it all as a zip.

Commit
c8cfb4c
Date
16 Nov 2026
Files
62 files
Download the source (zip)

zip · 758 KB · SHA-256 6ce65b028777bf92…

traymenu.html

383 lines · 79 KB · HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>openhop menu</title>
<!--
openhop tray menu. Shown in a frameless, transparent window of exactly 280 x 312 CSS px above the tray icon.
Python -> page: window.renderMenu({ status: 'ok'|'warn'|'busy'|'bad'|'unknown', title, sub, hops, last_hop })
(call before every show; the window is reused, so this also resets hover/focus)
Page -> Python: pywebview.api.menu_action('open'|'hop'|'fix_all'|'quit'), pywebview.api.menu_close()
optional pull on first load: pywebview.api.menu_state()
Every call is guarded, so the page also works with no API (preview).
-->
<style>
/* Inter (latin subset, SIL Open Font License) embedded so it works offline */
@font-face {
font-family: "Inter";
font-style: normal;
font-weight: 400 700;
font-display: swap;
src: local("Inter"), local("Inter Variable"), url(data:font/woff2;base64,d09GMgABAAAAALyAABUAAAAB4CAAALwFAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGoZeG4KyRBzVcD9IVkFSi2k/TVZBUl4GYD9TVEFUgU4nJgCFNi9sEQgKgbtAgaEUC4gOADCCnD4BNgIkA5AYBCAFhi4HoQQMB1tzzZFCvBvP7u3DbGpQpdsQgMqps1L7r3ADN3ekcLpSd3VjDvdRxlSwXT24HeDivrPV7P/////PTiZjjG6zbhuAgIaVWf//oFG6m0fKpZa1GtEM3hHeiRiGTOHDNEtW1uphm9xD8Yfsc845xSOllI6MZ0bgBa6OXQbsGPkQKYlQqD3X9YVVvH2KntB6YJwvZMXkp+C5yraOrUrG4lPZsKGIy79I0v3UzBZt9SM6yqcJLyKfWogpGCTMhFHtxxQ74e+iXfmlkqJiNbeKZ4KLcfByGbnFit+pfrn4okou/l1zuyzDbEtoImSSXDLgSfrNakEiSjNkyuNXIhj2Rtg8HXFaJ1HMmcuGV+Se8CUCw/bq3NAqMQ78EUkhmkVBNNkIe66aFY24EF5FxJKmvYhLeZu+817KeHDRANVOdSZTE0mx05wGy3iIsAUf0f92lq9M9/vv/v/fb8Oa8yVqT0nuI2nTGlyeDouviNs9inRBSSqDf7jIJKu0nX6r99J6jx/12cSUdscJp/KxG3QT7RY/9SEwOBbgQ6oeY7Wz9aQv/8DXVf25LyKzMVb1gPyyV/Vl7QRt6Yojsq2qemYjy5LWBREQDCugh4gIihyuKEEw4qrLEgyHmBCRJ4m6LkFU2IMVOZKIiIiYOEQeMxhxWTBhSKjoeZiRLHLKDI9u9i8BQgghYQQIEEKYUxQFUXDWDq/aau0aNzrutm2vd78V8cbevb39PbuWZ+c8x6yKiPAv2cH/SXIzsw/6FFq5J1BCrkRshmBunSgGwlBJAxEEpGLApFwUq2DBGCNGjNwYg41Bb8RokWEBgmRpAypG/w8j8yOHxzn7l6YGDJgwUT8nKWxnYvunm0dKKkBbSk3TVKjTFqliMpggPjnuPrMz5WTD46b9o6Xicz8RK9tuu7tvrowTla6+VY2ikiAhJBCHQEhQ+fE36//kJECQUp/ObldcunvvM5Mvk9KrX8/F1mREaYECwcJRbVYVmlQxSMieub9uWxgmi8RIlphMT53AF76nKsiZ0PP9fv+5+lz6NKMTYVIxFkhYYhkun/JxgkCrUW8HgAHfZv5wV/Vceo2IEwFWEZPFfBFfSpOnX/qnojXxvfbOns7sUMptOJJCQsyoiP+evOentnLVv/qvc+q3CjpUOcAOsAPo0KMDOG0kq58AOljNltFOGB3g1Wk39AQ+xS8O8/f2tb0KFOBgKOMZL1U4wNeMYxxsv9E/WGcJZSGtFOEB7fTCvnubsV0HO3elSVt20/zFnBL… 62,939 more characters on this line, see Raw
}
:root {
--text: #ecebe4;
--muted: #a8a59b;
--dim: #7a776f;
--line: rgba(236, 233, 222, 0.09);
--amber: #f2b318;
--amber-text: #f7cc5c;
--ink: #1f2125;
--paper: #efede6;
--ok: #3fb97a;
--warn: #f07d3a;
--bad: #e5534b;
--info: #6fa8d6;
--tone: #7a776f;
--ease-out: cubic-bezier(0.2, 0.8, 0.2, 1);
--ease-in: cubic-bezier(0.5, 0, 0.75, 0);
--sans: "Inter", "Segoe UI Variable Text", "Segoe UI", system-ui, sans-serif;
--display: "Bahnschrift", "DIN Alternate", "Segoe UI", sans-serif;
--i-open: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><rect x='3' y='4' width='18' height='16' rx='1.5'/><path d='M3 9h18'/></svg>");
--i-hop: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><path d='M3 20c1-8 6-12 10-12s6.5 3 7.5 7'/><path d='M21.5 9.5 20.5 15l-5.3-1.6'/><path d='M2 20h4'/></svg>");
--i-wrench: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><path d='M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.77-3.77a6 6 0 0 1-7.94 7.94l-6.91 6.91a2.12 2.12 0 0 1-3-3l6.91-6.91a6 6 0 0 1 7.94-7.94l-3.76 3.76z'/></svg>");
--i-power: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><path d='M12 2v10'/><path d='M18.4 6.6a9 9 0 1 1-12.77.04'/></svg>");
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { width: 280px; height: 312px; background: transparent; overflow: hidden; }
body {
font-family: var(--sans);
font-size: 13px;
color: var(--text);
user-select: none;
-webkit-font-smoothing: antialiased;
cursor: default;
}
.menu {
--c: 12px;
position: relative;
width: 280px;
height: 312px;
display: flex;
flex-direction: column;
background:
radial-gradient(260px 120px at 0% 0%, color-mix(in srgb, var(--tone) 12%, transparent), transparent 70%),
linear-gradient(180deg, #25272c 0%, #1b1d21 100%);
clip-path: polygon(var(--c) 0, 100% 0, 100% calc(100% - var(--c)), calc(100% - var(--c)) 100%, 0 100%, 0 var(--c));
transform-origin: 100% 100%;
}
/* opens up from the tray, closes quicker than it opens */
.menu.enter { animation: menuIn 380ms cubic-bezier(0.25, 0.8, 0.3, 1); }
.menu.leave { animation: menuOut 150ms var(--ease-in) forwards; }
@keyframes menuIn { from { opacity: 0; transform: translateY(14px) scale(0.9); } to { opacity: 1; transform: none; } }
@keyframes menuOut { from { opacity: 1; transform: none; } to { opacity: 0; transform: translateY(8px) scale(0.96); } }
/* the header and each option deal in after the panel, bottom-up feel without moving far */
.menu.enter .head, .menu.enter .item, .menu.enter .divider { animation: itemIn 420ms cubic-bezier(0.25, 0.8, 0.3, 1) both; }
.menu.enter .head { animation-delay: 60ms; }
.menu.enter .items > :nth-child(1) { animation-delay: 110ms; }
.menu.enter .items > :nth-child(2) { animation-delay: 150ms; }
.menu.enter .items > :nth-child(3) { animation-delay: 190ms; }
.menu.enter .items > :nth-child(4) { animation-delay: 220ms; }
.menu.enter .items > :nth-child(5) { animation-delay: 240ms; }
@keyframes itemIn { from { opacity: 0; transform: translateX(-12px); } to { opacity: 1; transform: none; } }
.menu[data-status="ok"] { --tone: var(--ok); }
.menu[data-status="warn"] { --tone: var(--warn); }
.menu[data-status="bad"] { --tone: var(--bad); }
.menu[data-status="busy"] { --tone: var(--info); }
.frame { position: absolute; inset: 0; pointer-events: none; }
/* Status header */
.head {
position: relative;
display: grid;
grid-template-columns: 36px minmax(0, 1fr);
column-gap: 12px;
align-items: center;
padding: 16px 16px 14px 18px;
border-bottom: 1px solid var(--line);
}
.head::before {
content: "";
position: absolute;
left: 0;
top: 12px;
bottom: 12px;
width: 4px;
background: var(--tone);
}
.menu[data-status="bad"] .head::before { background: repeating-linear-gradient(-45deg, var(--bad) 0 5px, #3a1d1c 5px 10px); }
.menu[data-status="busy"] .head::before { background: repeating-linear-gradient(-45deg, var(--info) 0 5px, #1f2c38 5px 10px); background-size: 100% 14.14px; animation: stripes 0.9s linear infinite; }
@keyframes stripes { to { background-position: 0 14.14px; } }
.mark { width: 36px; height: 36px; display: block; grid-row: span 2; }
.brandline {
display: flex;
align-items: center;
gap: 7px;
font-family: var(--display);
font-size: 11px;
font-weight: 600;
letter-spacing: 1px;
text-transform: uppercase;
color: var(--dim);
}
.dot { width: 7px; height: 7px; border-radius: 1px; background: var(--tone); box-shadow: 0 0 0 3px color-mix(in srgb, var(--tone) 22%, transparent); }
.menu[data-status="busy"] .dot { animation: pulse 0.9s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.35; } }
.state-word { color: var(--tone); }
.menu[data-status="unknown"] .state-word { color: var(--dim); }
.title {
margin-top: 3px;
font-family: var(--display);
font-size: 16px;
font-weight: 600;
line-height: 1.2;
color: var(--paper);
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.sub {
grid-column: 2;
margin-top: 2px;
font-size: 12px;
color: var(--muted);
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
font-variant-numeric: tabular-nums;
}
.textcol { min-width: 0; }
/* Items */
.items { flex: 1; display: flex; flex-direction: column; justify-content: center; padding: 7px; gap: 2px; }
.item {
height: 48px;
display: flex;
align-items: center;
gap: 12px;
padding: 0 12px;
border: 0;
border-radius: 3px;
background: transparent;
color: var(--text);
font-family: var(--sans);
font-size: 13.5px;
font-weight: 600;
text-align: left;
cursor: pointer;
outline: none;
box-shadow: inset 0 0 0 var(--amber);
transition: background-color 90ms var(--ease-out), box-shadow 90ms var(--ease-out), color 90ms var(--ease-out), transform 70ms var(--ease-out);
}
.item::before {
content: "";
width: 17px;
height: 17px;
flex-shrink: 0;
background: var(--muted);
-webkit-mask: var(--icon) center / contain no-repeat;
mask: var(--icon) center / contain no-repeat;
transition: background-color 90ms var(--ease-out);
}
.item[data-action="open"] { --icon: var(--i-open); }
.item[data-action="hop"] { --icon: var(--i-hop); }
.item[data-action="fix_all"] { --icon: var(--i-wrench); }
.item[data-action="quit"] { --icon: var(--i-power); }
.item .lbl { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .hint { font-family: var(--display); font-size: 11.5px; font-weight: 500; letter-spacing: 0.3px; color: var(--dim); white-space: nowrap; }
.item.sel {
background-color: #303238;
box-shadow: inset 3px 0 0 var(--amber);
}
.item.sel::before { background: var(--amber); }
.item:active { transform: translateY(1px); }
/* "Fix everything" becomes the obvious action when something is wrong */
.item.urgent { color: var(--amber-text); }
.item.urgent::before { background: var(--amber); }
.item.urgent .hint {
color: var(--ink);
background: linear-gradient(180deg, #f9c537, #e4a60f);
padding: 1px 6px 0;
border-radius: 2px;
font-weight: 600;
}
.item.quit.sel { box-shadow: inset 3px 0 0 var(--bad); }
.item.quit.sel::before { background: var(--bad); }
.item.quit.sel { color: #ffb3ad; }
@media (prefers-reduced-motion: reduce) {
.menu.enter, .menu.leave { animation-duration: 1ms; }
.menu.enter .head, .menu.enter .item, .menu.enter .divider { animation: none; }
.item, .item::before { transition-duration: 1ms; }
.head::before, .dot { animation: none !important; }
}
.divider { height: 1px; background: var(--line); margin: 4px 6px; flex-shrink: 0; }
/* Opaque window version (see notify.html): the menu fills the window, Windows 11 rounds the corners. */
html, body { width: 100vw; height: 100vh; background: #1f2125; }
.menu { width: 100vw; height: 100vh; clip-path: none; box-shadow: inset 0 0 0 1px rgba(236, 233, 222, 0.10); }
.menu.enter { animation: menuFade 160ms ease-out; }
.menu.leave { animation: menuFadeOut 120ms ease-in forwards; }
@keyframes menuFade { from { opacity: 0; } to { opacity: 1; } }
@keyframes menuFadeOut { from { opacity: 1; } to { opacity: 0; } }
.frame { display: none; }
</style>
</head>
<body>
<div class="menu" id="menu" data-status="unknown" role="menu" aria-label="openhop">
<svg class="frame" viewBox="0 0 280 312" preserveAspectRatio="none" aria-hidden="true">
<path d="M12 0.5 H279.5 V300 L268 311.5 H0.5 V12 Z" fill="none" stroke="rgba(236,233,222,0.16)" stroke-width="1" vector-effect="non-scaling-stroke"/>
</svg>
<div class="head">
<svg class="mark" viewBox="0 0 100 100" aria-hidden="true">
<path d="M8 1 L92 1 L99 8 L99 92 L92 99 L8 99 L1 92 L1 8 Z" fill="#f2b318"/>
<rect x="22" y="17" width="15" height="66" fill="#1f2125"/>
<path d="M41 41.5 H51 Q68.5 41.5 68.5 59 V83" fill="none" stroke="#1f2125" stroke-width="15"/>
</svg>
<div class="textcol">
<div class="brandline"><span>openhop</span><span class="dot"></span><span class="state-word" id="stateWord"></span></div>
<div class="title" id="mTitle"></div>
</div>
<div class="sub" id="mSub"></div>
</div>
<div class="items" id="items">
<button class="item" role="menuitem" data-action="open"><span class="lbl" data-i18n="open"></span></button>
<button class="item" role="menuitem" data-action="hop"><span class="lbl" data-i18n="hop"></span><span class="hint" data-i18n="hopHint"></span></button>
<button class="item" role="menuitem" data-action="fix_all"><span class="lbl" data-i18n="fix"></span><span class="hint" id="fixHint"></span></button>
<div class="divider" role="separator"></div>
<button class="item quit" role="menuitem" data-action="quit"><span class="lbl" data-i18n="quit"></span></button>
</div>
</div>
<script>
const STRINGS = {
en: {
"open": "Open openhop",
"hop": "Get a new IP",
"hopHint": "~12 s",
"fix": "Fix everything",
"fixNeeded": "Needed",
"fixNone": "",
"quit": "Quit openhop",
"status.ok": "OK",
"status.warn": "Warning",
"status.busy": "Busy",
"status.bad": "Problem",
"status.unknown": "",
"title.ok": "Everything is working",
"title.warn": "Working, with warnings",
"title.busy": "Getting a new IP…",
"title.bad": "OpenCode needs attention",
"title.unknown": "Checking…",
"hops.0": "No new IPs yet",
"hops.1": "1 new IP so far",
"hops.n": "{n} new IPs so far",
"last": "last {time}"
}
};
let LANG = "en";
function t(key, vars) {
let s = (STRINGS[LANG] && key in STRINGS[LANG]) ? STRINGS[LANG][key] : (key in STRINGS.en ? STRINGS.en[key] : key);
if (vars) s = s.replace(/\{(\w+)\}/g, (m, k) => (k in vars ? String(vars[k]) : m));
return s;
}
const $ = (id) => document.getElementById(id);
const call = (name, ...args) => {
try {
const fn = window.pywebview && window.pywebview.api && window.pywebview.api[name];
if (typeof fn === "function") return Promise.resolve(fn(...args)).catch(() => undefined);
} catch (e) { /* API is optional */ }
return Promise.resolve(undefined);
};
document.querySelectorAll("[data-i18n]").forEach((el) => { el.textContent = t(el.dataset.i18n); });
const items = () => Array.from(document.querySelectorAll(".item"));
let sel = -1;
let acting = false;
function select(i, focus = true) {
const list = items();
sel = i < 0 ? -1 : (i + list.length) % list.length;
list.forEach((it, k) => it.classList.toggle("sel", k === sel));
if (focus && sel >= 0) list[sel].focus({ preventScroll: true });
}
function renderMenu(state) {
const s = state || {};
const status = ["ok", "warn", "busy", "bad"].includes(s.status) ? s.status : "unknown";
$("menu").dataset.status = status;
$("stateWord").textContent = t("status." + status);
$("mTitle").textContent = s.title || t("title." + status);
$("mTitle").title = s.sub || "";
const hops = Number(s.hops) || 0;
let sub = hops === 0 ? t("hops.0") : hops === 1 ? t("hops.1") : t("hops.n", { n: hops });
if (s.last_hop) {
const time = new Date(s.last_hop * 1000).toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" });
sub += " · " + t("last", { time });
}
$("mSub").textContent = sub;
const urgent = status === "bad" || status === "warn";
document.querySelector('[data-action="fix_all"]').classList.toggle("urgent", urgent);
$("fixHint").textContent = urgent ? t("fixNeeded") : t("fixNone");
// fresh state for a reused window: nothing hovered, no pending close, replay the entrance
acting = false;
clearTimeout(leaveTimer);
const menu = $("menu");
menu.classList.remove("leave", "enter");
void menu.offsetWidth;
menu.classList.add("enter");
select(-1, false);
if (document.activeElement && document.activeElement.blur) document.activeElement.blur();
}
let leaveTimer = null;
function closeMenu() {
const menu = $("menu");
if (menu.classList.contains("leave")) return;
menu.classList.remove("enter");
menu.classList.add("leave");
clearTimeout(leaveTimer);
leaveTimer = setTimeout(() => call("menu_close"), 150);
}
function act(action) {
if (acting) return;
acting = true;
call("menu_action", action);
}
items().forEach((it, k) => {
it.addEventListener("mouseenter", () => select(k, false));
it.addEventListener("click", () => act(it.dataset.action));
});
$("items").addEventListener("mouseleave", () => select(-1, false));
document.addEventListener("keydown", (e) => {
const n = items().length;
if (e.key === "Escape") { e.preventDefault(); closeMenu(); }
else if (e.key === "ArrowDown") { e.preventDefault(); select(sel < 0 ? 0 : sel + 1); }
else if (e.key === "ArrowUp") { e.preventDefault(); select(sel < 0 ? n - 1 : sel - 1); }
else if (e.key === "Home") { e.preventDefault(); select(0); }
else if (e.key === "End") { e.preventDefault(); select(n - 1); }
else if (e.key === "Enter" || e.key === " ") {
e.preventDefault();
if (sel >= 0) act(items()[sel].dataset.action);
}
});
window.addEventListener("blur", closeMenu);
window.addEventListener("focus", () => { clearTimeout(leaveTimer); $("menu").classList.remove("leave"); });
document.addEventListener("contextmenu", (e) => e.preventDefault());
window.renderMenu = renderMenu;
renderMenu(null);
// Optional pull once the API is there (Python normally pushes with renderMenu before each show)
function pull() { call("menu_state").then((st) => { if (st) renderMenu(st); }); }
if (window.pywebview && window.pywebview.api) pull();
else window.addEventListener("pywebviewready", pull);
</script>
</body>
</html>