import angular from 'angular' ; import autobind from 'autobind-decorator' ; import browser from 'webextension-polyfill' ; import { AppHelperService } from '../../../../app/shared/app-helper/app-helper.service' ; import { ApiService } from '../../../../shared/api/api.interface' ; import { BookmarkHelperService } from '../../../../shared/bookmark/bookmark-helper/bookmark-helper.service' ; import { ExceptionHandler } from '../../../../shared/errors/errors.interface' ; import Globals from '../../../../shared/global-shared.constants' ; import { MessageCommand } from '../../../../shared/global-shared.enum' ; import { LogService } from '../../../../shared/log/log.service' ; import { StoreService } from '../../../../shared/store/store.service' ; import { Sync } from '../../../../shared/sync/sync.interface' ; import { SyncService } from '../../../../shared/sync/sync.service' ; import { UtilityService } from '../../../../shared/utility/utility.service' ; import { WorkingService } from '../../../../shared/working/working.service' ; import { WebExtPlatformService } from '../../../shared/webext-platform/webext-platform.service' ; @ autobind export abstract class WebExtAppHelperService extends AppHelperService { $filter : ng . FilterFactory ; bookmarkHelperSvc : BookmarkHelperService ; platformSvc : WebExtPlatformService ; static $inject = [ '$exceptionHandler' , '$filter' , '$location' , '$q' , '$timeout' , 'ApiService' , 'BookmarkHelperService' , 'LogService' , 'PlatformService' , 'StoreService' , 'SyncService' , 'UtilityService' , 'WorkingService' ] ; constructor ( $exceptionHandler , $filter , $location , $q , $timeout , ApiSvc , BookmarkHelperSvc , LogSvc , PlatformSvc , StoreSvc , SyncSvc , UtilitySvc , WorkingSvc ) { super ( $exceptionHandler , $location , $q , $timeout , ApiSvc , LogSvc , PlatformSvc , StoreSvc , SyncSvc , UtilitySvc , WorkingSvc ) ; this . $filter = $filter ; this . bookmarkHelperSvc = BookmarkHelperSvc ; } confirmBeforeSyncing ( ) { return true ; } copyTextToClipboard ( text ) { return this . $q . resolve ( ) . then ( ( ) => navigator . clipboard . writeText ( text ) ) ; } currentUrlBookmarked ( ) { return this . utilitySvc . isSyncEnabled ( ) . then ( ( syncEnabled ) => { if ( ! syncEnabled ) { return false ; } return this . bookmarkHelperSvc . findCurrentUrlInBookmarks ( ) . then ( ( result ) => { return ! angular . isUndefined ( result ?? undefined ) ; } ) ; } ) ; } getCurrentSync ( ) { return this . platformSvc . sendMessage ( { command : MessageCommand . GetCurrentSync } ) ; } abstract getHelpPages ( ) ; getNextScheduledSyncUpdateCheck ( ) { return browser . alarms . get ( Globals . Alarms . SyncUpdatesCheck . Name ) . then ( ( alarm ) => { return ! alarm ? new Date ( '' ) : new Date ( alarm . scheduledTime ) ; } ) ; } getSyncQueueLength ( ) { return this . platformSvc . sendMessage ( { command : MessageCommand . GetSyncQueueLength } ) ; } openUrl ( event ? , url ? ) { event ?. preventDefault ( ) ; if ( url ) { this . platformSvc . openUrl ( url ) ; } else if ( event ?. currentTarget ) { this . platformSvc . openUrl ( ( event . currentTarget as HTMLLinkElement ) . href ) ; } else { this . logSvc . logWarning ( 'Couldn’t open url' ) ; } } removePermissions ( ) { return browser . permissions . remove ( this . platformSvc . optionalPermissions ) . then ( ( ) => { this . logSvc . logInfo ( 'Optional permissions removed' ) ; } ) ; } requestPermissions ( ) { return browser . permissions . request ( this . platformSvc . optionalPermissions ) . then ( ( granted ) => { this . logSvc . logInfo ( `Optional permissions ${ ! granted ? 'not ' : '' }granted` ) ; return granted ; } ) ; } }