How to register fileaction?

Hello,

I can´t find a proper docu and searching & try/error based on github seems not too successfull.

I want to register a “play” fileaction for audioplay and also register it as default-action for mp3s.

I am not sure what to use:
OCA.Files.fileActions.register
or
OCA.Files.fileActions.registerAction
+
OCA.Files.fileActions.setDefault

my current setup does not seem to work:

OCA.Files.fileActions.registerAction({
name: ‘Play’,
displayName: t(‘audioplayer’, ‘Play’),
mime: ‘audio/mpeg’,
permissions: OC.PERMISSION_READ,
icon: function () {
return OC.imagePath(‘core’, ‘actions/sound’);
},
actionHandler: openInMusic
});

OCA.Files.fileActions.setDefault(‘audio/mpeg’, ‘Play’);

in this case, the default action works - but it is not displayed in the context-menu

Have a look at this file:

Specifically this bit:

			for (i = 0; i < mediaTypesLength; i++) {
				// Each click handler gets the same function and images array and
				// is responsible to load the slideshow
				OCA.Files.fileActions.register(mediaTypes[i], 'View', OC.PERMISSION_READ, '',
					galleryFileAction.onView);
				OCA.Files.fileActions.setDefault(mediaTypes[i], 'View');
			}

Just saw this. The context menu requires a different registration.

1 Like

Hello,
I want to bring this up again and ask for help here.
It was working some time, but with the current 12 it is not working again.

as above, the default action is assigned. when I use the console to debug OCA.Files.fileActions, its also looking good. only the menu item is missing

Object = $1
$el: n [<div class="dummy-fileactions hidden">] (1)
_showMenuClosure: function()
_updateListeners: [] (0)

actions: Object
application/cmd: {Edit: Object}
application/javascript: {Edit: Object}
application/json: {Edit: Object}
application/x-empty: {Edit: Object}
application/x-msdos-program: {Edit: Object}
application/x-pearl: {Edit: Object}
application/x-php: {Edit: Object}
application/x-text: {Edit: Object}
application/xml: {Edit: Object}
application/yaml: {Edit: Object}
audio/flac: {audio: Object}
audio/m4b: {audio: Object}
audio/mp4: {audio: Object}
audio/mpeg: {audio: Object}
audio/wav: {audio: Object}
text: {Edit: Object}

defaults: Object
application/cmd: "Edit"
application/javascript: "Edit"
application/json: "Edit"
application/x-empty: "Edit"
application/x-msdos-program: "Edit"
application/x-pearl: "Edit"
application/x-php: "Edit"
application/x-text: "Edit"
application/xml: "Edit"
application/yaml: "Edit"
audio/flac: "audio"
audio/m4b: "audio"
audio/mp4: "audio"
audio/mpeg: "audio"
audio/wav: "audio"
text: "Edit"

icons: {Edit: function, audio: "/owncloud/core/img/actions/sound.svg"}

one additional finding:
when I trigger the fileActions.register, the items are shown in the entry.
as soon as I trigger the setDefault, it is being removed again.

bump.

somehow it is really not working :frowning:

Removing the default action from the menu is actually by intention. Since it is triggered when clicking the file, there is no need to have another entry to perform that action in the menu.

Thank you @juliushaertl for this finding & clarification. Knowing that it was designed to be this way saves the debugging :wink: