Skip to content

Commit e5a85a0

Browse files
committed
feat: add downloadCallback for Viewer handler
Signed-off-by: silver <s.szmajduch@posteo.de>
1 parent 497152a commit e5a85a0

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

src/viewer.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,26 @@ if (typeof OCA.Viewer === 'undefined') {
2828
group: null,
2929
theme: 'default',
3030
canCompare: true,
31+
downloadCallback: async (fileInfo) => {
32+
// Save any unsaved changes before download
33+
logger.debug('Download callback triggered', { fileInfo })
34+
const editors = window.OCA?.Text?.editorComponents
35+
logger.debug('Active editors', { editors, count: editors?.size })
36+
if (editors instanceof Set) {
37+
for (const editor of editors) {
38+
logger.debug('Checking editor', {
39+
editorFileId: editor?.fileId,
40+
fileInfoId: fileInfo.fileid,
41+
dirty: editor?.dirty
42+
})
43+
if (editor?.fileId === fileInfo.fileid && editor?.dirty) {
44+
logger.debug('Saving file before download', { fileId: fileInfo.fileid })
45+
await editor.save()
46+
return
47+
}
48+
}
49+
}
50+
logger.debug('No matching editor found or no unsaved changes')
51+
},
3152
})
3253
}

0 commit comments

Comments
 (0)