@@ -253,7 +253,7 @@ export default {
253253 // we got a valid path! Load file...
254254 if (path .trim () !== ' ' ) {
255255 logger .info (' Opening viewer for file ' , { path })
256- this .openFile (path)
256+ this .openFile (path, OCA . Viewer . overrideHandlerId )
257257 } else {
258258 // path is empty, we're closing!
259259 this .cleanup ()
@@ -340,8 +340,9 @@ export default {
340340 * Open the view and display the clicked file
341341 *
342342 * @param {string} path the file path to open
343+ * @param {string|null} overrideHandlerId the ID of the handler with which to view the files, if any
343344 */
344- async openFile (path ) {
345+ async openFile (path , overrideHandlerId = null ) {
345346 // cancel any previous requests
346347 this .cancelRequestFile ()
347348 this .cancelRequestFolder ()
@@ -380,13 +381,24 @@ export default {
380381 // retrieve and store the file info
381382 let fileInfo = await fileRequest (path)
382383
383- // get original mime
384- let mime = fileInfo .mime
384+ // get original mime and alias
385+ const mime = fileInfo .mime
386+ const alias = mime .split (' /' )[0 ]
385387
386- this .theme = this .registeredHandlers [mime].theme ?? ' dark'
388+ let handler
389+ // Try provided handler, if any
390+ if (overrideHandlerId !== null ) {
391+ const overrideHandler = Object .values (this .registeredHandlers ).find (h => h .id === overrideHandlerId)
392+ handler = overrideHandler ?? handler
393+ }
394+ // If no provided handler, or provided handler not found: try a supported handler with mime/mime-alias
395+ if (! handler) {
396+ handler = this .registeredHandlers [mime] ?? this .registeredHandlers [alias]
397+ }
387398
399+ this .theme = handler .theme ?? ' dark'
388400 // if we don't have a handler for this mime, abort
389- if (! (mime in this . components ) ) {
401+ if (! handler ) {
390402 logger .error (' The following file could not be displayed' , { fileName, fileInfo })
391403 showError (t (' viewer' , ' There is no plugin available to display this file type' ))
392404 this .close ()
@@ -428,13 +440,8 @@ export default {
428440 // get saved fileInfo
429441 fileInfo = this .fileList [this .currentIndex ]
430442
431- // override mimetype if existing alias
432- if (! this .components [mime]) {
433- mime = mime .split (' /' )[0 ]
434- }
435-
436443 // show file
437- this .currentFile = new File (fileInfo, mime, this . components [mime] )
444+ this .currentFile = new File (fileInfo, mime, handler . component )
438445 this .updatePreviousNext ()
439446
440447 // if sidebar was opened before, let's update the file
0 commit comments