Skip to content

Commit a61d330

Browse files
committed
add shake to wake
1 parent 8781019 commit a61d330

File tree

5 files changed

+32
-12
lines changed

5 files changed

+32
-12
lines changed

components/Player.vue

+1-4
Original file line numberDiff line numberDiff line change
@@ -237,10 +237,7 @@ export default {
237237
if (mins === 'chapter') {
238238
this.$store.commit('player/sleep', 'chapter')
239239
} else {
240-
const seconds = mins * 60 // mins to seconds
241-
const milliseconds = seconds * 1000 // conds to milliseconds
242-
this.$store.dispatch('player/sleeptimer', milliseconds)
243-
this.$store.commit('player/sleepend', Date.now() + milliseconds)
240+
this.$store.dispatch('player/sleeptimer', mins)
244241
}
245242
this.setsleeptimer = false
246243
},

layouts/page.vue

+11-7
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ export default {
6363
showplayer () {
6464
return this.$store.state.app.player
6565
},
66+
fadeout () {
67+
return this.$store.state.player.fadeout
68+
},
6669
player () {
6770
return this.$store.state.player.player
6871
},
@@ -99,13 +102,15 @@ export default {
99102
}
100103
}
101104
},
102-
grantdevicemotion (to, from) {
103-
console.log('grantdevicemotion event')
104-
console.log(to)
105+
fadeout (to, from) {
105106
if (to !== from) {
106107
if (to !== null) {
107-
console.log('permission granteds')
108-
window.addEventListener('devicemotion', this.motion, false)
108+
if(this.grantdevicemotion !== null) {
109+
console.log('permission granted')
110+
window.addEventListener('devicemotion', this.motion, false)
111+
}
112+
} else {
113+
window.removeEventListener('devicemotion', this.motion, false)
109114
}
110115
}
111116
},
@@ -208,8 +213,7 @@ export default {
208213
}
209214
210215
if (this.moveCounter > 2) {
211-
console.log('SHAKE!!!')
212-
alert('shake!!')
216+
this.$store.dispatch('player/clearFadeout')
213217
this.moveCounter = 0
214218
}
215219

store/player/actions.js

+15-1
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,21 @@ export function setGlobalSeek (context) {
7676

7777
}
7878

79-
export function sleeptimer (context, milliseconds) {
79+
export function sleeptimer (context, mins) {
80+
const seconds = mins * 60 // mins to seconds
81+
const milliseconds = seconds * 1000 // conds to milliseconds
82+
8083
const timerid = setTimeout(() => {
8184
// context.state.player.pause()
8285
context.commit('sleepend', null)
8386
context.commit('sleep', null)
8487
fadeOut(context)
8588
}, milliseconds)
89+
8690
context.commit('sleep', timerid)
91+
context.commit('player/sleepamount', mins)
92+
context.commit('player/sleepend', Date.now() + milliseconds)
93+
8794
}
8895

8996
export function fadeOut (context) {
@@ -108,3 +115,10 @@ export function clearSleepTmer (context) {
108115
context.commit('sleepend', null)
109116
context.commit('sleep', null)
110117
}
118+
119+
export function clearFadeout (context) {
120+
const mins = context.state.sleepamount
121+
clearInterval(context.state.fadeout)
122+
context.state.player.volume = 1
123+
sleeptimer(context, mins)
124+
}

store/player/mutations.js

+4
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ export function sleep (state, data) {
3535
state.sleep = data
3636
}
3737

38+
export function sleepamount (state, data) {
39+
state.sleepamount = data
40+
}
41+
3842
export function fadeout (state, data) {
3943
state.fadeout = data
4044
}

store/player/state.js

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export default {
1111
path: ''
1212
},
1313
sleep: null,
14+
sleepamount: null,
1415
sleepend: null,
1516
fadeout: null
1617
}

0 commit comments

Comments
 (0)