8398832960
Rebuild homekit.html with centered layout, cleaner PIN input, and consistent styling matching the rest of the frontend. Add www/design-system.html as a living component reference for all UI elements used across the Strix frontend.
514 lines
18 KiB
HTML
514 lines
18 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
|
|
<meta name="theme-color" content="#0a0a0f">
|
|
<title>Strix - HomeKit Pairing</title>
|
|
<style>
|
|
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
|
|
|
|
:root {
|
|
--bg-primary: #0a0a0f;
|
|
--bg-secondary: #1a1a24;
|
|
--bg-tertiary: #24242f;
|
|
--bg-elevated: #2a2a38;
|
|
--purple-primary: #8b5cf6;
|
|
--purple-light: #a78bfa;
|
|
--purple-dark: #7c3aed;
|
|
--purple-glow: rgba(139, 92, 246, 0.3);
|
|
--purple-glow-strong: rgba(139, 92, 246, 0.5);
|
|
--text-primary: #e0e0e8;
|
|
--text-secondary: #a0a0b0;
|
|
--text-tertiary: #606070;
|
|
--success: #10b981;
|
|
--error: #ef4444;
|
|
--border-color: rgba(139, 92, 246, 0.15);
|
|
--font-primary: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', sans-serif;
|
|
--font-mono: 'SF Mono', 'Monaco', 'Inconsolata', 'Fira Code', monospace;
|
|
--transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
|
|
--transition-base: 250ms cubic-bezier(0.4, 0, 0.2, 1);
|
|
--shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.5);
|
|
}
|
|
|
|
html { font-size: 16px; -webkit-font-smoothing: antialiased; }
|
|
|
|
body {
|
|
font-family: var(--font-primary);
|
|
background: var(--bg-primary);
|
|
color: var(--text-primary);
|
|
line-height: 1.5;
|
|
min-height: 100vh;
|
|
}
|
|
|
|
.screen {
|
|
min-height: 100vh;
|
|
padding: 1.5rem;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
animation: fadeIn var(--transition-base);
|
|
}
|
|
|
|
.container { max-width: 480px; width: 100%; }
|
|
|
|
@media (min-width: 768px) {
|
|
.screen { padding: 3rem 1.5rem; }
|
|
.container { max-width: 540px; }
|
|
}
|
|
|
|
.hero { text-align: center; margin-bottom: 3rem; }
|
|
|
|
.title {
|
|
font-size: 4rem; font-weight: 700;
|
|
letter-spacing: 0.1em; margin-bottom: 0.5rem;
|
|
background: linear-gradient(135deg, var(--purple-light), var(--purple-primary));
|
|
-webkit-background-clip: text; -webkit-text-fill-color: transparent;
|
|
background-clip: text;
|
|
}
|
|
|
|
.subtitle { font-size: 0.875rem; color: var(--text-secondary); }
|
|
|
|
.form-group { margin-bottom: 1.5rem; }
|
|
|
|
.label {
|
|
display: flex; align-items: center; gap: 0.5rem;
|
|
font-size: 0.875rem; font-weight: 500;
|
|
color: var(--text-secondary); margin-bottom: 0.75rem;
|
|
justify-content: center;
|
|
}
|
|
|
|
/* Info icon + tooltip */
|
|
.info-icon {
|
|
position: relative; display: inline-flex;
|
|
align-items: center; justify-content: center;
|
|
width: 16px; height: 16px; cursor: help;
|
|
color: var(--text-tertiary); transition: color var(--transition-fast);
|
|
}
|
|
|
|
.info-icon:hover { color: var(--purple-primary); }
|
|
.info-icon svg { width: 16px; height: 16px; }
|
|
|
|
.tooltip {
|
|
position: absolute; top: calc(100% + 8px); left: 50%;
|
|
transform: translateX(-50%);
|
|
background: var(--bg-elevated);
|
|
border: 1px solid var(--purple-primary);
|
|
border-radius: 8px; padding: 1rem;
|
|
width: 320px; max-width: 90vw;
|
|
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6), 0 0 0 1px var(--purple-glow);
|
|
z-index: 1000; opacity: 0; visibility: hidden;
|
|
transition: opacity var(--transition-fast), visibility var(--transition-fast);
|
|
pointer-events: none;
|
|
}
|
|
|
|
.tooltip::after {
|
|
content: ''; position: absolute; bottom: 100%; left: 50%;
|
|
transform: translateX(-50%);
|
|
border: 6px solid transparent; border-bottom-color: var(--purple-primary);
|
|
}
|
|
|
|
.info-icon:hover .tooltip { opacity: 1; visibility: visible; }
|
|
|
|
.tooltip-title { font-weight: 600; color: var(--purple-primary); margin-bottom: 0.5rem; font-size: 0.875rem; }
|
|
.tooltip-text { font-size: 0.75rem; line-height: 1.5; color: var(--text-secondary); }
|
|
|
|
/* PIN input */
|
|
.pin-row {
|
|
display: flex; align-items: center; justify-content: center;
|
|
gap: 0;
|
|
}
|
|
|
|
.pin-group { display: flex; gap: 0.375rem; }
|
|
|
|
.pin-separator {
|
|
font-size: 1.5rem; font-weight: 300;
|
|
color: var(--text-tertiary);
|
|
padding: 0 0.5rem;
|
|
line-height: 1;
|
|
user-select: none;
|
|
}
|
|
|
|
.pin-digit {
|
|
width: 57px; height: 69px;
|
|
background: var(--bg-secondary);
|
|
border: 2px solid var(--border-color);
|
|
border-radius: 8px;
|
|
color: var(--text-primary);
|
|
font-family: var(--font-mono);
|
|
font-size: 1.375rem; font-weight: 600;
|
|
text-align: center;
|
|
outline: none;
|
|
transition: all var(--transition-fast);
|
|
caret-color: var(--purple-primary);
|
|
-moz-appearance: textfield;
|
|
}
|
|
|
|
.pin-digit::-webkit-inner-spin-button,
|
|
.pin-digit::-webkit-outer-spin-button {
|
|
-webkit-appearance: none; margin: 0;
|
|
}
|
|
|
|
.pin-digit:focus {
|
|
border-color: var(--purple-primary);
|
|
box-shadow: 0 0 0 3px var(--purple-glow);
|
|
}
|
|
|
|
.pin-digit.filled {
|
|
border-color: var(--purple-light);
|
|
background: rgba(139, 92, 246, 0.06);
|
|
}
|
|
|
|
.pin-digit.error {
|
|
border-color: var(--error);
|
|
box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.2);
|
|
animation: shake 0.4s ease;
|
|
}
|
|
|
|
.pin-digit.success {
|
|
border-color: var(--success);
|
|
box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.2);
|
|
}
|
|
|
|
@media (max-width: 400px) {
|
|
.pin-digit { width: 36px; height: 48px; font-size: 1.125rem; }
|
|
.pin-separator { padding: 0 0.25rem; font-size: 1.25rem; }
|
|
.pin-group { gap: 0.25rem; }
|
|
}
|
|
|
|
/* Error */
|
|
.error-box {
|
|
padding: 1rem;
|
|
background: rgba(239, 68, 68, 0.1);
|
|
border: 1px solid rgba(239, 68, 68, 0.3);
|
|
border-radius: 8px;
|
|
color: var(--error);
|
|
font-size: 0.875rem;
|
|
margin-bottom: 1.5rem;
|
|
display: none;
|
|
animation: fadeIn var(--transition-fast);
|
|
}
|
|
|
|
.error-box.visible { display: block; }
|
|
|
|
/* Buttons */
|
|
.btn {
|
|
display: inline-flex; align-items: center; justify-content: center;
|
|
gap: 0.5rem; padding: 1rem 1.5rem; border-radius: 8px;
|
|
font-size: 1rem; font-weight: 600; font-family: var(--font-primary);
|
|
cursor: pointer; transition: all var(--transition-fast);
|
|
border: none; outline: none;
|
|
}
|
|
|
|
.btn-primary {
|
|
background: linear-gradient(135deg, var(--purple-primary), var(--purple-dark));
|
|
color: white; box-shadow: 0 4px 12px var(--purple-glow);
|
|
}
|
|
.btn-primary:hover:not(:disabled) {
|
|
transform: translateY(-2px);
|
|
box-shadow: 0 8px 20px var(--purple-glow-strong);
|
|
}
|
|
.btn-primary:active:not(:disabled) { transform: translateY(0); }
|
|
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
|
|
|
|
.btn-large { width: 100%; padding: 1.5rem; font-size: 1.125rem; }
|
|
|
|
.btn-outline {
|
|
display: inline-flex; align-items: center; justify-content: center;
|
|
gap: 0.5rem; padding: 1rem 1.5rem; border-radius: 8px;
|
|
font-size: 1rem; font-weight: 600; font-family: var(--font-primary);
|
|
cursor: pointer; transition: all var(--transition-fast);
|
|
background: transparent; color: var(--text-secondary);
|
|
border: 1px solid var(--border-color); width: 100%;
|
|
margin-top: 0.75rem;
|
|
}
|
|
.btn-outline:hover { border-color: var(--purple-primary); color: var(--purple-light); }
|
|
|
|
/* Pairing spinner */
|
|
.pairing-spinner {
|
|
width: 20px; height: 20px;
|
|
border: 2px solid rgba(255, 255, 255, 0.3);
|
|
border-top-color: white;
|
|
border-radius: 50%;
|
|
animation: spin 0.7s linear infinite;
|
|
}
|
|
|
|
@keyframes spin { to { transform: rotate(360deg); } }
|
|
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
|
|
@keyframes shake {
|
|
0%, 100% { transform: translateX(0); }
|
|
20%, 60% { transform: translateX(-4px); }
|
|
40%, 80% { transform: translateX(4px); }
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
|
|
<div class="screen">
|
|
<div class="container">
|
|
<div class="hero">
|
|
<h1 class="title" style="-webkit-text-fill-color:var(--text-primary); background:none;">HOME KIT</h1>
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label class="label">
|
|
Pairing Code
|
|
<span class="info-icon">
|
|
<svg viewBox="0 0 16 16" fill="none">
|
|
<circle cx="8" cy="8" r="7" stroke="currentColor" stroke-width="1.5"/>
|
|
<path d="M8 7v4M8 5v.5" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"/>
|
|
</svg>
|
|
<div class="tooltip">
|
|
<div class="tooltip-title">HomeKit Pairing Code</div>
|
|
<p class="tooltip-text">The 8-digit code is usually printed on a label on the camera itself, on the packaging, or in the setup manual. It looks like XXX-XX-XXX.</p>
|
|
</div>
|
|
</span>
|
|
</label>
|
|
|
|
<div class="pin-row" id="pin-row">
|
|
<div class="pin-group" id="group-0"></div>
|
|
<span class="pin-separator">-</span>
|
|
<div class="pin-group" id="group-1"></div>
|
|
<span class="pin-separator">-</span>
|
|
<div class="pin-group" id="group-2"></div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="error-box" id="error-box"></div>
|
|
|
|
<button class="btn btn-primary btn-large" id="btn-pair" disabled>Pair Device</button>
|
|
<button class="btn-outline" id="btn-standard">Skip, use Standard Discovery</button>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
var params = new URLSearchParams(location.search);
|
|
|
|
var ip = params.get('ip') || '';
|
|
var ports = params.get('ports') || '';
|
|
var mac = params.get('mac') || '';
|
|
var vendor = params.get('vendor') || '';
|
|
var server = params.get('server') || '';
|
|
var hostname = params.get('hostname') || '';
|
|
var latency = params.get('latency') || '';
|
|
var mdnsName = params.get('mdns_name') || '';
|
|
var mdnsModel = params.get('mdns_model') || '';
|
|
var mdnsCategory = params.get('mdns_category') || '';
|
|
var mdnsPort = params.get('mdns_port') || '';
|
|
var mdnsPaired = params.get('mdns_paired') || '';
|
|
var mdnsDeviceId = params.get('mdns_device_id') || '';
|
|
|
|
// PIN input -- 8 digits: 3-2-3
|
|
var pinGroups = [3, 2, 3];
|
|
var inputs = [];
|
|
|
|
pinGroups.forEach(function(count, gi) {
|
|
var group = document.getElementById('group-' + gi);
|
|
for (var i = 0; i < count; i++) {
|
|
var input = document.createElement('input');
|
|
input.type = 'text';
|
|
input.inputMode = 'numeric';
|
|
input.pattern = '[0-9]';
|
|
input.maxLength = 1;
|
|
input.className = 'pin-digit';
|
|
input.autocomplete = 'off';
|
|
group.appendChild(input);
|
|
inputs.push(input);
|
|
}
|
|
});
|
|
|
|
inputs.forEach(function(input, idx) {
|
|
input.addEventListener('input', function(e) {
|
|
var v = input.value.replace(/\D/g, '');
|
|
input.value = v ? v[0] : '';
|
|
|
|
hideError();
|
|
|
|
if (v && idx < inputs.length - 1) {
|
|
inputs[idx + 1].focus();
|
|
}
|
|
|
|
updateState();
|
|
});
|
|
|
|
input.addEventListener('keydown', function(e) {
|
|
if (e.key === 'Backspace') {
|
|
if (input.value === '' && idx > 0) {
|
|
inputs[idx - 1].focus();
|
|
inputs[idx - 1].value = '';
|
|
updateState();
|
|
e.preventDefault();
|
|
}
|
|
}
|
|
|
|
if (e.key === 'ArrowLeft' && idx > 0) {
|
|
inputs[idx - 1].focus();
|
|
e.preventDefault();
|
|
}
|
|
if (e.key === 'ArrowRight' && idx < inputs.length - 1) {
|
|
inputs[idx + 1].focus();
|
|
e.preventDefault();
|
|
}
|
|
|
|
if (e.key === 'Enter') {
|
|
doPair();
|
|
}
|
|
});
|
|
|
|
input.addEventListener('focus', function() {
|
|
input.select();
|
|
});
|
|
|
|
// paste support -- distribute digits across fields
|
|
input.addEventListener('paste', function(e) {
|
|
e.preventDefault();
|
|
var text = (e.clipboardData || window.clipboardData).getData('text');
|
|
var digits = text.replace(/\D/g, '');
|
|
|
|
for (var i = 0; i < digits.length && idx + i < inputs.length; i++) {
|
|
inputs[idx + i].value = digits[i];
|
|
}
|
|
|
|
var next = Math.min(idx + digits.length, inputs.length - 1);
|
|
inputs[next].focus();
|
|
updateState();
|
|
});
|
|
});
|
|
|
|
function getPin() {
|
|
var pin = '';
|
|
for (var i = 0; i < inputs.length; i++) {
|
|
pin += inputs[i].value;
|
|
}
|
|
return pin;
|
|
}
|
|
|
|
function updateState() {
|
|
var pin = getPin();
|
|
document.getElementById('btn-pair').disabled = pin.length !== 8;
|
|
|
|
inputs.forEach(function(input) {
|
|
if (input.value) {
|
|
input.classList.add('filled');
|
|
} else {
|
|
input.classList.remove('filled');
|
|
}
|
|
input.classList.remove('error');
|
|
input.classList.remove('success');
|
|
});
|
|
}
|
|
|
|
function showError(msg) {
|
|
var el = document.getElementById('error-box');
|
|
el.textContent = msg;
|
|
el.classList.add('visible');
|
|
inputs.forEach(function(input) { input.classList.add('error'); });
|
|
}
|
|
|
|
function hideError() {
|
|
document.getElementById('error-box').classList.remove('visible');
|
|
}
|
|
|
|
function showSuccess() {
|
|
inputs.forEach(function(input) {
|
|
input.classList.remove('error');
|
|
input.classList.add('success');
|
|
});
|
|
}
|
|
|
|
// pair
|
|
var btnPair = document.getElementById('btn-pair');
|
|
btnPair.addEventListener('click', doPair);
|
|
|
|
async function doPair() {
|
|
var pin = getPin();
|
|
if (pin.length !== 8) return;
|
|
|
|
var port = parseInt(mdnsPort, 10);
|
|
if (!ip || !port || !mdnsDeviceId) {
|
|
showError('Missing device information. Go back and re-probe.');
|
|
return;
|
|
}
|
|
|
|
hideError();
|
|
|
|
btnPair.disabled = true;
|
|
var origText = btnPair.textContent;
|
|
btnPair.textContent = '';
|
|
|
|
var spinner = document.createElement('div');
|
|
spinner.className = 'pairing-spinner';
|
|
btnPair.appendChild(spinner);
|
|
|
|
var label = document.createTextNode(' Pairing...');
|
|
btnPair.appendChild(label);
|
|
|
|
inputs.forEach(function(input) { input.disabled = true; });
|
|
|
|
try {
|
|
var r = await fetch('api/homekit/pair', {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({
|
|
ip: ip,
|
|
port: port,
|
|
device_id: mdnsDeviceId,
|
|
pin: pin
|
|
})
|
|
});
|
|
|
|
if (!r.ok) {
|
|
var text = await r.text();
|
|
inputs.forEach(function(input) { input.disabled = false; });
|
|
btnPair.textContent = origText;
|
|
updateState();
|
|
showError(text || 'Pairing failed (HTTP ' + r.status + ')');
|
|
inputs[0].focus();
|
|
return;
|
|
}
|
|
|
|
var data = await r.json();
|
|
|
|
showSuccess();
|
|
btnPair.textContent = 'Paired!';
|
|
|
|
// redirect to create.html with the homekit URL
|
|
setTimeout(function() {
|
|
var p = new URLSearchParams();
|
|
p.set('url', data.url);
|
|
if (ip) p.set('ip', ip);
|
|
if (mac) p.set('mac', mac);
|
|
if (vendor) p.set('vendor', vendor);
|
|
if (mdnsName) p.set('model', mdnsName);
|
|
if (hostname) p.set('hostname', hostname);
|
|
window.location.href = 'create.html?' + p.toString();
|
|
}, 800);
|
|
|
|
} catch (e) {
|
|
inputs.forEach(function(input) { input.disabled = false; });
|
|
btnPair.textContent = origText;
|
|
updateState();
|
|
showError('Connection error: ' + e.message);
|
|
}
|
|
}
|
|
|
|
// navigation
|
|
document.getElementById('btn-standard').addEventListener('click', function() {
|
|
var p = new URLSearchParams();
|
|
if (ip) p.set('ip', ip);
|
|
if (ports) p.set('ports', ports);
|
|
if (mac) p.set('mac', mac);
|
|
if (vendor) p.set('vendor', vendor);
|
|
if (server) p.set('server', server);
|
|
if (hostname) p.set('hostname', hostname);
|
|
if (latency) p.set('latency', latency);
|
|
window.location.href = 'standard.html?' + p.toString();
|
|
});
|
|
|
|
// autofocus first input
|
|
inputs[0].focus();
|
|
</script>
|
|
|
|
</body>
|
|
</html>
|