Retry icons the shell couldn't draw; draw from the listed activities
On a phone the first dozen apps in the drawer kept coming back without an icon. Icons are now drawn from the LauncherActivityInfo objects apps.json was built from (falling back to resolveActivity), failures are logged under "ultra" with the reason, and the page asks again for any icon that came back empty, up to three times with backoff. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019EEjkJVV72Lu8ndDVWg5BT
This commit is contained in:
2 files changed
+30
-5
No files matched your search
@@ -98,6 +98,7 @@ public class MainActivity extends Activity {
|
|||||||
private LauncherApps launcher;
|
private LauncherApps launcher;
|
||||||
private final UserHandle user = Process.myUserHandle();
|
private final UserHandle user = Process.myUserHandle();
|
||||||
private final Map<String, byte[]> icons = new ConcurrentHashMap<>();
|
private final Map<String, byte[]> icons = new ConcurrentHashMap<>();
|
||||||
|
private final Map<String, LauncherActivityInfo> activities = new ConcurrentHashMap<>();
|
||||||
private final Handler main = new Handler(Looper.getMainLooper());
|
private final Handler main = new Handler(Looper.getMainLooper());
|
||||||
private final ExecutorService iconThread = Executors.newSingleThreadExecutor();
|
private final ExecutorService iconThread = Executors.newSingleThreadExecutor();
|
||||||
|
|
||||||
@@ -274,6 +275,7 @@ public class MainActivity extends Activity {
|
|||||||
ComponentName cn = a.getComponentName();
|
ComponentName cn = a.getComponentName();
|
||||||
if (cn.getPackageName().equals(getPackageName())) continue;
|
if (cn.getPackageName().equals(getPackageName())) continue;
|
||||||
String c = cn.flattenToShortString();
|
String c = cn.flattenToShortString();
|
||||||
|
activities.put(c, a);
|
||||||
apps.put(new JSONObject()
|
apps.put(new JSONObject()
|
||||||
.put("label", labels.get(a))
|
.put("label", labels.get(a))
|
||||||
.put("component", c)
|
.put("component", c)
|
||||||
@@ -299,6 +301,7 @@ public class MainActivity extends Activity {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (png != null) icons.put(c, png);
|
if (png != null) icons.put(c, png);
|
||||||
|
else Log.w("ultra", "no icon for " + c);
|
||||||
return png;
|
return png;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -306,9 +309,17 @@ public class MainActivity extends Activity {
|
|||||||
private byte[] drawIcon(String c) {
|
private byte[] drawIcon(String c) {
|
||||||
ComponentName cn = c == null ? null : ComponentName.unflattenFromString(c);
|
ComponentName cn = c == null ? null : ComponentName.unflattenFromString(c);
|
||||||
if (cn == null) return null;
|
if (cn == null) return null;
|
||||||
LauncherActivityInfo info = launcher.resolveActivity(
|
// Prefer the LauncherActivityInfo that apps.json was built from; resolve only if it
|
||||||
new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_LAUNCHER).setComponent(cn), user);
|
// isn't there (e.g. an icon asked for before the list was built).
|
||||||
if (info == null) return null;
|
LauncherActivityInfo info = activities.get(c);
|
||||||
|
if (info == null) {
|
||||||
|
info = launcher.resolveActivity(
|
||||||
|
new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_LAUNCHER).setComponent(cn), user);
|
||||||
|
}
|
||||||
|
if (info == null) {
|
||||||
|
Log.w("ultra", "no launchable activity for " + c);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
int dpi = getResources().getDisplayMetrics().densityDpi;
|
int dpi = getResources().getDisplayMetrics().densityDpi;
|
||||||
Drawable d = info.getIcon(dpi);
|
Drawable d = info.getIcon(dpi);
|
||||||
if (d == null) d = getPackageManager().getDefaultActivityIcon();
|
if (d == null) d = getPackageManager().getDefaultActivityIcon();
|
||||||
|
|||||||
+16
-2
@@ -75,9 +75,23 @@
|
|||||||
if (host.loadIcons) host.loadIcons(JSON.stringify(want));
|
if (host.loadIcons) host.loadIcons(JSON.stringify(want));
|
||||||
else gotIcons(Object.fromEntries(want.map((k) => [k, k])));
|
else gotIcons(Object.fromEntries(want.map((k) => [k, k])));
|
||||||
};
|
};
|
||||||
|
// An icon the shell couldn't draw ("") is asked for again, up to 3 times, with backoff;
|
||||||
|
// until then, and after, it shows as a blank disc.
|
||||||
|
const tries = new Map();
|
||||||
const gotIcons = (batch) => {
|
const gotIcons = (batch) => {
|
||||||
for (const k in batch) { iconSrc.set(k, batch[k]); asked.delete(k); }
|
const again = [];
|
||||||
|
for (const k in batch) {
|
||||||
|
iconSrc.set(k, batch[k]); asked.delete(k);
|
||||||
|
const n = tries.get(k) || 0;
|
||||||
|
if (!batch[k] && n < 3) { tries.set(k, n + 1); again.push(k); }
|
||||||
|
}
|
||||||
fillIcons();
|
fillIcons();
|
||||||
|
if (again.length) setTimeout(() => {
|
||||||
|
for (const k of again) iconSrc.delete(k);
|
||||||
|
for (const img of document.querySelectorAll("img.icon[data-icon]"))
|
||||||
|
if (again.includes(img.dataset.icon)) img.__icon = undefined;
|
||||||
|
fillIcons();
|
||||||
|
}, 800 * (tries.get(again[0]) || 1));
|
||||||
};
|
};
|
||||||
window.ultraIcons = gotIcons; // the shell calls this before ultraHome exists, too
|
window.ultraIcons = gotIcons; // the shell calls this before ultraHome exists, too
|
||||||
|
|
||||||
@@ -108,7 +122,7 @@
|
|||||||
widgetAdded: (id) => app.dispatch(WIDGET_ADDED, id),
|
widgetAdded: (id) => app.dispatch(WIDGET_ADDED, id),
|
||||||
widgetMenu: (id) => app.dispatch(WIDGET_MENU, id),
|
widgetMenu: (id) => app.dispatch(WIDGET_MENU, id),
|
||||||
place: () => { placed = ""; place(); },
|
place: () => { placed = ""; place(); },
|
||||||
resetIcons: () => { iconSrc.clear(); asked.clear();
|
resetIcons: () => { iconSrc.clear(); asked.clear(); tries.clear();
|
||||||
for (const img of document.querySelectorAll("img.icon")) img.__icon = undefined; },
|
for (const img of document.querySelectorAll("img.icon")) img.__icon = undefined; },
|
||||||
};
|
};
|
||||||
document.addEventListener("visibilitychange", () => { if (!document.hidden) window.ultraHome.tick(); });
|
document.addEventListener("visibilitychange", () => { if (!document.hidden) window.ultraHome.tick(); });
|
||||||
|
|||||||
Reference in new issue
Block a user