feat: hide the deploy button when the Dokku server is not connected

This commit is contained in:
James Murdza
2024-12-31 10:40:45 -08:00
parent e8590703f8
commit f3f91ea16f
4 changed files with 41 additions and 18 deletions

View File

@ -13,7 +13,10 @@ export class SSHSocketClient {
private conn: Client
private config: SSHConfig
private socketPath: string
private isConnected: boolean = false
private _isConnected: boolean = false
public get isConnected(): boolean {
return this._isConnected
}
// Constructor initializes the SSH client and sets up configuration
constructor(config: SSHConfig, socketPath: string) {
@ -34,7 +37,7 @@ export class SSHSocketClient {
private closeConnection() {
console.log("Closing SSH connection...")
this.conn.end()
this.isConnected = false
this._isConnected = false
process.exit(0)
}
@ -44,17 +47,17 @@ export class SSHSocketClient {
this.conn
.on("ready", () => {
console.log("SSH connection established")
this.isConnected = true
this._isConnected = true
resolve()
})
.on("error", (err) => {
console.error("SSH connection error:", err)
this.isConnected = false
this._isConnected = false
reject(err)
})
.on("close", () => {
console.log("SSH connection closed")
this.isConnected = false
this._isConnected = false
})
.connect(this.config)
})

View File

@ -170,8 +170,20 @@ export class Sandbox {
// Handle checking if an app exists
const handleAppExists: SocketHandler = async ({ appName }) => {
if (!this.dokkuClient)
throw new Error("Failed to check app existence: No Dokku client")
if (!this.dokkuClient) {
console.log("Failed to check app existence: No Dokku client")
return {
success: false,
}
}
if (!this.dokkuClient.isConnected) {
console.log(
"Failed to check app existence: The Dokku client is not connected"
)
return {
success: false,
}
}
return {
success: true,
exists: await this.dokkuClient.appExists(appName),