Phase 2 start: desktop window (pywebview)
Setup screen (create/open library), update buttons, drag-and-drop import, Garmin Connect login with MFA prompt, sources overview, settings, live log. Jobs run one at a time in a worker thread. Single instance on Windows. Dashboard can be copied to extra paths (copy_dashboard_to). App API test. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
273
src/mygarmin/app/ui.html
Normal file
273
src/mygarmin/app/ui.html
Normal file
@@ -0,0 +1,273 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>myGarmin</title>
|
||||
<style>
|
||||
/* Same visual language as the dashboard; fonts fall back to system ones so the app works offline */
|
||||
:root {
|
||||
--bg: #f7f7f4; --surface: #ffffff; --fg: #171a17; --muted: #5d625c; --rule: #dfe1db; --accent: #1f6f5c; --accent-fg: #ffffff;
|
||||
--warn: #b5560f; --bad: #b3261e; --good: #1f6f5c;
|
||||
--display: "Fraunces", Georgia, serif; --body: "IBM Plex Sans", "Segoe UI", system-ui, sans-serif; --mono: "IBM Plex Mono", Consolas, ui-monospace, monospace;
|
||||
color-scheme: light;
|
||||
}
|
||||
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) {
|
||||
--bg: #141613; --surface: #1c1f1b; --fg: #eceee9; --muted: #a4a9a2; --rule: #2f332e; --accent: #5fc2a6; --accent-fg: #0d1f19;
|
||||
--warn: #e39a52; --bad: #ef7b72; --good: #5fc2a6; color-scheme: dark } }
|
||||
* { box-sizing: border-box }
|
||||
body { margin: 0; background: var(--bg); color: var(--fg); font: 14px/1.5 var(--body) }
|
||||
header.top { display: flex; align-items: center; gap: 16px; padding: 14px 24px; border-bottom: 1px solid var(--rule); background: var(--surface); position: sticky; top: 0; z-index: 5 }
|
||||
header.top h1 { font: 600 22px var(--display); margin: 0 }
|
||||
header.top .lib { color: var(--muted); font: 12px var(--mono); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; min-width: 0 }
|
||||
main { max-width: 1180px; margin: 0 auto; padding: 24px; display: grid; gap: 20px }
|
||||
h2 { font: 600 18px var(--display); margin: 0 0 8px }
|
||||
h3 { font: 600 14px var(--body); margin: 0 0 6px }
|
||||
p { margin: 0 0 8px }
|
||||
.muted, .note { color: var(--muted) }
|
||||
.note { font-size: 13px }
|
||||
.card { background: var(--surface); border: 1px solid var(--rule); border-radius: 8px; padding: 16px 18px; min-width: 0 }
|
||||
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); gap: 20px; align-items: start }
|
||||
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px }
|
||||
.tile { background: var(--surface); border: 1px solid var(--rule); border-radius: 8px; padding: 12px 16px }
|
||||
.tile b { display: block; font: 600 24px var(--display); font-variant-numeric: tabular-nums }
|
||||
.tile span { color: var(--muted); font-size: 12px }
|
||||
button, .btn { font: 500 14px var(--body); border-radius: 6px; padding: 8px 14px; border: 1px solid var(--rule); background: var(--surface); color: var(--fg); cursor: pointer }
|
||||
button.primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); font-weight: 600 }
|
||||
button.big { padding: 12px 22px; font-size: 15px }
|
||||
button:disabled { opacity: .5; cursor: default }
|
||||
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px }
|
||||
button.link { border: 0; background: none; color: var(--accent); padding: 0; text-decoration: underline }
|
||||
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center }
|
||||
label { display: grid; gap: 4px; font-size: 13px; color: var(--muted) }
|
||||
input, select, textarea { font: 14px var(--body); background: var(--bg); color: var(--fg); border: 1px solid var(--rule); border-radius: 6px; padding: 7px 9px; width: 100% }
|
||||
textarea { font: 12px var(--mono); min-height: 52px }
|
||||
.form { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)) }
|
||||
.form .wide { grid-column: 1 / -1 }
|
||||
#drop { border: 2px dashed var(--rule); border-radius: 10px; padding: 26px 18px; text-align: center; transition: border-color .15s, background .15s }
|
||||
#drop.over { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, transparent) }
|
||||
#drop b { font: 600 16px var(--display); display: block; margin-bottom: 4px }
|
||||
table { border-collapse: collapse; width: 100%; font-size: 13px; font-variant-numeric: tabular-nums }
|
||||
th, td { padding: 5px 8px; text-align: right; border-bottom: 1px solid var(--rule) }
|
||||
th:first-child, td:first-child { text-align: left }
|
||||
#log { font: 12px/1.45 var(--mono); background: var(--bg); border: 1px solid var(--rule); border-radius: 6px; padding: 10px; height: 260px; overflow: auto; white-space: pre-wrap; margin: 0 }
|
||||
.status { display: inline-flex; align-items: center; gap: 6px; font-size: 13px }
|
||||
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; background: var(--muted) }
|
||||
.dot.ok { background: var(--good) } .dot.off { background: var(--warn) }
|
||||
.busy { color: var(--accent); font-weight: 600 }
|
||||
details > summary { cursor: pointer; font: 600 14px var(--body); list-style-position: inside }
|
||||
details[open] > summary { margin-bottom: 10px }
|
||||
.help td, .help th { text-align: left; vertical-align: top }
|
||||
.recent button { font: 12px var(--mono); text-align: left; width: 100% }
|
||||
.hidden { display: none !important }
|
||||
@media (prefers-reduced-motion: reduce) { * { transition: none !important } }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<header class="top">
|
||||
<h1>myGarmin</h1>
|
||||
<div class="lib" id="libPath"></div>
|
||||
<span class="busy hidden" id="busy" role="status" aria-live="polite"></span>
|
||||
<button id="switchLib" class="hidden" onclick="ui.call('close_library').then(ui.render)">Switch library</button>
|
||||
</header>
|
||||
|
||||
<main>
|
||||
<!-- no library yet -->
|
||||
<section id="setup" class="hidden">
|
||||
<div class="card">
|
||||
<h2>Welcome</h2>
|
||||
<p class="muted">myGarmin keeps your activity and health history in one <b>library folder</b> on this PC: the original files, a database and your dashboard. Nothing is uploaded anywhere.</p>
|
||||
</div>
|
||||
<div class="grid2" style="margin-top:20px">
|
||||
<div class="card">
|
||||
<h2>Create a new library</h2>
|
||||
<div class="form">
|
||||
<label class="wide">Folder<div class="row" style="flex-wrap:nowrap"><input id="newPath" placeholder="e.g. D:\myGarmin"><button onclick="ui.pick('newPath')">Browse…</button></div></label>
|
||||
<label>Your name<input id="newName" placeholder="shown on the dashboard"></label>
|
||||
<label>Birth year<input id="newBirth" type="number" min="1900" max="2030" placeholder="for age comparisons"></label>
|
||||
<label>Sex<select id="newSex"><option value="">Not set</option><option value="M">Male</option><option value="F">Female</option></select></label>
|
||||
<label>Home time zone<input id="newTz" list="tzList"></label>
|
||||
</div>
|
||||
<p class="note" style="margin-top:8px">Birth year and sex are used only to rate VO2max and show ages; leave them empty if you prefer.</p>
|
||||
<button class="primary" onclick="ui.create()">Create library</button>
|
||||
</div>
|
||||
<div class="card">
|
||||
<h2>Open an existing library</h2>
|
||||
<div class="row" style="flex-wrap:nowrap"><input id="openPath" placeholder="library folder"><button onclick="ui.pick('openPath')">Browse…</button><button class="primary" onclick="ui.open()">Open</button></div>
|
||||
<div id="recent" class="recent" style="margin-top:12px;display:grid;gap:6px"></div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- library open -->
|
||||
<section id="home" class="hidden" style="display:grid;gap:20px">
|
||||
<div class="tiles" id="tiles"></div>
|
||||
|
||||
<div class="card">
|
||||
<div class="row" style="justify-content:space-between">
|
||||
<div>
|
||||
<h2 style="margin:0">Keep it up to date</h2>
|
||||
<p class="note" style="margin:2px 0 0">Reads the watch if it is connected by USB, fetches new data from Garmin Connect, then rebuilds the dashboard and the track exports.</p>
|
||||
</div>
|
||||
<button class="primary big job" onclick="ui.job('update', true, true)">Update everything</button>
|
||||
</div>
|
||||
<div class="row" style="margin-top:12px">
|
||||
<button class="job" onclick="ui.job('watch')">Read watch (USB)</button>
|
||||
<button class="job" onclick="ui.job('sync')">Sync Garmin Connect</button>
|
||||
<button class="job" onclick="ui.job('build')">Rebuild dashboard</button>
|
||||
<button class="job" onclick="ui.job('export')">Export tracks (GPX + AlpineQuest)</button>
|
||||
<span style="flex:1"></span>
|
||||
<button onclick="ui.call('open_dashboard')" id="openDash">Open dashboard</button>
|
||||
<button onclick="ui.call('open_folder', 'exports')">Open exports</button>
|
||||
<button onclick="ui.call('open_folder')">Open library folder</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="grid2">
|
||||
<div class="card">
|
||||
<h2>Add data</h2>
|
||||
<div id="drop">
|
||||
<b>Drop files or folders here</b>
|
||||
<span class="muted">Garmin or Strava export zips, a copied watch <code>GARMIN</code> folder, or .fit .tcx .gpx .trk files</span>
|
||||
<div class="row" style="justify-content:center;margin-top:12px">
|
||||
<button class="job" onclick="ui.chooseFiles()">Choose files…</button>
|
||||
<button class="job" onclick="ui.chooseFolder()">Choose a folder…</button>
|
||||
</div>
|
||||
</div>
|
||||
<details style="margin-top:14px">
|
||||
<summary>Where do I get my data?</summary>
|
||||
<table class="help">
|
||||
<tr><th>Garmin Connect</th><td>garmin.com → Account → Data Management → <b>Export Your Data</b>. Garmin e-mails a zip (can take days); drop it here as is. Gives all activities plus daily sleep, HRV, stress and more.</td></tr>
|
||||
<tr><th>Strava</th><td>strava.com → Settings → My Account → <b>Download or Delete Your Account</b> → Request your archive. Drop the zip here as is.</td></tr>
|
||||
<tr><th>AlpineQuest</th><td>Copy the <code>.trk</code> files from the phone (AlpineQuest folder) to the PC and drop them here.</td></tr>
|
||||
<tr><th>Garmin watch</th><td>Connect it by USB and press <b>Read watch</b>. Newer watches only keep a few weeks of data, so do this regularly or use Garmin Connect.</td></tr>
|
||||
<tr><th>Races</th><td>Optional: put a <code>races.csv</code> in the library folder with <code>date,event,time</code> and optionally <code>km,age_grade,position,pb</code>.</td></tr>
|
||||
</table>
|
||||
</details>
|
||||
</div>
|
||||
|
||||
<div style="display:grid;gap:20px">
|
||||
<div class="card">
|
||||
<h2>Garmin Connect</h2>
|
||||
<div id="gcIn" class="hidden">
|
||||
<p><span class="status"><i class="dot ok"></i>Logged in</span> <span class="note">· the login token is kept on this PC only</span></p>
|
||||
<button class="link" onclick="ui.call('logout').then(ui.render)">Log out</button>
|
||||
</div>
|
||||
<div id="gcOut" class="hidden">
|
||||
<p class="note"><span class="status"><i class="dot off"></i>Not logged in.</span> Garmin has no official personal API; this logs in the way the Connect app does and may stop working when Garmin changes its login. Your password is not stored.</p>
|
||||
<div class="form">
|
||||
<label>E-mail<input id="gcEmail" type="email" autocomplete="username"></label>
|
||||
<label>Password<input id="gcPass" type="password" autocomplete="current-password"></label>
|
||||
</div>
|
||||
<div class="row" style="margin-top:10px"><button class="primary job" onclick="ui.login()">Log in</button></div>
|
||||
</div>
|
||||
<div id="gcMfa" class="hidden" style="margin-top:10px">
|
||||
<label>Code from your authenticator app or e-mail<div class="row" style="flex-wrap:nowrap"><input id="mfaCode" inputmode="numeric" autocomplete="one-time-code"><button class="primary" onclick="ui.sendMfa()">Send</button></div></label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card">
|
||||
<h2>What is in the library</h2>
|
||||
<table id="srcTable"></table>
|
||||
<p class="note" id="healthLine" style="margin-top:8px"></p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<details id="settingsBox">
|
||||
<summary>Settings</summary>
|
||||
<div class="form">
|
||||
<label>Name<input id="sName"></label>
|
||||
<label>Birth year<input id="sBirth" type="number" min="1900" max="2030"></label>
|
||||
<label>Sex<select id="sSex"><option value="">Not set</option><option value="M">Male</option><option value="F">Female</option></select></label>
|
||||
<label>Home time zone<input id="sTz" list="tzList"></label>
|
||||
<label class="wide">Also copy the dashboard to (one path per line, e.g. a OneDrive folder)<textarea id="sCopies"></textarea></label>
|
||||
</div>
|
||||
<div class="row" style="margin-top:10px"><button class="primary" onclick="ui.saveSettings()">Save settings</button><span class="note">Rebuild the dashboard afterwards to apply.</span></div>
|
||||
</details>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<div class="row" style="justify-content:space-between"><h2 style="margin:0">Log</h2><button class="link" onclick="document.getElementById('log').textContent=''">Clear</button></div>
|
||||
<pre id="log" aria-live="polite"></pre>
|
||||
</div>
|
||||
</section>
|
||||
<datalist id="tzList"></datalist>
|
||||
<p class="note" id="foot"></p>
|
||||
</main>
|
||||
|
||||
<script>
|
||||
const $ = id => document.getElementById(id);
|
||||
let S = null;
|
||||
const ui = {
|
||||
async call(fn, ...args) {
|
||||
try { return await window.pywebview.api[fn](...args) } catch (e) { ui.log('Error: ' + (e.message || e)); return null }
|
||||
},
|
||||
log(line) { const l = $('log'); if (!l) return; l.textContent += line + '\n'; l.scrollTop = l.scrollHeight },
|
||||
async render(state) {
|
||||
S = state || await ui.call('state'); if (!S) return;
|
||||
if (S.error) { alert(S.error); S = await ui.call('state') }
|
||||
$('foot').textContent = `myGarmin ${S.version}`;
|
||||
if (!$('tzList').children.length) $('tzList').innerHTML = S.timezones.map(z => `<option value="${z}">`).join('');
|
||||
const L = S.library;
|
||||
$('setup').classList.toggle('hidden', !!L); $('home').classList.toggle('hidden', !L); $('switchLib').classList.toggle('hidden', !L);
|
||||
$('libPath').textContent = L ? L.root : '';
|
||||
ui.busy(S.busy);
|
||||
if (!L) {
|
||||
if (!$('newTz').value) $('newTz').value = S.tz_guess;
|
||||
$('recent').innerHTML = S.recent.length ? '<p class="note" style="margin:0">Recently used</p>' + S.recent.map(r => `<button data-p="${r.replace(/"/g, '"')}">${r.replace(/</g, '<')}</button>`).join('') : '';
|
||||
$('recent').querySelectorAll('button').forEach(b => b.onclick = () => { $('openPath').value = b.dataset.p; ui.open() });
|
||||
return;
|
||||
}
|
||||
const n = v => (v ?? 0).toLocaleString();
|
||||
$('tiles').innerHTML = [[n(L.shown), 'activities on the dashboard'], [L.last_activity ? L.last_activity.slice(0, 10) : '—', 'latest activity'],
|
||||
[n(L.health.days), 'days of health data'], [L.health.last || '—', 'latest health day'], [L.dashboard || 'not built yet', 'dashboard built']]
|
||||
.map(([v, l]) => `<div class="tile"><b>${v}</b><span>${l}</span></div>`).join('');
|
||||
const label = { fit: 'Garmin (FIT)', tcx: 'Garmin (TCX)', alpinequest: 'AlpineQuest', strava: 'Strava', gpx: 'GPX' };
|
||||
$('srcTable').innerHTML = '<thead><tr><th>Source</th><th>Recordings</th><th>On dashboard</th><th>Latest</th></tr></thead><tbody>' +
|
||||
(L.sources.length ? L.sources.map(r => `<tr><td>${label[r.source] || r.source}</td><td>${n(r.n)}</td><td>${n(r.shown)}</td><td>${(r.last || '').slice(0, 10)}</td></tr>`).join('')
|
||||
: '<tr><td colspan="4" class="muted">Nothing yet: add some data.</td></tr>') + '</tbody>';
|
||||
$('healthLine').textContent = L.health.days ? `Daily health ${L.health.first} to ${L.health.last}. Recordings left out of the dashboard are copies of an outing another source also recorded, transport, or too short.` : 'No daily health data yet: import a Garmin Connect export or log in to Garmin Connect.';
|
||||
$('gcIn').classList.toggle('hidden', !L.garmin_login); $('gcOut').classList.toggle('hidden', L.garmin_login);
|
||||
$('openDash').disabled = !L.dashboard;
|
||||
const s = L.settings;
|
||||
if (!$('settingsBox').open) { $('sName').value = s.name || ''; $('sBirth').value = s.birth_year || ''; $('sSex').value = s.sex || ''; $('sTz').value = s.home_tz || 'UTC';
|
||||
$('sCopies').value = (s.copy_dashboard_to || []).join('\n') }
|
||||
},
|
||||
busy(name) {
|
||||
$('busy').textContent = name ? `Working: ${name}…` : ''; $('busy').classList.toggle('hidden', !name);
|
||||
document.querySelectorAll('button.job').forEach(b => b.disabled = !!name);
|
||||
},
|
||||
async job(fn, ...args) {
|
||||
const r = await ui.call(fn, ...args);
|
||||
if (r && !r.ok) { ui.log(r.error); return }
|
||||
ui.busy(fn); ui.log(`— ${fn} started ${new Date().toLocaleTimeString()}`);
|
||||
},
|
||||
done(name, ok, state) { ui.log(`— ${name} ${ok ? 'finished' : 'stopped'} ${new Date().toLocaleTimeString()}`); $('gcMfa').classList.add('hidden'); ui.render(state) },
|
||||
dropped(paths) { ui.log('Dropped: ' + paths.join(', ')); ui.job('import_paths', paths) },
|
||||
async chooseFiles() { const p = await ui.call('pick_files'); if (p && p.length) ui.job('import_paths', p) },
|
||||
async chooseFolder() { const p = await ui.call('pick_folder'); if (p) ui.job('import_paths', [p]) },
|
||||
async pick(id) { const p = await ui.call('pick_folder'); if (p) $(id).value = p },
|
||||
async create() {
|
||||
ui.render(await ui.call('create_library', $('newPath').value.trim(), $('newName').value.trim(), $('newBirth').value, $('newSex').value, $('newTz').value.trim() || 'UTC'));
|
||||
},
|
||||
async open() { ui.render(await ui.call('open_library', $('openPath').value.trim())) },
|
||||
async saveSettings() {
|
||||
const st = await ui.call('save_settings', $('sName').value.trim(), $('sBirth').value, $('sSex').value, $('sTz').value.trim() || 'UTC', $('sCopies').value);
|
||||
$('settingsBox').open = false; ui.render(st); ui.log('Settings saved.');
|
||||
},
|
||||
async login() {
|
||||
const e = $('gcEmail').value.trim(), p = $('gcPass').value; if (!e || !p) return;
|
||||
$('gcPass').value = ''; ui.job('login', e, p);
|
||||
},
|
||||
askMfa() { $('gcMfa').classList.remove('hidden'); $('mfaCode').focus(); ui.log('Garmin asks for a verification code.') },
|
||||
sendMfa() { ui.call('mfa', $('mfaCode').value); $('mfaCode').value = ''; $('gcMfa').classList.add('hidden') },
|
||||
};
|
||||
// visual feedback while dragging (the drop itself is handled in Python, which sees the full paths)
|
||||
const drop = $('drop');
|
||||
['dragenter', 'dragover'].forEach(t => drop.addEventListener(t, e => { e.preventDefault(); drop.classList.add('over') }));
|
||||
['dragleave', 'drop'].forEach(t => drop.addEventListener(t, () => drop.classList.remove('over')));
|
||||
window.addEventListener('pywebviewready', () => ui.render());
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user