File size: 1,428 Bytes
2d8be8f | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | <script>
import { show, hide, setTheme, setDockVisibility } from '@tauri-apps/api/app'
let { onMessage } = $props()
/** @type {import('@tauri-apps/api/window').Theme | 'auto'} */
let theme = $state('auto')
let dockVisible = $state(true)
function showApp() {
hideApp()
.then(() => {
setTimeout(() => {
show()
.then(() => onMessage('Shown app'))
.catch(onMessage)
}, 2000)
})
.catch(onMessage)
}
function hideApp() {
return hide()
.then(() => onMessage('Hide app'))
.catch(onMessage)
}
async function switchTheme() {
switch (theme) {
case 'dark':
theme = 'light'
break
case 'light':
theme = 'auto'
break
case 'auto':
theme = 'dark'
break
}
setTheme(theme === 'auto' ? null : theme)
}
async function toggleDockVisibility() {
await setDockVisibility(!dockVisible)
dockVisible = !dockVisible
}
</script>
<div>
<button
class="btn"
id="show"
title="Hides and shows the app after 2 seconds"
onclick={showApp}>Show</button
>
<button class="btn" id="hide" onclick={hideApp}>Hide</button>
<button class="btn" id="switch-theme" onclick={switchTheme}
>Switch Theme ({theme})</button
>
<button class="btn" id="toggle-dock-visibility" onclick={toggleDockVisibility}>Toggle dock visibility</button>
</div>
|