import { DatePipe , Location } from "@angular/common" ; import { Component } from "@angular/core" ; import { ActivatedRoute , Router } from "@angular/router" ; import { first } from "rxjs/operators" ; import { EnvironmentService } from "jslib-common/abstractions/environment.service" ; import { I18nService } from "jslib-common/abstractions/i18n.service" ; import { LogService } from "jslib-common/abstractions/log.service" ; import { MessagingService } from "jslib-common/abstractions/messaging.service" ; import { PlatformUtilsService } from "jslib-common/abstractions/platformUtils.service" ; import { PolicyService } from "jslib-common/abstractions/policy.service" ; import { SendService } from "jslib-common/abstractions/send.service" ; import { UserService } from "jslib-common/abstractions/user.service" ; import { PopupUtilsService } from "../services/popup-utils.service" ; import { AddEditComponent as BaseAddEditComponent } from "jslib-angular/components/send/add-edit.component" ; @ Component ( { selector : "app-send-add-edit" , templateUrl : "send-add-edit.component.html" , } ) export class SendAddEditComponent extends BaseAddEditComponent { showOptions = false ; isFirefox = false ; inPopout = false ; inSidebar = false ; isLinux = false ; isUnsupportedMac = false ; constructor ( i18nService , platformUtilsService , userService , messagingService , policyService , environmentService , datePipe , sendService , private route , private router , private location , private popupUtilsService , logService ) { super ( i18nService , platformUtilsService , environmentService , datePipe , sendService , userService , messagingService , policyService , logService ) ; } get showFileSelector ( ) : boolean { return ! ( this . editMode || this . showFilePopoutMessage ) ; } get showFilePopoutMessage ( ) : boolean { return ( ! this . editMode && ( this . showFirefoxFileWarning || this . showSafariFileWarning || this . showChromiumFileWarning ) ) ; } get showFirefoxFileWarning ( ) : boolean { return this . isFirefox && ! ( this . inSidebar || this . inPopout ) ; } get showSafariFileWarning ( ) : boolean { return this . isSafari && ! this . inPopout ; } get showChromiumFileWarning ( ) : boolean { return ( ( this . isLinux || this . isUnsupportedMac ) && ! this . isFirefox && ! ( this . inSidebar || this . inPopout ) ) ; } popOutWindow ( ) { this . popupUtilsService . popOut ( window ) ; } async ngOnInit ( ) { this . isFirefox = this . platformUtilsService . isFirefox ( ) ; this . inPopout = this . popupUtilsService . inPopout ( window ) ; this . inSidebar = this . popupUtilsService . inSidebar ( window ) ; this . isLinux = window ?. navigator ?. userAgent . indexOf ( "Linux" ) !== - 1 ; this . isUnsupportedMac = this . platformUtilsService . isChrome ( ) && window ?. navigator ?. appVersion . includes ( "Mac OS X 11" ) ; this . route . queryParams . pipe ( first ( ) ) . subscribe ( async ( params ) => { if ( params . sendId ) { this . sendId = params . sendId ; } if ( params . type ) { const type = parseInt ( params . type , null ) ; this . type = type ; } await this . load ( ) ; } ) ; window . setTimeout ( ( ) => { if ( ! this . editMode ) { document . getElementById ( "name" ) . focus ( ) ; } } , 200 ) ; } async submit ( ) { if ( await super . submit ( ) ) { this . cancel ( ) ; return true ; } return false ; } async delete ( ) { if ( await super . delete ( ) ) { this . cancel ( ) ; return true ; } return false ; } cancel ( ) { if ( ( window as any ) . previousPopupUrl . startsWith ( "/add-send" ) ) { this . router . navigate ( [ "tabs/send" ] ) ; } else { this . location . back ( ) ; } } }