Long-press menu in the app drawer, with Uninstall

Long-pressing an app in the drawer now opens a menu (Add to home or
Remove from home, App info, Uninstall) instead of adding it straight to
home. Uninstall fires ACTION_DELETE for the app's package (needs
REQUEST_DELETE_PACKAGES) and is hidden for system apps, which apps.json
now flags. When the uninstalled app leaves the reloaded list, its home
slot is removed too.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XicVK7N1cmDdm1ZwpHAxFD
This commit is contained in:
Claude committed 2026-10-22 07:30:57 +00:00
1 parent c3f3e4eedb
commit 8e2f2e8192
8 files changed
+105 -10

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
# ultra launcher # ultra launcher
An Android home screen written as an [ultra](https://github.com/nandi-conda/ultra) app (LPython compiled to WebAssembly, Elm-style). The home starts blank (add a clock widget if you want one): long-press it to add apps (the drawer opens in a pick mode) or widgets, and long-press anything on it to drag it somewhere else; let go without moving to get its menu, or, for a widget, handles on its edges that resize it to the grid. Swipe down for the drawer with every app and a search (Enter opens the first match); long-press an app there to put it on the home screen, and swipe up to close it. The panel at the top has a **Windows** button that opens Recents. The layout is saved in localStorage. An Android home screen written as an [ultra](https://github.com/nandi-conda/ultra) app (LPython compiled to WebAssembly, Elm-style). The home starts blank (add a clock widget if you want one): long-press it to add apps (the drawer opens in a pick mode) or widgets, and long-press anything on it to drag it somewhere else; let go without moving to get its menu, or, for a widget, handles on its edges that resize it to the grid. Swipe down for the drawer with every app and a search (Enter opens the first match); long-press an app there for its menu (add to home, app info, uninstall; system apps have no uninstall), and swipe up to close it. The panel at the top has a **Windows** button that opens Recents. The layout is saved in localStorage.
## Install ## Install
+2
View File
@@ -4,6 +4,8 @@
<!-- The updater downloads new builds of the launcher and installs them over itself. --> <!-- The updater downloads new builds of the launcher and installs them over itself. -->
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" /> <uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
<!-- Uninstall from the app drawer's long-press menu (ACTION_DELETE needs it on Android 9+). -->
<uses-permission android:name="android.permission.REQUEST_DELETE_PACKAGES" />
<!-- Android 11+ package visibility: list every launchable activity. --> <!-- Android 11+ package visibility: list every launchable activity. -->
<queries> <queries>
@@ -9,6 +9,7 @@ import android.content.Context;
import android.content.ActivityNotFoundException; import android.content.ActivityNotFoundException;
import android.content.ComponentName; import android.content.ComponentName;
import android.content.Intent; import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.LauncherActivityInfo; import android.content.pm.LauncherActivityInfo;
import android.content.pm.LauncherApps; import android.content.pm.LauncherApps;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
@@ -69,7 +70,7 @@ import java.util.concurrent.Executors;
* to wasm), packaged as assets and served to a transparent WebView from a virtual https * to wasm), packaged as assets and served to a transparent WebView from a virtual https
* origin. This class answers the two dynamic URLs the app fetches: * origin. This class answers the two dynamic URLs the app fetches:
* *
* apps.json {"apps": [{"label", "component", "icon"}]}, every launchable activity * apps.json {"apps": [{"label", "component", "icon", "system"}]}, every launchable activity
* icon?c=COMP the activity's icon as a PNG * icon?c=COMP the activity's icon as a PNG
* widgets.json {"widgets": [{"label", "app", "provider", "icon", "h"}]}, every widget provider * widgets.json {"widgets": [{"label", "app", "provider", "icon", "h"}]}, every widget provider
* wicon?p=PROV the provider's icon as a PNG * wicon?p=PROV the provider's icon as a PNG
@@ -281,10 +282,13 @@ public class MainActivity extends Activity {
if (cn.getPackageName().equals(getPackageName())) continue; if (cn.getPackageName().equals(getPackageName())) continue;
String c = cn.flattenToShortString(); String c = cn.flattenToShortString();
activities.put(c, a); activities.put(c, a);
apps.put(new JSONObject() JSONObject o = new JSONObject()
.put("label", labels.get(a)) .put("label", labels.get(a))
.put("component", c) .put("component", c)
.put("icon", "icon?c=" + Uri.encode(c))); .put("icon", "icon?c=" + Uri.encode(c));
// System apps can't be uninstalled, so the drawer offers no Uninstall for them.
if ((a.getApplicationInfo().flags & ApplicationInfo.FLAG_SYSTEM) != 0) o.put("system", true);
apps.put(o);
} }
return new JSONObject().put("apps", apps).toString(); return new JSONObject().put("apps", apps).toString();
} }
@@ -754,6 +758,15 @@ public class MainActivity extends Activity {
}); });
} }
/** The system asks the user to confirm; the app list reloads when the package goes. */
@JavascriptInterface public void uninstall(String component) {
main.post(() -> {
ComponentName cn = ComponentName.unflattenFromString(component);
if (cn != null) startIntent(new Intent(Intent.ACTION_DELETE,
Uri.fromParts("package", cn.getPackageName(), null)));
});
}
@JavascriptInterface public void addWidget(String provider) { @JavascriptInterface public void addWidget(String provider) {
main.post(() -> MainActivity.this.addWidget(provider)); main.post(() -> MainActivity.this.addWidget(provider));
} }
+10
View File
@@ -115,6 +115,16 @@ const BASE = process.env.BASE || "http://localhost:8000";
await swipe(200, 500); await swipe(200, 500);
await p.waitForSelector(".drawer .tile", { timeout: 2000 }); await p.waitForSelector(".drawer .tile", { timeout: 2000 });
await longpress(".apps .tile:first-child"); await longpress(".apps .tile:first-child");
assert.deepEqual(await p.$$eval(".sheet-item", (bs) => bs.map((b) => b.textContent)), ["Add to home", "App info", "Uninstall"]);
await p.click(".sheet-item:has-text('Uninstall')"); await settle();
assert.equal(await p.textContent("#toast"), "Uninstall com.example.calculator/.MainActivity");
assert.ok(!(await p.$(".sheet")) && (await p.$(".drawer")), "uninstalling closes the menu, not the drawer");
await p.fill(".drawer input", "phone"); await settle();
await longpress(".apps .tile:first-child");
assert.ok(!(await p.$(".sheet-item:has-text('Uninstall')")), "system apps can't be uninstalled");
await p.click(".sheet-overlay", { position: { x: 10, y: 10 } }); await p.fill(".drawer input", ""); await settle();
await longpress(".apps .tile:first-child");
await p.click(".sheet-item:has-text('Add to home')"); await settle();
assert.equal(await p.textContent(".notice"), "Added to home"); assert.equal(await p.textContent(".notice"), "Added to home");
await swipe(600, 200); await swipe(600, 200);
await p.waitForSelector(".drawer", { state: "detached", timeout: 2000 }); // swipe up closes it await p.waitForSelector(".drawer", { state: "detached", timeout: 2000 }); // swipe up closes it
+71 -6
View File
@@ -32,6 +32,11 @@ def launch(component: i32) -> None:
def app_info(component: i32) -> None: def app_info(component: i32) -> None:
pass pass
@jscall
def uninstall(component: i32) -> None:
"""Ask the system to uninstall the package of a "pkg/cls" string handle."""
pass
@jscall @jscall
def add_widget(provider: i32) -> None: def add_widget(provider: i32) -> None:
"""Bind (and configure) a widget; the shell answers with WIDGET_ADDED(id).""" """Bind (and configure) a widget; the shell answers with WIDGET_ADDED(id)."""
@@ -80,7 +85,7 @@ CLOSE_DRAWER: Const[i32] = 15
OPEN_APP: Const[i32] = 16 # arg: row in the app list OPEN_APP: Const[i32] = 16 # arg: row in the app list
OPEN_FIRST: Const[i32] = 17 OPEN_FIRST: Const[i32] = 17
OPEN_HOME: Const[i32] = 18 # arg: home slot OPEN_HOME: Const[i32] = 18 # arg: home slot
ADD_HOME: Const[i32] = 19 # arg: row in the app list (long press in the drawer) ADD_HOME: Const[i32] = 19 # arg: row in the app list
TOGGLE_HOME: Const[i32] = 20 # arg: row in the app list (drawer in pick mode) TOGGLE_HOME: Const[i32] = 20 # arg: row in the app list (drawer in pick mode)
MENU: Const[i32] = 21 # long press on the empty home MENU: Const[i32] = 21 # long press on the empty home
CLOSE_SHEET: Const[i32] = 23 CLOSE_SHEET: Const[i32] = 23
@@ -107,6 +112,9 @@ CHECK_UPDATES: Const[i32] = 43
WIDGET_COLS: Const[i32] = 44 # arg: columns for the widget just added (0: the whole row) WIDGET_COLS: Const[i32] = 44 # arg: columns for the widget just added (0: the whole row)
GRID: Const[i32] = 45 # arg: columns * 4096 + rows that fit on the screen GRID: Const[i32] = 45 # arg: columns * 4096 + rows that fit on the screen
MOVE_CELL: Const[i32] = 47 # arg: row * 64 + column of the empty cell the lifted slot is over MOVE_CELL: Const[i32] = 47 # arg: row * 64 + column of the empty cell the lifted slot is over
APP_MENU: Const[i32] = 48 # arg: row in the app list (long press in the drawer)
APP_INFO: Const[i32] = 49 # arg: row in the app list
UNINSTALL: Const[i32] = 50 # arg: row in the app list
CAP: Const[i32] = 512 CAP: Const[i32] = 512
HOME_CAP: Const[i32] = 200 HOME_CAP: Const[i32] = 200
@@ -119,6 +127,7 @@ NONE: Const[i32] = 0
SHEET_MENU: Const[i32] = 1 SHEET_MENU: Const[i32] = 1
SHEET_ITEM: Const[i32] = 2 SHEET_ITEM: Const[i32] = 2
SHEET_WIDGETS: Const[i32] = 3 SHEET_WIDGETS: Const[i32] = 3
SHEET_APP: Const[i32] = 4
# ---- Model # ---- Model
# Every module-level array is i32[512], even where HOME_CAP or WCAP is smaller: # Every module-level array is i32[512], even where HOME_CAP or WCAP is smaller:
@@ -129,6 +138,7 @@ SHEET_WIDGETS: Const[i32] = 3
labels: i32[512] = empty(512, dtype=int32) labels: i32[512] = empty(512, dtype=int32)
comps: i32[512] = empty(512, dtype=int32) comps: i32[512] = empty(512, dtype=int32)
icons: i32[512] = empty(512, dtype=int32) icons: i32[512] = empty(512, dtype=int32)
system: i32[512] = empty(512, dtype=int32) # 1: a system app, which can't be uninstalled
n: i32 = 0 n: i32 = 0
# The home screen, in order. An app slot keeps its component name in hstr; # The home screen, in order. An app slot keeps its component name in hstr;
# a widget slot keeps the widget's label there, its host id in hwid, its # a widget slot keeps the widget's label there, its host id in hwid, its
@@ -169,6 +179,8 @@ drawer: i32 = 0
picking: i32 = 0 # drawer is in "add apps" mode: taps toggle home slots picking: i32 = 0 # drawer is in "add apps" mode: taps toggle home slots
sheet: i32 = 0 sheet: i32 = 0
item: i32 = -1 # home slot the item sheet is about item: i32 = -1 # home slot the item sheet is about
app_row: i32 = -1 # row in the app list the app sheet is about
gone: i32 = 0 # component being uninstalled: its home slot goes when it leaves the list
lifted: i32 = -1 # home slot picked up by a long press, being dragged lifted: i32 = -1 # home slot picked up by a long press, being dragged
resizing: i32 = -1 # widget slot showing resize handles resizing: i32 = -1 # widget slot showing resize handles
regrab: i32 = 0 # the lifted slot was grabbed while showing handles: drop it back into them regrab: i32 = 0 # the lifted slot was grabbed while showing handles: drop it back into them
@@ -176,7 +188,7 @@ pending: i32 = 0 # JSON handle of a request in flight
def init() -> None: def init() -> None:
global query, wquery, err, notice, scratch, nh, next_key, pending global query, wquery, err, notice, scratch, gone, nh, next_key, pending
i: i32 i: i32
h: i32 h: i32
k: i32 k: i32
@@ -185,6 +197,7 @@ def init() -> None:
err = s_new() err = s_new()
notice = s_new() notice = s_new()
scratch = s_new() scratch = s_new()
gone = s_new()
count: i32 = load_i32("ultra.home.n", 0) count: i32 = load_i32("ultra.home.n", 0)
for i in range(count): for i in range(count):
h = s_new() h = s_new()
@@ -262,10 +275,12 @@ def load_apps(doc: i32) -> None:
ok = j_str(row, "label", labels[n]) ok = j_str(row, "label", labels[n])
ok = j_str(row, "component", comps[n]) ok = j_str(row, "component", comps[n])
ok = j_str(row, "icon", icons[n]) ok = j_str(row, "icon", icons[n])
system[n] = j_int(row, "system")
j_free(row) j_free(row)
n += 1 n += 1
j_free(arr) j_free(arr)
j_free(doc) j_free(doc)
drop_gone()
def load_widgets(doc: i32) -> None: def load_widgets(doc: i32) -> None:
@@ -374,6 +389,21 @@ def add_app(row: i32) -> None:
say("Added to home") say("Added to home")
def drop_gone() -> None:
"""Once an app uninstalled from the drawer is out of the list, take it off home."""
i: i32
if s_len(gone) == 0:
return
for i in range(n):
if s_eq(comps[i], gone) == 1:
return
for i in range(nh):
if hkind[i] == APP and s_eq(hstr[i], gone) == 1:
remove_slot(i)
break
s_clear(gone)
def remove_slot(at: i32) -> None: def remove_slot(at: i32) -> None:
global nh global nh
j: i32 j: i32
@@ -486,22 +516,26 @@ def slot_of_widget(wid: i32) -> i32:
def close_all() -> None: def close_all() -> None:
global drawer, picking, sheet, item, lifted, resizing, regrab global drawer, picking, sheet, item, app_row, lifted, resizing, regrab
s_clear(query) s_clear(query)
drawer = 0 drawer = 0
picking = 0 picking = 0
sheet = NONE sheet = NONE
item = -1 item = -1
app_row = -1
lifted = -1 lifted = -1
resizing = -1 resizing = -1
regrab = 0 regrab = 0
# ---- Update # ---- Update
def update(msg: i32, arg: i32) -> None: def update(msg: i32, arg: i32) -> None:
global loading, drawer, picking, sheet, item, pending, wloading, chosen, lifted, resizing, regrab, ncols, nrows global loading, drawer, picking, sheet, item, app_row, pending, wloading, chosen, lifted, resizing, regrab, ncols, nrows
i: i32 i: i32
if msg == LOADED: if msg == LOADED:
load_apps(arg) load_apps(arg)
if sheet == SHEET_APP: # rows may have moved
sheet = NONE
app_row = -1
elif msg == WIDGETS_LOADED: elif msg == WIDGETS_LOADED:
load_widgets(arg) load_widgets(arg)
elif msg == QUERY: elif msg == QUERY:
@@ -532,8 +566,23 @@ def update(msg: i32, arg: i32) -> None:
resizing = -1 resizing = -1
launch(hstr[arg]) launch(hstr[arg])
elif msg == ADD_HOME: elif msg == ADD_HOME:
haptic()
add_app(arg) add_app(arg)
sheet = NONE
app_row = -1
elif msg == APP_MENU:
if drawer == 1 and sheet == NONE:
haptic()
app_row = arg
sheet = SHEET_APP
elif msg == APP_INFO:
app_info(comps[arg])
sheet = NONE
app_row = -1
elif msg == UNINSTALL:
s_copy(gone, comps[arg])
uninstall(comps[arg])
sheet = NONE
app_row = -1
elif msg == TOGGLE_HOME: elif msg == TOGGLE_HOME:
i = home_of(arg) i = home_of(arg)
if i >= 0: if i >= 0:
@@ -598,6 +647,7 @@ def update(msg: i32, arg: i32) -> None:
elif msg == CLOSE_SHEET: elif msg == CLOSE_SHEET:
sheet = NONE sheet = NONE
item = -1 item = -1
app_row = -1
elif msg == PICK_APPS: elif msg == PICK_APPS:
sheet = NONE sheet = NONE
drawer = 1 drawer = 1
@@ -631,6 +681,7 @@ def update(msg: i32, arg: i32) -> None:
remove_slot(arg) remove_slot(arg)
sheet = NONE sheet = NONE
item = -1 item = -1
app_row = -1
elif msg == MOVE: elif msg == MOVE:
if arg > 0: if arg > 0:
swap_slots(arg, arg - 1) swap_slots(arg, arg - 1)
@@ -666,6 +717,7 @@ def update(msg: i32, arg: i32) -> None:
elif sheet != NONE: elif sheet != NONE:
sheet = NONE sheet = NONE
item = -1 item = -1
app_row = -1
elif drawer == 1: elif drawer == 1:
drawer = 0 drawer = 0
picking = 0 picking = 0
@@ -872,7 +924,7 @@ def view_drawer() -> None:
on_click(TOGGLE_HOME, i) on_click(TOGGLE_HOME, i)
else: else:
on_click(OPEN_APP, i) on_click(OPEN_APP, i)
on_longpress(ADD_HOME, i) on_longpress(APP_MENU, i)
view_icon(icons[i]) view_icon(icons[i])
el("span") el("span")
cls("name") cls("name")
@@ -943,6 +995,19 @@ def view_sheet() -> None:
sheet_btn("Remove from home", REMOVE, item) sheet_btn("Remove from home", REMOVE, item)
else: else:
sheet_btn("Remove widget", REMOVE, item) sheet_btn("Remove widget", REMOVE, item)
elif sheet == SHEET_APP and app_row >= 0 and app_row < n:
el("h2")
cls("sheet-title")
text_ref(labels[app_row])
end()
i = home_of(app_row)
if i >= 0:
sheet_btn("Remove from home", REMOVE, i)
else:
sheet_btn("Add to home", ADD_HOME, app_row)
sheet_btn("App info", APP_INFO, app_row)
if system[app_row] == 0:
sheet_btn("Uninstall", UNINSTALL, app_row)
elif sheet == SHEET_WIDGETS: elif sheet == SHEET_WIDGETS:
el("h2") el("h2")
cls("sheet-title") cls("sheet-title")
BIN
View File
Binary file not shown.
+3
View File
@@ -57,6 +57,7 @@
}, },
{ {
"label": "Phone", "label": "Phone",
"system": true,
"component": "com.example.phone/.MainActivity", "component": "com.example.phone/.MainActivity",
"icon": "data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A//www.w3.org/2000/svg%22%20viewBox%3D%220%200%2048%2048%22%3E%3Ccircle%20cx%3D%2224%22%20cy%3D%2224%22%20r%3D%2224%22%20fill%3D%22%2314b8a6%22/%3E%3Ctext%20x%3D%2224%22%20y%3D%2231%22%20font-family%3D%22sans-serif%22%20font-size%3D%2220%22%20font-weight%3D%22600%22%20fill%3D%22%23fff%22%20text-anchor%3D%22middle%22%3EP%3C/text%3E%3C/svg%3E" "icon": "data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A//www.w3.org/2000/svg%22%20viewBox%3D%220%200%2048%2048%22%3E%3Ccircle%20cx%3D%2224%22%20cy%3D%2224%22%20r%3D%2224%22%20fill%3D%22%2314b8a6%22/%3E%3Ctext%20x%3D%2224%22%20y%3D%2231%22%20font-family%3D%22sans-serif%22%20font-size%3D%2220%22%20font-weight%3D%22600%22%20fill%3D%22%23fff%22%20text-anchor%3D%22middle%22%3EP%3C/text%3E%3C/svg%3E"
}, },
@@ -67,11 +68,13 @@
}, },
{ {
"label": "Play Store", "label": "Play Store",
"system": true,
"component": "com.example.playstore/.MainActivity", "component": "com.example.playstore/.MainActivity",
"icon": "data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A//www.w3.org/2000/svg%22%20viewBox%3D%220%200%2048%2048%22%3E%3Ccircle%20cx%3D%2224%22%20cy%3D%2224%22%20r%3D%2224%22%20fill%3D%22%2306b6d4%22/%3E%3Ctext%20x%3D%2224%22%20y%3D%2231%22%20font-family%3D%22sans-serif%22%20font-size%3D%2220%22%20font-weight%3D%22600%22%20fill%3D%22%23fff%22%20text-anchor%3D%22middle%22%3EP%3C/text%3E%3C/svg%3E" "icon": "data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A//www.w3.org/2000/svg%22%20viewBox%3D%220%200%2048%2048%22%3E%3Ccircle%20cx%3D%2224%22%20cy%3D%2224%22%20r%3D%2224%22%20fill%3D%22%2306b6d4%22/%3E%3Ctext%20x%3D%2224%22%20y%3D%2231%22%20font-family%3D%22sans-serif%22%20font-size%3D%2220%22%20font-weight%3D%22600%22%20fill%3D%22%23fff%22%20text-anchor%3D%22middle%22%3EP%3C/text%3E%3C/svg%3E"
}, },
{ {
"label": "Settings", "label": "Settings",
"system": true,
"component": "com.example.settings/.MainActivity", "component": "com.example.settings/.MainActivity",
"icon": "data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A//www.w3.org/2000/svg%22%20viewBox%3D%220%200%2048%2048%22%3E%3Ccircle%20cx%3D%2224%22%20cy%3D%2224%22%20r%3D%2224%22%20fill%3D%22%2371717a%22/%3E%3Ctext%20x%3D%2224%22%20y%3D%2231%22%20font-family%3D%22sans-serif%22%20font-size%3D%2220%22%20font-weight%3D%22600%22%20fill%3D%22%23fff%22%20text-anchor%3D%22middle%22%3ES%3C/text%3E%3C/svg%3E" "icon": "data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A//www.w3.org/2000/svg%22%20viewBox%3D%220%200%2048%2048%22%3E%3Ccircle%20cx%3D%2224%22%20cy%3D%2224%22%20r%3D%2224%22%20fill%3D%22%2371717a%22/%3E%3Ctext%20x%3D%2224%22%20y%3D%2231%22%20font-family%3D%22sans-serif%22%20font-size%3D%2220%22%20font-weight%3D%22600%22%20fill%3D%22%23fff%22%20text-anchor%3D%22middle%22%3ES%3C/text%3E%3C/svg%3E"
}, },
+2
View File
@@ -25,6 +25,7 @@
const host = window.Android || { const host = window.Android || {
launch: (c) => toast("Open " + c), launch: (c) => toast("Open " + c),
appInfo: (c) => toast("App info for " + c), appInfo: (c) => toast("App info for " + c),
uninstall: (c) => toast("Uninstall " + c),
addWidget: () => setTimeout(() => window.ultraHome.widgetAdded(demoWidget++), 0), addWidget: () => setTimeout(() => window.ultraHome.widgetAdded(demoWidget++), 0),
removeWidget: () => {}, removeWidget: () => {},
placeWidgets: () => {}, placeWidgets: () => {},
@@ -122,6 +123,7 @@
imports: ({ strs }) => ({ imports: ({ strs }) => ({
launch: (h) => host.launch(strs[h]), launch: (h) => host.launch(strs[h]),
app_info: (h) => host.appInfo(strs[h]), app_info: (h) => host.appInfo(strs[h]),
uninstall: (h) => host.uninstall(strs[h]),
add_widget: (h) => host.addWidget(strs[h]), add_widget: (h) => host.addWidget(strs[h]),
remove_widget: (id) => host.removeWidget(id), remove_widget: (id) => host.removeWidget(id),
open_settings: () => host.openSettings(), open_settings: () => host.openSettings(),