(function () { "use strict"; var PASSWORD_KEY = "iss2.desktop.password"; var PASSWORD_TTL_MS = 5 * 60 * 1000; var LAUNCHER_ENABLED = window.ISS2_DESKTOP_LAUNCHER_ENABLED !== false; var TARGET_NAMES = { "Mac Mini Desktop": true, "Mac Mini Desktop (iss2)": true }; function now() { return Date.now ? Date.now() : new Date().getTime(); } function normalizeText(value) { return (value || "").replace(/\s+/g, " ").trim(); } function isSmallTouchDevice() { var coarsePointer = false; try { coarsePointer = !!(window.matchMedia && window.matchMedia("(pointer: coarse)").matches); } catch (ignored) { coarsePointer = false; } var width = Math.min(window.innerWidth || 0, window.screen && window.screen.width || 0) || window.innerWidth || 0; var height = Math.min(window.innerHeight || 0, window.screen && window.screen.height || 0) || window.innerHeight || 0; return coarsePointer && Math.min(width, height) <= 900; } function clampMobileDevicePixelRatio() { if (!isSmallTouchDevice() || (window.devicePixelRatio || 1) <= 1) { return; } try { Object.defineProperty(window, "devicePixelRatio", { configurable: true, get: function () { return 1; } }); document.documentElement.classList.add("iss2-dpr-clamped"); } catch (ignored) { /* Some browsers expose devicePixelRatio as read-only. */ } } function getStoredPassword() { var raw; var parsed; try { raw = window.sessionStorage.getItem(PASSWORD_KEY); parsed = raw && JSON.parse(raw); } catch (ignored) { return null; } if (!parsed || !parsed.password || !parsed.expiresAt || parsed.expiresAt < now()) { clearStoredPassword(); return null; } return parsed; } function clearStoredPassword() { try { window.sessionStorage.removeItem(PASSWORD_KEY); } catch (ignored) { /* Session storage can be disabled in private browser modes. */ } } function storePassword(password, clientId) { try { window.sessionStorage.setItem(PASSWORD_KEY, JSON.stringify({ password: password, clientId: clientId, expiresAt: now() + PASSWORD_TTL_MS })); return true; } catch (ignored) { return false; } } function extractClientId(href) { var match = String(href || "").match(/#\/client\/([^?#]+)/); return match && decodeURIComponent(match[1]); } function ensureStyles() { if (document.getElementById("iss2-launcher-style")) { return; } var style = document.createElement("style"); style.id = "iss2-launcher-style"; style.textContent = [ ".iss2-launcher-overlay{position:fixed;inset:0;z-index:2147483647;background:rgba(0,0,0,.74);display:flex;align-items:center;justify-content:center;padding:24px;font-family:-apple-system,BlinkMacSystemFont,\"Segoe UI\",sans-serif}", ".iss2-launcher-card{width:min(420px,100%);background:#101820;color:#f7fafc;border:1px solid rgba(255,255,255,.14);border-radius:14px;box-shadow:0 24px 80px rgba(0,0,0,.5);padding:22px}", ".iss2-launcher-title{font-size:20px;font-weight:700;margin:0 0 8px}", ".iss2-launcher-copy{font-size:14px;line-height:1.45;color:#cbd5e1;margin:0 0 18px}", ".iss2-launcher-label{display:block;font-size:13px;font-weight:650;margin:0 0 8px;color:#e2e8f0}", ".iss2-launcher-input{box-sizing:border-box;width:100%;height:46px;border-radius:9px;border:1px solid #64748b;background:#020617;color:#fff;font-size:18px;padding:0 12px;outline:none}", ".iss2-launcher-input:focus{border-color:#38bdf8;box-shadow:0 0 0 3px rgba(56,189,248,.22)}", ".iss2-launcher-actions{display:flex;gap:10px;justify-content:flex-end;margin-top:18px}", ".iss2-launcher-button{height:42px;border:0;border-radius:9px;padding:0 16px;font-size:15px;font-weight:650}", ".iss2-launcher-button.primary{background:#38bdf8;color:#07111f}", ".iss2-launcher-button.secondary{background:#1e293b;color:#e2e8f0}", ".iss2-launcher-error{display:none;color:#fecaca;font-size:13px;margin-top:10px}", ".iss2-launcher-handoff .global-status-modal .parameters-required{visibility:hidden}" ].join("\n"); document.head.appendChild(style); } function removeModal(modal) { if (modal && modal.parentNode) { modal.parentNode.removeChild(modal); } } function showPasswordModal(href, clientId) { ensureStyles(); var modal = document.createElement("div"); var card = document.createElement("form"); var title = document.createElement("h1"); var copy = document.createElement("p"); var label = document.createElement("label"); var input = document.createElement("input"); var error = document.createElement("div"); var actions = document.createElement("div"); var cancel = document.createElement("button"); var submit = document.createElement("button"); modal.className = "iss2-launcher-overlay"; card.className = "iss2-launcher-card"; title.className = "iss2-launcher-title"; copy.className = "iss2-launcher-copy"; label.className = "iss2-launcher-label"; input.className = "iss2-launcher-input"; error.className = "iss2-launcher-error"; actions.className = "iss2-launcher-actions"; cancel.className = "iss2-launcher-button secondary"; submit.className = "iss2-launcher-button primary"; title.textContent = "Mac Mini Desktop"; copy.textContent = "Enter the desktop VNC password before opening the desktop."; label.textContent = "Desktop VNC password"; error.textContent = "Enter the desktop VNC password to continue."; cancel.textContent = "Cancel"; submit.textContent = "Continue"; input.type = "password"; input.autocomplete = "current-password"; input.autocapitalize = "none"; input.autocorrect = "off"; input.spellcheck = false; cancel.type = "button"; submit.type = "submit"; label.appendChild(input); actions.appendChild(cancel); actions.appendChild(submit); card.appendChild(title); card.appendChild(copy); card.appendChild(label); card.appendChild(error); card.appendChild(actions); modal.appendChild(card); document.body.appendChild(modal); card.addEventListener("submit", function (event) { var password = input.value; event.preventDefault(); if (!password) { error.style.display = "block"; input.focus(); return; } if (!storePassword(password, clientId)) { error.textContent = "This browser blocked session storage. Try a normal tab."; error.style.display = "block"; input.focus(); return; } removeModal(modal); window.location.href = href; }); cancel.addEventListener("click", function () { removeModal(modal); }); modal.addEventListener("click", function (event) { if (event.target === modal) { removeModal(modal); } }); window.setTimeout(function () { input.focus(); }, 0); } function shouldIntercept(anchor) { var name; var label; if (!anchor || !/#\/client\//.test(anchor.href || "")) { return false; } name = anchor.querySelector && anchor.querySelector(".name"); label = normalizeText(name ? name.textContent : anchor.textContent); return !!TARGET_NAMES[label]; } function interceptDesktopTileClicks() { document.addEventListener("click", function (event) { var anchor = event.target && event.target.closest && event.target.closest("a"); var clientId; if (!shouldIntercept(anchor)) { return; } clientId = extractClientId(anchor.href); event.preventDefault(); event.stopPropagation(); event.stopImmediatePropagation(); showPasswordModal(anchor.href, clientId); }, true); } function installAngularPasswordHandoff() { if (!window.angular) { return; } window.angular.module("client").config(["$provide", function ($provide) { $provide.decorator("ManagedClient", ["$delegate", "$rootScope", function ($delegate, $rootScope) { var originalGetInstance = $delegate.getInstance; $delegate.getInstance = function (id) { var managedClient = originalGetInstance.apply(this, arguments); var originalRequired = managedClient.client.onrequired; managedClient.client.onrequired = function (parameters) { var stored = getStoredPassword(); var values = {}; var hasPassword = false; parameters.forEach(function (name) { if (name === "password") { hasPassword = true; } }); if (!stored || !hasPassword || stored.clientId !== managedClient.id) { return originalRequired.apply(this, arguments); } document.body.classList.add("iss2-launcher-handoff"); parameters.forEach(function (name) { if (name === "password") { values[name] = stored.password; } else { values[name] = ""; } }); function sendValues() { managedClient.requiredParameters = values; $delegate.sendArguments(managedClient, values); managedClient.requiredParameters = null; clearStoredPassword(); window.setTimeout(function () { document.body.classList.remove("iss2-launcher-handoff"); }, 250); } if ($rootScope.$$phase) { sendValues(); } else { $rootScope.$apply(sendValues); } }; return managedClient; }; return $delegate; }]); }]); } clampMobileDevicePixelRatio(); if (LAUNCHER_ENABLED) { interceptDesktopTileClicks(); installAngularPasswordHandoff(); } }());