mirror of
https://github.com/nextcloud/richdocuments.git
synced 2025-12-17 13:08:43 +01:00
fix: file action for opening pdf files with richdocuments
Signed-off-by: Elizabeth Danzberger <lizzy7128@tutanota.de>
This commit is contained in:
parent
bee4679492
commit
43a82631d2
7 changed files with 79 additions and 3 deletions
|
|
@ -44,6 +44,7 @@ return array(
|
|||
'OCA\\Richdocuments\\Listener\\BeforeFetchPreviewListener' => $baseDir . '/../lib/Listener/BeforeFetchPreviewListener.php',
|
||||
'OCA\\Richdocuments\\Listener\\BeforeTemplateRenderedListener' => $baseDir . '/../lib/Listener/BeforeTemplateRenderedListener.php',
|
||||
'OCA\\Richdocuments\\Listener\\FileCreatedFromTemplateListener' => $baseDir . '/../lib/Listener/FileCreatedFromTemplateListener.php',
|
||||
'OCA\\Richdocuments\\Listener\\LoadAdditionalListener' => $baseDir . '/../lib/Listener/LoadAdditionalListener.php',
|
||||
'OCA\\Richdocuments\\Listener\\LoadViewerListener' => $baseDir . '/../lib/Listener/LoadViewerListener.php',
|
||||
'OCA\\Richdocuments\\Listener\\ReferenceListener' => $baseDir . '/../lib/Listener/ReferenceListener.php',
|
||||
'OCA\\Richdocuments\\Listener\\RegisterTemplateFileCreatorListener' => $baseDir . '/../lib/Listener/RegisterTemplateFileCreatorListener.php',
|
||||
|
|
|
|||
|
|
@ -59,6 +59,7 @@ class ComposerStaticInitRichdocuments
|
|||
'OCA\\Richdocuments\\Listener\\BeforeFetchPreviewListener' => __DIR__ . '/..' . '/../lib/Listener/BeforeFetchPreviewListener.php',
|
||||
'OCA\\Richdocuments\\Listener\\BeforeTemplateRenderedListener' => __DIR__ . '/..' . '/../lib/Listener/BeforeTemplateRenderedListener.php',
|
||||
'OCA\\Richdocuments\\Listener\\FileCreatedFromTemplateListener' => __DIR__ . '/..' . '/../lib/Listener/FileCreatedFromTemplateListener.php',
|
||||
'OCA\\Richdocuments\\Listener\\LoadAdditionalListener' => __DIR__ . '/..' . '/../lib/Listener/LoadAdditionalListener.php',
|
||||
'OCA\\Richdocuments\\Listener\\LoadViewerListener' => __DIR__ . '/..' . '/../lib/Listener/LoadViewerListener.php',
|
||||
'OCA\\Richdocuments\\Listener\\ReferenceListener' => __DIR__ . '/..' . '/../lib/Listener/ReferenceListener.php',
|
||||
'OCA\\Richdocuments\\Listener\\RegisterTemplateFileCreatorListener' => __DIR__ . '/..' . '/../lib/Listener/RegisterTemplateFileCreatorListener.php',
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" height="32" width="32" version="1.0" viewBox="0 0 32 32">
|
||||
<path style="color:#000000;block-progression:tb;text-transform:none;text-indent:0" fill="#fff" d="m4.6992 2.004c-0.395 0.0764-0.7062 0.4666-0.6992 0.875v26.244c0 0.46 0.4122 0.876 0.8632 0.876h22.276c0.452 0 0.864-0.416 0.864-0.876v-20.284c-0.008-0.1338-0.046-0.266-0.11-0.383l-6.624-6.3984c-0.086-0.0328-0.178-0.051-0.27-0.0546h-16.137c-0.0532-0.0053-0.11-0.0053-0.1636 0zm3.3008 3.996h12v2h-12v-2zm0 6h10v2h-10v-2zm0 6h16v2h-16v-2zm0 6h8v2h-8v-2z"/>
|
||||
</svg>
|
||||
</svg>
|
||||
|
Before Width: | Height: | Size: 613 B After Width: | Height: | Size: 612 B |
|
|
@ -33,6 +33,7 @@ use OCA\Richdocuments\Listener\AddFeaturePolicyListener;
|
|||
use OCA\Richdocuments\Listener\BeforeFetchPreviewListener;
|
||||
use OCA\Richdocuments\Listener\BeforeTemplateRenderedListener;
|
||||
use OCA\Richdocuments\Listener\FileCreatedFromTemplateListener;
|
||||
use OCA\Richdocuments\Listener\LoadAdditionalListener;
|
||||
use OCA\Richdocuments\Listener\LoadViewerListener;
|
||||
use OCA\Richdocuments\Listener\ReferenceListener;
|
||||
use OCA\Richdocuments\Listener\RegisterTemplateFileCreatorListener;
|
||||
|
|
@ -56,6 +57,7 @@ use OCP\AppFramework\Bootstrap\IBootstrap;
|
|||
use OCP\AppFramework\Bootstrap\IRegistrationContext;
|
||||
use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent;
|
||||
use OCP\Collaboration\Reference\RenderReferenceEvent;
|
||||
use OCP\Collaboration\Resources\LoadAdditionalScriptsEvent;
|
||||
use OCP\Files\Template\FileCreatedFromTemplateEvent;
|
||||
use OCP\Files\Template\RegisterTemplateCreatorEvent;
|
||||
use OCP\Preview\BeforePreviewFetchedEvent;
|
||||
|
|
@ -79,6 +81,7 @@ class Application extends App implements IBootstrap {
|
|||
$context->registerEventListener(FileCreatedFromTemplateEvent::class, FileCreatedFromTemplateListener::class);
|
||||
$context->registerEventListener(AddContentSecurityPolicyEvent::class, AddContentSecurityPolicyListener::class);
|
||||
$context->registerEventListener(AddFeaturePolicyEvent::class, AddFeaturePolicyListener::class);
|
||||
$context->registerEventListener(LoadAdditionalScriptsEvent::class, LoadAdditionalListener::class);
|
||||
$context->registerEventListener(LoadViewer::class, LoadViewerListener::class);
|
||||
$context->registerEventListener(ShareLinkAccessedEvent::class, ShareLinkListener::class);
|
||||
$context->registerEventListener(BeforePreviewFetchedEvent::class, BeforeFetchPreviewListener::class);
|
||||
|
|
|
|||
24
lib/Listener/LoadAdditionalListener.php
Normal file
24
lib/Listener/LoadAdditionalListener.php
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
|
||||
namespace OCA\Richdocuments\Listener;
|
||||
|
||||
use OCA\Richdocuments\AppInfo\Application;
|
||||
use OCP\Collaboration\Resources\LoadAdditionalScriptsEvent;
|
||||
use OCP\EventDispatcher\Event;
|
||||
use OCP\EventDispatcher\IEventListener;
|
||||
use OCP\Util;
|
||||
|
||||
/** @template-implements IEventListener<LoadAdditionalScriptsEvent> */
|
||||
class LoadAdditionalListener implements IEventListener {
|
||||
public function handle(Event $event): void {
|
||||
// If not a LoadAdditionalScriptsEvent, we should do nothing
|
||||
if (!($event instanceof LoadAdditionalScriptsEvent)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// If we can add an init script, we add the file-actions script
|
||||
if (method_exists(Util::class, 'addInitScript')) {
|
||||
Util::addInitScript(Application::APPNAME, 'richdocuments-fileActions');
|
||||
}
|
||||
}
|
||||
}
|
||||
40
src/file-actions.js
Normal file
40
src/file-actions.js
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
import { registerFileAction, FileAction } from '@nextcloud/files'
|
||||
import { getCapabilities } from '@nextcloud/capabilities'
|
||||
import { translate as t } from '@nextcloud/l10n'
|
||||
|
||||
// eslint-disable-next-line import/no-unresolved
|
||||
import appIcon from '../img/app.svg?raw'
|
||||
|
||||
const richdocuments = getCapabilities().richdocuments
|
||||
|
||||
const openPdf = new FileAction({
|
||||
id: 'office-open-pdf',
|
||||
|
||||
iconSvgInline: () => {
|
||||
// Make sure the icon is the correct color
|
||||
return appIcon.replaceAll(/#(fff|0{6})/g, 'currentColor')
|
||||
},
|
||||
|
||||
displayName: () => {
|
||||
return t('richdocuments',
|
||||
'Edit with {productName}',
|
||||
{ productName: richdocuments.productName })
|
||||
},
|
||||
|
||||
enabled: () => {
|
||||
// Only enable the file action when files_pdfviewer is enabled
|
||||
const optionalMimetypes = richdocuments.mimetypesNoDefaultOpen
|
||||
return optionalMimetypes.includes('application/pdf')
|
||||
},
|
||||
|
||||
exec: (file) => {
|
||||
// If no viewer API, we can't open the document
|
||||
if (!OCA.Viewer) {
|
||||
return
|
||||
}
|
||||
|
||||
OCA.Viewer.openWith('richdocuments', { path: file.path })
|
||||
},
|
||||
})
|
||||
|
||||
registerFileAction(openPdf)
|
||||
11
webpack.js
11
webpack.js
|
|
@ -7,6 +7,7 @@ const BabelLoaderExcludeNodeModulesExcept = require('babel-loader-exclude-node-m
|
|||
webpackConfig.entry = {
|
||||
viewer: path.join(__dirname, 'src', 'viewer.js'),
|
||||
files: path.join(__dirname, 'src', 'files.js'),
|
||||
fileActions: path.join(__dirname, 'src', 'file-actions.js'),
|
||||
document: path.join(__dirname, 'src', 'document.js'),
|
||||
admin: path.join(__dirname, 'src', 'admin.js'),
|
||||
personal: path.join(__dirname, 'src', 'personal.js'),
|
||||
|
|
@ -17,7 +18,7 @@ webpackConfig.entry = {
|
|||
webpackRules.RULE_JS.test = /\.m?js$/
|
||||
webpackRules.RULE_JS.exclude = BabelLoaderExcludeNodeModulesExcept([
|
||||
'@nextcloud/dialogs',
|
||||
'@nextcloud/event-bus'
|
||||
'@nextcloud/event-bus',
|
||||
])
|
||||
|
||||
// Replaces rules array
|
||||
|
|
@ -27,7 +28,13 @@ webpackConfig.module.rules = Object.values(webpackRules)
|
|||
webpackConfig.module.rules.push({
|
||||
test: /\.tsx?$/,
|
||||
use: ['babel-loader', 'ts-loader'],
|
||||
exclude: /node_modules/
|
||||
exclude: /node_modules/,
|
||||
})
|
||||
|
||||
// Raw files rule
|
||||
webpackConfig.module.rules.push({
|
||||
resourceQuery: /raw/,
|
||||
type: 'asset/source',
|
||||
})
|
||||
|
||||
// Add typescript extension resolver
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue