@@ -5,6 +5,7 @@ import android.appwidget.AppWidgetProviderInfo
55import android.content.ComponentName
66import android.content.Context
77import android.os.Build
8+ import android.util.Log
89import androidx.annotation.RequiresApi
910import androidx.collection.intSetOf
1011import androidx.core.content.edit
@@ -15,6 +16,8 @@ import kotlinx.coroutines.CoroutineScope
1516import kotlinx.coroutines.Dispatchers
1617import kotlinx.coroutines.launch
1718
19+ private const val TAG = " WidgetPreviewPublisher"
20+
1821/* *
1922 * Publishes widget previews for the launcher widget picker (Android 15+).
2023 * Handles rate limiting by checking if preview is already published and tracking app version.
@@ -57,15 +60,25 @@ object WidgetPreviewPublisher {
5760 return @launch
5861 }
5962
60- val result = GlanceAppWidgetManager (context)
61- .setWidgetPreviews(
62- WledWidgetReceiver ::class ,
63- intSetOf(AppWidgetProviderInfo .WIDGET_CATEGORY_HOME_SCREEN ),
64- )
63+ try {
64+ val result = GlanceAppWidgetManager (context)
65+ .setWidgetPreviews(
66+ WledWidgetReceiver ::class ,
67+ intSetOf(AppWidgetProviderInfo .WIDGET_CATEGORY_HOME_SCREEN ),
68+ )
6569
66- // Only save version if successful (not rate-limited)
67- if (result == SET_WIDGET_PREVIEWS_RESULT_SUCCESS ) {
68- prefs.edit { putInt(KEY_PREVIEW_VERSION , currentVersionCode) }
70+ // Only save version if successful (not rate-limited)
71+ if (result == SET_WIDGET_PREVIEWS_RESULT_SUCCESS ) {
72+ prefs.edit { putInt(KEY_PREVIEW_VERSION , currentVersionCode) }
73+ }
74+ } catch (e: kotlinx.coroutines.CancellationException ) {
75+ throw e
76+ } catch (e: IllegalArgumentException ) {
77+ Log .e(TAG , " Failed to publish widget previews: system limit or invalid state" , e)
78+ } catch (e: android.os.RemoteException ) {
79+ Log .e(TAG , " Failed to publish widget previews: binder error" , e)
80+ } catch (@Suppress(" TooGenericExceptionCaught" ) e: Exception ) {
81+ Log .e(TAG , " Failed to publish widget previews: unexpected error" , e)
6982 }
7083 }
7184 }
0 commit comments