From 2eef4ffcb7589ff0a8caa0b5956ce26e2bfae657 Mon Sep 17 00:00:00 2001 From: Donavan Becker Date: Tue, 7 Nov 2023 23:18:22 -0600 Subject: [PATCH] add child bridge restart --- .../manage-plugins-modal.component.html | 21 +++++-- .../manage-plugins-modal.component.ts | 59 ++++++++++++++++++- 2 files changed, 74 insertions(+), 6 deletions(-) diff --git a/ui/src/app/core/manage-plugins/manage-plugins-modal/manage-plugins-modal.component.html b/ui/src/app/core/manage-plugins/manage-plugins-modal/manage-plugins-modal.component.html index 120ed04e7..491564464 100644 --- a/ui/src/app/core/manage-plugins/manage-plugins-modal/manage-plugins-modal.component.html +++ b/ui/src/app/core/manage-plugins/manage-plugins-modal/manage-plugins-modal.component.html @@ -8,14 +8,25 @@

Restart Required

-

-

- Please restart Homebridge for the changes to apply. Alternatively, if you have this plugin running in child bridges, you can close this modal and restart these instead. +

+

+ Please restart Homebridge for the changes to apply. Alternatively, if you have this plugin running in child + bridges, you can close this modal and restart these instead.

+ -

@@ -53,4 +64,4 @@
{{ release.name }}
- + \ No newline at end of file diff --git a/ui/src/app/core/manage-plugins/manage-plugins-modal/manage-plugins-modal.component.ts b/ui/src/app/core/manage-plugins/manage-plugins-modal/manage-plugins-modal.component.ts index 2079df874..3a8ffa259 100644 --- a/ui/src/app/core/manage-plugins/manage-plugins-modal/manage-plugins-modal.component.ts +++ b/ui/src/app/core/manage-plugins/manage-plugins-modal/manage-plugins-modal.component.ts @@ -20,9 +20,16 @@ export class ManagePluginsModalComponent implements OnInit, OnDestroy { @Input() pluginName; @Input() targetVersion = 'latest'; @Input() action; + @Input() plugin; private io = this.$ws.connectToNamespace('plugins'); + public canConfigure = true; + public configBlocks: any[] = []; + public enabledBlocks: Record = {}; + public usernameCache: Map = new Map(); + public deviceInfo: Map = new Map(); + private term = new Terminal(); private termTarget: HTMLElement; private fitAddon = new FitAddon(); @@ -32,6 +39,7 @@ export class ManagePluginsModalComponent implements OnInit, OnDestroy { public showReleaseNotes = false; public justUpdatedPlugin = false; public updateToBeta = false; + public restartInProgress: Record = {}; public changeLog: string; public release; @@ -45,6 +53,7 @@ export class ManagePluginsModalComponent implements OnInit, OnDestroy { public activeModal: NgbActiveModal, public $toastr: ToastrService, private translate: TranslateService, + private $translate: TranslateService, private $settings: SettingsService, private $api: ApiService, private $ws: WsService, @@ -54,7 +63,8 @@ export class ManagePluginsModalComponent implements OnInit, OnDestroy { this.term.loadAddon(this.fitAddon); } - ngOnInit() { + ngOnInit(): void { + this.loadPluginConfig(); this.termTarget = document.getElementById('plugin-log-output'); this.term.open(this.termTarget); this.fitAddon.fit(); @@ -97,6 +107,32 @@ export class ManagePluginsModalComponent implements OnInit, OnDestroy { } } + loadPluginConfig() { + this.$api.get(`/config-editor/plugin/${encodeURIComponent(this.plugin.name)}`).subscribe( + (configBlocks) => { + this.configBlocks = configBlocks; + for (const [i, block] of this.configBlocks.entries()) { + if (block._bridge && block._bridge.username) { + this.enabledBlocks[i] = true; + this.usernameCache.set(i, block._bridge.username); + this.getDeviceInfo(block._bridge.username); + } + } + }, + (err) => { + this.canConfigure = false; + }, + ); + } + + async getDeviceInfo(username: string) { + try { + this.deviceInfo[username] = await this.$api.get(`/server/pairings/${username.replace(/:/g, '')}`).toPromise(); + } catch (e) { + this.deviceInfo[username] = false; + } + } + install() { if (!this.onlineUpdateOk) { return; @@ -178,6 +214,27 @@ export class ManagePluginsModalComponent implements OnInit, OnDestroy { ); } + async restartChildBridge(username: string) { + this.restartInProgress[username] = true; + try { + await this.$api.put(`/server/restart/${username.replace(/:/g, '')}`, {}).toPromise(); + this.$toastr.success( + this.$translate.instant('child_bridge.toast_restart_requested'), + this.$translate.instant('toast.title_success'), + ); + } catch (err) { + this.$toastr.error( + 'Failed to restart bridge: ' + err.error?.message, + this.$translate.instant('toast.title_error'), + ); + this.restartInProgress[username] = false; + } finally { + setTimeout(() => { + this.restartInProgress[username] = false; + }, 12000); + } + } + upgradeHomebridge() { this.io.request('homebridge-update', { version: this.targetVersion,