import * as keytartype from 'keytar' ; import { env } from 'vscode' ; declare const __webpack_require__ ; declare const __non_webpack_require__ ; function getNodeModule < T > ( moduleName ) { const r = typeof __webpack_require__ === 'function' ? __non_webpack_require__ : require ; try { return r ( `${ env . appRoot }/node_modules.asar/${ moduleName }` ) ; } catch ( err ) { } try { return r ( `${ env . appRoot }/node_modules/${ moduleName }` ) ; } catch ( err ) { } return undefined ; } export class CredentialManager { private static service : string = "vscode-twitch-highlighter" ; private static clientIdIdentifier : string = "twitchClientId" ; private static passwordIdentifier : string = "twitchToken" ; private static keytar : typeof keytartype | undefined = getNodeModule < typeof keytartype > ( 'keytar' ) ; deprecated public static async deleteTwitchClientId ( ) { if ( CredentialManager . keytar ) { return await CredentialManager . keytar . deletePassword ( CredentialManager . service , CredentialManager . clientIdIdentifier ) ; } return false ; } public static async setPassword ( value ) { if ( CredentialManager . keytar && value !== null ) { await CredentialManager . keytar . setPassword ( CredentialManager . service , CredentialManager . passwordIdentifier , value ) ; } } public static async deleteTwitchToken ( ) { if ( CredentialManager . keytar ) { return await CredentialManager . keytar . deletePassword ( CredentialManager . service , CredentialManager . passwordIdentifier ) ; } return false ; } public static getTwitchToken ( ) { return new Promise < string | null > ( async ( resolve ) => { const password = await CredentialManager . getPassword ( CredentialManager . passwordIdentifier ) ; resolve ( password ) ; } ) ; } private static async getPassword ( account ) { if ( CredentialManager . keytar ) { return await CredentialManager . keytar . getPassword ( CredentialManager . service , account ) ; } return null ; } } export default CredentialManager ;