Skip to content
Snippets Groups Projects
Commit 038b40b8 authored by fenn-cs's avatar fenn-cs
Browse files

feat(editLocallyAction): Handle possible no local client scenario

parent 70dd8d51
No related branches found
No related tags found
No related merge requests found
...@@ -6,11 +6,62 @@ import { encodePath } from '@nextcloud/paths' ...@@ -6,11 +6,62 @@ import { encodePath } from '@nextcloud/paths'
import { generateOcsUrl } from '@nextcloud/router' import { generateOcsUrl } from '@nextcloud/router'
import { getCurrentUser } from '@nextcloud/auth' import { getCurrentUser } from '@nextcloud/auth'
import { FileAction, Permission, type Node } from '@nextcloud/files' 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 { translate as t } from '@nextcloud/l10n'
import axios from '@nextcloud/axios' import axios from '@nextcloud/axios'
import LaptopSvg from '@mdi/svg/svg/laptop.svg?raw' 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 openLocalClient = async function(path: string) {
const link = generateOcsUrl('apps/files/api/v1') + '/openlocaleditor?format=json' const link = generateOcsUrl('apps/files/api/v1') + '/openlocaleditor?format=json'
...@@ -43,7 +94,7 @@ export const action = new FileAction({ ...@@ -43,7 +94,7 @@ export const action = new FileAction({
}, },
async exec(node: Node) { async exec(node: Node) {
openLocalClient(node.path) attemptOpenLocalClient(node.path)
return null return null
}, },
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment