|
1 |
| -import { extensionContext, useCommand, useWebviewPanel } from 'reactive-vscode'; |
| 1 | +import { extensionContext, useCommand } from 'reactive-vscode'; |
2 | 2 | import * as vscode from 'vscode';
|
3 | 3 |
|
| 4 | +let panel: vscode.WebviewPanel | undefined; |
| 5 | + |
4 | 6 | export function activate() {
|
5 | 7 | useCommand('vue.welcome', () => {
|
6 |
| - useWebviewPanel('vue.welcome', 'Welcome to Vue', getWelcomeHtml(), vscode.ViewColumn.One, { |
7 |
| - webviewOptions: { |
8 |
| - enableScripts: true, |
9 |
| - }, |
10 |
| - onDidReceiveMessage(message) { |
11 |
| - switch (message.command) { |
12 |
| - case 'verifySponsor': |
13 |
| - vscode.commands.executeCommand('vue.action.verify'); |
14 |
| - break; |
15 |
| - case 'openVideo': |
16 |
| - vscode.env.openExternal( |
17 |
| - vscode.Uri.parse(`https://www.youtube.com/watch?v=${message.id}`), |
18 |
| - ); |
19 |
| - break; |
20 |
| - } |
21 |
| - }, |
| 8 | + if (panel) { |
| 9 | + panel.reveal(vscode.ViewColumn.One); |
| 10 | + return; |
| 11 | + } |
| 12 | + |
| 13 | + panel = vscode.window.createWebviewPanel( |
| 14 | + 'vue.welcome', |
| 15 | + 'Welcome to Vue', |
| 16 | + vscode.ViewColumn.One, |
| 17 | + { enableScripts: true }, |
| 18 | + ); |
| 19 | + |
| 20 | + panel.webview.html = getWelcomeHtml(); |
| 21 | + panel.webview.onDidReceiveMessage(message => { |
| 22 | + switch (message.command) { |
| 23 | + case 'verifySponsor': |
| 24 | + vscode.commands.executeCommand('vue.action.verify'); |
| 25 | + break; |
| 26 | + case 'openVideo': |
| 27 | + vscode.env.openExternal( |
| 28 | + vscode.Uri.parse(`https://www.youtube.com/watch?v=${message.id}`), |
| 29 | + ); |
| 30 | + break; |
| 31 | + } |
| 32 | + }); |
| 33 | + |
| 34 | + panel.onDidDispose(() => { |
| 35 | + panel = undefined; |
22 | 36 | });
|
23 | 37 | });
|
24 | 38 | }
|
@@ -351,7 +365,7 @@ function getWelcomeHtml() {
|
351 | 365 | ></iframe>
|
352 | 366 | </a>
|
353 | 367 | </div>
|
354 |
| - <p id="video-reminder" style="margin-top:0.5rem; text-align:center; color:var(--vscode-foreground);"> |
| 368 | + <p id="video-reminder" style="margin-top: 0.5rem; text-align: center; color: var(--vscode-foreground);"> |
355 | 369 | ⚠️ Unable to load the video? <a href="https://www.youtube.com/watch?v=RcPcO4_Ct_U">Watch on YouTube</a>
|
356 | 370 | </p>
|
357 | 371 | <script>
|
@@ -403,7 +417,7 @@ function getWelcomeHtml() {
|
403 | 417 | </div>
|
404 | 418 | </div>
|
405 | 419 |
|
406 |
| - <div style="display: flex; flex-direction: column; align-items: center; gap: 1rem;"> |
| 420 | + <div id="verify-container" style="display: flex; flex-direction: column; align-items: center; gap: 1rem;"> |
407 | 421 | <p>Support the development and unlock these features:</p>
|
408 | 422 | <a href="https://github.com/sponsors/johnsoncodehk" target="_blank"
|
409 | 423 | style="display: inline-flex; align-items: center; gap: 0.5rem; padding: 0.5rem 1rem; background-color: var(--vscode-button-background); color: var(--vscode-button-foreground); border-radius: 4px; text-decoration: none;">
|
@@ -470,17 +484,17 @@ function getWelcomeHtml() {
|
470 | 484 | <h2>❤️ Thanks to Our Sponsors</h2>
|
471 | 485 | <div class="card sponsors-card" style="text-align: center; padding: 1.5rem;">
|
472 | 486 | <p style="margin-top: 0;">This project is made possible thanks to our generous sponsors:</p>
|
473 |
| - <div id="sponsors-container" style="max-width:100%;margin:0 auto;"></div> |
474 |
| - <script> |
475 |
| - fetch('https://cdn.jsdelivr.net/gh/johnsoncodehk/sponsors/sponsors.svg') |
476 |
| - .then(r => r.text()) |
477 |
| - .then(svg => { |
478 |
| - const wrap = document.getElementById('sponsors-container'); |
479 |
| - wrap.innerHTML = svg; |
480 |
| - }) |
481 |
| - .catch(() => { |
482 |
| - document.getElementById('sponsors-container').textContent = 'Failed to load sponsors'; |
483 |
| - }); |
| 487 | + <div id="sponsors-container" style="max-width: 100%; margin: 0 auto;"></div> |
| 488 | + <script type="module"> |
| 489 | + const container = document.getElementById('sponsors-container'); |
| 490 | + try { |
| 491 | + const res = await fetch('https://cdn.jsdelivr.net/gh/johnsoncodehk/sponsors/sponsors.svg'); |
| 492 | + const svg = await res.text(); |
| 493 | + container.innerHTML = svg; |
| 494 | + } |
| 495 | + catch { |
| 496 | + container.textContent = 'Failed to load sponsors'; |
| 497 | + } |
484 | 498 | </script>
|
485 | 499 | <p style="margin-bottom: 0;">
|
486 | 500 | <a href="https://github.com/sponsors/johnsoncodehk" target="_blank">Become a sponsor</a> to support Vue
|
|
0 commit comments