Skip to content

Commit cfcae9d

Browse files
committed
fix: viewer files router in standalone mode
Signed-off-by: skjnldsv <skjnldsv@protonmail.com>
1 parent fcfa54e commit cfcae9d

2 files changed

Lines changed: 33 additions & 11 deletions

File tree

src/files_actions/viewerAction.ts

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,23 @@
55
import type { Node, View } from '@nextcloud/files'
66

77
import { DefaultType, FileAction, Permission, registerFileAction } from '@nextcloud/files'
8+
import { emit } from '@nextcloud/event-bus'
9+
import { logger } from '../services/logger'
810
import { t } from '@nextcloud/l10n'
911
import svgEye from '@mdi/svg/svg/eye.svg?raw'
10-
import { emit } from '@nextcloud/event-bus'
1112

1213
/**
1314
* @param node The file to open
1415
* @param view any The files view
1516
* @param dir the directory path
1617
*/
1718
function pushToHistory(node: Node, view: View, dir: string) {
19+
if (!window.OCP?.Files?.Router) {
20+
// No router, we're in standalone mode
21+
logger.debug('No router found, skipping history push')
22+
return
23+
}
24+
1825
const editing = window.OCP.Files.Router.query.editing === 'true' ? 'true' : 'false'
1926
window.OCP.Files.Router.goToRoute(
2027
null,
@@ -27,13 +34,20 @@ function pushToHistory(node: Node, view: View, dir: string) {
2734
* @param editing True if the file is being edited
2835
*/
2936
export function toggleEditor(editing = false) {
37+
if (!window.OCP?.Files?.Router) {
38+
// No router, we're in standalone mode
39+
logger.debug('No router found, skipping toggle editor')
40+
return
41+
}
42+
43+
// Update the URL query param
3044
const newQuery = { ...window.OCP.Files.Router.query, editing: editing ? 'true' : 'false' }
3145
window.OCP.Files.Router.goToRoute(null, window.OCP.Files.Router.params, newQuery)
3246
}
3347

3448
const onPopState = () => {
35-
emit('editor:toggle', window.OCP.Files.Router.query?.editing === 'true')
36-
if (window.OCP.Files.Router.query.openfile !== 'true') {
49+
emit('editor:toggle', window.OCP?.Files?.Router?.query?.editing === 'true')
50+
if (window.OCP?.Files?.Router?.query?.openfile !== 'true') {
3751
window.OCA.Viewer.close()
3852
window.removeEventListener('popstate', onPopState)
3953
}
@@ -47,14 +61,21 @@ const onPopState = () => {
4761
*/
4862
async function execAction(node: Node, view: View, dir: string): Promise<boolean|null> {
4963
const onClose = () => {
64+
// If there is no router, we're in standalone mode
65+
if (!window.OCP?.Files?.Router) {
66+
return
67+
}
68+
5069
// This can sometime be called with the openfile set to true already. But we don't want to keep openfile when closing the viewer.
51-
const newQuery = { ...window.OCP.Files.Router.query }
70+
const newQuery = { ...window.OCP?.Files?.Router?.query }
5271
delete newQuery.openfile
5372
delete newQuery.editing
54-
window.OCP.Files.Router.goToRoute(null, window.OCP.Files.Router.params, newQuery)
73+
window.OCP?.Files?.Router?.goToRoute(null, window.OCP?.Files?.Router?.params, newQuery)
5574
}
5675

57-
window.addEventListener('popstate', onPopState)
76+
if (window.OCP?.Files?.Router) {
77+
window.addEventListener('popstate', onPopState)
78+
}
5879

5980
pushToHistory(node, view, dir)
6081
window.OCA.Viewer.open({

src/views/Viewer.vue

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -189,22 +189,22 @@ import isMobile from '@nextcloud/vue/dist/Mixins/isMobile.js'
189189
190190
import { canDownload } from '../utils/canDownload.ts'
191191
import { extractFilePaths, extractFilePathFromSource } from '../utils/fileUtils.ts'
192-
import getSortingConfig from '../services/FileSortingConfig.ts'
192+
import { toggleEditor } from '../files_actions/viewerAction.ts'
193193
import cancelableRequest from '../utils/CancelableRequest.js'
194194
import Error from '../components/Error.vue'
195+
import fetchNode from '../services/FetchFile.ts'
195196
import File from '../models/file.js'
196197
import getFileInfo from '../services/FileInfo.ts'
197-
import fetchNode from '../services/FetchFile.ts'
198198
import getFileList from '../services/FileList.ts'
199-
import Mime from '../mixins/Mime.js'
199+
import getSortingConfig from '../services/FileSortingConfig.ts'
200200
import logger from '../services/logger.js'
201+
import Mime from '../mixins/Mime.js'
201202
202203
import Delete from 'vue-material-design-icons/TrashCanOutline.vue'
203204
import Download from 'vue-material-design-icons/TrayArrowDown.vue'
204205
import Fullscreen from 'vue-material-design-icons/Fullscreen.vue'
205206
import FullscreenExit from 'vue-material-design-icons/FullscreenExit.vue'
206207
import Pencil from 'vue-material-design-icons/PencilOutline.vue'
207-
import { toggleEditor } from '../files_actions/viewerAction.ts'
208208
209209
// Dynamic loading
210210
const NcModal = () => import('@nextcloud/vue/dist/Components/NcModal.js')
@@ -661,7 +661,8 @@ export default defineComponent({
661661
const fileInfo = await fileRequest(path)
662662
console.debug('File info for ' + path + ' fetched', fileInfo)
663663
await this.openFileInfo(fileInfo, overrideHandlerId)
664-
if (window.OCP.Files.Router.query.editing === 'true' && this.canEdit) {
664+
if (!this.isStandalone && this.canEdit
665+
&& window.OCP?.Files?.Router?.query?.editing === 'true') {
665666
this.toggleEditor(true)
666667
}
667668
} catch (error) {

0 commit comments

Comments
 (0)