debounce tab progress updates

This commit is contained in:
Eugene Pankov 2022-01-22 14:16:59 +01:00
parent 53cbb8a7e3
commit 88bbdd0da1
No known key found for this signature in database
GPG key ID: 5896FCBBDD1CF4F4
3 changed files with 13 additions and 12 deletions

View file

@ -1,4 +1,4 @@
import { Observable, Subject, distinctUntilChanged } from 'rxjs' import { Observable, Subject, distinctUntilChanged, filter, debounceTime } from 'rxjs'
import { EmbeddedViewRef, ViewContainerRef, ViewRef } from '@angular/core' import { EmbeddedViewRef, ViewContainerRef, ViewRef } from '@angular/core'
import { RecoveryToken } from '../api/tabRecovery' import { RecoveryToken } from '../api/tabRecovery'
import { BaseComponent } from './base.component' import { BaseComponent } from './base.component'
@ -61,7 +61,6 @@ export abstract class BaseTabComponent extends BaseComponent {
/* @hidden */ /* @hidden */
viewContainerEmbeddedRef?: EmbeddedViewRef<any> viewContainerEmbeddedRef?: EmbeddedViewRef<any>
private progressClearTimeout: number
private titleChange = new Subject<string>() private titleChange = new Subject<string>()
private focused = new Subject<void>() private focused = new Subject<void>()
private blurred = new Subject<void>() private blurred = new Subject<void>()
@ -87,6 +86,12 @@ export abstract class BaseTabComponent extends BaseComponent {
this.blurred$.subscribe(() => { this.blurred$.subscribe(() => {
this.hasFocus = false this.hasFocus = false
}) })
this.subscribeUntilDestroyed(this.progress.pipe(
filter(x => x !== null),
debounceTime(5000),
), () => {
this.setProgress(null)
})
} }
setTitle (title: string): void { setTitle (title: string): void {
@ -103,14 +108,6 @@ export abstract class BaseTabComponent extends BaseComponent {
*/ */
setProgress (progress: number|null): void { setProgress (progress: number|null): void {
this.progress.next(progress) this.progress.next(progress)
if (progress) {
if (this.progressClearTimeout) {
clearTimeout(this.progressClearTimeout)
}
this.progressClearTimeout = setTimeout(() => {
this.setProgress(null)
}, 5000) as any
}
} }
/** /**

View file

@ -1,6 +1,7 @@
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */ /* eslint-disable @typescript-eslint/explicit-module-boundary-types */
import { Component, Input, Optional, Inject, HostBinding, HostListener, NgZone } from '@angular/core' import { Component, Input, Optional, Inject, HostBinding, HostListener, NgZone } from '@angular/core'
import { NgbModal } from '@ng-bootstrap/ng-bootstrap' import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
import { auditTime } from 'rxjs'
import { TabContextMenuItemProvider } from '../api/tabContextMenuProvider' import { TabContextMenuItemProvider } from '../api/tabContextMenuProvider'
import { BaseTabComponent } from './baseTab.component' import { BaseTabComponent } from './baseTab.component'
import { RenameTabModalComponent } from './renameTabModal.component' import { RenameTabModalComponent } from './renameTabModal.component'
@ -47,7 +48,9 @@ export class TabHeaderComponent extends BaseComponent {
} }
ngOnInit () { ngOnInit () {
this.subscribeUntilDestroyed(this.tab.progress$, progress => { this.subscribeUntilDestroyed(this.tab.progress$.pipe(
auditTime(300),
), progress => {
this.zone.run(() => { this.zone.run(() => {
this.progress = progress this.progress = progress
}) })

View file

@ -2,6 +2,7 @@ import { NgModule } from '@angular/core'
import { PlatformService, LogService, UpdaterService, DockingService, HostAppService, ThemesService, Platform, AppService, ConfigService, WIN_BUILD_FLUENT_BG_SUPPORTED, isWindowsBuild, HostWindowService, HotkeyProvider, ConfigProvider, FileProvider } from 'tabby-core' import { PlatformService, LogService, UpdaterService, DockingService, HostAppService, ThemesService, Platform, AppService, ConfigService, WIN_BUILD_FLUENT_BG_SUPPORTED, isWindowsBuild, HostWindowService, HotkeyProvider, ConfigProvider, FileProvider } from 'tabby-core'
import { TerminalColorSchemeProvider } from 'tabby-terminal' import { TerminalColorSchemeProvider } from 'tabby-terminal'
import { SFTPContextMenuItemProvider } from 'tabby-ssh' import { SFTPContextMenuItemProvider } from 'tabby-ssh'
import { auditTime } from 'rxjs'
import { HyperColorSchemes } from './colorSchemes' import { HyperColorSchemes } from './colorSchemes'
import { ElectronPlatformService } from './services/platform.service' import { ElectronPlatformService } from './services/platform.service'
@ -68,7 +69,7 @@ export default class ElectronModule {
let lastProgress: number|null = null let lastProgress: number|null = null
app.tabOpened$.subscribe(tab => { app.tabOpened$.subscribe(tab => {
tab.progress$.subscribe(progress => { tab.progress$.pipe(auditTime(250)).subscribe(progress => {
if (lastProgress === progress) { if (lastProgress === progress) {
return return
} }