|
|
|
@@ -33,7 +33,7 @@ class UsageUpdateWorker(
|
|
|
|
|
prefs.saveUsageData(data)
|
|
|
|
|
} catch (_: Exception) {}
|
|
|
|
|
animJob.cancel()
|
|
|
|
|
animJob.join() // wait for the minimum-rotation finally block to finish
|
|
|
|
|
animJob.join()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pushWidgetUpdate()
|
|
|
|
@@ -43,23 +43,25 @@ class UsageUpdateWorker(
|
|
|
|
|
private suspend fun rotateRefreshIcon() {
|
|
|
|
|
val manager = AppWidgetManager.getInstance(context)
|
|
|
|
|
val ids = manager.getAppWidgetIds(ComponentName(context, ClaudeUsageWidget::class.java))
|
|
|
|
|
var totalDegrees = 0f
|
|
|
|
|
val startMs = System.currentTimeMillis()
|
|
|
|
|
val msPerRotation = 800L // one full rotation every 0.8 seconds
|
|
|
|
|
|
|
|
|
|
fun angleAt(now: Long) = ((now - startMs) % msPerRotation) * 360f / msPerRotation
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
while (true) {
|
|
|
|
|
ClaudeUsageWidget.currentRotation = (ClaudeUsageWidget.currentRotation + 6f) % 360f
|
|
|
|
|
totalDegrees += 6f
|
|
|
|
|
ClaudeUsageWidget.currentRotation = angleAt(System.currentTimeMillis())
|
|
|
|
|
ids.forEach { id -> ClaudeUsageWidget.updateWidget(context, manager, id) }
|
|
|
|
|
delay(33) // 30 fps, one full rotation per second
|
|
|
|
|
delay(16) // aim for ~60fps; IPC speed sets the real ceiling
|
|
|
|
|
}
|
|
|
|
|
} finally {
|
|
|
|
|
// Even if the fetch finishes early, complete at least one full 360°
|
|
|
|
|
// Finish the current rotation cleanly — run until at least one full spin
|
|
|
|
|
withContext(NonCancellable) {
|
|
|
|
|
while (totalDegrees < 360f) {
|
|
|
|
|
ClaudeUsageWidget.currentRotation = (ClaudeUsageWidget.currentRotation + 6f) % 360f
|
|
|
|
|
totalDegrees += 6f
|
|
|
|
|
val minEndMs = startMs + msPerRotation
|
|
|
|
|
while (System.currentTimeMillis() < minEndMs) {
|
|
|
|
|
ClaudeUsageWidget.currentRotation = angleAt(System.currentTimeMillis())
|
|
|
|
|
ids.forEach { id -> ClaudeUsageWidget.updateWidget(context, manager, id) }
|
|
|
|
|
delay(33)
|
|
|
|
|
delay(16)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|