Skip to content

Commit

Permalink
fix: get current connection name correctly on win32
Browse files Browse the repository at this point in the history
  • Loading branch information
wuzi committed Apr 18, 2021
1 parent 13e1b10 commit 834d361
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/utils/wg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,17 @@ export async function getCurrentConnectionName(): Promise<string> {
throw new Error(e.message);
}

const splittedText: string[] = e.stderr.split(":");
const indexOfName = splittedText[0].lastIndexOf(" ");
const connectionName = splittedText[0].substring(indexOfName + 1, splittedText[0].length);
let connectionName = "";

if (process.platform === "win32") {
const splittedText: string[] = e.stderr.split("Unable to access interface");
const indexOfSymbol = splittedText[1].indexOf(":");
connectionName = splittedText[1].substring(1, indexOfSymbol);
} else {
const splittedText: string[] = e.stderr.split(":");
const indexOfName = splittedText[0].lastIndexOf(" ");
connectionName = splittedText[0].substring(indexOfName + 1, splittedText[0].length);
}

return connectionName;
}
Expand Down

0 comments on commit 834d361

Please sign in to comment.