From a509a62ce5763d08f4b0423b0d218572addb3bd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Thu, 13 Jun 2024 14:23:13 +0200 Subject: [PATCH 1/4] chore: Refactor frontend capabilities to a service to be able to update on the fly MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- src/components/AdminSettings.vue | 3 ++- src/file-actions.js | 8 +++--- src/files.js | 27 ++++++++++--------- src/helpers/isDocument.js | 4 +-- src/helpers/types.js | 4 ++- src/services/capabilities.ts | 45 +++++++++++++++++++++++++++++++ src/services/collabora.js | 11 ++++---- src/view/DocumentTargetPicker.vue | 3 ++- src/view/NewFileMenu.js | 9 ++++--- src/view/Office.vue | 4 +-- src/viewer.js | 4 +-- 11 files changed, 85 insertions(+), 37 deletions(-) create mode 100644 src/services/capabilities.ts diff --git a/src/components/AdminSettings.vue b/src/components/AdminSettings.vue index e6a04d1135..4ca5e687e1 100644 --- a/src/components/AdminSettings.vue +++ b/src/components/AdminSettings.vue @@ -409,6 +409,7 @@ import SettingsFontList from './SettingsFontList.vue' import '@nextcloud/dialogs/style.css' import { getCallbackBaseUrl } from '../helpers/url.js' +import { getCapabilities } from '../services/capabilities.ts' const SERVER_STATE_OK = 0 const SERVER_STATE_LOADING = 1 @@ -529,7 +530,7 @@ export default { const protocol = this.checkUrlProtocol(newVal) const nextcloudProtocol = this.checkUrlProtocol(window.location.href) if (protocol !== nextcloudProtocol) this.serverError = PROTOCOL_MISMATCH - else this.serverError = Object.values(OC.getCapabilities().richdocuments.collabora).length > 0 ? SERVER_STATE_OK : SERVER_STATE_CONNECTION_ERROR + else this.serverError = Object.values(getCapabilities().collabora).length > 0 ? SERVER_STATE_OK : SERVER_STATE_CONNECTION_ERROR } }, isSetup() { diff --git a/src/file-actions.js b/src/file-actions.js index 02202d04da..4c33583821 100644 --- a/src/file-actions.js +++ b/src/file-actions.js @@ -3,14 +3,12 @@ * SPDX-License-Identifier: AGPL-3.0-or-later */ import { registerFileAction, FileAction } from '@nextcloud/files' -import { getCapabilities } from '@nextcloud/capabilities' +import { getCapabilities } from './services/capabilities.ts' 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', @@ -22,12 +20,12 @@ const openPdf = new FileAction({ displayName: () => { return t('richdocuments', 'Edit with {productName}', - { productName: richdocuments.productName }) + { productName: getCapabilities().productName }) }, enabled: () => { // Only enable the file action when files_pdfviewer is enabled - const optionalMimetypes = richdocuments.mimetypesNoDefaultOpen + const optionalMimetypes = getCapabilities().mimetypesNoDefaultOpen return optionalMimetypes.includes('application/pdf') }, diff --git a/src/files.js b/src/files.js index 31bb270fd9..07291514d1 100644 --- a/src/files.js +++ b/src/files.js @@ -18,6 +18,7 @@ import FilesAppIntegration from './view/FilesAppIntegration.js' import { splitPath } from './helpers/index.js' import { enableScrollLock, disableScrollLock } from './helpers/safariFixer.js' import NewFileMenu from './view/NewFileMenu.js' +import { getCapabilities } from './services/capabilities.ts' const FRAME_DOCUMENT = 'FRAME_DOCUMENT' const PostMessages = new PostMessageService({ @@ -34,11 +35,11 @@ const odfViewer = { receivedLoading: false, isProxyStarting: false, isCollaboraConfigured: ( - (OC.getCapabilities().richdocuments.config.wopi_url.indexOf('proxy.php') !== -1) - || (typeof OC.getCapabilities().richdocuments.collabora === 'object' && OC.getCapabilities().richdocuments.collabora.length !== 0)), - supportedMimes: OC.getCapabilities().richdocuments.mimetypes.concat(OC.getCapabilities().richdocuments.mimetypesNoDefaultOpen), - excludeMimeFromDefaultOpen: OC.getCapabilities().richdocuments.mimetypesNoDefaultOpen, - hideDownloadMimes: OC.getCapabilities().richdocuments.mimetypesSecureView, + (getCapabilities().config.wopi_url.indexOf('proxy.php') !== -1) + || (typeof getCapabilities().collabora === 'object' && getCapabilities().collabora.length !== 0)), + supportedMimes: getCapabilities().mimetypes.concat(getCapabilities().mimetypesNoDefaultOpen), + excludeMimeFromDefaultOpen: getCapabilities().mimetypesNoDefaultOpen, + hideDownloadMimes: getCapabilities().mimetypesSecureView, onEdit(fileName, context) { let fileDir @@ -50,7 +51,7 @@ const odfViewer = { if (!odfViewer.isCollaboraConfigured) { $.get(generateOcsUrl('cloud/capabilities?format=json')).then( e => { - if ((OC.getCapabilities().richdocuments.config.wopi_url.indexOf('proxy.php') !== -1) + if ((getCapabilities().config.wopi_url.indexOf('proxy.php') !== -1) || (typeof e.ocs.data.capabilities.richdocuments.collabora === 'object' && e.ocs.data.capabilities.richdocuments.collabora.length !== 0)) { odfViewer.isCollaboraConfigured = true @@ -101,11 +102,11 @@ const odfViewer = { const $iframe = $('