From 915230673903585308225e984e5142bac040ef51 Mon Sep 17 00:00:00 2001 From: Eugene Date: Thu, 7 May 2026 01:08:18 +0200 Subject: [PATCH] add user confirmation for zmodem transfers --- tabby-terminal/src/features/zmodem.ts | 39 ++++++++++++++++----------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/tabby-terminal/src/features/zmodem.ts b/tabby-terminal/src/features/zmodem.ts index ff25d24a..68b274d1 100644 --- a/tabby-terminal/src/features/zmodem.ts +++ b/tabby-terminal/src/features/zmodem.ts @@ -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 - 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): 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())) } }