diff --git a/app/static/js/app.js b/app/static/js/app.js index 0a2d373..a5c2c13 100644 --- a/app/static/js/app.js +++ b/app/static/js/app.js @@ -1702,8 +1702,74 @@ async function loadDeviceStats() { // Load stats when Stats tab is clicked document.addEventListener('DOMContentLoaded', () => { document.getElementById('statsTabBtn')?.addEventListener('shown.bs.tab', loadDeviceStats); + document.getElementById('shareTabBtn')?.addEventListener('shown.bs.tab', loadDeviceShare); }); +/** + * Load device share tab - generate QR code and URI for sharing own contact + */ +async function loadDeviceShare() { + const container = document.getElementById('deviceShareContent'); + if (!container) return; + + container.innerHTML = '
Loading...
'; + + try { + const response = await fetch('/api/device/info'); + const data = await response.json(); + + if (!data.success) { + container.innerHTML = `
${escapeHtml(data.error)}
`; + return; + } + + const info = data.info; + if (!info || !info.public_key || !info.name) { + container.innerHTML = '
Device info not available
'; + return; + } + + const contactType = info.adv_type || 1; + const uri = `meshcore://contact/add?name=${encodeURIComponent(info.name)}&public_key=${info.public_key}&type=${contactType}`; + + const typeNames = { 1: 'Companion', 2: 'Repeater', 3: 'Room Server', 4: 'Sensor' }; + + let html = '
'; + html += '

Share this QR code or URI so others can add your device as a contact.

'; + html += '
'; + html += '
' + escapeHtml(info.name) + '
'; + html += '
' + escapeHtml(typeNames[contactType] || 'Unknown') + '
'; + html += '
'; + + html += '
'; + html += ''; + html += '
'; + html += ''; + html += ''; + html += '
'; + html += '
'; + + container.innerHTML = html; + + // Generate QR code + const qrContainer = document.getElementById('shareQrCode'); + if (qrContainer && typeof QRCode !== 'undefined') { + new QRCode(qrContainer, { + text: uri, + width: 200, + height: 200, + colorDark: '#000000', + colorLight: '#ffffff', + correctLevel: QRCode.CorrectLevel.M + }); + } + + } catch (error) { + console.error('Error loading device share:', error); + container.innerHTML = '
Failed to load device info
'; + } +} + // ============================================================================= // Settings Modal // ============================================================================= diff --git a/app/templates/base.html b/app/templates/base.html index ca797df..6a736e2 100644 --- a/app/templates/base.html +++ b/app/templates/base.html @@ -312,6 +312,9 @@ +
@@ -328,6 +331,13 @@
+
+
+
+ Click to generate share code +
+
+
@@ -610,6 +620,9 @@ + + +