Skip to content

Commit

Permalink
wip: Enhance capabilities to handle fullscreen mode #913
Browse files Browse the repository at this point in the history
  • Loading branch information
cnouguier committed Aug 1, 2024
1 parent e629bf5 commit d8aecf3
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
6 changes: 6 additions & 0 deletions core/client/components/action/KAction.vue
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,12 @@ async function onClicked (event) {
watch(() => props.toggled, (value) => {
if (isToggled.value !== value) isToggled.value = value
})
// Expose
defineExpose({
isToggled,
toggle
})
</script>

<style lang="scss" scoped>
Expand Down
24 changes: 24 additions & 0 deletions core/client/components/action/KToggleFullscreenAction.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<template>
<KAction
ref="actionRef"
v-bind="props"
:handler="toggleFullscreen"
/>
</template>

<script setup>
import { ref, watch } from 'vue'
import { actionProps, isFullscreen, toggleFullscreen } from '../../utils'
import KAction from './KAction.vue'
// Props
const props = defineProps(_.pick(actionProps, ['id', 'label', 'tooltip', 'icon', 'toggle']))
// Data
const actionRef = ref(null)
// Watch
watch(isFullscreen, () => {
if (actionRef.value.isToggled !== isFullscreen.value) actionRef.value.toggle()
})
</script>
15 changes: 13 additions & 2 deletions core/client/utils/utils.screen.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import _ from 'lodash'
import logger from 'loglevel'
import {toRef } from 'vue'
import { Screen } from 'quasar'
import { AppFullscreen } from 'quasar'

export const isFullscreen = toRef(AppFullscreen, 'isActive')

export function computeResponsiveWidth (width) {
let breakpointWidth = width
if (typeof width === 'object') {
Expand Down Expand Up @@ -53,6 +56,14 @@ export function getOrientation () {
}

export async function toggleFullscreen () {
if (AppFullscreen.isActive) return AppFullscreen.request()
else return AppFullscreen.exit()
return new Promise((resolve, reject) => {
AppFullscreen.toggle()
.then(() => {
resolve(true)
})
.catch(err => {
logger.warn(`[KDK] Cannot toggle fullscreen mode: ${err}`)
reject(false)
})
})
}

0 comments on commit d8aecf3

Please sign in to comment.