v1.5: time-based rotation angle — constant speed regardless of IPC load
This commit is contained in:
@@ -11,8 +11,8 @@ android {
|
|||||||
applicationId = "me.khodak.claudeusage"
|
applicationId = "me.khodak.claudeusage"
|
||||||
minSdk = 26
|
minSdk = 26
|
||||||
targetSdk = 34
|
targetSdk = 34
|
||||||
versionCode = 5
|
versionCode = 6
|
||||||
versionName = "1.4"
|
versionName = "1.5"
|
||||||
}
|
}
|
||||||
|
|
||||||
signingConfigs {
|
signingConfigs {
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ class UsageUpdateWorker(
|
|||||||
prefs.saveUsageData(data)
|
prefs.saveUsageData(data)
|
||||||
} catch (_: Exception) {}
|
} catch (_: Exception) {}
|
||||||
animJob.cancel()
|
animJob.cancel()
|
||||||
animJob.join() // wait for the minimum-rotation finally block to finish
|
animJob.join()
|
||||||
}
|
}
|
||||||
|
|
||||||
pushWidgetUpdate()
|
pushWidgetUpdate()
|
||||||
@@ -43,23 +43,25 @@ class UsageUpdateWorker(
|
|||||||
private suspend fun rotateRefreshIcon() {
|
private suspend fun rotateRefreshIcon() {
|
||||||
val manager = AppWidgetManager.getInstance(context)
|
val manager = AppWidgetManager.getInstance(context)
|
||||||
val ids = manager.getAppWidgetIds(ComponentName(context, ClaudeUsageWidget::class.java))
|
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 {
|
try {
|
||||||
while (true) {
|
while (true) {
|
||||||
ClaudeUsageWidget.currentRotation = (ClaudeUsageWidget.currentRotation + 12f) % 360f
|
ClaudeUsageWidget.currentRotation = angleAt(System.currentTimeMillis())
|
||||||
totalDegrees += 12f
|
|
||||||
ids.forEach { id -> ClaudeUsageWidget.updateWidget(context, manager, id) }
|
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 {
|
} 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) {
|
withContext(NonCancellable) {
|
||||||
while (totalDegrees < 360f) {
|
val minEndMs = startMs + msPerRotation
|
||||||
ClaudeUsageWidget.currentRotation = (ClaudeUsageWidget.currentRotation + 6f) % 360f
|
while (System.currentTimeMillis() < minEndMs) {
|
||||||
totalDegrees += 6f
|
ClaudeUsageWidget.currentRotation = angleAt(System.currentTimeMillis())
|
||||||
ids.forEach { id -> ClaudeUsageWidget.updateWidget(context, manager, id) }
|
ids.forEach { id -> ClaudeUsageWidget.updateWidget(context, manager, id) }
|
||||||
delay(33)
|
delay(16)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user