All files / src/views HomeScreenPanel.ts

100% Statements 48/48
90.9% Branches 10/11
100% Functions 3/3
100% Lines 48/48

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 491x 1x 1x 1x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 1x 1x 1x 1x 6x 5x 5x 5x 5x 6x 6x 6x 4x 4x 4x 4x 6x 2x 2x 2x 2x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x  
import * as vscode from 'vscode';
import * as fs from 'fs';
import * as path from 'path';
 
export class HomeScreenPanel {
    constructor(private readonly extensionUri: vscode.Uri, private readonly context: vscode.ExtensionContext) {}
 
    public async getHtml(webview: vscode.Webview, liveShareInstalled: boolean, loggedIn: boolean, userInfo?: { email?: string, username?: string }) {
        const cacheBuster = Date.now();
        const panelStyleUri = webview.asWebviewUri(vscode.Uri.joinPath(this.extensionUri, 'media', 'panel.css'));
        const homeStyleUri = webview.asWebviewUri(vscode.Uri.joinPath(this.extensionUri, 'media', 'homeScreenPanel.css'));
 
        let liveShareStatusHtml = '';
        if (!liveShareInstalled) {
            liveShareStatusHtml = `<div class="status-block">
                <p>Live Share extension is not installed.</p>
                <button class="home-button" id="installLiveShareBtn">Install Live Share</button>
            </div>`;
        } else {
            liveShareStatusHtml = `<div class="status-block success">
                <p>Live Share installed</p>
            </div>`;
        }
 
        let loginStatusHtml = '';
        if (!loggedIn) {
            loginStatusHtml = `<div class="status-block">
                <p>Please sign in with GitHub to continue.</p>
                <button class="home-button" id="loginBtn">Sign in with GitHub</button>
            </div>`;
        } else {
            loginStatusHtml = `<div class="status-block success">
                <p>Logged in as <strong>${userInfo?.email || userInfo?.username || 'user'}</strong></p>
            </div>`;
        }
 
        const templatePath = vscode.Uri.joinPath(this.extensionUri, 'media', 'homeScreenPanel.html').fsPath;
        const htmlTemplate = fs.readFileSync(templatePath, 'utf8');
 
        const html = htmlTemplate
            .replace('{{PANEL_STYLE_URI}}', `${panelStyleUri.toString()}?v=${cacheBuster}`)
            .replace('{{HOME_STYLE_URI}}', `${homeStyleUri.toString()}?v=${cacheBuster}`)
            .replace('{{LIVE_SHARE_STATUS}}', liveShareStatusHtml)
            .replace('{{LOGIN_STATUS}}', loginStatusHtml);
 
        return html;
    }
}