v1.3: smooth 30fps rotation (6° steps), guaranteed minimum one full spin per tap

This commit is contained in:
2026-05-22 16:00:17 +00:00
parent d86ffabb98
commit f6f7accfa5
2 changed files with 24 additions and 6 deletions
+2 -2
View File
@@ -11,8 +11,8 @@ android {
applicationId = "me.khodak.claudeusage"
minSdk = 26
targetSdk = 34
versionCode = 3
versionName = "1.2"
versionCode = 4
versionName = "1.3"
}
signingConfigs {
@@ -8,9 +8,11 @@ import android.content.Context
import android.content.Intent
import android.os.SystemClock
import androidx.work.*
import kotlinx.coroutines.NonCancellable
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import me.khodak.claudeusage.data.PreferencesManager
class UsageUpdateWorker(
@@ -31,6 +33,7 @@ class UsageUpdateWorker(
prefs.saveUsageData(data)
} catch (_: Exception) {}
animJob.cancel()
animJob.join() // wait for the minimum-rotation finally block to finish
}
pushWidgetUpdate()
@@ -40,10 +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
try {
while (true) {
ClaudeUsageWidget.currentRotation = (ClaudeUsageWidget.currentRotation + 30f) % 360f
ClaudeUsageWidget.currentRotation = (ClaudeUsageWidget.currentRotation + 6f) % 360f
totalDegrees += 6f
ids.forEach { id -> ClaudeUsageWidget.updateWidget(context, manager, id) }
delay(83) // ~12 fps one full rotation per second
delay(33) // 30 fps, one full rotation per second
}
} finally {
// Even if the fetch finishes early, complete at least one full 360°
withContext(NonCancellable) {
while (totalDegrees < 360f) {
ClaudeUsageWidget.currentRotation = (ClaudeUsageWidget.currentRotation + 6f) % 360f
totalDegrees += 6f
ids.forEach { id -> ClaudeUsageWidget.updateWidget(context, manager, id) }
delay(33)
}
}
}
}