|
| 1 | +import { useEffect, useState } from "react"; |
| 2 | +import { createPortal } from "react-dom"; |
| 3 | +import { getBuildInfo } from "@/utils/buildInfo"; |
| 4 | +import openExternal from "@/utils/external"; |
| 5 | +import { |
| 6 | + migrateToStelliverse, |
| 7 | + STELLIVERSE_GITLAB_URL, |
| 8 | + STELLIVERSE_RELEASES_URL, |
| 9 | +} from "@/utils/migration"; |
| 10 | + |
| 11 | +// ───────────────────────────────────────────────────────────────────────────── |
| 12 | +// MigrationGate — overlay d'adieu de StarTrad. L'app a été réécrite et rebaptisée |
| 13 | +// « Stelliverse ». Cette build finale verrouille l'app derrière un popup BLOQUANT |
| 14 | +// (non fermable, façon BanGate) avec un bouton qui télécharge + installe la |
| 15 | +// dernière Stelliverse depuis GitLab. |
| 16 | +// |
| 17 | +// Exception Microsoft Store : on ne peut pas pousser d'install externe (règles du |
| 18 | +// Store) → variante sobre, SANS bouton de téléchargement, qui explique et renvoie |
| 19 | +// vers le lien. Elle reste fermable (l'app Store doit rester utilisable). |
| 20 | +// ───────────────────────────────────────────────────────────────────────────── |
| 21 | + |
| 22 | +const FONTS_HREF = |
| 23 | + "https://fonts.googleapis.com/css2?family=Oswald:wght@300;400;500;600;700&family=Rajdhani:wght@400;500;600;700&family=Geist+Mono:wght@400;500&display=swap"; |
| 24 | + |
| 25 | +const CSS = ` |
| 26 | +.mig-gate{position:fixed;inset:0;z-index:2147483647;display:flex;align-items:center;justify-content:center;padding:24px; |
| 27 | + background:rgba(5,8,15,.93);backdrop-filter:blur(4px);font-family:'Rajdhani',sans-serif;color:#eaf2ff;user-select:none} |
| 28 | +.mig-card{position:relative;width:480px;max-width:100%;overflow:hidden;border-radius:18px; |
| 29 | + background:linear-gradient(180deg,rgba(16,23,37,.98),rgba(8,13,22,.98)); |
| 30 | + border:1px solid rgba(132,176,224,.32);box-shadow:0 30px 80px rgba(2,6,14,.7)} |
| 31 | +.mig-card::before{content:"";position:absolute;left:0;right:0;top:0;height:2px;background:linear-gradient(90deg,transparent,#54e6ff,transparent);opacity:.8} |
| 32 | +.mig-inner{padding:30px 30px 26px;text-align:center} |
| 33 | +.mig-eyebrow{font-family:'Geist Mono',monospace;font-size:9px;letter-spacing:.28em;text-transform:uppercase;color:#54e6ff} |
| 34 | +.mig-rename{display:flex;align-items:center;justify-content:center;gap:14px;margin:16px 0 6px;flex-wrap:wrap} |
| 35 | +.mig-old{font-family:'Oswald',sans-serif;font-weight:500;font-size:21px;color:#5d6f88;text-decoration:line-through;text-decoration-color:rgba(255,122,122,.55);text-decoration-thickness:2px} |
| 36 | +.mig-arr{color:#5d6f88;font-size:18px} |
| 37 | +.mig-new{font-family:'Oswald',sans-serif;font-weight:700;font-size:34px;color:#fff;line-height:1} |
| 38 | +.mig-new b{color:#54e6ff} |
| 39 | +.mig-h1{font-family:'Oswald',sans-serif;font-weight:300;font-size:25px;color:#fff;margin-top:14px} |
| 40 | +.mig-h1 b{font-weight:600} |
| 41 | +.mig-body{margin-top:12px;font-size:14.5px;line-height:1.6;color:#9fb2cc} |
| 42 | +.mig-body b{color:#eaf2ff;font-weight:600} |
| 43 | +.mig-body .mig-hl{color:#54e6ff;font-weight:600} |
| 44 | +.mig-assure{margin-top:16px;display:flex;align-items:flex-start;gap:10px;text-align:left; |
| 45 | + background:rgba(84,230,255,.05);border:1px solid rgba(84,230,255,.18);border-radius:12px;padding:12px 14px} |
| 46 | +.mig-assure svg{flex:none;width:18px;height:18px;stroke:#54e6ff;stroke-width:1.8;fill:none;margin-top:1px} |
| 47 | +.mig-assure .mig-t{font-size:13px;line-height:1.5;color:#9fb2cc} |
| 48 | +.mig-assure .mig-t b{color:#fff;font-weight:600} |
| 49 | +.mig-btn{margin-top:22px;width:100%;display:inline-flex;align-items:center;justify-content:center;gap:10px;cursor:pointer; |
| 50 | + font-family:'Oswald',sans-serif;font-weight:600;font-size:16px;letter-spacing:.04em;text-transform:uppercase; |
| 51 | + color:#04121a;background:linear-gradient(180deg,#5ce0ff,#21bdec);border:none;border-radius:12px;padding:15px 20px;transition:.15s} |
| 52 | +.mig-btn:hover{filter:brightness(1.06)} |
| 53 | +.mig-btn:disabled{opacity:.7;cursor:default} |
| 54 | +.mig-btn svg{width:18px;height:18px;stroke:#04121a;stroke-width:2.2;fill:none;stroke-linecap:round;stroke-linejoin:round} |
| 55 | +.mig-foot{margin-top:13px;font-family:'Geist Mono',monospace;font-size:9px;letter-spacing:.07em;color:#5d6f88} |
| 56 | +.mig-brand{margin-top:20px;padding-top:16px;border-top:1px solid rgba(132,176,224,.16);font-family:'Geist Mono',monospace;font-size:8.5px;letter-spacing:.1em;text-transform:uppercase;color:#5d6f88} |
| 57 | +.mig-link{color:#54e6ff;cursor:pointer;text-decoration:underline;text-underline-offset:3px} |
| 58 | +/* variante Store (sobre) */ |
| 59 | +.mig-card.mig-store{width:430px;border-color:rgba(132,176,224,.22)} |
| 60 | +.mig-card.mig-store::before{background:linear-gradient(90deg,transparent,#5d6f88,transparent);opacity:.5} |
| 61 | +.mig-store .mig-new b{color:#9fb2cc} |
| 62 | +.mig-store-close{margin-top:20px;font-family:'Geist Mono',monospace;font-size:10px;letter-spacing:.1em;text-transform:uppercase; |
| 63 | + color:#9fb2cc;cursor:pointer;background:none;border:1px solid rgba(132,176,224,.3);border-radius:9px;padding:9px 18px;transition:.15s} |
| 64 | +.mig-store-close:hover{color:#fff;border-color:#9fb2cc} |
| 65 | +`; |
| 66 | + |
| 67 | +function injectAssets() { |
| 68 | + if (typeof document === "undefined") return; |
| 69 | + if (!document.getElementById("mig-fonts")) { |
| 70 | + const link = document.createElement("link"); |
| 71 | + link.id = "mig-fonts"; |
| 72 | + link.rel = "stylesheet"; |
| 73 | + link.href = FONTS_HREF; |
| 74 | + document.head.appendChild(link); |
| 75 | + } |
| 76 | + if (!document.getElementById("mig-style")) { |
| 77 | + const style = document.createElement("style"); |
| 78 | + style.id = "mig-style"; |
| 79 | + style.textContent = CSS; |
| 80 | + document.head.appendChild(style); |
| 81 | + } |
| 82 | +} |
| 83 | + |
| 84 | +export function MigrationGate() { |
| 85 | + const [isStore, setIsStore] = useState<boolean | null>(null); |
| 86 | + const [storeDismissed, setStoreDismissed] = useState(false); |
| 87 | + const [migrating, setMigrating] = useState(false); |
| 88 | + |
| 89 | + useEffect(() => { |
| 90 | + injectAssets(); |
| 91 | + let cancelled = false; |
| 92 | + getBuildInfo() |
| 93 | + .then((info) => { |
| 94 | + if (!cancelled) setIsStore(info.distribution === "microsoft-store"); |
| 95 | + }) |
| 96 | + .catch(() => { |
| 97 | + if (!cancelled) setIsStore(false); |
| 98 | + }); |
| 99 | + return () => { |
| 100 | + cancelled = true; |
| 101 | + }; |
| 102 | + }, []); |
| 103 | + |
| 104 | + // Tant qu'on ne sait pas (build info en cours), on n'affiche rien. |
| 105 | + if (isStore === null) return null; |
| 106 | + |
| 107 | + const onMigrate = async () => { |
| 108 | + setMigrating(true); |
| 109 | + try { |
| 110 | + await migrateToStelliverse(); |
| 111 | + } finally { |
| 112 | + // si on est toujours là (échec / fallback navigateur), on réactive le bouton |
| 113 | + setMigrating(false); |
| 114 | + } |
| 115 | + }; |
| 116 | + |
| 117 | + // ── Variante Microsoft Store : sobre, sans bouton de téléchargement, fermable ── |
| 118 | + if (isStore) { |
| 119 | + if (storeDismissed) return null; |
| 120 | + return createPortal( |
| 121 | + <div className="mig-gate" onContextMenu={(e) => e.preventDefault()}> |
| 122 | + <div className="mig-card mig-store"> |
| 123 | + <div className="mig-inner"> |
| 124 | + <div className="mig-eyebrow">Changement de nom</div> |
| 125 | + <div className="mig-rename"> |
| 126 | + <span className="mig-old">StarTrad FR</span> |
| 127 | + <span className="mig-arr">→</span> |
| 128 | + <span className="mig-new"> |
| 129 | + Stelli<b>verse</b> |
| 130 | + </span> |
| 131 | + </div> |
| 132 | + <h1 className="mig-h1"> |
| 133 | + StarTrad devient <b>Stelliverse</b> |
| 134 | + </h1> |
| 135 | + <div className="mig-body"> |
| 136 | + L'app a été réécrite et rebaptisée <span className="mig-hl">Stelliverse</span>. |
| 137 | + La version Microsoft Store ne peut pas l'installer à ta place — tu la |
| 138 | + retrouveras en cherchant{" "} |
| 139 | + <b>« Stelliverse »</b> dans le Microsoft Store, ou ici : |
| 140 | + <br /> |
| 141 | + <span |
| 142 | + className="mig-link" |
| 143 | + onClick={() => openExternal(STELLIVERSE_GITLAB_URL)} |
| 144 | + > |
| 145 | + gitlab.com/drrakendu78/Stelliverse |
| 146 | + </span> |
| 147 | + </div> |
| 148 | + <button className="mig-store-close" onClick={() => setStoreDismissed(true)}> |
| 149 | + J'ai compris |
| 150 | + </button> |
| 151 | + <div className="mig-brand">Stelliverse · par Djamel Lazreg</div> |
| 152 | + </div> |
| 153 | + </div> |
| 154 | + </div>, |
| 155 | + document.body |
| 156 | + ); |
| 157 | + } |
| 158 | + |
| 159 | + // ── Variante normale : popup BLOQUANT (non fermable) + bouton de migration ── |
| 160 | + return createPortal( |
| 161 | + <div className="mig-gate" onContextMenu={(e) => e.preventDefault()}> |
| 162 | + <div className="mig-card"> |
| 163 | + <div className="mig-inner"> |
| 164 | + <div className="mig-eyebrow">Changement de nom</div> |
| 165 | + <div className="mig-rename"> |
| 166 | + <span className="mig-old">StarTrad FR</span> |
| 167 | + <span className="mig-arr">→</span> |
| 168 | + <span className="mig-new"> |
| 169 | + Stelli<b>verse</b> |
| 170 | + </span> |
| 171 | + </div> |
| 172 | + <h1 className="mig-h1"> |
| 173 | + StarTrad devient <b>Stelliverse</b> |
| 174 | + </h1> |
| 175 | + <div className="mig-body"> |
| 176 | + L'app a été <b>entièrement réécrite et modernisée</b>, puis rebaptisée{" "} |
| 177 | + <span className="mig-hl">Stelliverse</span>. Cette version est la{" "} |
| 178 | + <b>toute dernière de StarTrad</b> — la suite se passe sur Stelliverse. |
| 179 | + </div> |
| 180 | + <div className="mig-assure"> |
| 181 | + <svg viewBox="0 0 24 24"> |
| 182 | + <path d="M9 12l2 2 4-4" /> |
| 183 | + <path d="M21 12a9 9 0 1 1-18 0 9 9 0 0 1 18 0z" /> |
| 184 | + </svg> |
| 185 | + <div className="mig-t"> |
| 186 | + <b>Rien n'est perdu.</b> Ton compte et tes sauvegardes sont conservés : tu |
| 187 | + te reconnectes avec le même Discord et tout est là. |
| 188 | + </div> |
| 189 | + </div> |
| 190 | + <button className="mig-btn" onClick={onMigrate} disabled={migrating}> |
| 191 | + {migrating ? ( |
| 192 | + "Téléchargement…" |
| 193 | + ) : ( |
| 194 | + <> |
| 195 | + <svg viewBox="0 0 24 24"> |
| 196 | + <path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4" /> |
| 197 | + <path d="M7 10l5 5 5-5" /> |
| 198 | + <path d="M12 15V3" /> |
| 199 | + </svg> |
| 200 | + Télécharger Stelliverse |
| 201 | + </> |
| 202 | + )} |
| 203 | + </button> |
| 204 | + <div className="mig-foot"> |
| 205 | + Téléchargement & installation automatiques · puis Stelliverse se lance |
| 206 | + </div> |
| 207 | + <div className="mig-brand"> |
| 208 | + <span |
| 209 | + className="mig-link" |
| 210 | + onClick={() => openExternal(STELLIVERSE_RELEASES_URL)} |
| 211 | + > |
| 212 | + Ou télécharger manuellement |
| 213 | + </span> |
| 214 | + </div> |
| 215 | + </div> |
| 216 | + </div> |
| 217 | + </div>, |
| 218 | + document.body |
| 219 | + ); |
| 220 | +} |
| 221 | + |
| 222 | +export default MigrationGate; |
0 commit comments