/** * Copyright (c) HashiCorp, Inc. * SPDX-License-Identifier: BUSL-1.1 */ import Component from '@glimmer/component'; import { inject as service } from '@ember/service'; import { action } from '@ember/object'; import { loading } from 'ember-loading'; import { notifyError } from 'core/decorators/notify'; export default class SettingsCardClientAgentComponent extends Component { // =services @service ipc; @service router; @service loading; // =attributes /** * Checks if the status returned by the client agent is "running" * @return {boolean} */ get isClientAgentStatusRunning() { return this.args.model.clientAgentStatus?.status === 'running'; } /** * Checks if the client agent is actively running * @return {boolean} */ get isClientAgentActive() { return ( this.args.model.clientAgentStatus?.status === 'running' || this.args.model.clientAgentStatus?.status === 'paused' ); } /** * Return the button icon based on the current state of the client agent * @return {string} */ get buttonIcon() { if (this.loading.isLoading) { return 'loading'; } else { return this.isClientAgentStatusRunning ? 'pause' : 'play'; } } // =actions /** * Changes the state of the client agent based on the current state. * @return {Promise} */ @action @loading @notifyError(({ message }) => message) async changeClientAgentState() { if (this.isClientAgentStatusRunning) { await this.ipc.invoke('pauseClientAgent'); } else { await this.ipc.invoke('resumeClientAgent'); } await this.router.refresh('scopes.scope.projects.settings'); } }