diff --git a/android/app/src/main/java/dev/ultra/launcher/MainActivity.java b/android/app/src/main/java/dev/ultra/launcher/MainActivity.java index d249456..59d318a 100644 --- a/android/app/src/main/java/dev/ultra/launcher/MainActivity.java +++ b/android/app/src/main/java/dev/ultra/launcher/MainActivity.java @@ -98,6 +98,7 @@ public class MainActivity extends Activity { private LauncherApps launcher; private final UserHandle user = Process.myUserHandle(); private final Map icons = new ConcurrentHashMap<>(); + private final Map activities = new ConcurrentHashMap<>(); private final Handler main = new Handler(Looper.getMainLooper()); private final ExecutorService iconThread = Executors.newSingleThreadExecutor(); @@ -274,6 +275,7 @@ public class MainActivity extends Activity { ComponentName cn = a.getComponentName(); if (cn.getPackageName().equals(getPackageName())) continue; String c = cn.flattenToShortString(); + activities.put(c, a); apps.put(new JSONObject() .put("label", labels.get(a)) .put("component", c) @@ -299,6 +301,7 @@ public class MainActivity extends Activity { return null; } if (png != null) icons.put(c, png); + else Log.w("ultra", "no icon for " + c); return png; } } @@ -306,9 +309,17 @@ public class MainActivity extends Activity { private byte[] drawIcon(String c) { ComponentName cn = c == null ? null : ComponentName.unflattenFromString(c); if (cn == null) return null; - LauncherActivityInfo info = launcher.resolveActivity( - new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_LAUNCHER).setComponent(cn), user); - if (info == null) return null; + // Prefer the LauncherActivityInfo that apps.json was built from; resolve only if it + // isn't there (e.g. an icon asked for before the list was built). + 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; Drawable d = info.getIcon(dpi); if (d == null) d = getPackageManager().getDefaultActivityIcon(); diff --git a/web/index.html b/web/index.html index 20241da..734846b 100644 --- a/web/index.html +++ b/web/index.html @@ -75,9 +75,23 @@ if (host.loadIcons) host.loadIcons(JSON.stringify(want)); 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) => { - 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(); + 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 @@ -108,7 +122,7 @@ widgetAdded: (id) => app.dispatch(WIDGET_ADDED, id), widgetMenu: (id) => app.dispatch(WIDGET_MENU, id), 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; }, }; document.addEventListener("visibilitychange", () => { if (!document.hidden) window.ultraHome.tick(); });