import { Component , NgZone , OnInit , ViewEncapsulation } from '@angular/core' ; import { MatDialog } from '@angular/material/dialog' ; import { Router } from '@angular/router' ; import { OpenDialogReturnValue , remote } from 'electron' ; import { Logger } from '../../core/logger' ; import { ProductInformation } from '../../core/product-information' ; import { AppearanceService } from '../../services/appearance/appearance.service' ; import { CollectionService } from '../../services/collection/collection.service' ; import { TranslatorService } from '../../services/translator/translator.service' ; import { ErrorDialogComponent } from '../dialogs/error-dialog/error-dialog.component' ; @ Component ( { selector : 'app-welcome-page' , templateUrl : './welcome.component.html' , styleUrls : [ './welcome.component.scss' ] , encapsulation : ViewEncapsulation . None , } ) export class WelcomeComponent implements OnInit { constructor ( private translator , private collection , public appearance , private dialog , private zone , public router , private logger ) { } public applicationName : string = ProductInformation . applicationName . toUpperCase ( ) ; public isBusy : boolean = false ; public ngOnInit ( ) { } public async openDirectoryChooserAsync ( ) { this . logger . info ( 'Opening directory chooser' , 'WelcomeComponent' , 'openDirectoryChooserAsync' ) ; const selectFolderText = await this . translator . getAsync ( 'DialogTitles.SelectFolder' ) ; const openDialogReturnValue = await remote . dialog . showOpenDialog ( { title : selectFolderText , properties : [ 'openDirectory' ] , } ) ; if ( openDialogReturnValue == undefined || openDialogReturnValue . filePaths == undefined || openDialogReturnValue . filePaths . length === 0 ) { this . logger . warn ( 'No folder was selected' , 'WelcomeComponent' , 'openDirectoryChooserAsync' ) ; return ; } const selectedParentDirectory = openDialogReturnValue . filePaths [ 0 ] ; this . logger . info ( `Selected directory: '${ selectedParentDirectory }'` , 'WelcomeComponent' , 'openDirectoryChooserAsync' ) ; this . zone . run ( async ( ) => { this . isBusy = true ; if ( ! ( await this . collection . setStorageDirectoryAsync ( selectedParentDirectory ) ) ) { const errorText = await this . translator . getAsync ( 'ErrorTexts.StorageDirectoryCreationError' , { storageDirectory : selectedParentDirectory , } ) ; this . dialog . open ( ErrorDialogComponent , { width : '450px' , data : { errorText : errorText } , } ) ; } await this . collection . initializeAsync ( ) ; this . isBusy = false ; this . router . navigate ( [ '/collection' ] ) ; } ) ; } }