diff --git a/README.md b/README.md index f523f1e..9ec435d 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # 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 with a clock: 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 under the clock 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 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. ## Install 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 1006bb0..5e23586 100644 --- a/android/app/src/main/java/dev/ultra/launcher/MainActivity.java +++ b/android/app/src/main/java/dev/ultra/launcher/MainActivity.java @@ -26,7 +26,6 @@ import android.os.Looper; import android.os.Process; import android.os.UserHandle; import android.provider.Settings; -import android.text.format.DateFormat; import android.util.Base64; import android.util.Log; import android.util.SizeF; @@ -75,13 +74,13 @@ import java.util.concurrent.Executors; * wicon?p=PROV the provider's icon as a PNG * * and exposes window.Android (launch, appInfo, addWidget, removeWidget, placeWidgets, - * widgetLimits, excludeGestures, openSettings, pickWallpaper, openRecents, haptic, is24Hour) + * widgetLimits, excludeGestures, openSettings, pickWallpaper, openRecents, haptic) * for the app's @jscall imports and index.html. * * Widgets are real AppWidgetHostViews in a layer above the WebView. The page reports where * its live widget slots are (placeWidgets), and this class moves the views there. Package - * changes, the home button, back, resume, a new widget and a long press on a widget reach - * the page as window.ultraHome.reload() / home() / back() / tick() / widgetAdded(id) / + * changes, the home button, back, a new widget and a long press on a widget reach + * the page as window.ultraHome.reload() / home() / back() / widgetAdded(id) / * widgetMenu(id). */ public class MainActivity extends Activity { @@ -203,12 +202,6 @@ public class MainActivity extends Activity { js("home()"); } - @Override - protected void onResume() { - super.onResume(); - js("tick()"); - } - // A home screen has nowhere to go back to; let the page clear its search or edit mode. @Override @SuppressWarnings("deprecation") @@ -769,10 +762,6 @@ public class MainActivity extends Activity { @JavascriptInterface public void openRecents() { main.post(MainActivity.this::openRecents); } - - @JavascriptInterface public boolean is24Hour() { - return DateFormat.is24HourFormat(MainActivity.this); - } } // ------------------------------------------------------------ serving diff --git a/tests/e2e.cjs b/tests/e2e.cjs index 09dce0c..0e9dbaa 100644 --- a/tests/e2e.cjs +++ b/tests/e2e.cjs @@ -15,10 +15,10 @@ const BASE = process.env.BASE || "http://localhost:8000"; await p.evaluate(() => localStorage.clear()); await p.reload(); await p.waitForSelector(".hint"); - assert.match(await p.textContent(".clock .time"), /^\d{1,2}:\d\d$/); - const longpress = async (sel) => { + assert.ok(!(await p.$(".clock")), "home has no built-in clock"); + const longpress = async (sel, fy = 0.5) => { const r = await p.locator(sel).first().boundingBox(); - await p.mouse.move(r.x + r.width / 2, r.y + r.height / 2); + await p.mouse.move(r.x + r.width / 2, r.y + r.height * fy); await p.mouse.down(); await p.waitForTimeout(650); await p.mouse.up(); await settle(); }; const homeApps = () => p.$$eval(".slots .name", (ns) => ns.map((n) => n.textContent)); @@ -30,8 +30,8 @@ const BASE = process.env.BASE || "http://localhost:8000"; assert.equal(await p.$$eval(".apps .tile.on", (ts) => ts.length), 3); await p.click(".drawer-head >> text=Done"); await settle(); assert.deepEqual(await homeApps(), ["Chrome", "Gmail", "Phone"]); - // add a widget - await longpress(".clock"); + // add a widget: long press on blank home, below the apps + await longpress(".home", 0.95); await p.click(".sheet-item >> text=Add widget"); await p.waitForSelector(".widget-list li"); // search the picker by widget name and by the app it comes from diff --git a/web/app.py b/web/app.py index f0bca3e..e45624c 100644 --- a/web/app.py +++ b/web/app.py @@ -54,18 +54,7 @@ def open_recents() -> None: def haptic() -> None: pass -@jscall -def clock_time(dst: i32) -> None: - """Write the local time ("15:04") into dst.""" - pass - -@jscall -def clock_date(dst: i32) -> None: - """Write the local date ("Tuesday, October 21") into dst.""" - pass - -# ---- Msg (index.html and MainActivity.java send TICK through WIDGET_MENU) -TICK: Const[i32] = 1 +# ---- Msg (index.html and MainActivity.java send RELOAD through WIDGET_MENU) RELOAD: Const[i32] = 2 HOME: Const[i32] = 3 BACK: Const[i32] = 4 @@ -151,8 +140,6 @@ chosen: i32 = -1 # widget row being added query: i32 = 0 wquery: i32 = 0 # widget picker search -now: i32 = 0 -today: i32 = 0 err: i32 = 0 notice: i32 = 0 notice_gen: i32 = 0 @@ -168,14 +155,12 @@ pending: i32 = 0 # JSON handle of a request in flight def init() -> None: - global query, wquery, now, today, err, notice, scratch, nh, next_key, pending + global query, wquery, err, notice, scratch, nh, next_key, pending i: i32 h: i32 k: i32 query = s_new() wquery = s_new() - now = s_new() - today = s_new() err = s_new() notice = s_new() scratch = s_new() @@ -194,9 +179,6 @@ def init() -> None: nh += 1 else: s_free(h) - clock_time(now) - clock_date(today) - after(5000, TICK, 0) pending = http_get("apps.json", LOADED) @@ -562,11 +544,6 @@ def update(msg: i32, arg: i32) -> None: elif msg == NOTICE_DONE: if arg == notice_gen: s_clear(notice) - elif msg == TICK: - clock_time(now) - clock_date(today) - if arg == 0: - after(5000, TICK, 0) elif msg == RELOAD: pending = http_get("apps.json", LOADED) elif msg == HOME: @@ -675,7 +652,7 @@ def view_home_slot(i: i32) -> None: def view_panel() -> None: - """The panel under the clock: shortcuts to system surfaces.""" + """The panel at the top of home: shortcuts to system surfaces.""" el("section") cls("panel") attr("aria-label", "Shortcuts") @@ -705,16 +682,6 @@ def view_home() -> None: on_click(OPEN_DRAWER, 0) end() - el("header") - cls("clock") - div("time") - text_ref(now) - end() - div("date") - text_ref(today) - end() - end() - view_panel() el("ul") diff --git a/web/app.wasm b/web/app.wasm index 32c6320..028dc46 100644 Binary files a/web/app.wasm and b/web/app.wasm differ diff --git a/web/index.html b/web/index.html index 2ee7a43..a2d5d9b 100644 --- a/web/index.html +++ b/web/index.html @@ -33,18 +33,9 @@ pickWallpaper: () => toast("Pick a wallpaper"), openRecents: () => toast("Show open windows"), haptic: () => navigator.vibrate?.(10), - is24Hour: () => false, }; if (!window.Android) document.documentElement.classList.add("demo"); - let fmtTime, fmtDate; - const formats = () => { - fmtTime = new Intl.DateTimeFormat(undefined, - { hour: "numeric", minute: "2-digit", hourCycle: host.is24Hour() ? "h23" : "h12" }); - fmtDate = new Intl.DateTimeFormat(undefined, { weekday: "long", month: "long", day: "numeric" }); - }; - formats(); - // Tell the shell where the live widget slots are (CSS px, viewport-relative). let placed = ""; const place = () => { @@ -114,13 +105,11 @@ pick_wallpaper: () => host.pickWallpaper(), open_recents: () => host.openRecents(), haptic: () => host.haptic(), - clock_time: (h) => { strs[h] = fmtTime.format(new Date()).replace(/\s?[AP]M$/i, ""); }, - clock_date: (h) => { strs[h] = fmtDate.format(new Date()); }, }), }); // Messages the shell and the gestures below send (keep in sync with app.py). - const TICK = 1, RELOAD = 2, HOME = 3, BACK = 4, SWIPE_DOWN = 5, SWIPE_UP = 6, + const RELOAD = 2, HOME = 3, BACK = 4, SWIPE_DOWN = 5, SWIPE_UP = 6, WIDGET_ADDED = 7, WIDGET_MENU = 8, DRAG_TO = 35, DROP = 36, RESIZE = 40; // Dragging a home slot. A long press lifts it (app.py marks it .lifted); moving the @@ -220,7 +209,6 @@ addEventListener("touchmove", (e) => { if (rs && e.cancelable) e.preventDefault(); }, { passive: false }); window.ultraHome = { - tick: () => { formats(); app.dispatch(TICK, 1); }, reload: () => app.dispatch(RELOAD, 0), home: () => { app.dispatch(HOME, 0); window.scrollTo({ top: 0, behavior: "smooth" }); }, back: () => app.dispatch(BACK, 0), @@ -232,7 +220,6 @@ 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(); }); addEventListener("scroll", () => requestAnimationFrame(place), { passive: true }); addEventListener("resize", () => requestAnimationFrame(place)); diff --git a/web/style.css b/web/style.css index bc13db8..4007eea 100644 --- a/web/style.css +++ b/web/style.css @@ -21,11 +21,6 @@ body { margin: 0; min-height: 100vh; color: #fff; -webkit-tap-highlight-color: t .pull::before { content: ""; display: block; width: 2.25rem; height: .3rem; margin: auto; border-radius: 999px; background: rgb(255 255 255 / .45); } -.clock { text-align: center; text-shadow: 0 1px 8px rgb(0 0 0 / .45); margin-bottom: 2rem; } -.clock .time { font-size: 4rem; font-weight: 200; line-height: 1; letter-spacing: -.02em; - font-variant-numeric: tabular-nums; } -.clock .date { margin-top: .5rem; font-size: 1rem; opacity: .9; } - .panel { display: flex; gap: .5rem; margin: 0 auto 2rem; padding: .5rem; max-width: 22rem; border-radius: 1.25rem; background: rgb(255 255 255 / .12); border: 1px solid rgb(255 255 255 / .16); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px); }