|
1 | 1 | <!doctype html> |
2 | | -<html lang="en"> |
| 2 | +<html lang="en" data-startup="loading"> |
3 | 3 | <head> |
4 | 4 | <meta charset="UTF-8" /> |
5 | 5 | <meta |
|
8 | 8 | /> |
9 | 9 | <meta name="viewport" content="width=device-width, initial-scale=1.0" /> |
10 | 10 | <title>Deep Code</title> |
11 | | - <link rel="stylesheet" href="{{cssUri}}" /> |
| 11 | + <style> |
| 12 | + html[data-startup] body { |
| 13 | + margin: 0; |
| 14 | + overflow: hidden; |
| 15 | + background: #fff; |
| 16 | + } |
| 17 | + html[data-startup] body > :not(#startupScreen) { |
| 18 | + opacity: 0 !important; |
| 19 | + pointer-events: none !important; |
| 20 | + } |
| 21 | + #startupScreen { |
| 22 | + position: fixed; |
| 23 | + inset: 0; |
| 24 | + z-index: 2147483647; |
| 25 | + display: grid; |
| 26 | + place-items: center; |
| 27 | + background: #fff; |
| 28 | + color: #555; |
| 29 | + font: 13px/1.5 system-ui, sans-serif; |
| 30 | + text-align: center; |
| 31 | + } |
| 32 | + .startup-spinner { |
| 33 | + box-sizing: border-box; |
| 34 | + width: 24px; |
| 35 | + height: 24px; |
| 36 | + border: 2px solid #e5e5e5; |
| 37 | + border-top-color: #666; |
| 38 | + border-radius: 50%; |
| 39 | + animation: startup-spin 0.8s linear infinite; |
| 40 | + } |
| 41 | + .startup-error { display: none; padding: 20px; } |
| 42 | + .startup-error button { |
| 43 | + padding: 5px 14px; |
| 44 | + border: 1px solid #ccc; |
| 45 | + border-radius: 4px; |
| 46 | + background: #fff; |
| 47 | + color: #333; |
| 48 | + font: inherit; |
| 49 | + cursor: pointer; |
| 50 | + } |
| 51 | + html[data-startup="error"] .startup-spinner { display: none; } |
| 52 | + html[data-startup="error"] .startup-error { display: block; } |
| 53 | + @keyframes startup-spin { to { transform: rotate(360deg); } } |
| 54 | + @media (prefers-reduced-motion: reduce) { |
| 55 | + .startup-spinner { animation: none; } |
| 56 | + } |
| 57 | + </style> |
| 58 | + <script nonce="{{nonce}}"> |
| 59 | + (() => { |
| 60 | + let stylesReady = false; |
| 61 | + let sessionReady = false; |
| 62 | + let finished = false; |
| 63 | + let failed = false; |
| 64 | + let resolveStyles; |
| 65 | + const stylesLoaded = new Promise((resolve) => { resolveStyles = resolve; }); |
| 66 | + const timeout = setTimeout(fail, 15000); |
| 67 | + |
| 68 | + function cleanup() { |
| 69 | + clearTimeout(timeout); |
| 70 | + document.removeEventListener("load", onLoad, true); |
| 71 | + window.removeEventListener("error", onError, true); |
| 72 | + } |
| 73 | + function fail() { |
| 74 | + if (finished || failed) return; |
| 75 | + failed = true; |
| 76 | + cleanup(); |
| 77 | + document.documentElement.dataset.startup = "error"; |
| 78 | + } |
| 79 | + function reveal() { |
| 80 | + if (!stylesReady || !sessionReady || finished || failed) return; |
| 81 | + clearTimeout(timeout); |
| 82 | + requestAnimationFrame(() => { |
| 83 | + if (finished || failed) return; |
| 84 | + finished = true; |
| 85 | + cleanup(); |
| 86 | + document.documentElement.removeAttribute("data-startup"); |
| 87 | + document.getElementById("startupScreen").remove(); |
| 88 | + const app = document.querySelector(".app"); |
| 89 | + app.removeAttribute("inert"); |
| 90 | + app.removeAttribute("aria-busy"); |
| 91 | + }); |
| 92 | + } |
| 93 | + function onLoad(event) { |
| 94 | + if (event.target?.id !== "appStyles") return; |
| 95 | + event.target.media = "all"; |
| 96 | + stylesReady = true; |
| 97 | + resolveStyles(); |
| 98 | + reveal(); |
| 99 | + } |
| 100 | + function onError(event) { |
| 101 | + if (event.target === window || event.target?.id === "appStyles" || event.target?.tagName === "SCRIPT") fail(); |
| 102 | + } |
| 103 | + document.addEventListener("load", onLoad, true); |
| 104 | + window.addEventListener("error", onError, true); |
| 105 | + document.addEventListener("click", (event) => { |
| 106 | + if (event.target?.id === "startupRetry") window.location.reload(); |
| 107 | + }); |
| 108 | + window.deepcodeStartup = { |
| 109 | + stylesLoaded, |
| 110 | + ready() { |
| 111 | + sessionReady = true; |
| 112 | + reveal(); |
| 113 | + } |
| 114 | + }; |
| 115 | + })(); |
| 116 | + </script> |
| 117 | + <!-- Keep the startup screen paintable while the app stylesheet loads. --> |
| 118 | + <link id="appStyles" rel="stylesheet" href="{{cssUri}}" media="print" /> |
12 | 119 | </head> |
13 | 120 | <body> |
| 121 | + <div id="startupScreen"> |
| 122 | + <div class="startup-spinner" role="status" aria-label="Loading"></div> |
| 123 | + <div class="startup-error" role="alert"> |
| 124 | + <p>Unable to load Deep Code.</p> |
| 125 | + <button id="startupRetry" type="button">Retry</button> |
| 126 | + </div> |
| 127 | + </div> |
14 | 128 | <dialog id="undoDialog" aria-labelledby="undoTitle"> |
15 | 129 | <div class="undo-heading"><strong id="undoTitle">Undo</strong><button id="undoBack" type="button" hidden>Back</button><button id="undoClose" type="button">Close</button></div> |
16 | 130 | <div id="undoBody"></div> |
17 | 131 | </dialog> |
18 | | - <div class="app"> |
| 132 | + <div class="app" inert aria-busy="true"> |
19 | 133 | <div class="header-container"> |
20 | 134 | <div class="header-left"> |
21 | 135 | <div class="session-selector" id="sessionSelector"> |
|
3067 | 3181 | updateSkillsButtonTooltip(); |
3068 | 3182 | refreshSlashMenu(); |
3069 | 3183 | } |
| 3184 | + if (message.type === "initializeEmpty" || message.type === "loadSession") { |
| 3185 | + window.deepcodeStartup.ready(); |
| 3186 | + } |
3070 | 3187 | }); |
3071 | 3188 |
|
3072 | 3189 | // 监听窗口大小变化,重新计算连接线 |
|
3078 | 3195 | }, 100); |
3079 | 3196 | }); |
3080 | 3197 |
|
3081 | | - // webview 准备就绪,请求初始数据 |
3082 | | - vscode.postMessage({ type: "ready", ...(Object.hasOwn(savedState, "sessionId") ? { sessionId: savedState.sessionId } : {}) }); |
3083 | | - |
3084 | | - // 请求可用技能列表 |
3085 | | - vscode.postMessage({ type: "requestSkills" }); |
| 3198 | + window.deepcodeStartup.stylesLoaded.then(() => { |
| 3199 | + // Wait for styles before rendering the initial session and measuring its layout. |
| 3200 | + vscode.postMessage({ type: "ready", ...(Object.hasOwn(savedState, "sessionId") ? { sessionId: savedState.sessionId } : {}) }); |
| 3201 | + vscode.postMessage({ type: "requestSkills" }); |
| 3202 | + }); |
3086 | 3203 | </script> |
3087 | 3204 | </body> |
3088 | 3205 | </html> |
0 commit comments