Skip to content

Commit 2fb0bb5

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

File tree

2 files changed

+34
-11
lines changed

2 files changed

+34
-11
lines changed

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: 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)