@@ -13,12 +13,16 @@ class ICloudController {
1313 private _tagHash : Map < number , Event > ;
1414 private _dataLoadingComplete : boolean ;
1515 private appSettings : SettingInterface ;
16+ private maxReconnectAttempt : number ;
17+ private reconnectAttempt : number ;
1618
1719 constructor ( ) {
1820 this . _tagHash = new Map < number , Event > ( ) ;
1921 this . _pendingTagsBuffer = [ ] ;
2022 this . _calendars = [ ] ;
2123 this . _dataLoadingComplete = false ;
24+ this . maxReconnectAttempt = 5 ;
25+ this . reconnectAttempt = 0 ;
2226 }
2327
2428 injectPath ( pluginPath : string ) {
@@ -76,13 +80,32 @@ class ICloudController {
7680 return await this . _calendarService . postEvent ( event . value , calendar . ctag ) ;
7781 }
7882
83+ async awaitReady ( ) {
84+ await this . _iCloud . awaitReady ;
85+ }
86+
7987 isLoggedIn ( ) {
8088 return this . _iCloud != undefined && ( this . _iCloud . status == iCloudServiceStatus . Ready || this . _iCloud . status == iCloudServiceStatus . Trusted )
8189 }
8290
8391 async getICloudEvents ( missedDateRange : DateRange ) : Promise < iCloudCalendarEvent [ ] > {
8492 return await this . _calendarService . events ( missedDateRange . start , missedDateRange . end ) ;
8593 }
94+
95+ refreshRequestCookies ( requestUrlParams : { url , method , headers , body } ) {
96+ const oldHeader = requestUrlParams . headers ;
97+ oldHeader . Cookie = this . _iCloud . authStore . getHeaders ( ) . Cookie ;
98+ return ;
99+ }
100+
101+ checkMaxReconnectAttempt ( ) : boolean {
102+ this . reconnectAttempt += 1 ;
103+ return this . reconnectAttempt < this . maxReconnectAttempt ;
104+ }
105+
106+ resetReconnectAttempt ( ) {
107+ this . reconnectAttempt = 0 ;
108+ }
86109}
87110
88111const iCloudController = new ICloudController ( ) ;
0 commit comments