Skip to content

Commit

Permalink
restart child bridge after save setting custom ui
Browse files Browse the repository at this point in the history
  • Loading branch information
bwp91 committed Nov 12, 2023
1 parent 43d8564 commit 824ef9c
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,30 @@ <h5 class="modal-title">{{ plugin.displayName || plugin.name }}</h5>
</button>
</div>

<div class="modal-body" style="min-height: 110px;">
<div class="modal-body" style="min-height: 110px;" [hidden]="!justSavedAndExited">
<h3 class="text-center primary-text" [translate]="'platform.version.title_service_restart_required'">
Restart Required
</h3>
<p *ngIf="['homebridge', 'homebridge-config-ui-x'].includes(plugin.name) || childBridges.length === 0" class="text-center grey-text"
[translate]="'plugins.manage.message_thanks_for_updating_restart'">
Please restart Homebridge for the changes to apply.
</p>
<p *ngIf="!['homebridge', 'homebridge-config-ui-x'].includes(plugin.name) && childBridges.length > 0" class="text-center grey-text"
[translate]="'plugins.manage.message_thanks_for_updating_restart_child_bridges'">
Please restart the plugin's child bridges for the changes to apply.
</p>
<div class="text-center">
<button type="button" class="btn btn-primary" *ngIf="!['homebridge', 'homebridge-config-ui-x'].includes(plugin.name) && childBridges.length > 0"
(click)="onRestartChildBridgeClick()">
{{ (childBridges.length === 1 ? 'plugins.manage.child_bridge_button_restart_now_one' : 'plugins.manage.child_bridge_button_restart_now') | translate }}
</button>
<button type="button" class="btn btn-primary"
*ngIf="['homebridge', 'homebridge-config-ui-x'].includes(plugin.name) || childBridges.length === 0" (click)="onRestartHomebridgeClick()"
[translate]="'plugins.manage.button_restart_now'">Restart Homebridge</button>
</div>
</div>

<div class="modal-body" style="min-height: 110px;" [hidden]="justSavedAndExited">
<div *ngIf="loading" class="text-center primary-text">
<i class="fa fa-fw fa-cog fa-spin" style="font-size: 72px;"></i>
</div>
Expand Down Expand Up @@ -45,7 +68,7 @@ <h5 class="modal-title">{{ plugin.displayName || plugin.name }}</h5>
</div>
</div>

<div class="modal-footer justify-content-between">
<div class="modal-footer justify-content-between" [hidden]="justSavedAndExited">
<div style="min-width: 25%;" class="text-left">
<button *ngIf="plugin.name !== 'homebridge-config-ui-x'" class="btn btn-danger"
[ngbTooltip]="'form.button_delete' | translate" container="body" [disabled]="saveInProgress"
Expand All @@ -71,6 +94,4 @@ <h5 class="modal-title">{{ plugin.displayName || plugin.name }}</h5>
</button>
</div>
</div>


</div>
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { environment } from '@/environments/environment';
import { ApiService } from '@/app/core/api.service';
import { WsService } from '@/app/core/ws.service';
import { NotificationService } from '@/app/core/notification.service';
import { Router } from '@angular/router';

@Component({
selector: 'app-custom-plugins',
Expand All @@ -29,8 +30,10 @@ export class CustomPluginsComponent implements OnInit, OnDestroy {

public loading = true;
public saveInProgress = false;
public justSavedAndExited = false;
public pluginSpinner = false;
public uiLoaded = false;
public childBridges: any[] = [];

private basePath: string;
private iframe: HTMLIFrameElement;
Expand All @@ -57,6 +60,7 @@ export class CustomPluginsComponent implements OnInit, OnDestroy {
private $translate: TranslateService,
private $toastr: ToastrService,
private $api: ApiService,
private $router: Router,
private $ws: WsService,
private $notification: NotificationService,
) { }
Expand Down Expand Up @@ -402,7 +406,7 @@ export class CustomPluginsComponent implements OnInit, OnDestroy {
/**
* Fired when a custom form is cancelled or submitted
*
* @param action
* @param formEvent
*/
formActionEvent(formEvent: 'cancel' | 'submit') {
this.iframe.contentWindow.postMessage({
Expand All @@ -428,16 +432,17 @@ export class CustomPluginsComponent implements OnInit, OnDestroy {
return await this.$api.post(`/config-editor/plugin/${encodeURIComponent(this.plugin.name)}`, this.pluginConfig)
.toPromise()
.then(data => {
this.$toastr.success(
this.$translate.instant('plugins.settings.toast_restart_required'),
this.$translate.instant('plugins.settings.toast_plugin_config_saved'),
);
// this.$toastr.success(
// this.$translate.instant('plugins.settings.toast_restart_required'),
// this.$translate.instant('plugins.settings.toast_plugin_config_saved'),
// );

this.saveInProgress = false;
this.$notification.configUpdated.next(undefined);
// this.$notification.configUpdated.next(undefined);

if (exit) {
this.activeModal.close();
this.getChildBridges();
this.justSavedAndExited = true;
}
})
.catch(err => {
Expand All @@ -446,6 +451,47 @@ export class CustomPluginsComponent implements OnInit, OnDestroy {
});
}

getChildBridges(): any[] {
try {
this.$api.get('/status/homebridge/child-bridges').subscribe((data: any[]) => {
data.forEach((bridge) => {
if (this.plugin.name === bridge.plugin) {
this.childBridges.push(bridge);
}
});
});
return this.childBridges;
} catch (err) {
this.$toastr.error(err.message, this.$translate.instant('toast.title_error'));
return [];
}
}

public onRestartHomebridgeClick() {
this.$router.navigate(['/restart']);
this.activeModal.close();
}

public async onRestartChildBridgeClick() {
try {
for (const bridge of this.childBridges) {
await this.$api.put(`/server/restart/${bridge.username}`, {}).toPromise();
}
this.$toastr.success(
this.$translate.instant('plugins.manage.child_bridge_restart_success'),
this.$translate.instant('toast.title_success'),
);
} catch (err) {
this.$notification.configUpdated.next(undefined); // highlight the restart icon in the navbar
this.$toastr.error(
this.$translate.instant('plugins.manage.child_bridge_restart_failed'),
this.$translate.instant('toast.title_error'),
);
} finally {
this.activeModal.close();
}
}

deletePluginConfig() {
this.updateConfigBlocks([]);
this.savePluginConfig(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ <h5 class="modal-title">Logs: {{ plugin.displayName || plugin.name }}</h5>
</button>
</div>
<div class="modal-body d-flex flex-row flex-grow-1 w-100 p-0">
<div #pluginlogoutput class="w-100 bg-black plugin-log-output terminal align-self-end w-100 h-100 mb-1 p-2"></div>

<div #pluginlogoutput class="w-100 bg-black plugin-log-output terminal align-self-end w-100 h-100 mb-0 p-2"></div>
</div>
</div>
2 changes: 1 addition & 1 deletion ui/src/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@
"platform.linux.shutdown.message_server_will_power_down": "The server will power down shortly.",
"platform.linux.shutdown.title_shutting_down_server": "Shutting Down Server",
"platform.version.message_service_restart_required": "WARNING: Homebridge UI v{{ uiVersion }} has been installed, but the server service is still running v{{ serverVersion }}.",
"platform.version.title_service_restart_required": "Service Restart Required",
"platform.version.title_service_restart_required": "Homebridge Restart Required",
"plugins.button_api_documentation": "API Documentation",
"plugins.button_homepage": "Plugin Homepage",
"plugins.button_install": "Install",
Expand Down

0 comments on commit 824ef9c

Please sign in to comment.