<commit_before>'use strict';

import { window, workspace } from 'vscode';

import { LiveServerHelper } from './LiveServerHelper';
import { StatusbarUi } from './StatusbarUi';
import { Config } from './Config';
import { Helper, SUPPRORTED_EXT } from './Helper';

import * as opn from 'opn';

export class AppModel {

    private IsServerRunning: boolean;
    private IsStaging: boolean;
    private LiveServerInstance;
    private runningPort: number;

    constructor() {
        this.IsServerRunning = false;
        this.runningPort = null;

        this.HaveAnySupportedFile(() => {
            StatusbarUi.Init();
        });

    }

    public Golive(pathUri?: string) {

        if (!window.activeTextEditor && !workspace.rootPath) {
            this.showPopUpMsg(`Open a file or folder...`, true);
            return;
        }

        const workspacePath = workspace.rootPath || '';
        const openedDocUri = pathUri || (window.activeTextEditor ? window.activeTextEditor.document.fileName : '');
        let pathInfos = Helper.ExtractFilePath(workspacePath, openedDocUri, Config.getRoot);

        if (this.IsServerRunning) {
            this.openBrowser(this.runningPort,
                Helper.getSubPathIfSupported(pathInfos.rootPath, openedDocUri) || '');
            return;
        }
        if (pathInfos.HasVirtualRootError) {
            this.showPopUpMsg('Invaild Path in liveServer.settings.root settings. live Server will serve from workspace root', true);
        }

        let params = Helper.generateParams(pathInfos.rootPath, Config.getPort,
            Config.getIgnoreFiles, workspacePath, Config.getAdditionalTags, () => {
                this.tagMissedCallback();
            });

        if (this.IsStaging) return;

        LiveServerHelper.StartServer(params, (serverInstance) => {
            if (serverInstance && serverInstance.address()) {
                this.LiveServerInstance = serverInstance;
                this.runningPort = serverInstance.address().port;
                this.ToggleStatusBar();
                this.showPopUpMsg(`Server is Started at port : ${this.runningPort}`);

                if (!Config.getNoBrowser) {
                    this.openBrowser(this.runningPort,
                        Helper.getSubPathIfSupported(pathInfos.rootPath, openedDocUri) || '');
                }
            }
            else {
                this.showPopUpMsg(`Error on port ${Config.getPort}. It may be already in use. Please change it through settings.`, true);
                this.IsServerRunning = true; // to revert status - cheat :p
                this.ToggleStatusBar(); // reverted
            }
        });

        this.IsStaging = true;
        StatusbarUi.Working('Starting...');
    }

    public GoOffline() {
        if (!this.IsServerRunning) {
            this.showPopUpMsg(`Server is not already running`);
            return;
        }
        LiveServerHelper.StopServer(this.LiveServerInstance, () => {
            this.showPopUpMsg('Server is now offline.');
            this.ToggleStatusBar();
            this.LiveServerInstance = null;
            this.runningPort = null;
        });

        StatusbarUi.Working('Disposing...');

    }

    private tagMissedCallback() {
        this.showPopUpMsg('Live Reload is not possible without body or head tag.', null, true);
    }

    private showPopUpMsg(msg: string, isErrorMsg: boolean = false, isWarning: boolean = false) {
        if (isErrorMsg) {<commit_msg>small fixes in statusbar button<commit_after>'use strict';

import { window, workspace } from 'vscode';

import { LiveServerHelper } from './LiveServerHelper';
import { StatusbarUi } from './StatusbarUi';
import { Config } from './Config';
import { Helper, SUPPRORTED_EXT } from './Helper';

import * as opn from 'opn';

export class AppModel {

    private IsServerRunning: boolean;
    private IsStaging: boolean;
    private LiveServerInstance;
    private runningPort: number;

    constructor() {
        this.IsServerRunning = false;
        this.runningPort = null;

        this.HaveAnySupportedFile(() => {
            StatusbarUi.Init();
        });

    }

    public Golive(pathUri?: string) {

        if (!window.activeTextEditor && !workspace.rootPath) {
            this.showPopUpMsg(`Open a file or folder...`, true);
            return;
        }

        const workspacePath = workspace.rootPath || '';
        const openedDocUri = pathUri || (window.activeTextEditor ? window.activeTextEditor.document.fileName : '');
        let pathInfos = Helper.ExtractFilePath(workspacePath, openedDocUri, Config.getRoot);

        if (this.IsServerRunning) {
            this.openBrowser(this.runningPort,
                Helper.getSubPathIfSupported(pathInfos.rootPath, openedDocUri) || '');
            return;
        }
        if (pathInfos.HasVirtualRootError) {
            this.showPopUpMsg('Invaild Path in liveServer.settings.root settings. live Server will serve from workspace root', true);
        }

        let params = Helper.generateParams(pathInfos.rootPath, Config.getPort,
            Config.getIgnoreFiles, workspacePath, Config.getAdditionalTags, () => {
                this.tagMissedCallback();
            });

        if (this.IsStaging) return;

        LiveServerHelper.StartServer(params, (serverInstance) => {
            if (serverInstance && serverInstance.address()) {
                this.LiveServerInstance = serverInstance;
                this.runningPort = serverInstance.address().port;
                this.ToggleStatusBar();
                this.showPopUpMsg(`Server is Started at port : ${this.runningPort}`);

                if (!Config.getNoBrowser) {
                    this.openBrowser(this.runningPort,
                        Helper.getSubPathIfSupported(pathInfos.rootPath, openedDocUri) || '');
                }
            }
            else {
                this.showPopUpMsg(`Error on port ${Config.getPort}. It may be already in use. Please change it through settings.`, true);
                this.IsServerRunning = true; // to revert status - cheat :p
                this.ToggleStatusBar(); // reverted
            }
        });

        this.IsStaging = true;
        StatusbarUi.Working('Starting...');
    }

    public GoOffline() {
        if (this.IsStaging) return;
        if (!this.IsServerRunning) {
            this.showPopUpMsg(`Server is not already running`);
            return;
        }
        LiveServerHelper.StopServer(this.LiveServerInstance, () => {
            this.showPopUpMsg('Server is now offline.');
            this.ToggleStatusBar();
            this.LiveServerInstance = null;
            this.runningPort = null;
        });
        this.IsStaging = true;

        StatusbarUi.Working('Disposing...');

    }

    private tagMissedCallback() {
        this.showPopUpMsg('Live Reload is not possible without body or head tag.', null, true);
    }

    private showPopUpMsg(msg: string, isErrorMsg: boolean = false, isWarning: boolean = false) {
        if (isErrorMsg) {
{'fraction_non_alphanumeric': 0.11007224819379516, 'fraction_numerical': 0.0, 'mean_word_length': 2.198912550974173, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '457032', 'n_tokens_mistral': 1909, 'n_tokens_neox': 1837, 'n_words': 417}