Skip to content

Commit

Permalink
V0.1.1
Browse files Browse the repository at this point in the history
- Fix Listener not removing if reconnected
- Fix console spam when not ssh session
- Made console log look better
  • Loading branch information
BowsiePup committed Jan 9, 2024
1 parent 2b41c41 commit 5110e9d
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions src/components/WebAuthHandler.TerminalDecorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,25 @@ export class WebAuthHandlerDecorator extends TerminalDecorator {
}

log(...args: any[]) {
console.log('[WebAuthHandler]', ...args)
console.log('%c[WebAuthHandler]', 'color: #aaa', ...args)
}

attach(tab: ExtendedTerminalTabComponent): void {
// Clone the tab object so we can log it without it being mutated
this.log('Attaching to tab')
this.log('Attaching to tab', tab)

if (!(tab.frontend instanceof XTermFrontend)) {
// not xterm
this.log('Detaching from tab. reason: not xterm')
return
}

if (tab.profile.type !== 'ssh') {
// not ssh
this.log('Detaching from tab. reason: not ssh')
return
}

this.createActiveKIPromptListener(tab)

// When data is output to the terminal, remove the listener because the session has connected
Expand All @@ -44,10 +50,7 @@ export class WebAuthHandlerDecorator extends TerminalDecorator {

// When sessionChanged is emitted, create a new listener for activeKIPrompt
tab.sessionChanged$.subscribe(() => {
if (!tab._activeKIPromptListener) {
this.log('Creating listener for activeKIPrompt. reason: sessionChanged')
this.createActiveKIPromptListener(tab)
}
this.sessionChanged(tab)
})
}

Expand All @@ -59,6 +62,20 @@ export class WebAuthHandlerDecorator extends TerminalDecorator {
}
}

sessionChanged(tab: ExtendedTerminalTabComponent): void {
if (!tab._activeKIPromptListener) {
this.log('Creating listener for activeKIPrompt. reason: session changed')
this.createActiveKIPromptListener(tab)

// When data is output to the terminal, remove the listener because the session has connected
const outputListener = tab.output$.subscribe(() => {
this.log('Detaching from tab. reason: output')
this.removeActiveKIPromptListener(tab)
outputListener.unsubscribe()
})
}
}

createActiveKIPromptListener(tab: ExtendedTerminalTabComponent): void {
this.log('Creating listener for activeKIPrompt')
tab._activeKIPromptListener = true
Expand Down

0 comments on commit 5110e9d

Please sign in to comment.