From 9ace7b8a348ecf58497f72e0731ca3f0ee972bf3 Mon Sep 17 00:00:00 2001 From: Jan Ackermann Date: Tue, 27 Feb 2024 15:50:41 +0100 Subject: [PATCH 1/6] Warn user before closing browser when upload is in progress --- packages/web-runtime/src/components/UploadInfo.vue | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/packages/web-runtime/src/components/UploadInfo.vue b/packages/web-runtime/src/components/UploadInfo.vue index 434ca225f18..53114cc9651 100644 --- a/packages/web-runtime/src/components/UploadInfo.vue +++ b/packages/web-runtime/src/components/UploadInfo.vue @@ -175,7 +175,7 @@ export default defineComponent({ components: { ResourceListItem, ResourceIcon, ResourceName }, setup() { const capabilityStore = useCapabilityStore() - const capabilityRefs = storeToRefs(capabilityStore) + const configStore = useConfigStore() const { options: configOptions } = storeToRefs(configStore) @@ -283,6 +283,12 @@ export default defineComponent({ return requestIds.map((item) => `X-Request-Id: ${item}`).join('\r\n') } }, + mounted() { + window.addEventListener('beforeunload', this.onBeforeUnload) + }, + unmounted() { + window.removeEventListener('beforeunload', this.onBeforeUnload) + }, created() { this.$uppyService.subscribe('uploadStarted', () => { if (!this.remainingTime) { @@ -649,6 +655,11 @@ export default defineComponent({ }, getUploadItemClass(item) { return this.errors[item.meta.uploadId] ? 'upload-info-danger' : 'upload-info-success' + }, + onBeforeUnload(e: BeforeUnloadEvent) { + if (this.runningUploads) { + e.preventDefault() + } } } }) @@ -693,6 +704,7 @@ export default defineComponent({ .upload-info-danger { color: var(--oc-color-swatch-danger-default); } + .upload-info-success { color: var(--oc-color-swatch-success-default); } From 51f8a76f8f7aa2fa348aae87a7e4227d9fd1dd2a Mon Sep 17 00:00:00 2001 From: Jan Ackermann Date: Tue, 27 Feb 2024 15:53:30 +0100 Subject: [PATCH 2/6] Add changelog item --- ...nhancement-warn-user-before-close-browser-when-uploading | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 changelog/unreleased/enhancement-warn-user-before-close-browser-when-uploading diff --git a/changelog/unreleased/enhancement-warn-user-before-close-browser-when-uploading b/changelog/unreleased/enhancement-warn-user-before-close-browser-when-uploading new file mode 100644 index 00000000000..cb991c7cc42 --- /dev/null +++ b/changelog/unreleased/enhancement-warn-user-before-close-browser-when-uploading @@ -0,0 +1,6 @@ +Enhancement: Warn user before closing browser when upload is in progress + +We've added a warning message for the user, if they try to close the browser while upload is in progress. + +https://github.com/owncloud/web/pull/10519 +https://github.com/owncloud/web/issues/10500 From 194804928917bea3ddc89ee3a7918dca7c162064 Mon Sep 17 00:00:00 2001 From: Jan Ackermann Date: Tue, 27 Feb 2024 16:33:52 +0100 Subject: [PATCH 3/6] Use watcher --- .../web-runtime/src/components/UploadInfo.vue | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/packages/web-runtime/src/components/UploadInfo.vue b/packages/web-runtime/src/components/UploadInfo.vue index 53114cc9651..443b812f6b2 100644 --- a/packages/web-runtime/src/components/UploadInfo.vue +++ b/packages/web-runtime/src/components/UploadInfo.vue @@ -160,7 +160,7 @@ import { isUndefined } from 'lodash-es' import getSpeed from '@uppy/utils/lib/getSpeed' import { urlJoin } from '@ownclouders/web-client/src/utils' -import { useCapabilityStore, useConfigStore } from '@ownclouders/web-pkg' +import { useConfigStore } from '@ownclouders/web-pkg' import { formatFileSize, UppyResource, @@ -174,8 +174,6 @@ import { storeToRefs } from 'pinia' export default defineComponent({ components: { ResourceListItem, ResourceIcon, ResourceName }, setup() { - const capabilityStore = useCapabilityStore() - const configStore = useConfigStore() const { options: configOptions } = storeToRefs(configStore) @@ -283,11 +281,14 @@ export default defineComponent({ return requestIds.map((item) => `X-Request-Id: ${item}`).join('\r\n') } }, - mounted() { - window.addEventListener('beforeunload', this.onBeforeUnload) - }, - unmounted() { - window.removeEventListener('beforeunload', this.onBeforeUnload) + watch: { + runningUploads(val) { + if (val === 0) { + return window.removeEventListener('beforeunload', (this as any).onBeforeUnload) + } + + return window.addEventListener('beforeunload', (this as any).onBeforeUnload) + } }, created() { this.$uppyService.subscribe('uploadStarted', () => { From 11ad12a7e94f895f8aa1c8277ddbbbf8ab77f783 Mon Sep 17 00:00:00 2001 From: Jan Ackermann Date: Tue, 27 Feb 2024 18:44:22 +0100 Subject: [PATCH 4/6] Move to composition api --- .../web-runtime/src/components/UploadInfo.vue | 91 +++++++++++-------- 1 file changed, 54 insertions(+), 37 deletions(-) diff --git a/packages/web-runtime/src/components/UploadInfo.vue b/packages/web-runtime/src/components/UploadInfo.vue index 443b812f6b2..4e7cff88108 100644 --- a/packages/web-runtime/src/components/UploadInfo.vue +++ b/packages/web-runtime/src/components/UploadInfo.vue @@ -155,7 +155,7 @@