Skip to content

Commit

Permalink
Add sign-out event handling and panel HTML refresh for CloudPanel (#1789
Browse files Browse the repository at this point in the history
)

* Add sign-out event handling and panel HTML refresh for CloudPanel

- Implemented emitPanelEvent in Kernel to emit specific events to panels.
- Added signOut event handling in CloudPanel, which clears the app token and refreshes the panel HTML.
- Updated extension.ts to emit signOut event when appropriate, aligning session management behavior.

* Easier done with more reactiveness (#1803)

---------

Co-authored-by: Sebastian (Tiedtke) Huckleberry <[email protected]>
  • Loading branch information
pastuxso and sourishkrout authored Nov 19, 2024
1 parent 076f24b commit e9cf5b9
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/extension/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,10 @@ export class RunmeExtension {
} else {
const settingsDefault = getServerLifecycleIdentity()
await commands.executeCommand('runme.lifecycleIdentitySelection', settingsDefault)
kernel.emitPanelEvent('runme.cloud', 'onCommand', {
name: 'signOut',
panelId: 'runme.cloud',
})
}
kernel.updateFeatureContext('statefulAuth', !!session)
})
Expand Down
16 changes: 16 additions & 0 deletions src/extension/kernel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import {
type ExtensionName,
type FeatureContext,
FeatureName,
SyncSchema,
} from '../types'
import {
ClientMessages,
Expand Down Expand Up @@ -243,6 +244,21 @@ export class Kernel implements Disposable {
return getEnvProps(ext)
}

emitPanelEvent<K extends keyof SyncSchema>(
panelId: string,
eventName: K,
payload: SyncSchema[K],
) {
const panel = this.panelManager.getPanel(panelId)

if (!panel) {
log.error(`Panel ${panelId} not found`)
return
}

panel.getBus()?.emit(eventName, payload)
}

useMonitor() {
return this.monitor$.asObservable()
}
Expand Down
27 changes: 24 additions & 3 deletions src/extension/panels/cloud.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { ExtensionContext, WebviewView, window, ColorThemeKind, Uri, env } from 'vscode'
import { from } from 'rxjs'
import { take, withLatestFrom } from 'rxjs/operators'

import { fetchStaticHtml, resolveAppToken } from '../utils'
import { IAppToken } from '../services/runme'
Expand Down Expand Up @@ -94,10 +96,11 @@ export default class CloudPanel extends TanglePanel {
protected registerSubscribers(bus: SyncSchemaBus) {
return [
bus.on('onCommand', (cmdEvent) => {
if (cmdEvent?.name !== 'signIn') {
return
if (cmdEvent?.name === 'signIn') {
this.onSignIn(bus)
} else if (cmdEvent?.name === 'signOut') {
this.onSignOut(bus)
}
this.onSignIn(bus)
}),
bus.on('onArchiveCell', async (cmdEvent) => {
const answer = await window.showInformationMessage(
Expand Down Expand Up @@ -151,6 +154,24 @@ export default class CloudPanel extends TanglePanel {
try {
const appToken = await this.getAppToken(true)
bus.emit('onAppToken', appToken!)
from(this.getHydratedHtml())
.pipe(withLatestFrom(this.webview), take(1))
.subscribe(([html, recentWebview]) => {
recentWebview.html = html
})
} catch (err: any) {
log.error(err?.message || err)
}
}

private async onSignOut(bus: SyncSchemaBus) {
try {
bus.emit('onAppToken', { token: 'EMPTY' })
from(this.getHydratedHtml())
.pipe(withLatestFrom(this.webview), take(1))
.subscribe(([html, recentWebview]) => {
recentWebview.html = html
})
} catch (err: any) {
log.error(err?.message || err)
}
Expand Down

0 comments on commit e9cf5b9

Please sign in to comment.