Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvements for the VPN UI status #1235

Merged
merged 2 commits into from
Jun 17, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 50 additions & 43 deletions static/skywire-manager-src/src/app/services/vpn-client.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -514,19 +514,17 @@ export class VpnClientService {
retryWhen(errors =>
concat(errors.pipe(delay(this.standardWaitTime), take(3)), errors.pipe(mergeMap(err => throwError(err))))
),
).subscribe(() => {
).subscribe(appData => {
this.working = false;

// Update the local values.
if (startApp) {
this.currentEventData.vpnClientAppData.running = true;
const vpnClientData = this.processAppData(appData);
if (vpnClientData.running) {
this.lastServiceState = VpnServiceStates.Running;

this.vpnSavedDataService.updateHistory();
} else {
this.currentEventData.vpnClientAppData.running = false;
this.lastServiceState = VpnServiceStates.Off;
}
this.currentEventData.vpnClientAppData = vpnClientData;
this.currentEventData.updateDate = Date.now();

// Make the service work normally again.
this.sendUpdate();
Expand Down Expand Up @@ -679,42 +677,7 @@ export class VpnClientService {

// Get the required data from the app properties.
if (appData) {
vpnClientData = new VpnClientAppData();
vpnClientData.running = appData.status !== 0 && appData.status !== 2;
vpnClientData.connectionDuration = appData.connection_duration;

vpnClientData.appState = AppState.Stopped;
if (vpnClientData.running) {
if (appData.detailed_status === AppState.Connecting) {
vpnClientData.appState = AppState.Connecting;
} else if (appData.detailed_status === AppState.Running) {
vpnClientData.appState = AppState.Running;
} else if (appData.detailed_status === AppState.ShuttingDown) {
vpnClientData.appState = AppState.ShuttingDown;
} else if (appData.detailed_status === AppState.Reconnecting) {
vpnClientData.appState = AppState.Reconnecting;
}
} else if (appData.status === 2) {
vpnClientData.lastErrorMsg = appData.detailed_status;

if (!vpnClientData.lastErrorMsg) {
vpnClientData.lastErrorMsg = this.translateService.instant('vpn.status-page.unknown-error');
}
}

vpnClientData.killswitch = false;

if (appData.args && appData.args.length > 0) {
for (let i = 0; i < appData.args.length; i++) {
if (appData.args[i] === '-srv' && i + 1 < appData.args.length) {
vpnClientData.serverPk = appData.args[i + 1];
}

if (appData.args[i].toLowerCase().includes('-killswitch')) {
vpnClientData.killswitch = (appData.args[i] as string).toLowerCase().includes('true');
}
}
}
vpnClientData = this.processAppData(appData);
}

// Get the min hops value.
Expand Down Expand Up @@ -785,6 +748,50 @@ export class VpnClientService {
}));
}

/**
* Gets the required data from the app properties.
*/
private processAppData(appData: any): VpnClientAppData {
const vpnClientData = new VpnClientAppData();
vpnClientData.running = appData.status !== 0 && appData.status !== 2;
vpnClientData.connectionDuration = appData.connection_duration;

vpnClientData.appState = AppState.Stopped;
if (vpnClientData.running) {
if (appData.detailed_status === AppState.Connecting || appData.status === 3) {
vpnClientData.appState = AppState.Connecting;
} else if (appData.detailed_status === AppState.Running) {
vpnClientData.appState = AppState.Running;
} else if (appData.detailed_status === AppState.ShuttingDown) {
vpnClientData.appState = AppState.ShuttingDown;
} else if (appData.detailed_status === AppState.Reconnecting) {
vpnClientData.appState = AppState.Reconnecting;
}
} else if (appData.status === 2) {
vpnClientData.lastErrorMsg = appData.detailed_status;

if (!vpnClientData.lastErrorMsg) {
vpnClientData.lastErrorMsg = this.translateService.instant('vpn.status-page.unknown-error');
}
}

vpnClientData.killswitch = false;

if (appData.args && appData.args.length > 0) {
for (let i = 0; i < appData.args.length; i++) {
if (appData.args[i] === '-srv' && i + 1 < appData.args.length) {
vpnClientData.serverPk = appData.args[i + 1];
}

if (appData.args[i].toLowerCase().includes('-killswitch')) {
vpnClientData.killswitch = (appData.args[i] as string).toLowerCase().includes('true');
}
}
}

return vpnClientData;
}

/**
* Sends an update about the state of the VPN. It automatically sets the serviceState and
* busy properties of currentEventData.
Expand Down