Qt: show home icons at once on start, and keep them when other apps change
Home app tiles waited for the full app list (every app listed and labelled over JNI, slow on a phone) before they showed, while widgets showed at once. The last app list is now kept and the home starts from it; nothing on home is hidden until the fresh list has loaded. A package change used to reload every icon on screen; now only that package's icons are drawn again. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DPL5hiQsCq11CwCPnKPp9D
This commit is contained in:
7 files changed
+69
-32
No files matched your search
@@ -90,11 +90,11 @@ public class HomeActivity extends QtActivity {
|
||||
private final int[] layerAt = new int[2];
|
||||
|
||||
private final LauncherApps.Callback packages = new LauncherApps.Callback() {
|
||||
@Override public void onPackageRemoved(String pkg, UserHandle u) { appsChanged(); }
|
||||
@Override public void onPackageAdded(String pkg, UserHandle u) { appsChanged(); }
|
||||
@Override public void onPackageChanged(String pkg, UserHandle u) { appsChanged(); }
|
||||
@Override public void onPackagesAvailable(String[] pkgs, UserHandle u, boolean replacing) { appsChanged(); }
|
||||
@Override public void onPackagesUnavailable(String[] pkgs, UserHandle u, boolean replacing) { appsChanged(); }
|
||||
@Override public void onPackageRemoved(String pkg, UserHandle u) { appsChanged(pkg); }
|
||||
@Override public void onPackageAdded(String pkg, UserHandle u) { appsChanged(pkg); }
|
||||
@Override public void onPackageChanged(String pkg, UserHandle u) { appsChanged(pkg); }
|
||||
@Override public void onPackagesAvailable(String[] pkgs, UserHandle u, boolean replacing) { appsChanged(String.join(",", pkgs)); }
|
||||
@Override public void onPackagesUnavailable(String[] pkgs, UserHandle u, boolean replacing) { appsChanged(String.join(",", pkgs)); }
|
||||
};
|
||||
|
||||
@Override
|
||||
@@ -252,8 +252,9 @@ public class HomeActivity extends QtActivity {
|
||||
if (qtReady) Native.backPressed();
|
||||
}
|
||||
|
||||
private void appsChanged() {
|
||||
if (qtReady) Native.appsChanged();
|
||||
/** packages: the ones that changed, comma-separated, so only their icons are redrawn. */
|
||||
private void appsChanged(String packages) {
|
||||
if (qtReady) Native.appsChanged(packages == null ? "" : packages);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------ called from Qt
|
||||
|
||||
@@ -8,7 +8,7 @@ package dev.ultra.launcher;
|
||||
final class Native {
|
||||
private Native() {}
|
||||
|
||||
static native void appsChanged();
|
||||
static native void appsChanged(String packages); // comma-separated
|
||||
static native void homePressed();
|
||||
static native void backPressed();
|
||||
static native void insets(int top, int bottom);
|
||||
|
||||
+2
-2
@@ -10,7 +10,7 @@ Item {
|
||||
property var apps: [] // [{label, component, system}]
|
||||
property var homeSet: ({}) // component -> true: on the home screen
|
||||
property bool loading: true
|
||||
property int generation: 0
|
||||
property var iconGen: ({}) // package -> n, see Main.gen
|
||||
property real insetTop: 0
|
||||
property real insetBottom: 0
|
||||
property alias query: search.text
|
||||
@@ -117,7 +117,7 @@ Item {
|
||||
height: 84
|
||||
key: "a:" + (cell.app.component || "")
|
||||
label: cell.app.label || ""
|
||||
generation: root.generation
|
||||
generation: root.iconGen[(cell.app.component || "").split("/")[0]] || 0
|
||||
iconSize: 52
|
||||
fontSize: 12
|
||||
spacing: 6
|
||||
|
||||
+18
-13
@@ -28,7 +28,8 @@ Window {
|
||||
property var apps: [] // [{label, component, system}], by label
|
||||
property var appRow: ({}) // component -> row in apps
|
||||
property bool loading: true
|
||||
property int generation: 0 // bumped when the app list changes
|
||||
property var iconGen: ({}) // package -> n, bumped when it changes, so its icons reload
|
||||
function gen(component) { return iconGen[(component || "").split("/")[0]] || 0 }
|
||||
property var home: [] // slots, see Layout.js
|
||||
property bool drawerOpen: false
|
||||
property bool picking: false // the drawer adds apps to home / takes them off
|
||||
@@ -60,7 +61,9 @@ Window {
|
||||
readonly property real gridBottom: height - (insetBottom + 24)
|
||||
readonly property int nrows: home.length > 0
|
||||
? Math.max(1, Math.floor((gridBottom - gridTop + L.RGAP) / (L.CELL + L.RGAP))) : 0
|
||||
readonly property var hidden: home.map(s => s.kind === "app" && appRow[s.str] === undefined)
|
||||
// An app not in the list is gone (uninstalled, or on an unmounted card); until the
|
||||
// list has loaded, nothing is.
|
||||
readonly property var hidden: home.map(s => s.kind === "app" && !loading && appRow[s.str] === undefined)
|
||||
readonly property var packed: L.pack(home, cols, nrows, hidden)
|
||||
readonly property real gridH: Math.max(0, packed.rows * (L.CELL + L.RGAP) - L.RGAP)
|
||||
readonly property real contentH: gridTop + gridH + insetBottom + 24
|
||||
@@ -111,18 +114,19 @@ Window {
|
||||
say("Brought over your home screen");
|
||||
}
|
||||
|
||||
function loadApps() {
|
||||
const list = Host.apps();
|
||||
function loadApps() { setApps(Host.apps()); loading = false; dropGone(); }
|
||||
|
||||
function setApps(list) {
|
||||
const rows = {};
|
||||
for (let i = 0; i < list.length; i++) rows[list[i].component] = i;
|
||||
apps = list;
|
||||
appRow = rows;
|
||||
loading = false;
|
||||
dropGone();
|
||||
}
|
||||
|
||||
function reload() {
|
||||
generation++;
|
||||
function reload(packages) {
|
||||
const g = Object.assign({}, iconGen);
|
||||
for (const p of (packages || "").split(",")) if (p) g[p] = (g[p] || 0) + 1;
|
||||
iconGen = g;
|
||||
loadApps();
|
||||
if (sheet === "app") { sheet = ""; appSheetRow = -1; }
|
||||
}
|
||||
@@ -395,7 +399,7 @@ Window {
|
||||
// ---- Host
|
||||
Connections {
|
||||
target: Host
|
||||
function onAppsChanged() { root.reload() }
|
||||
function onAppsChanged(packages) { root.reload(packages) }
|
||||
function onHomePressed() { root.goHome() }
|
||||
function onBackPressed() { root.back() }
|
||||
function onWidgetAdded(id) { root.widgetAdded(id) }
|
||||
@@ -416,6 +420,7 @@ Window {
|
||||
|
||||
Component.onCompleted: {
|
||||
loadHome();
|
||||
setApps(Host.savedApps()); // icons and names show at once; the real list follows
|
||||
Host.ready();
|
||||
Qt.callLater(loadApps);
|
||||
}
|
||||
@@ -555,8 +560,8 @@ Window {
|
||||
visible: !slot.isWidget
|
||||
anchors.fill: parent
|
||||
key: "a:" + (slot.s.str || "")
|
||||
label: slot.row >= 0 ? root.apps[slot.row].label : ""
|
||||
generation: root.generation
|
||||
label: (root.apps[slot.row] || {}).label || ""
|
||||
generation: root.gen(slot.s.str)
|
||||
iconSize: 40
|
||||
fontSize: 11
|
||||
spacing: 4
|
||||
@@ -777,7 +782,7 @@ Window {
|
||||
apps: root.apps
|
||||
homeSet: root.homeSet
|
||||
loading: root.loading
|
||||
generation: root.generation
|
||||
iconGen: root.iconGen
|
||||
insetTop: root.insetTop
|
||||
insetBottom: root.insetBottom
|
||||
onEdgeChanged: root.cover()
|
||||
@@ -908,7 +913,7 @@ Window {
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
size: 40
|
||||
key: "w:" + wrow.p.provider
|
||||
generation: root.generation
|
||||
generation: root.gen(wrow.p.provider)
|
||||
}
|
||||
Column {
|
||||
x: 60
|
||||
|
||||
+25
-8
@@ -40,7 +40,12 @@ void post(F f) {
|
||||
if (g_backend) QMetaObject::invokeMethod(g_backend, f, Qt::QueuedConnection);
|
||||
}
|
||||
|
||||
void jAppsChanged(JNIEnv *, jclass) { post([] { emit g_backend->appsChanged(); }); }
|
||||
void jAppsChanged(JNIEnv *env, jclass, jstring packages) {
|
||||
const char *c = env->GetStringUTFChars(packages, nullptr);
|
||||
const QString s = QString::fromUtf8(c);
|
||||
env->ReleaseStringUTFChars(packages, c);
|
||||
post([=] { emit g_backend->appsChanged(s); });
|
||||
}
|
||||
void jHomePressed(JNIEnv *, jclass) { post([] { emit g_backend->homePressed(); }); }
|
||||
void jBackPressed(JNIEnv *, jclass) { post([] { emit g_backend->backPressed(); }); }
|
||||
void jInsets(JNIEnv *, jclass, jint top, jint bottom) { post([=] { g_backend->setInsets(top, bottom); }); }
|
||||
@@ -67,7 +72,7 @@ void registerNatives() {
|
||||
if (done) return;
|
||||
done = true;
|
||||
const JNINativeMethod methods[] = {
|
||||
{"appsChanged", "()V", reinterpret_cast<void *>(jAppsChanged)},
|
||||
{"appsChanged", "(Ljava/lang/String;)V", reinterpret_cast<void *>(jAppsChanged)},
|
||||
{"homePressed", "()V", reinterpret_cast<void *>(jHomePressed)},
|
||||
{"backPressed", "()V", reinterpret_cast<void *>(jBackPressed)},
|
||||
{"insets", "(II)V", reinterpret_cast<void *>(jInsets)},
|
||||
@@ -120,12 +125,7 @@ void Backend::ready() {
|
||||
#endif
|
||||
}
|
||||
|
||||
QVariantList Backend::apps() const {
|
||||
#ifdef Q_OS_ANDROID
|
||||
const QJsonDocument doc = QJsonDocument::fromJson(callString("apps").toUtf8());
|
||||
#else
|
||||
const QJsonDocument doc = demo(QStringLiteral("apps.json"));
|
||||
#endif
|
||||
static QVariantList appList(const QJsonDocument &doc) {
|
||||
QVariantList out;
|
||||
for (const QJsonValue &v : doc.object().value(QStringLiteral("apps")).toArray()) {
|
||||
const QJsonObject o = v.toObject();
|
||||
@@ -136,6 +136,23 @@ QVariantList Backend::apps() const {
|
||||
return out;
|
||||
}
|
||||
|
||||
// The app list, and a copy kept for the next start: listing (and labelling) every app
|
||||
// takes a while on a phone, so the home screen starts from the copy meanwhile.
|
||||
QVariantList Backend::apps() const {
|
||||
#ifdef Q_OS_ANDROID
|
||||
const QByteArray json = callString("apps").toUtf8();
|
||||
#else
|
||||
const QByteArray json = demo(QStringLiteral("apps.json")).toJson(QJsonDocument::Compact);
|
||||
#endif
|
||||
const QVariantList out = appList(QJsonDocument::fromJson(json));
|
||||
if (!out.isEmpty()) QSettings().setValue(QStringLiteral("apps"), QString::fromUtf8(json));
|
||||
return out;
|
||||
}
|
||||
|
||||
QVariantList Backend::savedApps() const {
|
||||
return appList(QJsonDocument::fromJson(QSettings().value(QStringLiteral("apps")).toString().toUtf8()));
|
||||
}
|
||||
|
||||
QVariantList Backend::widgetProviders() const {
|
||||
#ifdef Q_OS_ANDROID
|
||||
const QJsonDocument doc = QJsonDocument::fromJson(callString("widgetProviders").toUtf8());
|
||||
|
||||
+2
-1
@@ -28,6 +28,7 @@ public:
|
||||
|
||||
// Lists: [{label, component, system}] and [{label, app, provider, h}].
|
||||
Q_INVOKABLE QVariantList apps() const;
|
||||
Q_INVOKABLE QVariantList savedApps() const; // the last list apps() returned, for a quick start
|
||||
Q_INVOKABLE QVariantList widgetProviders() const;
|
||||
|
||||
Q_INVOKABLE void launch(const QString &component);
|
||||
@@ -65,7 +66,7 @@ public:
|
||||
|
||||
signals:
|
||||
void insetsChanged();
|
||||
void appsChanged();
|
||||
void appsChanged(const QString &packages); // comma-separated; empty: any
|
||||
void homePressed();
|
||||
void backPressed();
|
||||
void widgetAdded(int id);
|
||||
|
||||
@@ -346,6 +346,19 @@ int main(int argc, char *argv[]) {
|
||||
js("loadHome()");
|
||||
eq(homeLabels(), "Gmail,Chrome,Phone", "the layout is saved");
|
||||
|
||||
// Starting again: the saved app list names the home tiles before the real list loads,
|
||||
// and nothing is hidden meanwhile.
|
||||
js("apps = []; appRow = ({}); loading = true; setApps(Host.savedApps())");
|
||||
eq(homeLabels(), "Gmail,Chrome,Phone", "home tiles come from the saved app list");
|
||||
js("apps = []; appRow = ({})");
|
||||
eq(js("hidden.some(h => h)"), false, "nothing is hidden before the list loads");
|
||||
js("loadApps()");
|
||||
// A changed package reloads only its own icons.
|
||||
emit backend.appsChanged(QStringLiteral("com.example.chrome"));
|
||||
settle(50);
|
||||
eq(js("gen('com.example.chrome/.MainActivity') + ',' + gen('com.example.gmail/.MainActivity')"), "1,0",
|
||||
"a changed app's icons reload, the rest stay");
|
||||
|
||||
// The WebView build's saved home merges in: new slots go after, unpinned.
|
||||
emit backend.legacyHome(QStringLiteral(
|
||||
"{\"ultra.home.n\":\"3\",\"ultra.home.str.0\":\"com.example.clock/.MainActivity\","
|
||||
|
||||
Reference in new issue
Block a user