Skip to content

Commit 8dce420

Browse files
authored
feat: optional wake lock (#1676)
1 parent 1142d83 commit 8dce420

File tree

12 files changed

+52
-6
lines changed

12 files changed

+52
-6
lines changed

docs/custom/index.md

+2
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ selectable: true
5959
record: dev
6060
# enable Slidev's context menu, can be boolean, 'dev' or 'build'
6161
contextMenu: true
62+
# enable wake lock, can be boolean, 'dev' or 'build'
63+
wakeLock: true
6264

6365
# force color schema for the slides, can be 'auto', 'light', or 'dark'
6466
colorSchema: auto
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { useWakeLock as useVueUseWakeLock } from '@vueuse/core'
2+
import { watchEffect } from 'vue'
3+
import { wakeLockEnabled } from '../state'
4+
5+
export function useWakeLock() {
6+
const { request, release } = useVueUseWakeLock()
7+
8+
watchEffect((onCleanup) => {
9+
if (wakeLockEnabled.value)
10+
request('screen')
11+
onCleanup(release)
12+
})
13+
}

packages/client/constants.ts

+1
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,5 @@ export const HEADMATTER_FIELDS = [
8080
'htmlAttrs',
8181
'mdc',
8282
'contextMenu',
83+
'wakeLock',
8384
]

packages/client/internals/SelectList.vue

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type { SelectionItem } from './types'
55
66
const props = defineProps({
77
modelValue: {
8-
type: [Object, String, Number] as PropType<any>,
8+
type: [Object, String, Number, Boolean] as PropType<any>,
99
},
1010
title: {
1111
type: String,
@@ -43,7 +43,7 @@ const value = useVModel(props, 'modelValue', emit, { passive: true })
4343

4444
<style lang="postcss" scoped>
4545
.select-list {
46-
@apply py-2;
46+
@apply my-2;
4747
}
4848
4949
.item {
@@ -55,6 +55,6 @@ const value = useVModel(props, 'modelValue', emit, { passive: true })
5555
}
5656
5757
.title {
58-
@apply text-xs uppercase opacity-50 tracking-widest px-7 py-1;
58+
@apply text-xs uppercase opacity-50 tracking-widest px-7 py-1 select-none text-nowrap;
5959
}
6060
</style>
+18-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
<script setup lang="ts">
2-
import { slideScale } from '../state'
2+
import { useWakeLock } from '@vueuse/core'
3+
import { slideScale, wakeLockEnabled } from '../state'
34
import SelectList from './SelectList.vue'
45
import type { SelectionItem } from './types'
56
6-
const items: SelectionItem<number>[] = [
7+
const scaleItems: SelectionItem<number>[] = [
78
{
89
display: 'Fit',
910
value: 0,
@@ -13,10 +14,24 @@ const items: SelectionItem<number>[] = [
1314
value: 1,
1415
},
1516
]
17+
18+
const { isSupported } = useWakeLock()
19+
20+
const wakeLockItems: SelectionItem<boolean>[] = [
21+
{
22+
display: 'Enabled',
23+
value: true,
24+
},
25+
{
26+
display: 'Disabled',
27+
value: false,
28+
},
29+
]
1630
</script>
1731

1832
<template>
1933
<div class="text-sm select-none">
20-
<SelectList v-model="slideScale" title="Scale" :items="items" />
34+
<SelectList v-model="slideScale" title="Scale" :items="scaleItems" />
35+
<SelectList v-if="__SLIDEV_FEATURE_WAKE_LOCK__ && isSupported" v-model="wakeLockEnabled" title="Wake lock" :items="wakeLockItems" />
2136
</div>
2237
</template>

packages/client/pages/play.vue

+3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import SlidesShow from '../internals/SlidesShow.vue'
1010
import PrintStyle from '../internals/PrintStyle.vue'
1111
import { onContextMenu } from '../logic/contextMenu'
1212
import { useNav } from '../composables/useNav'
13+
import { useWakeLock } from '../composables/useWakeLock'
1314
import { useDrawings } from '../composables/useDrawings'
1415
import PresenterMouse from '../internals/PresenterMouse.vue'
1516
@@ -32,6 +33,8 @@ function onClick(e: MouseEvent) {
3233
3334
useSwipeControls(root)
3435
registerShortcuts()
36+
if (__SLIDEV_FEATURE_WAKE_LOCK__)
37+
useWakeLock()
3538
3639
const persistNav = computed(() => isScreenVertical.value || showEditor.value)
3740

packages/client/pages/presenter.vue

+3
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,14 @@ import ClicksSlider from '../internals/ClicksSlider.vue'
2424
import ContextMenu from '../internals/ContextMenu.vue'
2525
import { useNav } from '../composables/useNav'
2626
import { useDrawings } from '../composables/useDrawings'
27+
import { useWakeLock } from '../composables/useWakeLock'
2728
2829
const main = ref<HTMLDivElement>()
2930
3031
registerShortcuts()
3132
useSwipeControls(main)
33+
if (__SLIDEV_FEATURE_WAKE_LOCK__)
34+
useWakeLock()
3235
3336
const {
3437
clicksContext,

packages/client/state/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export const isOnFocus = computed(() => ['BUTTON', 'A'].includes(activeElement.v
2525
export const currentCamera = useLocalStorage<string>('slidev-camera', 'default', { listenToStorageChanges: false })
2626
export const currentMic = useLocalStorage<string>('slidev-mic', 'default', { listenToStorageChanges: false })
2727
export const slideScale = useLocalStorage<number>('slidev-scale', 0)
28+
export const wakeLockEnabled = useLocalStorage('slidev-wake-lock', true)
2829

2930
export const showPresenterCursor = useLocalStorage('slidev-presenter-cursor', true, { listenToStorageChanges: false })
3031
export const showEditor = useLocalStorage('slidev-show-editor', false, { listenToStorageChanges: false })

packages/parser/src/config.ts

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export function getDefaultConfig(): SlidevConfig {
3939
transition: undefined,
4040
editor: true,
4141
contextMenu: undefined,
42+
wakeLock: true,
4243
}
4344
}
4445

packages/slidev/node/vite/extendConfig.ts

+1
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ export function getDefine(options: ResolvedSlidevOptions): Record<string, string
230230
__SLIDEV_FEATURE_RECORD__: JSON.stringify(options.data.config.record === true || options.data.config.record === options.mode),
231231
__SLIDEV_FEATURE_PRESENTER__: JSON.stringify(options.data.config.presenter === true || options.data.config.presenter === options.mode),
232232
__SLIDEV_FEATURE_PRINT__: JSON.stringify(options.mode === 'export' || (options.mode === 'build' && [true, 'true', 'auto'].includes(options.data.config.download))),
233+
__SLIDEV_FEATURE_WAKE_LOCK__: JSON.stringify(options.data.config.wakeLock === true || options.data.config.wakeLock === options.mode),
233234
__SLIDEV_HAS_SERVER__: options.mode !== 'build' ? 'true' : 'false',
234235
}
235236
}

packages/types/src/config.ts

+4
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,10 @@ export interface SlidevConfig {
251251
* @default true
252252
*/
253253
contextMenu: boolean | 'dev' | 'build' | undefined
254+
/**
255+
* Enable wake lock
256+
*/
257+
wakeLock: boolean | 'dev' | 'build'
254258
}
255259

256260
export interface FontOptions {

shim.d.ts

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ declare global {
99
const __SLIDEV_FEATURE_RECORD__: boolean
1010
const __SLIDEV_FEATURE_PRESENTER__: boolean
1111
const __SLIDEV_FEATURE_PRINT__: boolean
12+
const __SLIDEV_FEATURE_WAKE_LOCK__: boolean
1213
const __SLIDEV_HAS_SERVER__: boolean
1314
}
1415

@@ -23,6 +24,7 @@ declare module '@vue/runtime-core' {
2324
__SLIDEV_FEATURE_RECORD__: boolean
2425
__SLIDEV_FEATURE_PRESENTER__: boolean
2526
__SLIDEV_FEATURE_PRINT__: boolean
27+
__SLIDEV_FEATURE_WAKE_LOCK__: boolean
2628
__SLIDEV_HAS_SERVER__: boolean
2729
}
2830
}

0 commit comments

Comments
 (0)