Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 37 additions & 1 deletion src_assets/common/assets/web/components/LogsSection.vue
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@
<i class="fas fa-copy me-1"></i>
{{ $t('troubleshooting.copy_config') }}
</button>
<span
class="dev-trigger"
@click="handleDevTap"
></span>
</div>
</div>
</div>
Expand All @@ -71,7 +75,11 @@
</template>

<script setup>
import { computed } from 'vue'
import { computed, ref } from 'vue'

const DEV_TAP_THRESHOLD = 7
const DEV_TAP_TIMEOUT = 3000
const DEV_STORAGE_KEY = 'sunshine_dev_mode'

const props = defineProps({
logFilter: {
Expand Down Expand Up @@ -161,6 +169,25 @@ const downloadLogs = async () => {
console.error('Failed to download logs:', e)
}
}

// Dev mode: 7 taps within 3 seconds
const devMode = ref(localStorage.getItem(DEV_STORAGE_KEY) === '1')
const devTapCount = ref(0)
let devTapTimer = null

const handleDevTap = () => {
devTapCount.value++
clearTimeout(devTapTimer)
devTapTimer = setTimeout(() => { devTapCount.value = 0 }, DEV_TAP_TIMEOUT)

if (devTapCount.value >= DEV_TAP_THRESHOLD) {
devTapCount.value = 0
devMode.value = !devMode.value
localStorage.setItem(DEV_STORAGE_KEY, devMode.value ? '1' : '0')
// Dispatch event so other components can react
window.dispatchEvent(new CustomEvent('sunshine-background-bypass', { detail: { enabled: devMode.value } }))
}
}
</script>

<style scoped>
Expand Down Expand Up @@ -314,4 +341,13 @@ const downloadLogs = async () => {
margin-top: 0.5rem;
}
}

.dev-trigger {
display: inline-block;
width: 12px;
min-height: 24px;
cursor: default;
user-select: none;
opacity: 0;
}
</style>
23 changes: 23 additions & 0 deletions src_assets/common/assets/web/composables/useBackground.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,19 @@ export function useBackground(options = {}) {

const getCurrentBackground = () => localStorage.getItem(storageKey) ?? defaultBackground

const isDevMode = () => localStorage.getItem('sunshine_dev_mode') === '1'

const clearDevBypass = () => {
if (localStorage.getItem('sunshine_dev_mode') === '1') {
localStorage.setItem('sunshine_dev_mode', '0')
}
}

const setBackground = async (imageUrl) => {
if (isDevMode()) {
document.body.style.background = ''
return
}
document.body.style.background = `url(${imageUrl}) center/cover fixed no-repeat`
if (isLocalImage(imageUrl)) {
try {
Expand All @@ -221,6 +233,7 @@ export function useBackground(options = {}) {
const loadBackground = () => setBackground(getCurrentBackground())

const saveBackground = async (imageData) => {
clearDevBypass()
try {
localStorage.setItem(storageKey, imageData)
} catch (error) {
Expand Down Expand Up @@ -310,6 +323,7 @@ export function useBackground(options = {}) {
}

const clearBackground = () => {
clearDevBypass()
localStorage.removeItem(storageKey)
return setBackground(defaultBackground)
}
Expand All @@ -321,6 +335,15 @@ export function useBackground(options = {}) {
const observer = new MutationObserver(handleThemeChange)
observer.observe(document.documentElement, observerConfig)
observer.observe(document.body, observerConfig)

// 监听背景旁路切换
window.addEventListener('sunshine-background-bypass', (e) => {
if (e.detail?.enabled) {
document.body.style.background = ''
} else {
loadBackground()
}
})
}

return {
Expand Down
Loading