mirror of
https://github.com/Eugeny/tabby.git
synced 2026-08-24 10:14:31 -05:00
add user confirmation for zmodem transfers
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
import colors from 'ansi-colors'
|
||||
import * as ZModem from 'zmodem.js'
|
||||
import { Observable, filter, first } from 'rxjs'
|
||||
import { Injectable } from '@angular/core'
|
||||
import { EnvironmentInjector, inject, Injectable } from '@angular/core'
|
||||
import { TerminalDecorator } from '../api/decorator'
|
||||
import { BaseTerminalTabComponent } from '../api/baseTerminalTab.component'
|
||||
import { SessionMiddleware } from '../api/middleware'
|
||||
import { LogService, Logger, HotkeysService, PlatformService, FileUpload } from 'tabby-core'
|
||||
import { LogService, Logger, PlatformService, FileUpload, TranslateService } from 'tabby-core'
|
||||
|
||||
const SPACER = ' '
|
||||
|
||||
@@ -16,15 +16,15 @@ class ZModemMiddleware extends SessionMiddleware {
|
||||
private activeSession: any = null
|
||||
private cancelEvent: Observable<any>
|
||||
|
||||
constructor (
|
||||
log: LogService,
|
||||
hotkeys: HotkeysService,
|
||||
private platform: PlatformService,
|
||||
) {
|
||||
private log = inject(LogService)
|
||||
private translate = inject(TranslateService)
|
||||
private platform = inject(PlatformService)
|
||||
|
||||
constructor () {
|
||||
super()
|
||||
this.cancelEvent = this.outputToSession$.pipe(filter(x => x.length === 1 && x[0] === 3))
|
||||
|
||||
this.logger = log.create('zmodem')
|
||||
this.logger = this.log.create('zmodem')
|
||||
this.sentry = new ZModem.Sentry({
|
||||
to_terminal: data => {
|
||||
if (this.isActive && this.activeSession) {
|
||||
@@ -33,6 +33,19 @@ class ZModemMiddleware extends SessionMiddleware {
|
||||
},
|
||||
sender: data => this.outputToSession.next(Buffer.from(data)),
|
||||
on_detect: async detection => {
|
||||
if ((await this.platform.showMessageBox({
|
||||
type: 'warning',
|
||||
message: this.translate.instant('Accept a ZMODEM session?'),
|
||||
buttons: [
|
||||
this.translate.instant('Accept'),
|
||||
this.translate.instant('Reject'),
|
||||
],
|
||||
defaultId: 0,
|
||||
cancelId: 1,
|
||||
})).response === 1) {
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
this.isActive = true
|
||||
await this.process(detection)
|
||||
@@ -229,13 +242,7 @@ class ZModemMiddleware extends SessionMiddleware {
|
||||
/** @hidden */
|
||||
@Injectable()
|
||||
export class ZModemDecorator extends TerminalDecorator {
|
||||
constructor (
|
||||
private log: LogService,
|
||||
private hotkeys: HotkeysService,
|
||||
private platform: PlatformService,
|
||||
) {
|
||||
super()
|
||||
}
|
||||
#injector = inject(EnvironmentInjector)
|
||||
|
||||
attach (terminal: BaseTerminalTabComponent<any>): void {
|
||||
setTimeout(() => {
|
||||
@@ -250,6 +257,6 @@ export class ZModemDecorator extends TerminalDecorator {
|
||||
if (!terminal.session) {
|
||||
return
|
||||
}
|
||||
terminal.session.middleware.unshift(new ZModemMiddleware(this.log, this.hotkeys, this.platform))
|
||||
terminal.session.middleware.unshift(this.#injector.runInContext(() => new ZModemMiddleware()))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user