-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor StatefulAuthProvider for static initialization and improved …
…session management (#1822) * Work in progress * Creating singleton * Singletonization * Sync repo * Sync tests * Reapply "Add sign-out event handling and panel HTML refresh for CloudPanel (#1789)" This reverts commit 0f76025. * Add AuthSessionChangeHandler to prevent multiple listener calls * Passing tests * Remove internal usage of the context from the AuthSessionChangeHandler * Branch sync * Removing kernel and RunmeUriHandler dependencies. * Decrease debounce time * Silently asks If there is a session for CloudPanel * No more silence on error * COde cleanup * Removes unnecessary code * Implementing new argument for silent token * Rollback reactive approach, it’s not working According to the docs, the value (webview) is not being emmited, it’s because the subscription should be settled before the call of the .next() function I need help on it. * Test failling * Rollback panel getAppToken * Passing tests * Cleanup * Minor variable change * Renamed `getSession` to `currentSession` for better clarity. - Refactored `ensureSession` to operate as an instance method instead of static. - Removes unnecessary code * Remove token retrieval from `getHydratedHtml` to prevent double authentication * repository sync * Remove getPlatformAuthSession function * Updates tests * Minor fix * Emit `signIn` event to update panel when login is triggered externally * Use cloud over platform * Fix tests --------- Co-authored-by: Sebastian Tiedtke <[email protected]>
- Loading branch information
1 parent
cb51a6c
commit 1a55850
Showing
37 changed files
with
663 additions
and
415 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import { Subject, Subscription } from 'rxjs' | ||
import { debounceTime, distinctUntilChanged } from 'rxjs/operators' | ||
import { authentication, AuthenticationSessionsChangeEvent, Disposable } from 'vscode' | ||
|
||
export default class AuthSessionChangeHandler implements Disposable { | ||
static #instance: AuthSessionChangeHandler | null = null | ||
|
||
#disposables: Disposable[] = [] | ||
#eventSubject: Subject<AuthenticationSessionsChangeEvent> | ||
#subscriptions: Subscription[] = [] | ||
#listeners: ((event: AuthenticationSessionsChangeEvent) => void)[] = [] | ||
|
||
private constructor(private debounceTimeMs: number = 100) { | ||
this.#eventSubject = new Subject<AuthenticationSessionsChangeEvent>() | ||
this.#subscriptions.push( | ||
this.#eventSubject | ||
.pipe(distinctUntilChanged(this.eventComparer), debounceTime(this.debounceTimeMs)) | ||
.subscribe((event) => { | ||
this.notifyListeners(event) | ||
}), | ||
) | ||
|
||
this.#disposables.push( | ||
authentication.onDidChangeSessions((e) => { | ||
this.#eventSubject.next(e) | ||
}), | ||
) | ||
} | ||
|
||
public static get instance(): AuthSessionChangeHandler { | ||
if (!this.#instance) { | ||
this.#instance = new AuthSessionChangeHandler() | ||
} | ||
|
||
return this.#instance | ||
} | ||
|
||
public addListener(listener: (event: AuthenticationSessionsChangeEvent) => void): void { | ||
this.#listeners.push(listener) | ||
} | ||
|
||
public removeListener(listener: (event: AuthenticationSessionsChangeEvent) => void): void { | ||
this.#listeners = this.#listeners.filter((l) => l !== listener) | ||
} | ||
|
||
private notifyListeners(event: AuthenticationSessionsChangeEvent): void { | ||
for (const listener of this.#listeners) { | ||
try { | ||
listener(event) | ||
} catch (err) { | ||
console.error('Error in listener:', err) | ||
} | ||
} | ||
} | ||
|
||
private eventComparer( | ||
previous: AuthenticationSessionsChangeEvent, | ||
current: AuthenticationSessionsChangeEvent, | ||
): boolean { | ||
return ( | ||
previous.provider.id === current.provider.id && | ||
JSON.stringify(previous) === JSON.stringify(current) | ||
) | ||
} | ||
|
||
public async dispose() { | ||
this.#disposables.forEach((d) => d.dispose()) | ||
this.#subscriptions = [] | ||
this.#eventSubject.complete() | ||
this.#listeners = [] | ||
|
||
AuthSessionChangeHandler.#instance = null | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.