Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions js/viewer-main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/viewer-main.js.map

Large diffs are not rendered by default.

23 changes: 15 additions & 8 deletions src/views/Viewer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,8 @@ export default {
isSidebarShown: false,
isFullscreenMode: false,
canSwipe: true,
isStandalone: !(OCA && OCA.Files && 'fileActions' in OCA.Files), // FIXME this probably needs some adjustment
// TODO: remove OCA?.Files?.fileActions when public Files is Vue
isStandalone: OCP?.Files === undefined && OCA?.Files?.fileActions === undefined,
theme: null,
root: getRootPath(),
handlerId: '',
Expand Down Expand Up @@ -527,15 +528,15 @@ export default {
this.Sidebar = OCA.Files.Sidebar.state
}

this.registerFileAction()
this.registerFileActions()

logger.info(`${this.handlers.length} viewer handlers registered`, { handlers: this.handlers })
})

window.addEventListener('resize', this.onResize)

if (this.isStandalone) {
logger.info('No OCA.Files app found, viewer is now in standalone mode')
logger.info('No OCP.Files app found, viewer is now in standalone mode')
}
},

Expand Down Expand Up @@ -881,7 +882,7 @@ export default {
},

registerLegacyAction({ mime, group }) {
if (!this.isStandalone) {
if (!this.isStandalone && OCA?.Files?.fileActions) {
// unregistered handler, let's go!
OCA.Files.fileActions.registerAction({
name: 'view',
Expand All @@ -891,7 +892,9 @@ export default {
actionHandler: legacyFilesActionHandler,
})
OCA.Files.fileActions.setDefault(mime, 'view')
logger.debug('Legacy file action registered for mime ' + mime, { mime, group })
}

// register groups
if (group) {
this.mimeGroups[mime] = group
Expand All @@ -914,7 +917,7 @@ export default {
}
},

registerFileAction() {
registerFileActions() {
if (!this.isStandalone) {
registerFileAction(new FileAction({
id: 'view',
Expand All @@ -924,9 +927,13 @@ export default {
iconSvgInline: () => EyeSvg,
default: DefaultType.DEFAULT,
enabled: (nodes) => {
return nodes.filter((node) => node.permissions & Permission.READ
&& this.Viewer.mimetypes.indexOf(node.mime) !== -1,
).length > 0
// Faster to check if at least one node doesn't match the requirements
const test = !nodes.some(node => (
(node.permissions & Permission.READ) === 0
|| !this.Viewer.mimetypes.includes(node.mime)
))
console.debug(test)
return test
},
exec: filesActionHandler,
}))
Expand Down