@ -16,7 +16,7 @@ import {
Uri ,
Uri ,
window ,
window ,
} from 'vscode' ;
} from 'vscode' ;
import { fetch } from '@env/fetch' ;
import { fetch , getProxyAgent } from '@env/fetch' ;
import { getPlatform } from '@env/platform' ;
import { getPlatform } from '@env/platform' ;
import { configuration } from '../../configuration' ;
import { configuration } from '../../configuration' ;
import { Commands , ContextKeys } from '../../constants' ;
import { Commands , ContextKeys } from '../../constants' ;
@ -71,6 +71,7 @@ export class SubscriptionService implements Disposable {
private _disposable : Disposable ;
private _disposable : Disposable ;
private _subscription ! : Subscription ;
private _subscription ! : Subscription ;
private _statusBarSubscription : StatusBarItem | undefined ;
private _statusBarSubscription : StatusBarItem | undefined ;
private _validationTimer : ReturnType < typeof setInterval > | undefined ;
constructor ( private readonly container : Container ) {
constructor ( private readonly container : Container ) {
this . _disposable = Disposable . from (
this . _disposable = Disposable . from (
@ -269,6 +270,11 @@ export class SubscriptionService implements Disposable {
@gate ( )
@gate ( )
@log ( )
@log ( )
logout ( reset : boolean = false ) : void {
logout ( reset : boolean = false ) : void {
if ( this . _validationTimer != null ) {
clearInterval ( this . _validationTimer ) ;
this . _validationTimer = undefined ;
}
this . _sessionPromise = undefined ;
this . _sessionPromise = undefined ;
if ( this . _session != null ) {
if ( this . _session != null ) {
void this . container . subscriptionAuthentication . removeSession ( this . _session . id ) ;
void this . container . subscriptionAuthentication . removeSession ( this . _session . id ) ;
@ -323,6 +329,7 @@ export class SubscriptionService implements Disposable {
try {
try {
const rsp = await fetch ( Uri . joinPath ( this . baseApiUri , 'resend-email' ) . toString ( ) , {
const rsp = await fetch ( Uri . joinPath ( this . baseApiUri , 'resend-email' ) . toString ( ) , {
method : 'POST' ,
method : 'POST' ,
agent : getProxyAgent ( ) ,
headers : {
headers : {
Authorization : ` Bearer ${ session . accessToken } ` ,
Authorization : ` Bearer ${ session . accessToken } ` ,
'User-Agent' : userAgent ,
'User-Agent' : userAgent ,
@ -477,6 +484,7 @@ export class SubscriptionService implements Disposable {
const rsp = await fetch ( Uri . joinPath ( this . baseApiUri , 'gitlens/checkin' ) . toString ( ) , {
const rsp = await fetch ( Uri . joinPath ( this . baseApiUri , 'gitlens/checkin' ) . toString ( ) , {
method : 'POST' ,
method : 'POST' ,
agent : getProxyAgent ( ) ,
headers : {
headers : {
Authorization : ` Bearer ${ session . accessToken } ` ,
Authorization : ` Bearer ${ session . accessToken } ` ,
'User-Agent' : userAgent ,
'User-Agent' : userAgent ,
@ -499,22 +507,21 @@ export class SubscriptionService implements Disposable {
throw new AccountValidationError ( 'Unable to validate account' , ex ) ;
throw new AccountValidationError ( 'Unable to validate account' , ex ) ;
} finally {
} finally {
this . startDailyCheckI nTimer ( ) ;
this . startDailyValidatio nTimer ( ) ;
}
}
}
}
private _dailyCheckInTimer : ReturnType < typeof setInterval > | undefined ;
private startDailyCheckInTimer ( ) : void {
if ( this . _dailyCheckInTimer != null ) {
clearInterval ( this . _dailyCheckInTimer ) ;
private startDailyValidationTimer ( ) : void {
if ( this . _validationTimer != null ) {
clearInterval ( this . _validationTimer ) ;
}
}
// Check twice a day to ensure we check in at least once a day
this . _dailyCheckI nTimer = setInterval ( ( ) = > {
// Check 4 times a day to ensure we validate at least once a day
this . _validatio nTimer = setInterval ( ( ) = > {
if ( this . _lastCheckInDate == null || this . _lastCheckInDate . getDate ( ) !== new Date ( ) . getDate ( ) ) {
if ( this . _lastCheckInDate == null || this . _lastCheckInDate . getDate ( ) !== new Date ( ) . getDate ( ) ) {
void this . ensureSession ( false , true ) ;
void this . ensureSession ( false , true ) ;
}
}
} , 1000 * 60 * 60 * 12 ) ;
} , 1000 * 60 * 60 * 6 ) ;
}
}
@debug ( )
@debug ( )