Skip to content

Commit

Permalink
build: prune admin bundle
Browse files Browse the repository at this point in the history
Signed-off-by: Varun Patil <radialapps@gmail.com>
  • Loading branch information
pulsejet committed Oct 30, 2023
1 parent 664bbae commit ba473e6
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 40 deletions.
4 changes: 3 additions & 1 deletion src/admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
35 changes: 0 additions & 35 deletions src/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() ?? '');

Expand All @@ -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) {
(<any>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
Expand Down
1 change: 0 additions & 1 deletion src/components/admin/AdminMain.vue
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ export default defineComponent({

methods: {
async refreshSystemConfig() {
console.log(this.components);
try {
this.loading++;
const res = await axios.get<ISystemConfig>(API.SYSTEM_CONFIG(null));
Expand Down
5 changes: 4 additions & 1 deletion src/globals.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
40 changes: 38 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
3 changes: 3 additions & 0 deletions src/services/utils/fragment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit ba473e6

Please sign in to comment.