99 lines
4.2 KiB
TypeScript
99 lines
4.2 KiB
TypeScript
import * as vscode from 'vscode';
|
|
import { ADClient } from './adClient';
|
|
|
|
export class StatusBarManager {
|
|
private restartADItem: vscode.StatusBarItem;
|
|
private restartHAItem: vscode.StatusBarItem;
|
|
private productionModeItem: vscode.StatusBarItem;
|
|
private errorItem: vscode.StatusBarItem;
|
|
private contextualItem: vscode.StatusBarItem;
|
|
|
|
constructor(private adClient: ADClient) {
|
|
// Reload AppDaemon apps
|
|
this.restartADItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left, 100);
|
|
this.restartADItem.command = 'appdaemon.restartAD';
|
|
this.restartADItem.text = '$(refresh) AD Apps';
|
|
this.restartADItem.tooltip = 'Reload all AppDaemon Apps';
|
|
this.restartADItem.show();
|
|
|
|
// Restart Home Assistant
|
|
this.restartHAItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left, 99);
|
|
this.restartHAItem.command = 'appdaemon.restartHA';
|
|
this.restartHAItem.text = '$(refresh) HA';
|
|
this.restartHAItem.tooltip = 'Restart Home Assistant';
|
|
this.restartHAItem.show();
|
|
|
|
// Production mode toggle
|
|
this.productionModeItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left, 98);
|
|
this.productionModeItem.command = 'appdaemon.toggleProductionMode';
|
|
this.updateProductionModeDisplay();
|
|
this.productionModeItem.show();
|
|
|
|
// Error log shortcut
|
|
this.errorItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left, 97);
|
|
this.errorItem.command = 'appdaemon.showErrors';
|
|
this.errorItem.text = '$(check) AD Errors';
|
|
this.errorItem.tooltip = 'Show AppDaemon Error Log';
|
|
this.errorItem.show();
|
|
|
|
// Contextual per-file restart button (hidden by default)
|
|
this.contextualItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left, 101);
|
|
this.contextualItem.command = 'appdaemon.restartCurrentFileApps';
|
|
|
|
// React to production mode changes
|
|
adClient.onProductionModeChanged(() => this.updateProductionModeDisplay());
|
|
}
|
|
|
|
/**
|
|
* Update (or hide) the contextual button based on apps found in the current file.
|
|
* @param appNames App names parsed from the active YAML, or empty to hide.
|
|
*/
|
|
updateContextualApps(appNames: string[]) {
|
|
if (appNames.length === 0) {
|
|
this.contextualItem.hide();
|
|
return;
|
|
}
|
|
const label = appNames.length <= 2
|
|
? appNames.join(', ')
|
|
: `${appNames.length} apps`;
|
|
this.contextualItem.text = `$(refresh) ${label}`;
|
|
this.contextualItem.tooltip = `Restart: ${appNames.join(', ')}`;
|
|
this.contextualItem.show();
|
|
}
|
|
|
|
updateProductionModeDisplay() {
|
|
const isProduction = this.adClient.isProductionMode();
|
|
if (isProduction) {
|
|
this.productionModeItem.text = '$(eye-closed) Prod ON';
|
|
this.productionModeItem.tooltip = 'Production Mode: ON — click to disable';
|
|
this.productionModeItem.backgroundColor = new vscode.ThemeColor('statusBarItem.warningBackground');
|
|
} else {
|
|
this.productionModeItem.text = '$(eye) Prod OFF';
|
|
this.productionModeItem.tooltip = 'Production Mode: OFF — click to enable';
|
|
this.productionModeItem.backgroundColor = undefined;
|
|
}
|
|
}
|
|
|
|
setErrorCount(count: number) {
|
|
if (count > 0) {
|
|
this.errorItem.text = `$(warning) AD Errors (${count})`;
|
|
this.errorItem.backgroundColor = new vscode.ThemeColor('statusBarItem.errorBackground');
|
|
this.errorItem.tooltip = `${count} error(s) — click to show or clear`;
|
|
this.errorItem.command = 'appdaemon.handleErrors';
|
|
} else {
|
|
this.errorItem.text = '$(check) AD Errors';
|
|
this.errorItem.backgroundColor = undefined;
|
|
this.errorItem.tooltip = 'No AppDaemon errors — click to view log';
|
|
this.errorItem.command = 'appdaemon.showErrors';
|
|
}
|
|
}
|
|
|
|
dispose() {
|
|
this.restartADItem.dispose();
|
|
this.restartHAItem.dispose();
|
|
this.productionModeItem.dispose();
|
|
this.errorItem.dispose();
|
|
this.contextualItem.dispose();
|
|
}
|
|
}
|