Skip to content

Commit

Permalink
Support for keytar in ASAR
Browse files Browse the repository at this point in the history
  • Loading branch information
chrmarti committed Feb 22, 2018
1 parent b680c00 commit e9c2a97
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions src/azure-account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,20 @@ import { AzureAccount, AzureSession, AzureLoginStatus, AzureResourceFilter, Azur

const localize = nls.loadMessageBundle();

let keytar: typeof keytarType;
try {
keytar = require(`${env.appRoot}/node_modules/keytar`)
} catch (e) {
// Not available.
const keytar = getNodeModule<typeof keytarType>('keytar');

function getNodeModule<T>(moduleName: string): T | undefined {
try {
return require(`${env.appRoot}/node_modules.asar/${moduleName}`);
} catch (err) {
// Not in ASAR.
}
try {
return require(`${env.appRoot}/node_modules/${moduleName}`);
} catch (err) {
// Not available.
}
return undefined;
}

const logVerbose = false;
Expand Down Expand Up @@ -201,6 +210,11 @@ export class AzureLoginHelper {
await keytar.setPassword(credentialsService, credentialsAccount, refreshToken);
}
await this.updateSessions(tokenResponses);
} catch (err) {
if (err instanceof AzureLoginError && err.reason) {
console.error(err.reason);
}
throw err;
} finally {
this.updateStatus();
}
Expand Down

0 comments on commit e9c2a97

Please sign in to comment.