mirror of
https://github.com/modrinth/code.git
synced 2026-08-27 10:04:52 +00:00
fix: hide ad webview when showing fullscreen content (#7110)
* fix: hide ad webview when showing fullscreen content * fixes
This commit is contained in:
@@ -95,8 +95,9 @@ import {
|
||||
hide_ads_window,
|
||||
init_ads_window,
|
||||
perform_ads_consent_action,
|
||||
release_ads_window_hold,
|
||||
should_show_ads_consent_popup,
|
||||
show_ads_window,
|
||||
take_ads_window_hold,
|
||||
} from '@/helpers/ads.js'
|
||||
import { debugAnalytics, initAnalytics, trackEvent } from '@/helpers/analytics'
|
||||
import { check_reachable } from '@/helpers/auth.js'
|
||||
@@ -166,6 +167,25 @@ function updateHistoryNavigationState() {
|
||||
canNavigateForward.value = historyState?.forward != null
|
||||
}
|
||||
|
||||
let fullscreenAdsWindowHold = false
|
||||
|
||||
async function handleFullscreenChange() {
|
||||
const fullscreen = document.fullscreenElement !== null
|
||||
if (fullscreen === fullscreenAdsWindowHold) return
|
||||
|
||||
fullscreenAdsWindowHold = fullscreen
|
||||
try {
|
||||
if (fullscreen) {
|
||||
await take_ads_window_hold()
|
||||
} else {
|
||||
await release_ads_window_hold()
|
||||
}
|
||||
} catch (error) {
|
||||
fullscreenAdsWindowHold = !fullscreen
|
||||
handleError(error)
|
||||
}
|
||||
}
|
||||
|
||||
updateHistoryNavigationState()
|
||||
|
||||
const APP_LEFT_NAV_WIDTH = '4rem'
|
||||
@@ -284,8 +304,8 @@ providePageContext({
|
||||
})
|
||||
provideModalBehavior({
|
||||
noblur: computed(() => !themeStore.advancedRendering),
|
||||
onShow: () => hide_ads_window(),
|
||||
onHide: () => show_ads_window(),
|
||||
onShow: () => take_ads_window_hold(),
|
||||
onHide: () => release_ads_window_hold(),
|
||||
})
|
||||
|
||||
const {
|
||||
@@ -360,6 +380,7 @@ onMounted(async () => {
|
||||
|
||||
document.querySelector('body').addEventListener('click', handleClick)
|
||||
document.querySelector('body').addEventListener('auxclick', handleAuxClick)
|
||||
document.addEventListener('fullscreenchange', handleFullscreenChange)
|
||||
|
||||
checkUpdates()
|
||||
})
|
||||
@@ -367,8 +388,13 @@ onMounted(async () => {
|
||||
onUnmounted(async () => {
|
||||
document.querySelector('body').removeEventListener('click', handleClick)
|
||||
document.querySelector('body').removeEventListener('auxclick', handleAuxClick)
|
||||
document.removeEventListener('fullscreenchange', handleFullscreenChange)
|
||||
clearDelayedUpdatePopup()
|
||||
|
||||
if (fullscreenAdsWindowHold) {
|
||||
fullscreenAdsWindowHold = false
|
||||
await release_ads_window_hold().catch(handleError)
|
||||
}
|
||||
await unlistenAdsConsent?.()
|
||||
await unlistenUpdateDownload?.()
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user