55import type { Node , View } from '@nextcloud/files'
66
77import { DefaultType , FileAction , Permission , registerFileAction } from '@nextcloud/files'
8+ import { emit } from '@nextcloud/event-bus'
9+ import { logger } from '../services/logger'
810import { t } from '@nextcloud/l10n'
911import 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 */
1718function 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 */
2936export 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
3448const 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 */
4862async 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 ( {
0 commit comments