Hello, I’ve written the following filelist.js code to register context menus based on specific file extensions (.request, .plan, .result) while developing a Nextcloud app.
However, I’m encountering an issue where after changing directories and returning, the context menus for files with these extensions either don’t appear or different menus show up. I’m reaching out to the external forum to find solutions or code improvement suggestions for this problem.
The functionality works correctly when not navigating to different directories.
I would appreciate any advice on possible solutions or code improvements to resolve this issue.
import { registerFileAction } from '@nextcloud/files'
import { generateUrl } from '@nextcloud/router'
import { translate as t } from '@nextcloud/l10n'
registerFileAction({
id: 'dnadoc-openRequest',
displayName: () => t('dnadoc', 'Request open'),
iconSvgInline: () => generateUrl('/svg/core/actions/edit'),
enabled: (files) => {
return files.length === 1 && files[0].basename.endsWith('.request')
},
exec: async (file) => {
try {
const path = `${file.dirname}/${file.basename}`
window.location.href = generateUrl('/apps/dnadoc/request') +
`?file=${encodeURIComponent(path)}`
return true
} catch (error) {
console.error('Error opening request:', error)
return false
}
},
order: 9999
})
registerFileAction({
id: 'dnadoc-openPlan',
displayName: () => t('dnadoc', 'Plan Open'),
iconSvgInline: () => generateUrl('/svg/core/actions/edit'),
enabled: (files) => {
return files.length === 1 && files[0].basename.endsWith('.plan')
},
exec: async (file) => {
try {
const path = `${file.dirname}/${file.basename}`
window.location.href = generateUrl('/apps/dnadoc/plan') +
`?file=${encodeURIComponent(path)}`
return true
} catch (error) {
console.error('Error opening plan:', error)
return false
}
},
order: 9998
})
registerFileAction({
id: 'dnadoc-openResult',
displayName: () => t('dnadoc', 'Result Open'),
iconSvgInline: () => generateUrl('/svg/core/actions/edit'),
enabled: (files) => {
return files.length === 1 && files[0].basename.endsWith('.result')
},
exec: async (file) => {
try {
const path = `${file.dirname}/${file.basename}`
window.location.href = generateUrl('/apps/dnadoc/result') +
`?file=${encodeURIComponent(path)}`
return true
} catch (error) {
console.error('Error opening result:', error)
return false
}
},
order: 9997
})
<?php
declare(strict_types=1);
namespace OCA\DnaDoc\AppInfo;
use OCP\AppFramework\App;
use OCP\AppFramework\Bootstrap\IBootstrap;
use OCP\AppFramework\Bootstrap\IRegistrationContext;
use OCP\AppFramework\Bootstrap\IBootContext;
class Application extends App implements IBootstrap {
public const APP_ID = 'dnadoc';
/** @psalm-suppress PossiblyUnusedMethod */
public function __construct() {
parent::__construct(self::APP_ID);
}
public function register(IRegistrationContext $context): void {
}
public function boot(IBootContext $context): void {
\OCP\Util::addInitScript(self::APP_ID, 'filelist');
}
}