Skip to content

Commit

Permalink
整理代码
Browse files Browse the repository at this point in the history
  • Loading branch information
sumneko committed Sep 27, 2024
1 parent 2d26586 commit b436b5d
Showing 1 changed file with 27 additions and 12 deletions.
39 changes: 27 additions & 12 deletions src/console/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,25 +34,40 @@ export function registerRequest(method: string, handler: ResponseHandler) {
requests.set(method, handler);
}

class Buttons extends vscode.Disposable {
private buttons: vscode.StatusBarItem[] = [];

constructor() {
super(() => {
for (let button of this.buttons) {
button.dispose();
}
});

let rd = this.addButton('🍉重载Lua');
rd.tooltip = '省的你输入 `.rd`';
rd.command = 'y3-helper.reloadLua';
}

addButton(text: string) {
let button = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left);
button.text = text;
button.show();
this.buttons.push(button);
return button;
}
}

export class Client extends vscode.Disposable {
static allClients: Client[] = [];

static button?: vscode.StatusBarItem;
static button?: Buttons;

static updateButton() {
if (this.allClients.length > 0) {
if (!this.button) {
this.button = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left);
this.button.text = '🍉重载Lua';
this.button.tooltip = '省的你输入 `.rd`';
this.button.command = 'y3-helper.reloadLua';
this.button.show();
}
this.button ??= new Buttons();
} else {
if (this.button) {
this.button.dispose();
this.button = undefined;
}
this.button?.dispose();
}
}

Expand Down

0 comments on commit b436b5d

Please sign in to comment.