Skip to content

Commit

Permalink
Better error handling/recovery when remote server stops
Browse files Browse the repository at this point in the history
  • Loading branch information
nisargjhaveri committed Jan 7, 2025
1 parent 549a8eb commit dc3c44f
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/serverConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as vscode from 'vscode';
import { ServerConnection } from 'remote-adb/client';
import { logger } from './logger';

let _serverConnection: ServerConnection;
let _serverConnection: ServerConnection|undefined = undefined;

function getPassword(password?: string) {
//TODO: Ask for password if not provided?
Expand Down Expand Up @@ -40,7 +40,18 @@ async function createServerConnection(server: string, password?: string): Promis
}

export async function getServerConnection(): Promise<ServerConnection> {
if (_serverConnection) {
logger.log("Checking server status by connecting to server");
const status = await _serverConnection.getServerStatus();

if (status._error) {
logger.log(`Cannot get server status: ${status._error}`);
_serverConnection = undefined;
}
}

if (!_serverConnection) {
logger.log("Getting server url from companion extension");
let uri: vscode.Uri|undefined = await vscode.commands.executeCommand("remote-adb.getExternalUrl");

if (!uri) {
Expand Down

0 comments on commit dc3c44f

Please sign in to comment.