]> source.dussan.org Git - nextcloud-server.git/commitdiff
feat(editLocallyAction): Handle possible no local client scenario
authorfenn-cs <fenn25.fn@gmail.com>
Thu, 11 Jul 2024 13:20:58 +0000 (14:20 +0100)
committerbackportbot[bot] <backportbot[bot]@users.noreply.github.com>
Wed, 31 Jul 2024 10:12:23 +0000 (10:12 +0000)
Resolves: https://github.com/nextcloud/server/issues/46438

Signed-off-by: fenn-cs <fenn25.fn@gmail.com>
apps/files/src/actions/editLocallyAction.ts

index f52f8191df87e5cd7b2b3df8395f68209f6a3b5d..e6e847e2fece89340caac09036bf2c33d4ea41f2 100644 (file)
@@ -23,11 +23,62 @@ import { encodePath } from '@nextcloud/paths'
 import { generateOcsUrl } from '@nextcloud/router'
 import { getCurrentUser } from '@nextcloud/auth'
 import { FileAction, Permission, type Node } from '@nextcloud/files'
-import { showError } from '@nextcloud/dialogs'
+import { showError, DialogBuilder } from '@nextcloud/dialogs'
 import { translate as t } from '@nextcloud/l10n'
 import axios from '@nextcloud/axios'
-
 import LaptopSvg from '@mdi/svg/svg/laptop.svg?raw'
+import IconCancel from '@mdi/svg/svg/cancel.svg?raw'
+import IconCheck from '@mdi/svg/svg/check.svg?raw'
+
+const confirmLocalEditDialog = (
+       localEditCallback: (openingLocally: boolean) => void = () => {},
+) => {
+       let callbackCalled = false
+
+       return (new DialogBuilder())
+               .setName(t('files', 'Edit file locally'))
+               .setText(t('files', 'The file should now open locally. If you don\'t see this happening, make sure that the desktop client is installed on your system.'))
+               .setButtons([
+                       {
+                               label: t('files', 'Retry local edit'),
+                               icon: IconCancel,
+                               callback: () => {
+                                       callbackCalled = true
+                                       localEditCallback(false)
+                               },
+                       },
+                       {
+                               label: t('files', 'Edit online'),
+                               icon: IconCheck,
+                               type: 'primary',
+                               callback: () => {
+                                       callbackCalled = true
+                                       localEditCallback(true)
+                               },
+                       },
+               ])
+               .build()
+               .show()
+               .then(() => {
+                       // Ensure the callback is called even if the dialog is dismissed in other ways
+                       if (!callbackCalled) {
+                               localEditCallback(true)
+                       }
+               })
+}
+
+const attemptOpenLocalClient = async (path: string) => {
+       openLocalClient(path)
+       confirmLocalEditDialog(
+               (openLocally: boolean) => {
+                       if (!openLocally) {
+                               window.OCA.Viewer.open({ path })
+                               return
+                       }
+                       openLocalClient(path)
+               },
+       )
+}
 
 const openLocalClient = async function(path: string) {
        const link = generateOcsUrl('apps/files/api/v1') + '/openlocaleditor?format=json'
@@ -60,7 +111,7 @@ export const action = new FileAction({
        },
 
        async exec(node: Node) {
-               openLocalClient(node.path)
+               attemptOpenLocalClient(node.path)
                return null
        },