Skip to content

Commit abfdc4f

Browse files
authored
Merge pull request #5234 from nextcloud/feat/favicon
feat: use filetype icon as favicon
2 parents dc9ffcf + 43790c3 commit abfdc4f

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

src/view/Office.vue

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ import axios from '@nextcloud/axios'
104104
import {
105105
generateUrl,
106106
imagePath,
107+
generateFilePath,
107108
} from '@nextcloud/router'
108109
import { isPublicShare, getSharingToken } from '@nextcloud/sharing/public'
109110
import { getCapabilities } from './../services/capabilities.ts'
@@ -195,6 +196,9 @@ export default {
195196
// Track the last requested save-as filename for export operations
196197
lastSaveAsFilename: null,
197198
199+
// Store original favicon for restoration
200+
originalFavicon: null,
201+
198202
formData: {
199203
action: null,
200204
accessToken: null,
@@ -256,6 +260,10 @@ export default {
256260
},
257261
},
258262
async mounted() {
263+
// Store and update favicon
264+
this.storeFavicon()
265+
this.updateFavicon()
266+
259267
this.postMessage = new PostMessageService({
260268
FRAME_DOCUMENT: () => document.getElementById(this.iframeId).contentWindow,
261269
})
@@ -302,6 +310,7 @@ export default {
302310
},
303311
beforeDestroy() {
304312
this.postMessage.unregisterPostMessageHandler(this.postMessageHandler)
313+
this.restoreFavicon()
305314
},
306315
methods: {
307316
async load() {
@@ -365,6 +374,7 @@ export default {
365374
FilesAppIntegration.updateFileInfo(undefined, Date.now())
366375
}
367376
disableScrollLock()
377+
this.restoreFavicon()
368378
this.$emit('close')
369379
},
370380
reload() {
@@ -537,6 +547,42 @@ export default {
537547
this.hasWidgetEditingEnabled = true
538548
},
539549
550+
getDocumentTypeIcon() {
551+
const mime = this.mime.toLowerCase()
552+
553+
if (mime.includes('spreadsheet')
554+
|| mime.includes('sheet')
555+
|| mime.includes('excel')
556+
|| mime.includes('csv')
557+
|| mime.includes('numbers')) {
558+
return 'x-office-spreadsheet'
559+
}
560+
561+
if (mime.includes('presentation')
562+
|| mime.includes('powerpoint')
563+
|| mime.includes('slideshow')
564+
|| mime.includes('keynote')) {
565+
return 'x-office-presentation'
566+
}
567+
568+
if (mime.includes('drawing')
569+
|| mime.includes('graphics')
570+
|| mime.includes('visio')) {
571+
return 'x-office-drawing'
572+
}
573+
574+
return 'x-office-document'
575+
},
576+
577+
restoreFavicon() {
578+
if (this.originalFavicon) {
579+
const link = document.querySelector('link[rel*="icon"]')
580+
if (link) {
581+
link.href = this.originalFavicon
582+
}
583+
}
584+
},
585+
540586
},
541587
}
542588
</script>

0 commit comments

Comments
 (0)