2021-08-18 00:01:11 +02:00
< template >
< div class = "text-white max-h-screen h-screen overflow-hidden bg-bg" >
< app -appbar / >
2021-09-23 03:40:35 +02:00
2021-08-18 00:01:11 +02:00
< Nuxt / >
2021-09-23 03:40:35 +02:00
2021-08-18 00:01:11 +02:00
< app -stream -container ref = "streamContainer" / >
2021-10-23 03:08:02 +02:00
2022-03-15 00:53:49 +01:00
< modals -item -edit -modal / >
2021-11-06 02:24:02 +01:00
< modals -user -collections -modal / >
2021-11-07 02:31:46 +01:00
< modals -edit -collection -modal / >
2021-11-28 03:11:35 +01:00
< modals -bookshelf -texture -modal / >
2021-10-18 01:05:43 +02:00
< readers -reader / >
2021-08-18 00:01:11 +02:00
< / div >
< / template >
< script >
2021-10-05 05:11:42 +02:00
import CloseButton from '@/components/widgets/CloseButton'
2021-08-18 00:01:11 +02:00
export default {
2021-08-24 02:37:40 +02:00
middleware : 'authenticated' ,
2021-08-18 00:01:11 +02:00
data ( ) {
return {
2021-11-07 20:02:56 +01:00
socket : null ,
isSocketConnected : false ,
isFirstSocketConnection : true ,
socketConnectionToastId : null
2021-08-18 00:01:11 +02:00
}
} ,
watch : {
$route ( newVal ) {
if ( this . $store . state . showEditModal ) {
this . $store . commit ( 'setShowEditModal' , false )
}
2022-03-13 23:10:48 +01:00
if ( this . $store . state . selectedLibraryItems ) {
this . $store . commit ( 'setSelectedLibraryItems' , [ ] )
2021-08-27 01:32:05 +02:00
}
2021-08-18 00:01:11 +02:00
}
} ,
computed : {
user ( ) {
2021-08-24 01:31:04 +02:00
return this . $store . state . user . user
2022-02-23 00:33:55 +01:00
} ,
isCasting ( ) {
return this . $store . state . globals . isCasting
2021-08-18 00:01:11 +02:00
}
} ,
methods : {
2021-12-04 01:03:34 +01:00
updateSocketConnectionToast ( content , type , timeout ) {
if ( this . socketConnectionToastId !== null && this . socketConnectionToastId !== undefined ) {
this . $toast . update ( this . socketConnectionToastId , { content : content , options : { timeout : timeout , type : type , closeButton : false , position : 'bottom-center' , onClose : ( ) => null , closeOnClick : timeout !== null } } , false )
} else {
this . socketConnectionToastId = this . $toast [ type ] ( content , { position : 'bottom-center' , timeout : timeout , closeButton : false , closeOnClick : timeout !== null } )
}
} ,
2021-08-18 00:01:11 +02:00
connect ( ) {
console . log ( '[SOCKET] Connected' )
2021-08-24 01:31:04 +02:00
var token = this . $store . getters [ 'user/getToken' ]
2021-08-18 00:01:11 +02:00
this . socket . emit ( 'auth' , token )
2021-11-07 20:02:56 +01:00
2021-12-04 01:03:34 +01:00
if ( ! this . isFirstSocketConnection || this . socketConnectionToastId !== null ) {
this . updateSocketConnectionToast ( 'Socket Connected' , 'success' , 5000 )
2021-11-07 20:02:56 +01:00
}
this . isFirstSocketConnection = false
this . isSocketConnected = true
} ,
connectError ( ) {
console . error ( '[SOCKET] connect error' )
2021-12-04 01:03:34 +01:00
this . updateSocketConnectionToast ( 'Socket Failed to Connect' , 'error' , null )
2021-08-18 00:01:11 +02:00
} ,
disconnect ( ) {
console . log ( '[SOCKET] Disconnected' )
2021-11-07 20:02:56 +01:00
this . isSocketConnected = false
2021-12-04 01:03:34 +01:00
this . updateSocketConnectionToast ( 'Socket Disconnected' , 'error' , null )
2021-11-07 20:02:56 +01:00
} ,
reconnect ( ) {
console . error ( '[SOCKET] reconnected' )
} ,
2021-12-04 01:03:34 +01:00
reconnectAttempt ( val ) {
console . log ( ` [SOCKET] reconnect attempt ${ val } ` )
2021-11-07 20:02:56 +01:00
} ,
reconnectError ( ) {
2021-12-04 01:03:34 +01:00
// console.error('[SOCKET] reconnect error')
2021-11-07 20:02:56 +01:00
} ,
reconnectFailed ( ) {
console . error ( '[SOCKET] reconnect failed' )
2021-08-18 00:01:11 +02:00
} ,
2022-01-06 01:01:33 +01:00
init ( payload , count = 0 ) {
if ( ! this . $refs . streamContainer ) {
if ( count > 20 ) {
console . error ( 'Stream container never mounted' )
return
}
setTimeout ( ( ) => {
this . init ( payload , ++ count )
} , 100 )
return
}
2021-08-18 00:01:11 +02:00
console . log ( 'Init Payload' , payload )
if ( payload . stream ) {
if ( this . $refs . streamContainer ) {
this . $refs . streamContainer . streamOpen ( payload . stream )
2022-01-06 01:01:33 +01:00
} else {
console . warn ( 'Stream Container not mounted' )
2021-08-18 00:01:11 +02:00
}
}
if ( payload . user ) {
2021-08-24 01:31:04 +02:00
this . $store . commit ( 'user/setUser' , payload . user )
this . $store . commit ( 'user/setSettings' , payload . user . settings )
2021-08-18 00:01:11 +02:00
}
2021-09-05 02:58:39 +02:00
if ( payload . serverSettings ) {
this . $store . commit ( 'setServerSettings' , payload . serverSettings )
2022-02-23 00:33:55 +01:00
if ( payload . serverSettings . chromecastEnabled ) {
console . log ( 'Chromecast enabled import script' )
require ( '@/plugins/chromecast.js' ) . default ( this )
}
2021-09-05 02:58:39 +02:00
}
2021-11-26 01:39:02 +01:00
// Start scans currently running
2021-10-06 04:10:49 +02:00
if ( payload . librariesScanning ) {
payload . librariesScanning . forEach ( ( libraryScan ) => {
this . scanStart ( libraryScan )
} )
}
2021-11-26 01:39:02 +01:00
// Remove any current scans that are no longer running
var currentScans = [ ... this . $store . state . scanners . libraryScans ]
currentScans . forEach ( ( ls ) => {
if ( ! payload . librariesScanning || ! payload . librariesScanning . find ( ( _ls ) => _ls . id === ls . id ) ) {
this . $toast . dismiss ( ls . toastId )
this . $store . commit ( 'scanners/remove' , ls )
}
} )
2021-10-09 00:30:20 +02:00
if ( payload . backups && payload . backups . length ) {
this . $store . commit ( 'setBackups' , payload . backups )
}
2021-10-23 03:08:02 +02:00
if ( payload . usersOnline ) {
this . $store . commit ( 'users/resetUsers' )
payload . usersOnline . forEach ( ( user ) => {
this . $store . commit ( 'users/updateUser' , user )
} )
}
2021-12-21 02:26:22 +01:00
this . $eventBus . $emit ( 'socket_init' )
2021-08-18 00:01:11 +02:00
} ,
streamOpen ( stream ) {
if ( this . $refs . streamContainer ) this . $refs . streamContainer . streamOpen ( stream )
} ,
streamClosed ( streamId ) {
if ( this . $refs . streamContainer ) this . $refs . streamContainer . streamClosed ( streamId )
} ,
streamProgress ( data ) {
if ( this . $refs . streamContainer ) this . $refs . streamContainer . streamProgress ( data )
} ,
streamReady ( ) {
if ( this . $refs . streamContainer ) this . $refs . streamContainer . streamReady ( )
} ,
streamReset ( payload ) {
if ( this . $refs . streamContainer ) this . $refs . streamContainer . streamReset ( payload )
} ,
2021-11-13 22:24:56 +01:00
streamError ( { id , errorMessage } ) {
this . $toast . error ( ` Stream Failed: ${ errorMessage } ` )
if ( this . $refs . streamContainer ) this . $refs . streamContainer . streamError ( id )
} ,
2021-10-05 05:11:42 +02:00
libraryAdded ( library ) {
this . $store . commit ( 'libraries/addUpdate' , library )
} ,
libraryUpdated ( library ) {
this . $store . commit ( 'libraries/addUpdate' , library )
} ,
libraryRemoved ( library ) {
this . $store . commit ( 'libraries/remove' , library )
} ,
2022-03-13 02:59:35 +01:00
libraryItemAdded ( libraryItem ) {
// this.$store.commit('libraries/updateFilterDataWithAudiobook', libraryItem)
} ,
2022-03-12 02:46:32 +01:00
libraryItemUpdated ( libraryItem ) {
if ( this . $store . state . selectedLibraryItem && this . $store . state . selectedLibraryItem . id === libraryItem . id ) {
this . $store . commit ( 'setSelectedLibraryItem' , libraryItem )
}
this . $eventBus . $emit ( ` ${ libraryItem . id } _updated ` , libraryItem )
} ,
2022-03-13 00:45:32 +01:00
libraryItemRemoved ( item ) {
if ( this . $route . name . startsWith ( 'item' ) ) {
if ( this . $route . params . id === item . id ) {
this . $router . replace ( ` /library/ ${ this . $store . state . libraries . currentLibraryId } ` )
}
}
} ,
2022-03-13 02:59:35 +01:00
libraryItemsUpdated ( libraryItems ) {
libraryItems . forEach ( ( li ) => {
this . libraryItemUpdated ( li )
} )
} ,
libraryItemsAdded ( libraryItems ) {
libraryItems . forEach ( ( ab ) => {
this . libraryItemAdded ( ab )
} )
} ,
2021-10-05 05:11:42 +02:00
scanComplete ( data ) {
2021-11-26 01:39:02 +01:00
console . log ( 'Scan complete received' , data )
2022-02-16 01:33:33 +01:00
var message = ` ${ data . type === 'match' ? 'Match' : 'Scan' } " ${ data . name } " complete! `
2021-10-05 05:11:42 +02:00
if ( data . results ) {
var scanResultMsgs = [ ]
var results = data . results
if ( results . added ) scanResultMsgs . push ( ` ${ results . added } added ` )
if ( results . updated ) scanResultMsgs . push ( ` ${ results . updated } updated ` )
if ( results . removed ) scanResultMsgs . push ( ` ${ results . removed } removed ` )
if ( results . missing ) scanResultMsgs . push ( ` ${ results . missing } missing ` )
if ( ! scanResultMsgs . length ) message += '\nEverything was up to date'
else message += '\n' + scanResultMsgs . join ( '\n' )
2021-08-25 03:24:40 +02:00
} else {
2022-02-16 01:33:33 +01:00
message = ` ${ data . type === 'match' ? 'Match' : 'Scan' } " ${ data . name } " was canceled `
2021-08-25 03:24:40 +02:00
}
2021-10-05 05:11:42 +02:00
var existingScan = this . $store . getters [ 'scanners/getLibraryScan' ] ( data . id )
if ( existingScan && ! isNaN ( existingScan . toastId ) ) {
2021-10-06 04:10:49 +02:00
this . $toast . update ( existingScan . toastId , { content : message , options : { timeout : 5000 , type : 'success' , closeButton : false , position : 'bottom-center' , onClose : ( ) => null } } , true )
2021-08-25 03:24:40 +02:00
} else {
2021-10-05 05:11:42 +02:00
this . $toast . success ( message , { timeout : 5000 , position : 'bottom-center' } )
2021-08-25 03:24:40 +02:00
}
2021-10-05 05:11:42 +02:00
this . $store . commit ( 'scanners/remove' , data )
2021-08-18 00:01:11 +02:00
} ,
2021-10-05 05:11:42 +02:00
onScanToastCancel ( id ) {
this . $root . socket . emit ( 'cancel_scan' , id )
} ,
scanStart ( data ) {
2022-02-16 01:33:33 +01:00
data . toastId = this . $toast ( ` ${ data . type === 'match' ? 'Matching' : 'Scanning' } " ${ data . name } "... ` , { timeout : false , type : 'info' , draggable : false , closeOnClick : false , closeButton : CloseButton , closeButtonClassName : 'cancel-scan-btn' , showCloseButtonOnHover : false , position : 'bottom-center' , onClose : ( ) => this . onScanToastCancel ( data . id ) } )
2021-10-05 05:11:42 +02:00
this . $store . commit ( 'scanners/addUpdate' , data )
} ,
scanProgress ( data ) {
var existingScan = this . $store . getters [ 'scanners/getLibraryScan' ] ( data . id )
if ( existingScan && ! isNaN ( existingScan . toastId ) ) {
data . toastId = existingScan . toastId
this . $toast . update ( existingScan . toastId , { content : ` Scanning " ${ existingScan . name } "... ${ data . progress . progress || 0 } % ` , options : { timeout : false } } , true )
2021-10-06 04:10:49 +02:00
} else {
data . toastId = this . $toast ( ` Scanning " ${ data . name } "... ` , { timeout : false , type : 'info' , draggable : false , closeOnClick : false , closeButton : CloseButton , closeButtonClassName : 'cancel-scan-btn' , showCloseButtonOnHover : false , position : 'bottom-center' , onClose : ( ) => this . onScanToastCancel ( data . id ) } )
2021-08-25 03:24:40 +02:00
}
2021-10-05 05:11:42 +02:00
this . $store . commit ( 'scanners/addUpdate' , data )
2021-08-18 00:01:11 +02:00
} ,
userUpdated ( user ) {
2021-08-24 01:31:04 +02:00
if ( this . $store . state . user . user . id === user . id ) {
this . $store . commit ( 'user/setUser' , user )
this . $store . commit ( 'user/setSettings' , user . settings )
2021-08-18 00:01:11 +02:00
}
} ,
2021-10-13 03:07:42 +02:00
userOnline ( user ) {
this . $store . commit ( 'users/updateUser' , user )
} ,
userOffline ( user ) {
this . $store . commit ( 'users/removeUser' , user )
} ,
userStreamUpdate ( user ) {
this . $store . commit ( 'users/updateUser' , user )
} ,
2021-10-24 22:53:51 +02:00
currentUserAudiobookUpdate ( payload ) {
this . $store . commit ( 'user/updateUserAudiobook' , payload )
} ,
2021-11-06 02:24:02 +01:00
collectionAdded ( collection ) {
this . $store . commit ( 'user/addUpdateCollection' , collection )
} ,
collectionUpdated ( collection ) {
this . $store . commit ( 'user/addUpdateCollection' , collection )
} ,
collectionRemoved ( collection ) {
2021-11-07 02:31:46 +01:00
if ( this . $route . name . startsWith ( 'collection' ) ) {
if ( this . $route . params . id === collection . id ) {
this . $router . replace ( ` /library/ ${ this . $store . state . libraries . currentLibraryId } /bookshelf/collections ` )
}
}
2021-11-06 02:24:02 +01:00
this . $store . commit ( 'user/removeCollection' , collection )
} ,
2021-09-15 03:45:00 +02:00
downloadToastClick ( download ) {
2021-09-18 01:40:30 +02:00
if ( ! download || ! download . audiobookId ) {
return console . error ( 'Invalid download object' , download )
}
2021-09-15 03:45:00 +02:00
} ,
2021-09-04 21:17:26 +02:00
downloadStarted ( download ) {
2021-09-15 03:45:00 +02:00
download . status = this . $constants . DownloadStatus . PENDING
2021-09-18 01:40:30 +02:00
download . toastId = this . $toast ( ` Preparing download " ${ download . filename } " ` , { timeout : false , draggable : false , closeOnClick : false , onClick : ( ) => this . downloadToastClick ( download ) } )
2021-09-04 21:17:26 +02:00
this . $store . commit ( 'downloads/addUpdateDownload' , download )
} ,
downloadReady ( download ) {
2021-09-15 03:45:00 +02:00
download . status = this . $constants . DownloadStatus . READY
var existingDownload = this . $store . getters [ 'downloads/getDownload' ] ( download . id )
2021-09-04 21:17:26 +02:00
2021-09-15 03:45:00 +02:00
if ( existingDownload && existingDownload . toastId !== undefined ) {
download . toastId = existingDownload . toastId
2021-09-18 01:40:30 +02:00
this . $toast . update ( existingDownload . toastId , { content : ` Download " ${ download . filename } " is ready! ` , options : { timeout : 5000 , type : 'success' , onClick : ( ) => this . downloadToastClick ( download ) } } , true )
2021-09-15 03:45:00 +02:00
} else {
this . $toast . success ( ` Download " ${ download . filename } " is ready! ` )
}
2021-09-04 21:17:26 +02:00
this . $store . commit ( 'downloads/addUpdateDownload' , download )
} ,
downloadFailed ( download ) {
2021-09-15 03:45:00 +02:00
download . status = this . $constants . DownloadStatus . FAILED
var existingDownload = this . $store . getters [ 'downloads/getDownload' ] ( download . id )
var failedMsg = download . isTimedOut ? 'timed out' : 'failed'
2021-09-04 21:17:26 +02:00
2021-09-15 03:45:00 +02:00
if ( existingDownload && existingDownload . toastId !== undefined ) {
download . toastId = existingDownload . toastId
2021-09-18 01:40:30 +02:00
this . $toast . update ( existingDownload . toastId , { content : ` Download " ${ download . filename } " ${ failedMsg } ` , options : { timeout : 5000 , type : 'error' , onClick : ( ) => this . downloadToastClick ( download ) } } , true )
2021-09-15 03:45:00 +02:00
} else {
console . warn ( 'Download failed no existing download' , existingDownload )
this . $toast . error ( ` Download " ${ download . filename } " ${ failedMsg } ` )
}
2021-09-04 21:17:26 +02:00
this . $store . commit ( 'downloads/addUpdateDownload' , download )
} ,
downloadKilled ( download ) {
2021-09-15 03:45:00 +02:00
var existingDownload = this . $store . getters [ 'downloads/getDownload' ] ( download . id )
if ( existingDownload && existingDownload . toastId !== undefined ) {
download . toastId = existingDownload . toastId
2021-09-18 01:40:30 +02:00
this . $toast . update ( existingDownload . toastId , { content : ` Download " ${ download . filename } " was terminated ` , options : { timeout : 5000 , type : 'error' , onClick : ( ) => this . downloadToastClick ( download ) } } , true )
2021-09-15 03:45:00 +02:00
} else {
console . warn ( 'Download killed no existing download found' , existingDownload )
this . $toast . error ( ` Download " ${ download . filename } " was terminated ` )
}
2021-09-04 21:17:26 +02:00
this . $store . commit ( 'downloads/removeDownload' , download )
} ,
downloadExpired ( download ) {
2021-09-15 03:45:00 +02:00
download . status = this . $constants . DownloadStatus . EXPIRED
2021-09-04 21:17:26 +02:00
this . $store . commit ( 'downloads/addUpdateDownload' , download )
} ,
2021-10-27 03:09:04 +02:00
showErrorToast ( message ) {
this . $toast . error ( message )
} ,
showSuccessToast ( message ) {
this . $toast . success ( message )
} ,
2021-10-09 00:30:20 +02:00
backupApplied ( ) {
// Force refresh
location . reload ( )
} ,
2021-08-18 00:01:11 +02:00
initializeSocket ( ) {
this . socket = this . $nuxtSocket ( {
name : process . env . NODE _ENV === 'development' ? 'dev' : 'prod' ,
persist : 'main' ,
2021-11-07 20:02:56 +01:00
teardown : false ,
2021-08-18 00:01:11 +02:00
transports : [ 'websocket' ] ,
2021-11-07 20:02:56 +01:00
upgrade : false ,
reconnection : true
2021-08-18 00:01:11 +02:00
} )
2021-11-07 22:28:06 +01:00
this . $root . socket = this . socket
2021-12-02 02:07:03 +01:00
console . log ( 'Socket initialized' )
2021-08-18 00:01:11 +02:00
this . socket . on ( 'connect' , this . connect )
this . socket . on ( 'connect_error' , this . connectError )
this . socket . on ( 'disconnect' , this . disconnect )
2021-12-04 01:03:34 +01:00
this . socket . io . on ( 'reconnect_attempt' , this . reconnectAttempt )
2021-11-07 20:02:56 +01:00
this . socket . io . on ( 'reconnect' , this . reconnect )
this . socket . io . on ( 'reconnect_error' , this . reconnectError )
this . socket . io . on ( 'reconnect_failed' , this . reconnectFailed )
2021-08-18 00:01:11 +02:00
this . socket . on ( 'init' , this . init )
// Stream Listeners
this . socket . on ( 'stream_open' , this . streamOpen )
this . socket . on ( 'stream_closed' , this . streamClosed )
this . socket . on ( 'stream_progress' , this . streamProgress )
this . socket . on ( 'stream_ready' , this . streamReady )
this . socket . on ( 'stream_reset' , this . streamReset )
2021-11-13 22:24:56 +01:00
this . socket . on ( 'stream_error' , this . streamError )
2021-08-18 00:01:11 +02:00
2021-10-05 05:11:42 +02:00
// Library Listeners
this . socket . on ( 'library_updated' , this . libraryUpdated )
this . socket . on ( 'library_added' , this . libraryAdded )
this . socket . on ( 'library_removed' , this . libraryRemoved )
2022-03-12 02:46:32 +01:00
// Library Item Listeners
2022-03-13 02:59:35 +01:00
this . socket . on ( 'item_added' , this . libraryItemAdded )
2022-03-12 02:46:32 +01:00
this . socket . on ( 'item_updated' , this . libraryItemUpdated )
2022-03-13 00:45:32 +01:00
this . socket . on ( 'item_removed' , this . libraryItemRemoved )
2022-03-13 02:59:35 +01:00
this . socket . on ( 'items_updated' , this . libraryItemsUpdated )
this . socket . on ( 'items_added' , this . libraryItemsAdded )
2022-03-12 02:46:32 +01:00
2021-08-18 00:01:11 +02:00
// User Listeners
this . socket . on ( 'user_updated' , this . userUpdated )
2021-10-13 03:07:42 +02:00
this . socket . on ( 'user_online' , this . userOnline )
this . socket . on ( 'user_offline' , this . userOffline )
this . socket . on ( 'user_stream_update' , this . userStreamUpdate )
2021-10-24 22:53:51 +02:00
this . socket . on ( 'current_user_audiobook_update' , this . currentUserAudiobookUpdate )
2021-08-18 00:01:11 +02:00
2021-11-06 02:24:02 +01:00
// User Collection Listeners
this . socket . on ( 'collection_added' , this . collectionAdded )
this . socket . on ( 'collection_updated' , this . collectionUpdated )
this . socket . on ( 'collection_removed' , this . collectionRemoved )
2021-08-18 00:01:11 +02:00
// Scan Listeners
this . socket . on ( 'scan_start' , this . scanStart )
this . socket . on ( 'scan_complete' , this . scanComplete )
this . socket . on ( 'scan_progress' , this . scanProgress )
2021-09-04 21:17:26 +02:00
// Download Listeners
this . socket . on ( 'download_started' , this . downloadStarted )
this . socket . on ( 'download_ready' , this . downloadReady )
this . socket . on ( 'download_failed' , this . downloadFailed )
this . socket . on ( 'download_killed' , this . downloadKilled )
this . socket . on ( 'download_expired' , this . downloadExpired )
2021-10-01 01:52:32 +02:00
2021-10-27 03:09:04 +02:00
// Toast Listeners
this . socket . on ( 'show_error_toast' , this . showErrorToast )
this . socket . on ( 'show_success_toast' , this . showSuccessToast )
2021-10-09 00:30:20 +02:00
this . socket . on ( 'backup_applied' , this . backupApplied )
2021-09-16 00:59:38 +02:00
} ,
showUpdateToast ( versionData ) {
var ignoreVersion = localStorage . getItem ( 'ignoreVersion' )
var latestVersion = versionData . latestVersion
if ( ! ignoreVersion || ignoreVersion !== latestVersion ) {
this . $toast . info ( ` Update is available! \ nCheck release notes for v ${ versionData . latestVersion } ` , {
position : 'top-center' ,
toastClassName : 'cursor-pointer' ,
bodyClassName : 'custom-class-1' ,
timeout : 20000 ,
closeOnClick : false ,
draggable : false ,
hideProgressBar : false ,
onClick : ( ) => {
window . open ( versionData . githubTagUrl , '_blank' )
} ,
onClose : ( ) => {
localStorage . setItem ( 'ignoreVersion' , versionData . latestVersion )
}
} )
} else {
console . warn ( ` Update is available but user chose to dismiss it! v ${ versionData . latestVersion } ` )
}
2021-10-23 03:08:02 +02:00
} ,
checkActiveElementIsInput ( ) {
var activeElement = document . activeElement
var inputs = [ 'input' , 'select' , 'button' , 'textarea' ]
return activeElement && inputs . indexOf ( activeElement . tagName . toLowerCase ( ) ) !== - 1
} ,
2021-10-24 21:02:49 +02:00
getHotkeyName ( e ) {
2021-10-23 23:49:34 +02:00
var keyCode = e . keyCode || e . which
if ( ! this . $keynames [ keyCode ] ) {
// Unused hotkey
2021-10-24 21:02:49 +02:00
return null
2021-10-23 03:08:02 +02:00
}
2021-10-23 23:49:34 +02:00
var keyName = this . $keynames [ keyCode ]
var name = keyName
if ( e . shiftKey ) name = 'Shift-' + keyName
if ( process . env . NODE _ENV !== 'production' ) {
console . log ( 'Hotkey command' , name )
}
2021-10-24 21:02:49 +02:00
return name
} ,
keyDown ( e ) {
var name = this . getHotkeyName ( e )
if ( ! name ) return
2021-10-23 23:49:34 +02:00
// Input is focused then ignore key press
2021-10-23 03:08:02 +02:00
if ( this . checkActiveElementIsInput ( ) ) {
return
}
2021-10-23 23:49:34 +02:00
// Modal is open
2021-10-24 21:02:49 +02:00
if ( this . $store . state . openModal && Object . values ( this . $hotkeys . Modal ) . includes ( name ) ) {
2021-10-23 23:49:34 +02:00
this . $eventBus . $emit ( 'modal-hotkey' , name )
2021-10-24 21:02:49 +02:00
e . preventDefault ( )
2021-10-23 23:49:34 +02:00
return
}
// EReader is open
2021-10-24 21:02:49 +02:00
if ( this . $store . state . showEReader && Object . values ( this . $hotkeys . EReader ) . includes ( name ) ) {
2021-10-23 23:49:34 +02:00
this . $eventBus . $emit ( 'reader-hotkey' , name )
2021-10-24 21:02:49 +02:00
e . preventDefault ( )
2021-10-23 23:49:34 +02:00
return
}
// Batch selecting
2022-03-13 23:10:48 +01:00
if ( this . $store . getters [ 'getNumLibraryItemsSelected' ] && name === 'Escape' ) {
2021-10-23 23:49:34 +02:00
// ESCAPE key cancels batch selection
2022-03-13 23:10:48 +01:00
this . $store . commit ( 'setSelectedLibraryItems' , [ ] )
2021-12-02 02:07:03 +01:00
this . $eventBus . $emit ( 'bookshelf-clear-selection' )
2021-10-24 21:02:49 +02:00
e . preventDefault ( )
2021-10-23 03:08:02 +02:00
return
}
// Playing audiobook
2022-03-14 01:34:31 +01:00
if ( this . $store . state . streamLibraryItem && Object . values ( this . $hotkeys . AudioPlayer ) . includes ( name ) ) {
2021-10-23 23:49:34 +02:00
this . $eventBus . $emit ( 'player-hotkey' , name )
2021-10-24 21:02:49 +02:00
e . preventDefault ( )
2021-10-23 03:08:02 +02:00
}
2022-02-09 18:19:02 +01:00
} ,
resize ( ) {
this . $store . commit ( 'globals/updateWindowSize' , { width : window . innerWidth , height : window . innerHeight } )
2021-08-18 00:01:11 +02:00
}
} ,
2021-12-02 02:07:03 +01:00
beforeMount ( ) {
this . initializeSocket ( )
} ,
2021-08-18 00:01:11 +02:00
mounted ( ) {
2022-02-09 18:19:02 +01:00
this . resize ( )
window . addEventListener ( 'resize' , this . resize )
2021-10-24 21:02:49 +02:00
window . addEventListener ( 'keydown' , this . keyDown )
2022-02-23 00:33:55 +01:00
2021-10-05 05:11:42 +02:00
this . $store . dispatch ( 'libraries/load' )
2021-10-07 04:08:52 +02:00
// If experimental features set in local storage
var experimentalFeaturesSaved = localStorage . getItem ( 'experimental' )
if ( experimentalFeaturesSaved === '1' ) {
this . $store . commit ( 'setExperimentalFeatures' , true )
}
2021-09-16 00:59:38 +02:00
this . $store
. dispatch ( 'checkForUpdate' )
. then ( ( res ) => {
if ( res && res . hasUpdate ) this . showUpdateToast ( res )
} )
. catch ( ( err ) => console . error ( err ) )
2021-08-27 14:01:47 +02:00
if ( this . $route . query . error ) {
this . $toast . error ( this . $route . query . error )
this . $router . replace ( this . $route . path )
}
2021-10-23 03:08:02 +02:00
} ,
beforeDestroy ( ) {
2022-02-09 18:19:02 +01:00
window . removeEventListener ( 'resize' , this . resize )
2021-10-24 21:02:49 +02:00
window . removeEventListener ( 'keydown' , this . keyDown )
2021-08-18 00:01:11 +02:00
}
}
2021-09-16 00:59:38 +02:00
< / script >
< style >
. Vue - Toastification _ _toast - body . custom - class - 1 {
font - size : 14 px ;
}
< / style >