-
Notifications
You must be signed in to change notification settings - Fork 514
Expand file tree
/
Copy pathmain.js
More file actions
112 lines (90 loc) · 3.55 KB
/
main.js
File metadata and controls
112 lines (90 loc) · 3.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/**
* SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import { getCSPNonce } from '@nextcloud/auth'
import { emit, subscribe } from '@nextcloud/event-bus'
import { generateFilePath } from '@nextcloud/router'
import { createApp, reactive, watch } from 'vue'
import App from './App.vue'
import { createTalkRouter } from './router/router.ts'
import { SettingsAPI } from './services/SettingsAPI.ts'
import store from './store/index.js'
import pinia from './stores/pinia.ts'
import { useSidebarStore } from './stores/sidebar.ts'
import { NextcloudGlobalsVuePlugin } from './utils/NextcloudGlobalsVuePlugin.js'
import { exposeVirtualBackgroundDebugConfig } from './utils/media/effects/virtual-background/runtimeConfig.js'
import './init.js'
// Leaflet icon patch
import 'leaflet/dist/leaflet.css'
import 'leaflet-defaulticon-compatibility/dist/leaflet-defaulticon-compatibility.webpack.css' // Re-uses images from ~leaflet package
import 'leaflet-defaulticon-compatibility'
if (!IS_DESKTOP) {
// CSP config for webpack dynamic chunk loading
__webpack_nonce__ = getCSPNonce()
// Correct the root of the app for chunk loading
// OC.linkTo matches the apps folders
// OC.generateUrl ensure the index.php (or not)
// We do not want the index.php since we're loading files
__webpack_public_path__ = generateFilePath('spreed', '', 'js/')
}
const router = createTalkRouter()
const instance = createApp(App, { fileInfo: null })
.use(store)
.use(pinia)
.use(router)
.use(NextcloudGlobalsVuePlugin)
.mount('#content')
window.store = store
// Setup Viewer to be used with Talk sidebar
/**
*
* @param sidebarElement
* @param resolve
*/
function waitForSidebarToBeOpen(sidebarElement, resolve) {
if ('ontransitionend' in sidebarElement) {
const resolveOnceSidebarWidthHasChanged = (event) => {
if (!['min-width', 'width', 'max-width', 'margin-right'].includes(event.propertyName)) {
return
}
sidebarElement.removeEventListener('transitionend', resolveOnceSidebarWidthHasChanged)
emit('files:sidebar:opened')
resolve()
}
sidebarElement.addEventListener('transitionend', resolveOnceSidebarWidthHasChanged)
} else {
const animationQuickValue = getComputedStyle(document.documentElement).getPropertyValue('--animation-quick')
// The browser does not support the "ontransitionend" event, so just
// wait a few milliseconds more than the duration of the transition.
setTimeout(() => {
console.debug('ontransitionend is not supported; the sidebar should have been fully shown by now')
emit('files:sidebar:opened')
resolve()
}, Number.parseInt(animationQuickValue) + 200)
}
}
subscribe('viewer:sidebar:open', (node) => {
const sidebarStore = useSidebarStore()
// The sidebar is already open, so this can return immediately.
if (sidebarStore.show) {
emit('files:sidebar:opened')
return
}
sidebarStore.showSidebar()
const sidebarElement = document.getElementById('app-sidebar') ?? document.getElementById('app-sidebar-vue')
// The Viewer adjusts its width to the sidebar width once the sidebar has
// been opened. The sidebar opens with an animation, so a delay is needed
// before the width can be properly adjusted.
return new Promise((resolve, reject) => {
waitForSidebarToBeOpen(sidebarElement, resolve)
})
})
// make the instance available to global components that might run on the same page
if (!window.OCA.Talk) {
window.OCA.Talk = reactive({})
}
exposeVirtualBackgroundDebugConfig(window.OCA.Talk)
OCA.Talk.instance = instance
OCA.Talk.Settings = SettingsAPI
export default instance