Skip to content

Commit 4069ddd

Browse files
skjnldsvbackportbot[bot]
authored andcommitted
fix: viewer files router in standalone mode
Signed-off-by: skjnldsv <skjnldsv@protonmail.com> [skip ci]
1 parent 03201d4 commit 4069ddd

2 files changed

Lines changed: 31 additions & 8 deletions

File tree

src/files_actions/viewerAction.ts

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,24 @@
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'
89
import { t } from '@nextcloud/l10n'
910
import svgEye from '@mdi/svg/svg/eye.svg?raw'
10-
import { emit } from '@nextcloud/event-bus'
11+
12+
import logger from '../services/logger.js'
1113

1214
/**
1315
* @param node The file to open
1416
* @param view any The files view
1517
* @param dir the directory path
1618
*/
1719
function pushToHistory(node: Node, view: View, dir: string) {
20+
if (!window.OCP?.Files?.Router) {
21+
// No router, we're in standalone mode
22+
logger.debug('No router found, skipping history push')
23+
return
24+
}
25+
1826
const editing = window.OCP.Files.Router.query.editing === 'true' ? 'true' : 'false'
1927
window.OCP.Files.Router.goToRoute(
2028
null,
@@ -27,13 +35,20 @@ function pushToHistory(node: Node, view: View, dir: string) {
2735
* @param editing True if the file is being edited
2836
*/
2937
export function toggleEditor(editing = false) {
38+
if (!window.OCP?.Files?.Router) {
39+
// No router, we're in standalone mode
40+
logger.debug('No router found, skipping toggle editor')
41+
return
42+
}
43+
44+
// Update the URL query param
3045
const newQuery = { ...window.OCP.Files.Router.query, editing: editing ? 'true' : 'false' }
3146
window.OCP.Files.Router.goToRoute(null, window.OCP.Files.Router.params, newQuery)
3247
}
3348

3449
const onPopState = () => {
35-
emit('editor:toggle', window.OCP.Files.Router.query?.editing === 'true')
36-
if (window.OCP.Files.Router.query.openfile !== 'true') {
50+
emit('editor:toggle', window.OCP?.Files?.Router?.query?.editing === 'true')
51+
if (window.OCP?.Files?.Router?.query?.openfile !== 'true') {
3752
window.OCA.Viewer.close()
3853
window.removeEventListener('popstate', onPopState)
3954
}
@@ -47,14 +62,21 @@ const onPopState = () => {
4762
*/
4863
async function execAction(node: Node, view: View, dir: string): Promise<boolean|null> {
4964
const onClose = () => {
65+
// If there is no router, we're in standalone mode
66+
if (!window.OCP?.Files?.Router) {
67+
return
68+
}
69+
5070
// 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 }
71+
const newQuery = { ...window.OCP?.Files?.Router?.query }
5272
delete newQuery.openfile
5373
delete newQuery.editing
54-
window.OCP.Files.Router.goToRoute(null, window.OCP.Files.Router.params, newQuery)
74+
window.OCP?.Files?.Router?.goToRoute(null, window.OCP?.Files?.Router?.params, newQuery)
5575
}
5676

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

5981
pushToHistory(node, view, dir)
6082
window.OCA.Viewer.open({

src/views/Viewer.vue

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,9 @@ import { extractFilePaths, extractFilePathFromSource } from '../utils/fileUtils.
207207
import cancelableRequest from '../utils/CancelableRequest.js'
208208
import canDownload from '../utils/canDownload.js'
209209
import Error from '../components/Error.vue'
210+
import fetchNode from '../services/FetchFile.ts'
210211
import File from '../models/file.js'
211212
import getFileInfo from '../services/FileInfo.ts'
212-
import fetchNode from '../services/FetchFile.ts'
213213
import getFileList from '../services/FileList.ts'
214214
import legacyFilesActionHandler from '../services/LegacyFilesActionHandler.js'
215215
import logger from '../services/logger.js'
@@ -654,7 +654,8 @@ export default defineComponent({
654654
const fileInfo = await fileRequest(path)
655655
console.debug('File info for ' + path + ' fetched', fileInfo)
656656
await this.openFileInfo(fileInfo, overrideHandlerId)
657-
if (window.OCP.Files.Router.query.editing === 'true' && this.canEdit) {
657+
if (!this.isStandalone && this.canEdit
658+
&& window.OCP?.Files?.Router?.query?.editing === 'true') {
658659
this.toggleEditor(true)
659660
}
660661
} catch (error) {

0 commit comments

Comments
 (0)