diff --git a/src/admin.ts b/src/admin.ts index 4301d1f0..7fba205d 100644 --- a/src/admin.ts +++ b/src/admin.ts @@ -3,7 +3,9 @@ import './bootstrap'; import Vue from 'vue'; import App from '@components/admin/AdminMain.vue'; -_m.mode = 'admin'; +globalThis._m = { + mode: 'admin', +} as any; export default new Vue({ el: '#vue-content', diff --git a/src/bootstrap.ts b/src/bootstrap.ts index 08357394..0ba0d966 100644 --- a/src/bootstrap.ts +++ b/src/bootstrap.ts @@ -6,42 +6,15 @@ import { generateFilePath } from '@nextcloud/router'; import { getRequestToken } from '@nextcloud/auth'; // Global components -import XImg from '@components/frame/XImg.vue'; import XLoadingIcon from '@components/XLoadingIcon.vue'; -import VueVirtualScroller from 'vue-virtual-scroller'; // Locals -import router, { routes } from './router'; import { constants, initstate } from '@services/utils'; import { translate, translatePlural } from '@services/l10n'; -// CSS for components -import 'vue-virtual-scroller/dist/vue-virtual-scroller.css'; - // Global CSS import './styles/global.scss'; -// Initialize global memories object -globalThis._m = { - mode: 'user', - - get route() { - return router.currentRoute; - }, - router: router, - routes: routes, - - modals: {} as any, - sidebar: {} as any, - viewer: {} as any, - video: {} as any, - - window: { - innerWidth: window.innerWidth, - innerHeight: window.innerHeight, - }, -}; - // CSP config for webpack dynamic chunk loading __webpack_nonce__ = window.btoa(getRequestToken() ?? ''); @@ -51,20 +24,12 @@ __webpack_nonce__ = window.btoa(getRequestToken() ?? ''); // We do not want the index.php since we're loading files __webpack_public_path__ = generateFilePath('memories', '', 'js/'); -// Generate client id for this instance -// Does not need to be cryptographically secure -_m.video.clientId = Math.random().toString(36).substring(2, 15).padEnd(12, '0'); -_m.video.clientIdPersistent = localStorage.getItem('videoClientIdPersistent') ?? _m.video.clientId; -localStorage.setItem('videoClientIdPersistent', _m.video.clientIdPersistent); - // Turn on virtual keyboard support if ('virtualKeyboard' in navigator) { (navigator.virtualKeyboard).overlaysContent = true; } // Register global components and plugins -Vue.use(VueVirtualScroller); -Vue.component('XImg', XImg); Vue.component('XLoadingIcon', XLoadingIcon); // Register global constants and functions diff --git a/src/components/admin/AdminMain.vue b/src/components/admin/AdminMain.vue index 474010bb..c4bd8ccf 100644 --- a/src/components/admin/AdminMain.vue +++ b/src/components/admin/AdminMain.vue @@ -78,7 +78,6 @@ export default defineComponent({ methods: { async refreshSystemConfig() { - console.log(this.components); try { this.loading++; const res = await axios.get(API.SYSTEM_CONFIG(null)); diff --git a/src/globals.d.ts b/src/globals.d.ts index 2406ca83..774f5a9e 100644 --- a/src/globals.d.ts +++ b/src/globals.d.ts @@ -27,7 +27,10 @@ declare global { }; }; - /** Global Memories object. Initialized in src/bootstrap.ts */ + /** + * Global Memories object. Initialized in main.ts + * Most of this is not available for admin.ts. + */ var _m: { mode: 'admin' | 'user'; route: Route; diff --git a/src/main.ts b/src/main.ts index 57344140..8eb18138 100644 --- a/src/main.ts +++ b/src/main.ts @@ -2,9 +2,45 @@ import './bootstrap'; import Vue from 'vue'; import App from './App.vue'; -import router from './router'; +import router, { routes } from './router'; -_m.mode = 'user'; +// Global components +import XImg from '@components/frame/XImg.vue'; +import VueVirtualScroller from 'vue-virtual-scroller'; + +// CSS for components +import 'vue-virtual-scroller/dist/vue-virtual-scroller.css'; + +// Initialize global memories object +globalThis._m = { + mode: 'user', + + get route() { + return router.currentRoute; + }, + router: router, + routes: routes, + + modals: {} as any, + sidebar: {} as any, + viewer: {} as any, + video: {} as any, + + window: { + innerWidth: window.innerWidth, + innerHeight: window.innerHeight, + }, +}; + +// Generate client id for this instance +// Does not need to be cryptographically secure +_m.video.clientId = Math.random().toString(36).substring(2, 15).padEnd(12, '0'); +_m.video.clientIdPersistent = localStorage.getItem('videoClientIdPersistent') ?? _m.video.clientId; +localStorage.setItem('videoClientIdPersistent', _m.video.clientIdPersistent); + +// Register global components and plugins +Vue.use(VueVirtualScroller); +Vue.component('XImg', XImg); export default new Vue({ el: '#content', diff --git a/src/services/utils/fragment.ts b/src/services/utils/fragment.ts index 615d7729..23db1187 100644 --- a/src/services/utils/fragment.ts +++ b/src/services/utils/fragment.ts @@ -190,6 +190,9 @@ export const fragment = { }; document.addEventListener('DOMContentLoaded', () => { + // Skip unless in user mode + if (_m.mode !== 'user') return; + // Only contextual fragments should be present on page load if (fragment.list.length) { const contextual = fragment.list.filter((frag) => frag.type === FragmentType.viewer);