Skip to content

Commit

Permalink
feat: getTime in every 5 second
Browse files Browse the repository at this point in the history
  • Loading branch information
JdaieLin committed Jul 5, 2020
1 parent 5449af0 commit afff01e
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions electron/src/renderer/components/MainWindow.vue
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,8 @@
chargeDialog: false,
chargingMarks: {
80: '80%',
}
},
timeUpdaterCount: 0
}
},
Expand Down Expand Up @@ -610,27 +611,28 @@
this.$socket.send('rtc_pi2rtc')
setTimeout(() => {
this.getDeviceTime()
}, 1500)
}, 1000)
this.timeDialog = false
},
syncRTC2Pi () {
this.$socket.send('rtc_rtc2pi')
setTimeout(() => {
this.getDeviceTime()
}, 1500)
}, 1000)
this.timeDialog = false
},
syncWebTime () {
this.$socket.send('rtc_web')
setTimeout(() => {
this.getDeviceTime()
}, 1500)
}, 1000)
this.timeDialog = false
},
timeUpdater () {
const that = this
const current = new Date().getTime()
// 相差两秒内,强行一致
this.timeUpdaterCount++
// align time if diff < 2000
if (this.rtcTime && this.sysTime) {
const diff = this.sysTime.diff(this.rtcTime)
if (Math.abs(diff) < 2000) {
Expand All @@ -652,6 +654,9 @@
setTimeout(() => {
that.timeUpdater()
}, 1000)
if (this.timeUpdaterCount % 5 === 0) {
this.getDeviceTime()
}
},
timeEditChange () {
this.setRtcAlarm()
Expand Down Expand Up @@ -721,6 +726,7 @@
this.$socket.send(`set_battery_charging_range ${this.chargingRestartPoint},100`)
},
getDeviceTime () {
if (!this.socketConnect) return
this.$socket.send('get rtc_time')
this.$socket.send('get system_time')
},
Expand Down

0 comments on commit afff01e

Please sign in to comment.