| 1 | /* Generated by tools/gen_ui.py from src/ui.html. Do not edit by hand. */ |
| 2 | #ifndef SX_CPLOGIN_UI_HTML_H |
| 3 | #define SX_CPLOGIN_UI_HTML_H |
| 4 | |
| 5 | static const char *UI_HTML = |
| 6 | "<!DOCTYPE html>\n" |
| 7 | "<html lang=\"en\"><head><meta charset=\"utf-8\">\n" |
| 8 | "<meta name=\"viewport\" content=\"width=device-width,initial-scale=1\">\n" |
| 9 | "<title>copilot</title>\n" |
| 10 | "\001\n" |
| 11 | "<style>\n" |
| 12 | "*{box-sizing:border-box}\n" |
| 13 | "html,body{margin:0;min-height:100%}\n" |
| 14 | "body{background:var(--bg);color:var(--text);font-family:var(--font);font-size:14px;\n" |
| 15 | " line-height:1.5;-webkit-font-smoothing:antialiased}\n" |
| 16 | "#app{max-width:840px;margin:0 auto;padding:16px 16px 40px}\n" |
| 17 | ".hd{display:flex;align-items:center;gap:10px;flex-wrap:wrap;margin-bottom:14px}\n" |
| 18 | ".hd .grow{flex:1 1 auto;min-width:0}\n" |
| 19 | ".hd h1{margin:0;font-size:18px;font-weight:650;letter-spacing:-.01em}\n" |
| 20 | ".hd .sub{font-size:11.5px;color:var(--text-2);margin-top:2px;white-space:nowrap;\n" |
| 21 | " overflow:hidden;text-overflow:ellipsis}\n" |
| 22 | ".pill{display:inline-flex;align-items:center;gap:6px;font-size:11.5px;font-weight:650;\n" |
| 23 | " padding:4px 10px;border-radius:999px;background:var(--surface-2);color:var(--text-2);\n" |
| 24 | " border:1px solid var(--line);white-space:nowrap}\n" |
| 25 | ".pill .dot{width:7px;height:7px;border-radius:50%;background:var(--gray);flex:0 0 auto}\n" |
| 26 | ".pill.ok{color:var(--green);border-color:rgba(48,209,88,.35)}\n" |
| 27 | ".pill.ok .dot{background:var(--green);box-shadow:0 0 0 3px rgba(48,209,88,.15)}\n" |
| 28 | ".pill.warn{color:var(--orange);border-color:rgba(255,159,10,.35)}\n" |
| 29 | ".pill.warn .dot{background:var(--orange)}\n" |
| 30 | ".pill.off .dot{background:var(--gray)}\n" |
| 31 | ".badge{display:inline-flex;align-items:center;gap:6px;font-size:12px;font-weight:600;\n" |
| 32 | " padding:4px 10px;border-radius:999px;background:var(--surface-2);color:var(--text);\n" |
| 33 | " border:1px solid var(--line);font-family:var(--mono);max-width:100%;overflow:hidden;\n" |
| 34 | " text-overflow:ellipsis;white-space:nowrap}\n" |
| 35 | ".card{background:var(--bg-card);border:1px solid var(--line);border-radius:14px;\n" |
| 36 | " padding:16px;margin-bottom:12px}\n" |
| 37 | ".card h2{margin:0 0 4px;font-size:13px;font-weight:700;letter-spacing:.08em;\n" |
| 38 | " text-transform:uppercase;color:var(--text-2)}\n" |
| 39 | ".card .lead{margin:0 0 12px;font-size:12.5px;color:var(--text-2)}\n" |
| 40 | ".row{display:flex;align-items:center;gap:8px;flex-wrap:wrap}\n" |
| 41 | ".btn{background:var(--blue);color:#fff;border:0;border-radius:980px;padding:7px 16px;\n" |
| 42 | " font-weight:600;font-size:13px;cursor:pointer;font-family:inherit;\n" |
| 43 | " transition:transform .12s var(--ease),opacity .12s}\n" |
| 44 | ".btn:active{transform:scale(.98)}\n" |
| 45 | ".btn:disabled{opacity:.5;cursor:default}\n" |
| 46 | ".btn.ghost{background:var(--surface-2);color:var(--text);border:1px solid var(--line)}\n" |
| 47 | ".btn.ghost:hover{background:var(--surface-hover);border-color:var(--line-2)}\n" |
| 48 | ".btn.danger{background:transparent;color:var(--red);border:1px solid rgba(255,69,58,.35)}\n" |
| 49 | "a.btn{display:inline-flex;align-items:center;gap:6px;text-decoration:none}\n" |
| 50 | ".kv{display:grid;grid-template-columns:132px minmax(0,1fr);gap:6px 12px;font-size:13px}\n" |
| 51 | ".kv .k{color:var(--text-2);font-size:12px}\n" |
| 52 | ".kv .v{font-family:var(--mono);font-size:12px;word-break:break-all}\n" |
| 53 | ".kv .v.plain{font-family:var(--font);font-size:13px}\n" |
| 54 | ".step{display:none}\n" |
| 55 | ".step.on{display:block}\n" |
| 56 | ".hint{margin:10px 0 0;font-size:12px;color:var(--text-2)}\n" |
| 57 | ".note{font-size:12.5px;margin-top:10px;display:none}\n" |
| 58 | ".note.show{display:block}\n" |
| 59 | ".note.err{color:var(--red)}\n" |
| 60 | ".note.ok{color:var(--green)}\n" |
| 61 | ".usercode{font-family:var(--mono);font-size:34px;font-weight:700;letter-spacing:.16em;\n" |
| 62 | " color:var(--text);background:var(--code-bg);border:1px solid var(--line-2);\n" |
| 63 | " border-radius:12px;padding:16px 10px;margin-top:12px;text-align:center;\n" |
| 64 | " word-break:break-all;user-select:all}\n" |
| 65 | ".count{font-size:34px;font-weight:700;letter-spacing:-.02em;line-height:1.1}\n" |
| 66 | ".count small{font-size:13px;font-weight:600;color:var(--text-2);letter-spacing:0}\n" |
| 67 | ".wait{display:flex;align-items:center;gap:9px;margin-top:12px;font-size:12.5px;\n" |
| 68 | " color:var(--text-2)}\n" |
| 69 | ".wait .spin{display:inline-block;width:13px;height:13px;border-radius:50%;\n" |
| 70 | " border:2px solid var(--line-2);border-top-color:var(--blue);animation:sp .8s linear infinite}\n" |
| 71 | "@keyframes sp{to{transform:rotate(360deg)}}\n" |
| 72 | ".spin2{width:12px;height:12px;border-radius:50%;border:2px solid rgba(255,255,255,.35);\n" |
| 73 | " border-top-color:#fff;display:none;animation:sp .7s linear infinite}\n" |
| 74 | ".btn.loading .spin2{display:inline-block}\n" |
| 75 | ".acct{display:flex;align-items:center;gap:10px;padding:9px 0;border-top:1px solid var(--line);\n" |
| 76 | " font-size:13px}\n" |
| 77 | ".acct:first-child{border-top:0}\n" |
| 78 | ".acct .nm{font-family:var(--mono);font-size:12.5px;flex:1 1 auto;min-width:0;\n" |
| 79 | " overflow:hidden;text-overflow:ellipsis;white-space:nowrap}\n" |
| 80 | ".acct .tag{font-size:11px;font-weight:650;padding:3px 9px;border-radius:999px;\n" |
| 81 | " background:var(--surface-2);color:var(--text-2);white-space:nowrap}\n" |
| 82 | ".acct .tag.ok{color:var(--green)}\n" |
| 83 | ".acct .tag.warn{color:var(--orange)}\n" |
| 84 | ".empty{font-size:12.5px;color:var(--text-2)}\n" |
| 85 | ".toast{position:fixed;left:50%;bottom:24px;transform:translate(-50%,12px);opacity:0;\n" |
| 86 | " pointer-events:none;background:var(--modal-bg);border:1px solid var(--line-2);\n" |
| 87 | " color:var(--text);border-radius:999px;padding:8px 16px;font-size:12.5px;\n" |
| 88 | " box-shadow:var(--shadow-lg);transition:opacity .18s var(--ease),transform .18s var(--ease);\n" |
| 89 | " z-index:9;max-width:calc(100vw - 32px)}\n" |
| 90 | ".toast.show{opacity:1;transform:translate(-50%,0)}\n" |
| 91 | "#themeToggle{background:var(--surface-2);border:1px solid var(--line);color:var(--text);\n" |
| 92 | " border-radius:980px;padding:5px 12px;font-size:12px;font-weight:600;cursor:pointer;\n" |
| 93 | " font-family:inherit}\n" |
| 94 | "@media (max-width:520px){\n" |
| 95 | " #app{padding:12px 12px 32px}\n" |
| 96 | " .kv{grid-template-columns:1fr;gap:2px 0}\n" |
| 97 | " .kv .k{margin-top:8px}\n" |
| 98 | " .card{padding:13px;border-radius:12px}\n" |
| 99 | " .count{font-size:28px}\n" |
| 100 | " .usercode{font-size:27px;letter-spacing:.1em;padding:14px 6px}\n" |
| 101 | "}\n" |
| 102 | "</style>\n" |
| 103 | "</head>\n" |
| 104 | "<body>\n" |
| 105 | "<div id=\"app\">\n" |
| 106 | " <div class=\"hd\">\n" |
| 107 | " <div class=\"grow\">\n" |
| 108 | " <h1>GitHub Copilot</h1>\n" |
| 109 | " <div class=\"sub\" id=\"sub\">Device code login on this node</div>\n" |
| 110 | " </div>\n" |
| 111 | " <span class=\"badge\" id=\"userBadge\" style=\"display:none\"></span>\n" |
| 112 | " <span class=\"pill off\" id=\"pill\"><span class=\"dot\"></span><span id=\"pillText\">Checking</span></span>\n" |
| 113 | " <button id=\"themeToggle\" class=\"embed-hide\" type=\"button\">Theme</button>\n" |
| 114 | " </div>\n" |
| 115 | "\n" |
| 116 | " <div class=\"card\">\n" |
| 117 | " <h2>Session</h2>\n" |
| 118 | " <p class=\"lead\" id=\"sessionLead\">Reading the local Copilot credentials.</p>\n" |
| 119 | " <div class=\"kv\" id=\"session\"></div>\n" |
| 120 | " <div class=\"row\" style=\"margin-top:14px\">\n" |
| 121 | " <button class=\"btn ghost\" id=\"btnRefresh\" type=\"button\"><span class=\"spin2\"></span>Refresh Token Now</button>\n" |
| 122 | " <button class=\"btn ghost\" id=\"btnReload\" type=\"button\">Reload</button>\n" |
| 123 | " </div>\n" |
| 124 | " <div class=\"note\" id=\"refreshNote\"></div>\n" |
| 125 | " </div>\n" |
| 126 | "\n" |
| 127 | " <div class=\"card\">\n" |
| 128 | " <h2>Device login</h2>\n" |
| 129 | " <p class=\"lead\">Sign in with GitHub. The login CLI opens the device flow and writes the\n" |
| 130 | " credential file on this node; no token ever passes through this page.</p>\n" |
| 131 | "\n" |
| 132 | " <div class=\"step on\" id=\"step1\">\n" |
| 133 | " <div class=\"row\">\n" |
| 134 | " <button class=\"btn\" id=\"btnStart\" type=\"button\">Start GitHub Copilot Login</button>\n" |
| 135 | " <button class=\"btn ghost\" id=\"btnRelogin\" type=\"button\">Re-login (replace)</button>\n" |
| 136 | " </div>\n" |
| 137 | " <p class=\"hint\">This asks GitHub for a one-time code. Nothing is stored until you approve\n" |
| 138 | " it in the browser.</p>\n" |
| 139 | " <div class=\"note\" id=\"startNote\"></div>\n" |
| 140 | " </div>\n" |
| 141 | "\n" |
| 142 | " <div class=\"step\" id=\"step2\">\n" |
| 143 | " <p class=\"hint\" style=\"margin-top:0\">Enter this code at\n" |
| 144 | " <span style=\"font-family:var(--mono)\">github.com/login/device</span>:</p>\n" |
| 145 | " <div class=\"usercode\" id=\"userCode\">----</div>\n" |
| 146 | " <div class=\"row\" style=\"margin-top:12px\">\n" |
| 147 | " <button class=\"btn\" id=\"btnCopyOpen\" type=\"button\">Copy Code & Open GitHub</button>\n" |
| 148 | " <a class=\"btn ghost\" id=\"linkOpen\" href=\"https://github.com/login/device\"\n" |
| 149 | " target=\"_blank\" rel=\"noopener noreferrer\">Open GitHub</a>\n" |
| 150 | " <button class=\"btn danger\" id=\"btnCancel\" type=\"button\">Cancel</button>\n" |
| 151 | " </div>\n" |
| 152 | " <div class=\"wait\" id=\"waitBox\"><span class=\"spin\"></span>\n" |
| 153 | " <span id=\"waitText\">Waiting for GitHub confirmation...</span></div>\n" |
| 154 | " <div class=\"note\" id=\"loginNote\"></div>\n" |
| 155 | " </div>\n" |
| 156 | " </div>\n" |
| 157 | "\n" |
| 158 | " <div class=\"card\">\n" |
| 159 | " <h2>Named accounts</h2>\n" |
| 160 | " <p class=\"lead\">Every account file in the local accounts directory.</p>\n" |
| 161 | " <div id=\"accounts\"><div class=\"empty\">No named accounts.</div></div>\n" |
| 162 | " </div>\n" |
| 163 | "</div>\n" |
| 164 | "\n" |
| 165 | "<div class=\"toast\" id=\"toast\"></div>\n" |
| 166 | "\n" |
| 167 | "<script>\n" |
| 168 | "var q=new URLSearchParams(location.search);\n" |
| 169 | "var node=q.get('node')||'';\n" |
| 170 | "var sid=q.get('id')||'';\n" |
| 171 | "var pwd=q.get('pwd')||(node&&localStorage.getItem('bot_pwd_'+node))||\n" |
| 172 | " localStorage.getItem('bot_active_pwd')||'';\n" |
| 173 | "\n" |
| 174 | "/* Two call routes. Getting this wrong is the most common plugin bug:\n" |
| 175 | " * page served through the hub (bot.scorpiox.net/plugins?plugin=...&node=..)\n" |
| 176 | " * -> call the hub proxy back: /plugins?plugin=plugin_copilot_login&action=..\n" |
| 177 | " * opened directly on the node\n" |
| 178 | " * -> the plugin itself is the route: /plugin_copilot_login?action=..\n" |
| 179 | " * Calling /plugins?plugin= on the node returns the discovery list, not us. */\n" |
| 180 | "var HUB=q.get('plugin')||'';\n" |
| 181 | "function url(action,extra){\n" |
| 182 | " return (HUB?'/plugins?plugin='+encodeURIComponent(HUB):'/plugin_copilot_login')+\n" |
| 183 | " '?action='+encodeURIComponent(action)+\n" |
| 184 | " (extra?('&'+extra):'')+\n" |
| 185 | " (node?'&node='+encodeURIComponent(node):'')+\n" |
| 186 | " (sid?'&id='+encodeURIComponent(sid):'')+\n" |
| 187 | " (pwd?'&pwd='+encodeURIComponent(pwd):'');\n" |
| 188 | "}\n" |
| 189 | "function hdr(){\n" |
| 190 | " var h={};\n" |
| 191 | " if(pwd)h['X-Bot-Password']=pwd;\n" |
| 192 | " return h;\n" |
| 193 | "}\n" |
| 194 | "function api(action,extra){\n" |
| 195 | " return fetch(url(action,extra),{headers:hdr()}).then(function(r){\n" |
| 196 | " return r.json().catch(function(){return {ok:false,error:'bad response'};});\n" |
| 197 | " });\n" |
| 198 | "}\n" |
| 199 | "\n" |
| 200 | "var $=function(id){return document.getElementById(id);};\n" |
| 201 | "function toast(msg){\n" |
| 202 | " var t=$('toast');t.textContent=msg;t.classList.add('show');\n" |
| 203 | " clearTimeout(t._t);t._t=setTimeout(function(){t.classList.remove('show');},2200);\n" |
| 204 | "}\n" |
| 205 | "function note(el,msg,kind){\n" |
| 206 | " el.textContent=msg||'';\n" |
| 207 | " el.className='note'+(msg?' show '+(kind||''):'');\n" |
| 208 | "}\n" |
| 209 | "function kv(el,rows){\n" |
| 210 | " el.innerHTML='';\n" |
| 211 | " rows.forEach(function(r){\n" |
| 212 | " var a=document.createElement('div');a.className='k';a.textContent=r[0];\n" |
| 213 | " var b=document.createElement('div');b.className='v'+(r[2]?' plain':'');\n" |
| 214 | " b.textContent=r[1];el.appendChild(a);el.appendChild(b);\n" |
| 215 | " });\n" |
| 216 | "}\n" |
| 217 | "function fmtExpiry(sec){\n" |
| 218 | " if(typeof sec!=='number')return '-';\n" |
| 219 | " if(sec<=0)return 'expired';\n" |
| 220 | " if(sec<90)return sec+'s';\n" |
| 221 | " if(sec<5400)return Math.round(sec/60)+' min';\n" |
| 222 | " if(sec<172800)return Math.round(sec/3600)+' h';\n" |
| 223 | " if(sec<63072000)return Math.round(sec/86400)+' d';\n" |
| 224 | " return Math.round(sec/31536000)+' yr';\n" |
| 225 | "}\n" |
| 226 | "function setPill(st){\n" |
| 227 | " var p=$('pill'),t=$('pillText');\n" |
| 228 | " if(st.logged_in&&st.expired){p.className='pill warn';t.textContent='Expired';}\n" |
| 229 | " else if(st.logged_in){p.className='pill ok';t.textContent='Connected';}\n" |
| 230 | " else if(st.pending){p.className='pill warn';t.textContent='Signing in';}\n" |
| 231 | " else {p.className='pill off';t.textContent='Not Connected';}\n" |
| 232 | "}\n" |
| 233 | "function render(st){\n" |
| 234 | " setPill(st);\n" |
| 235 | " var badge=$('userBadge');\n" |
| 236 | " if(st.logged_in&&st.user){badge.style.display='';badge.textContent='@'+st.user;}\n" |
| 237 | " else badge.style.display='none';\n" |
| 238 | " $('sub').textContent=st.account&&st.account!=='default'\n" |
| 239 | " ? 'Device code login - '+st.account : 'Device code login on this node';\n" |
| 240 | "\n" |
| 241 | " if(st.logged_in){\n" |
| 242 | " $('sessionLead').textContent=st.expired\n" |
| 243 | " ? 'A Copilot session is stored but its derived token has expired. Use Refresh Token Now.'\n" |
| 244 | " : 'This node holds a GitHub Copilot session.';\n" |
| 245 | " }else{\n" |
| 246 | " $('sessionLead').textContent='No Copilot session on this node yet. Start a login below.';\n" |
| 247 | " }\n" |
| 248 | "\n" |
| 249 | " kv($('session'),[\n" |
| 250 | " ['Account', st.account||'-', true],\n" |
| 251 | " ['GitHub user', st.user||'-', true],\n" |
| 252 | " ['Logged in', st.logged_in?'yes':'no', true],\n" |
| 253 | " ['Derived token', st.logged_in?(st.expired?'expired':'valid'):'-', true],\n" |
| 254 | " ['Token expires', st.logged_in&&st.cache_present?fmtExpiry(st.expires_in_sec):'-', true],\n" |
| 255 | " ['Login pending', st.pending?'yes':'no', true],\n" |
| 256 | " ['Login CLI', st.cli_present?'found':'not found', true],\n" |
| 257 | " ['Scope', st.scope||'-', true],\n" |
| 258 | " ['Profile model', st.profile_exists?(st.profile||'-'):'not created', true],\n" |
| 259 | " ['Credentials', st.credentials_path||'-']\n" |
| 260 | " ]);\n" |
| 261 | "\n" |
| 262 | " var box=$('accounts');\n" |
| 263 | " box.innerHTML='';\n" |
| 264 | " var list=st.accounts||[];\n" |
| 265 | " if(!list.length){\n" |
| 266 | " var e=document.createElement('div');e.className='empty';\n" |
| 267 | " e.textContent='No named accounts.';box.appendChild(e);\n" |
| 268 | " }else{\n" |
| 269 | " list.forEach(function(a){\n" |
| 270 | " var row=document.createElement('div');row.className='acct';\n" |
| 271 | " var nm=document.createElement('div');nm.className='nm';nm.textContent=a.name;\n" |
| 272 | " var tg=document.createElement('div');\n" |
| 273 | " tg.className='tag '+(a.logged_in?(a.expired?'warn':'ok'):'');\n" |
| 274 | " tg.textContent=a.logged_in?(a.expired?'expired':'valid'):'no token';\n" |
| 275 | " row.appendChild(nm);row.appendChild(tg);box.appendChild(row);\n" |
| 276 | " });\n" |
| 277 | " }\n" |
| 278 | "\n" |
| 279 | " if(st.pending){showStep2();}\n" |
| 280 | "}\n" |
| 281 | "function load(){\n" |
| 282 | " return api('status').then(function(d){\n" |
| 283 | " if(d&&d.ok)render(d);\n" |
| 284 | " else toast((d&&d.error)||'status failed');\n" |
| 285 | " }).catch(function(e){toast('Status failed: '+e.message);});\n" |
| 286 | "}\n" |
| 287 | "\n" |
| 288 | "/* ---- device flow ---- */\n" |
| 289 | "var userCode='',VerifyUrl='https://github.com/login/device';\n" |
| 290 | "var pollTimer=null,pollInterval=5,pollStop=0;\n" |
| 291 | "\n" |
| 292 | "function showStep2(){\n" |
| 293 | " $('step1').classList.remove('on');\n" |
| 294 | " $('step2').classList.add('on');\n" |
| 295 | "}\n" |
| 296 | "function hideStep2(){\n" |
| 297 | " $('step1').classList.add('on');\n" |
| 298 | " $('step2').classList.remove('on');\n" |
| 299 | "}\n" |
| 300 | "function stopPolling(){\n" |
| 301 | " if(pollTimer){clearTimeout(pollTimer);pollTimer=null;}\n" |
| 302 | "}\n" |
| 303 | "function startPolling(){\n" |
| 304 | " stopPolling();\n" |
| 305 | " $('waitBox').style.display='';\n" |
| 306 | " $('waitText').textContent='Waiting for GitHub confirmation...';\n" |
| 307 | " var delay=Math.max(3,pollInterval||5)*1000;\n" |
| 308 | " pollTimer=setTimeout(function(){\n" |
| 309 | " api('poll').then(function(d){\n" |
| 310 | " if(d&&d.ok&&d.state==='done'){\n" |
| 311 | " stopPolling();\n" |
| 312 | " $('waitText').textContent='Authorized.';\n" |
| 313 | " note($('loginNote'),'Signed in'+(d.user?(' as @'+d.user):'')+'.','ok');\n" |
| 314 | " hideStep2();\n" |
| 315 | " render(d);\n" |
| 316 | " toast('GitHub Copilot connected');\n" |
| 317 | " return;\n" |
| 318 | " }\n" |
| 319 | " if(!d||!d.ok){\n" |
| 320 | " stopPolling();\n" |
| 321 | " $('waitBox').style.display='none';\n" |
| 322 | " var m=(d&&(d.detail||d.error))||'poll failed';\n" |
| 323 | " note($('loginNote'),m,'err');\n" |
| 324 | " return;\n" |
| 325 | " }\n" |
| 326 | " if(d.interval)pollInterval=d.interval;\n" |
| 327 | " pollTimer=setTimeout(function(){startPolling();},Math.max(3,pollInterval)*1000);\n" |
| 328 | " }).catch(function(e){\n" |
| 329 | " note($('loginNote'),'Poll failed: '+e.message,'err');\n" |
| 330 | " pollTimer=setTimeout(function(){startPolling();},Math.max(5,pollInterval)*1000);\n" |
| 331 | " });\n" |
| 332 | " },delay);\n" |
| 333 | "}\n" |
| 334 | "\n" |
| 335 | "function startLogin(force){\n" |
| 336 | " var b=force?$('btnRelogin'):$('btnStart');\n" |
| 337 | " b.disabled=true;b.classList.add('loading');\n" |
| 338 | " note($('startNote'),'Asking GitHub for a device code...');\n" |
| 339 | " api('start',force?'force=1':'').then(function(d){\n" |
| 340 | " b.disabled=false;b.classList.remove('loading');\n" |
| 341 | " note($('startNote'),'');\n" |
| 342 | " if(!d||!d.ok){\n" |
| 343 | " note($('startNote'),(d&&(d.detail||d.error))||'start failed','err');\n" |
| 344 | " return;\n" |
| 345 | " }\n" |
| 346 | " userCode=d.user_code||'';\n" |
| 347 | " VerifyUrl=d.verify_url||'https://github.com/login/device';\n" |
| 348 | " $('userCode').textContent=userCode||'----';\n" |
| 349 | " $('linkOpen').setAttribute('href',VerifyUrl);\n" |
| 350 | " pollInterval=d.interval||5;\n" |
| 351 | " showStep2();\n" |
| 352 | " note($('loginNote'),'');\n" |
| 353 | " startPolling();\n" |
| 354 | " }).catch(function(e){\n" |
| 355 | " b.disabled=false;b.classList.remove('loading');\n" |
| 356 | " note($('startNote'),'Start failed: '+e.message,'err');\n" |
| 357 | " });\n" |
| 358 | "}\n" |
| 359 | "\n" |
| 360 | "function copyOpen(){\n" |
| 361 | " var go=function(){window.open(VerifyUrl,'_blank','noopener');};\n" |
| 362 | " if(navigator.clipboard&&navigator.clipboard.writeText){\n" |
| 363 | " navigator.clipboard.writeText(userCode).then(function(){\n" |
| 364 | " toast('Code copied: '+userCode);go();\n" |
| 365 | " }).catch(function(){toast('Copy failed - select the code manually');go();});\n" |
| 366 | " }else{\n" |
| 367 | " try{\n" |
| 368 | " var r=document.createRange();r.selectNodeContents($('userCode'));\n" |
| 369 | " var s=window.getSelection();s.removeAllRanges();s.addRange(r);\n" |
| 370 | " document.execCommand('copy');\n" |
| 371 | " toast('Code copied: '+userCode);\n" |
| 372 | " }catch(e){toast('Copy not available - select the code manually');}\n" |
| 373 | " go();\n" |
| 374 | " }\n" |
| 375 | "}\n" |
| 376 | "\n" |
| 377 | "function cancelLogin(){\n" |
| 378 | " stopPolling();\n" |
| 379 | " api('cancel').then(function(){\n" |
| 380 | " hideStep2();\n" |
| 381 | " $('waitBox').style.display='';\n" |
| 382 | " note($('loginNote'),'');\n" |
| 383 | " toast('Pending login cancelled');\n" |
| 384 | " load();\n" |
| 385 | " }).catch(function(e){toast('Cancel failed: '+e.message);});\n" |
| 386 | "}\n" |
| 387 | "\n" |
| 388 | "function refreshToken(){\n" |
| 389 | " var b=$('btnRefresh');\n" |
| 390 | " b.disabled=true;b.classList.add('loading');\n" |
| 391 | " note($('refreshNote'),'Asking Copilot for a new derived token...');\n" |
| 392 | " api('refresh').then(function(d){\n" |
| 393 | " b.disabled=false;b.classList.remove('loading');\n" |
| 394 | " if(!d||!d.ok){\n" |
| 395 | " note($('refreshNote'),(d&&(d.detail||d.error))||'refresh failed','err');\n" |
| 396 | " return;\n" |
| 397 | " }\n" |
| 398 | " note($('refreshNote'),'Token refreshed. Expires in '+fmtExpiry(d.expires_in_sec)+'.','ok');\n" |
| 399 | " render(d);\n" |
| 400 | " }).catch(function(e){\n" |
| 401 | " b.disabled=false;b.classList.remove('loading');\n" |
| 402 | " note($('refreshNote'),'Refresh failed: '+e.message,'err');\n" |
| 403 | " });\n" |
| 404 | "}\n" |
| 405 | "\n" |
| 406 | "$('btnStart').onclick=function(){startLogin(false);};\n" |
| 407 | "$('btnRelogin').onclick=function(){startLogin(true);};\n" |
| 408 | "$('btnCopyOpen').onclick=copyOpen;\n" |
| 409 | "$('btnCancel').onclick=cancelLogin;\n" |
| 410 | "$('btnRefresh').onclick=refreshToken;\n" |
| 411 | "$('btnReload').onclick=load;\n" |
| 412 | "load();\n" |
| 413 | "</script>\n" |
| 414 | "\002</body></html>\n" |
| 415 | ; |
| 416 | |
| 417 | #endif /* SX_CPLOGIN_UI_HTML_H */ |