Skip to content

Commit

Permalink
fix(deps): replace PreventUnload with native browser functionality
Browse files Browse the repository at this point in the history
Signed-off-by: Maksim Sukharev <[email protected]>
  • Loading branch information
Antreesy committed May 13, 2024
1 parent ce8ec26 commit 32fa5dc
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 12 deletions.
17 changes: 14 additions & 3 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
<router-view />
</NcAppContent>
<RightSidebar :is-in-call="isInCall" />
<PreventUnload :when="warnLeaving || isSendingMessages" />
<MediaSettings :recording-consent-given.sync="recordingConsentGiven" />
<SettingsDialog />
<ConversationSettingsDialog />
Expand All @@ -23,7 +22,6 @@
<script>
import debounce from 'debounce'
import { provide } from 'vue'
import PreventUnload from 'vue-prevent-unload'

import { getCurrentUser } from '@nextcloud/auth'
import { emit, subscribe, unsubscribe } from '@nextcloud/event-bus'
Expand Down Expand Up @@ -58,7 +56,6 @@ export default {
NcAppContent,
NcContent,
LeftSidebar,
PreventUnload,
RightSidebar,
SettingsDialog,
ConversationSettingsDialog,
Expand Down Expand Up @@ -246,6 +243,10 @@ export default {
}
},

created() {
window.addEventListener('beforeunload', this.preventUnload)
},

beforeDestroy() {
this.debounceRefreshCurrentConversation.clear?.()
if (!getCurrentUser()) {
Expand All @@ -254,6 +255,8 @@ export default {
document.removeEventListener('visibilitychange', this.changeWindowVisibility)

unsubscribe('notifications:action:execute', this.interceptNotificationActions)

window.removeEventListener('beforeunload', this.preventUnload)
},

beforeMount() {
Expand Down Expand Up @@ -671,6 +674,14 @@ export default {
this.windowHeight = window.innerHeight - document.getElementById('header').clientHeight
},

preventUnload(event) {
if (!this.warnLeaving && !this.isSendingMessages) {
return
}

event.preventDefault()
},

/**
* Get a conversation's name.
*
Expand Down
20 changes: 16 additions & 4 deletions src/FilesSidebarCallViewApp.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,10 @@
<CallView v-if="showCallView"
:token="token"
:is-sidebar="true" />
<PreventUnload :when="warnLeaving" />
</div>
</template>

<script>
import PreventUnload from 'vue-prevent-unload'

import LoadingComponent from './components/LoadingComponent.vue'

import { useHashCheck } from './composables/useHashCheck.js'
Expand All @@ -35,7 +32,6 @@ export default {
render: (h) => h(LoadingComponent, { class: 'call-loading' }),
},
}),
PreventUnload,
TopBar: () => import(/* webpackChunkName: "files-sidebar-call-chunk" */'./components/TopBar/TopBar.vue'),
},

Expand Down Expand Up @@ -147,7 +143,23 @@ export default {
},
},

created() {
window.addEventListener('beforeunload', this.preventUnload)
},

beforeDestroy() {
window.removeEventListener('beforeunload', this.preventUnload)
},

methods: {
preventUnload(event) {
if (!this.warnLeaving) {
return
}

event.preventDefault()
},

setFileInfo(fileInfo) {
},

Expand Down
20 changes: 15 additions & 5 deletions src/PublicShareSidebar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
<CallView v-if="isInCall"
:token="token"
:is-sidebar="true" />
<PreventUnload :when="warnLeaving" />
<CallButton class="call-button" />
<ChatView />
<PollViewer />
Expand All @@ -37,8 +36,6 @@
</template>

<script>
import PreventUnload from 'vue-prevent-unload'

import { showError } from '@nextcloud/dialogs'
import { loadState } from '@nextcloud/initial-state'

Expand All @@ -64,7 +61,6 @@ import { checkBrowser } from './utils/browserCheck.js'
import { signalingKill } from './utils/webrtc/index.js'

export default {

name: 'PublicShareSidebar',

components: {
Expand All @@ -74,7 +70,6 @@ export default {
MediaSettings,
NcButton,
PollViewer,
PreventUnload,
TopBar,
TransitionWrapper,
},
Expand Down Expand Up @@ -126,6 +121,10 @@ export default {
},
},

created() {
window.addEventListener('beforeunload', this.preventUnload)
},

beforeMount() {
window.addEventListener('unload', () => {
if (this.token) {
Expand All @@ -139,7 +138,18 @@ export default {
})
},

beforeDestroy() {
window.removeEventListener('beforeunload', this.preventUnload)
},

methods: {
preventUnload(event) {
if (!this.warnLeaving) {
return
}

event.preventDefault()
},

async joinConversation() {
checkBrowser()
Expand Down

0 comments on commit 32fa5dc

Please sign in to comment.