Merge pull request #1469 from benscobie/issue/1434
Keep screen awake when viewing recipe
This commit is contained in:
commit
5f9820ed30
@ -208,6 +208,7 @@ export default {
|
|||||||
servings_cache: {},
|
servings_cache: {},
|
||||||
start_time: "",
|
start_time: "",
|
||||||
share_uid: window.SHARE_UID,
|
share_uid: window.SHARE_UID,
|
||||||
|
wake_lock: null,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
@ -218,8 +219,37 @@ export default {
|
|||||||
mounted() {
|
mounted() {
|
||||||
this.loadRecipe(window.RECIPE_ID)
|
this.loadRecipe(window.RECIPE_ID)
|
||||||
this.$i18n.locale = window.CUSTOM_LOCALE
|
this.$i18n.locale = window.CUSTOM_LOCALE
|
||||||
|
this.requestWakeLock()
|
||||||
|
},
|
||||||
|
beforeUnmount() {
|
||||||
|
this.destroyWakeLock()
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
requestWakeLock: async function() {
|
||||||
|
if ('wakeLock' in navigator) {
|
||||||
|
try {
|
||||||
|
this.wake_lock = await navigator.wakeLock.request('screen')
|
||||||
|
document.addEventListener('visibilitychange', this.visibilityChange)
|
||||||
|
} catch (err) {
|
||||||
|
console.log(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
destroyWakeLock: function() {
|
||||||
|
if (this.wake_lock != null) {
|
||||||
|
this.wake_lock.release()
|
||||||
|
.then(() => {
|
||||||
|
this.wake_lock = null
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
document.removeEventListener('visibilitychange', this.visibilityChange)
|
||||||
|
},
|
||||||
|
visibilityChange: async function() {
|
||||||
|
if (this.wake_lock != null && document.visibilityState === 'visible') {
|
||||||
|
await this.requestWakeLock()
|
||||||
|
}
|
||||||
|
},
|
||||||
loadRecipe: function (recipe_id) {
|
loadRecipe: function (recipe_id) {
|
||||||
apiLoadRecipe(recipe_id).then((recipe) => {
|
apiLoadRecipe(recipe_id).then((recipe) => {
|
||||||
if (window.USER_SERVINGS !== 0) {
|
if (window.USER_SERVINGS !== 0) {
|
||||||
|
Loading…
Reference in New Issue
Block a user