55import type { Node , View } from '@nextcloud/files'
66
77import { DefaultType , FileAction , Permission , registerFileAction } from '@nextcloud/files'
8+ import { emit } from '@nextcloud/event-bus'
89import { t } from '@nextcloud/l10n'
910import 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 */
1719function 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 */
2937export 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
3449const 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 */
4863async 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 ( {
0 commit comments