From 45743b891884a4a45eb7b7fd1d5637dc5328b83b Mon Sep 17 00:00:00 2001 From: Varun Patil Date: Tue, 2 May 2023 15:40:36 -0700 Subject: [PATCH] all: make OCA dep optional Signed-off-by: Varun Patil --- src/App.vue | 43 +++++++++++++++----------------- src/components/Sidebar.vue | 21 ++++++++++++++++ src/components/viewer/Viewer.vue | 2 +- src/main.ts | 20 --------------- 4 files changed, 42 insertions(+), 44 deletions(-) diff --git a/src/App.vue b/src/App.vue index 4adea819..0642dbc3 100644 --- a/src/App.vue +++ b/src/App.vue @@ -212,30 +212,27 @@ export default defineComponent({ root.style.setProperty('--plyr-color-main', colorPrimary); // Register sidebar metadata tab - const OCA = globalThis.OCA; - if (OCA.Files && OCA.Files.Sidebar) { - OCA.Files.Sidebar.registerTab( - new OCA.Files.Sidebar.Tab({ - id: 'memories-metadata', - name: this.t('memories', 'Info'), - icon: 'icon-details', + globalThis.OCA?.Files?.Sidebar?.registerTab( + new globalThis.OCA.Files.Sidebar.Tab({ + id: 'memories-metadata', + name: this.t('memories', 'Info'), + icon: 'icon-details', - mount(el, fileInfo, context) { - this.metadataComponent?.$destroy?.(); - this.metadataComponent = new Vue(Metadata as any); - this.metadataComponent.$mount(el); - this.metadataComponent.update(Number(fileInfo.id)); - }, - update(fileInfo) { - this.metadataComponent.update(Number(fileInfo.id)); - }, - destroy() { - this.metadataComponent?.$destroy?.(); - this.metadataComponent = null; - }, - }) - ); - } + mount(el, fileInfo, context) { + this.metadataComponent?.$destroy?.(); + this.metadataComponent = new Vue(Metadata as any); + this.metadataComponent.$mount(el); + this.metadataComponent.update(Number(fileInfo.id)); + }, + update(fileInfo) { + this.metadataComponent.update(Number(fileInfo.id)); + }, + destroy() { + this.metadataComponent?.$destroy?.(); + this.metadataComponent = null; + }, + }) + ); }, async beforeMount() { diff --git a/src/components/Sidebar.vue b/src/components/Sidebar.vue index 041ca16d..386ca530 100644 --- a/src/components/Sidebar.vue +++ b/src/components/Sidebar.vue @@ -51,6 +51,27 @@ export default defineComponent({ }, }, + created() { + if (globalThis.OCA) { + globalThis.OCA.Files ??= {}; + + // TODO: remove when we have a proper fileinfo standalone library + // original scripts are loaded from + // https://github.com/nextcloud/server/blob/5bf3d1bb384da56adbf205752be8f840aac3b0c5/lib/private/legacy/template.php#L120-L122 + Object.assign( + globalThis.OCA.Files, + { + App: { + fileList: { + filesClient: (globalThis.OC.Files).getClient(), + }, + }, + }, + globalThis.OCA.Files + ); + } + }, + mounted() { subscribe('files:sidebar:opened', this.handleNativeOpen); subscribe('files:sidebar:closed', this.handleNativeClose); diff --git a/src/components/viewer/Viewer.vue b/src/components/viewer/Viewer.vue index 8f110803..c18c9ace 100644 --- a/src/components/viewer/Viewer.vue +++ b/src/components/viewer/Viewer.vue @@ -361,7 +361,7 @@ export default defineComponent({ this.originalTitle = document.title; } if (photo) { - document.title = `${photo.basename} - ${globalThis.OCA.Theming?.name}`; + document.title = `${photo.basename} - ${globalThis.OCA?.Theming?.name}`; } else { document.title = this.originalTitle; this.originalTitle = null; diff --git a/src/main.ts b/src/main.ts index 5b0226f8..1220ded0 100644 --- a/src/main.ts +++ b/src/main.ts @@ -77,26 +77,6 @@ Vue.mixin(GlobalMixin as any); Vue.use(VueVirtualScroller); Vue.component('XImg', XImg); -// https://github.com/nextcloud/photos/blob/156f280c0476c483cb9ce81769ccb0c1c6500a4e/src/main.js -// TODO: remove when we have a proper fileinfo standalone library -// original scripts are loaded from -// https://github.com/nextcloud/server/blob/5bf3d1bb384da56adbf205752be8f840aac3b0c5/lib/private/legacy/template.php#L120-L122 -window.addEventListener('DOMContentLoaded', () => { - if (!globalThis.OCA.Files) { - globalThis.OCA.Files = {}; - } - // register unused client for the sidebar to have access to its parser methods - Object.assign( - globalThis.OCA.Files, - { - App: { - fileList: { filesClient: (globalThis.OC.Files).getClient() }, - }, - }, - globalThis.OCA.Files - ); -}); - let app = null; const adminSection = document.getElementById('memories-admin-content');