Skip to content

Commit

Permalink
feat(editLocallyAction): Handle possible no local client scenario
Browse files Browse the repository at this point in the history
Resolves: #46438

Signed-off-by: fenn-cs <fenn25.fn@gmail.com>
  • Loading branch information
Fenn-CS committed Jul 11, 2024
1 parent 64701f8 commit a113d41
Showing 1 changed file with 64 additions and 3 deletions.
67 changes: 64 additions & 3 deletions apps/files/src/actions/editLocallyAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,73 @@ 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 = (
title: string,
text: string,
confirmButtonText: string,
cancelButtonText: string,
callback: (openingLocally: boolean) => void = () => {},
) => {
let callbackCalled = false

return new DialogBuilder()
.setName(title)
.setText(text)
.setButtons([
{
label: confirmButtonText,
icon: IconCheck,
type: 'primary',
callback: () => {
callbackCalled = true
callback(true)

Check failure on line 35 in apps/files/src/actions/editLocallyAction.ts

View workflow job for this annotation

GitHub Actions / NPM lint

Unexpected literal in error position of callback
},
},
{
label: cancelButtonText,
icon: IconCancel,
callback: () => {
callbackCalled = true
callback(false)

Check failure on line 43 in apps/files/src/actions/editLocallyAction.ts

View workflow job for this annotation

GitHub Actions / NPM lint

Unexpected literal in error position of callback
},
},
])
.build()
.show()
.then(() => {
// Ensure the callback is called even if the dialog is dismissed in other ways
if (!callbackCalled) {
callback(false)

Check failure on line 52 in apps/files/src/actions/editLocallyAction.ts

View workflow job for this annotation

GitHub Actions / NPM lint

Unexpected literal in error position of callback
}
})
}

const startOpenLocalProcess = async (path: string) => {
showConfirmLocalEditModal(path)
}

const showConfirmLocalEditModal = async (path: string, fileName = '') => {
confirmLocalEditDialog(
t('files', 'Open file locally'),
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.'),
t('files', 'Retry to open locally'),
t('files', 'Continue editing online'),
(openLocally: boolean) => {
if (!openLocally) {
window.OCA.Viewer.open({ path: fileName })
return
}
openLocalClient(path)
},
)
}
const openLocalClient = async function(path: string) {
const link = generateOcsUrl('apps/files/api/v1') + '/openlocaleditor?format=json'

Expand Down Expand Up @@ -43,7 +104,7 @@ export const action = new FileAction({
},

async exec(node: Node) {
openLocalClient(node.path)
startOpenLocalProcess(node.path)
return null
},

Expand Down

0 comments on commit a113d41

Please sign in to comment.