Skip to content

Commit

Permalink
send timezone offset in minutes not hours
Browse files Browse the repository at this point in the history
  • Loading branch information
crc-32 committed Nov 29, 2024
1 parent b317e51 commit 873d35e
Showing 1 changed file with 6 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,6 @@ class SystemHandler(
pebbleDevice.systemService.appVersionRequestHandler = this::handleAppVersionRequest
listenForTimeChange()

negotiationScope.launch {
// Wait until watch is connected before sending time
ConnectionStateManager.connectionState.first { it is ConnectionState.Connected }

sendCurrentTime()
}

negotiationScope.launch {
ConnectionStateManager.connectionState.first { it is ConnectionState.Negotiating }
negotiate()
Expand Down Expand Up @@ -72,6 +65,7 @@ class SystemHandler(
Logging.i("Watch is in recovery mode, switching to recovery state")
recoveryMode(pebbleDevice)
} else {
sendCurrentTime()
negotiationsComplete(pebbleDevice)
}
}
Expand Down Expand Up @@ -113,6 +107,7 @@ class SystemHandler(
negotiationScope.launch {
val connectionScope = pebbleDevice.connectionScope.filterNotNull().first()
platformTimeChangedFlow(platformContext).onEach {
Logging.d("Time/timezone changed, updating time on watch")
sendCurrentTime()
}.launchIn(connectionScope)
}
Expand All @@ -122,14 +117,15 @@ class SystemHandler(
private suspend fun sendCurrentTime() {
val timezone = TimeZone.currentSystemDefault()
val now = Clock.System.now()

val timezoneOffsetMinutes = timezone.offsetAt(now).totalSeconds.seconds.inWholeMinutes
Logging.i("Sending current time to watch: $now, timezone: $timezone, offset: $timezoneOffsetMinutes")
val updateTimePacket = TimeMessage.SetUTC(
now.epochSeconds.toUInt(),
timezone.offsetAt(now).totalSeconds.seconds.inWholeHours.toShort(),
timezoneOffsetMinutes.toShort(),
timezone.id
)

systemService.send(updateTimePacket, PacketPriority.LOW)
systemService.send(updateTimePacket)
}

private suspend fun handleAppVersionRequest(): PhoneAppVersion.AppVersionResponse {
Expand Down

0 comments on commit 873d35e

Please sign in to comment.