Rewrite the launcher in MoonBit (old code moves to legacy/) (#1)
Launcher / test (push) Successful in 1m20s
Launcher / apk (push) Successful in 37s

This commit was merged in pull request #1.
This commit is contained in:
nandi committed 2026-11-23 01:57:10 +00:00
1 parent 7d2bf5996f
commit 2fa7bd745b
150 files changed
+8319 -462

No files matched your search

+31
View File
@@ -0,0 +1,31 @@
import QtQuick
// An app's or widget's icon from HomeActivity (image://icon/KEY), or a blank disc
// until it arrives or if it can't be drawn.
Item {
id: root
property string key: "" // "a:COMPONENT" or "w:PROVIDER"
property int generation: 0 // bumped when the app list changes, so icons reload
property real size: 40
width: size
height: size
Rectangle {
anchors.fill: parent
radius: width / 2
color: Qt.rgba(1, 1, 1, .18)
visible: img.status !== Image.Ready
}
Image {
id: img
anchors.fill: parent
asynchronous: true
fillMode: Image.PreserveAspectFit
smooth: true
mipmap: true
sourceSize.width: Math.ceil(root.size * Screen.devicePixelRatio)
sourceSize.height: Math.ceil(root.size * Screen.devicePixelRatio)
onStatusChanged: if (status === Image.Ready || status === Image.Error) console.info("ultra.icon shown", root.key, status === Image.Ready)
source: root.key ? "image://icon/" + encodeURIComponent(root.key) + "?" + root.generation : ""
}
}
+148
View File
@@ -0,0 +1,148 @@
import QtQuick
// Every app, with a search. It slides down over the home screen; swiping up past the
// end of the list (or Close, or back) puts it away. In pick mode a tap adds an app to
// the home screen or takes it off, and the keyboard stays down.
Item {
id: root
property bool open: false
property bool picking: false
property var apps: [] // [{label, component, system}]
property var homeSet: ({}) // component -> true: on the home screen
property bool loading: true
property bool warm: true // false: hold off making icons until it opens
property var iconGen: ({}) // package -> n, see Main.gen
property real insetTop: 0
property real insetBottom: 0
property alias query: search.text
readonly property real edge: y + height // the drawer's bottom edge, for covering widgets
readonly property var shown: {
const q = search.shown.toLowerCase();
const out = [];
for (let i = 0; i < apps.length; i++)
if (!q || apps[i].label.toLowerCase().indexOf(q) >= 0) out.push(i);
return out;
}
signal openApp(int row)
signal toggleApp(int row)
signal appMenu(int row)
signal closeRequested()
width: parent.width
height: parent.height
y: open ? 0 : -height
visible: y > -height
Behavior on y { NumberAnimation { duration: 220; easing.type: Easing.OutCubic } }
function openFirst() {
if (shown.length > 0 && search.shown.length > 0) openApp(shown[0]);
}
onOpenChanged: {
if (open && !picking) search.focusNow();
if (!open) {
search.input.focus = false;
Qt.inputMethod.hide();
search.text = "";
grid.positionViewAtBeginning();
}
}
Rectangle {
anchors.fill: parent
color: Qt.rgba(10 / 255, 10 / 255, 14 / 255, .9)
}
MouseArea { anchors.fill: parent } // nothing under the drawer takes its touches
Column {
id: head
x: Math.max(16, (root.width - 560) / 2 + 16)
width: Math.min(root.width, 560) - 32
y: root.insetTop + 16
spacing: 16
Row {
width: parent.width
spacing: 8
SearchField {
id: search
width: parent.width - close.width - 8
placeholder: "Search apps"
onAccepted: root.openFirst()
onEscaped: text = ""
}
PillButton {
id: close
anchors.verticalCenter: search.verticalCenter
text: root.picking ? "Done" : "Close"
onClicked: root.closeRequested()
}
}
Text {
visible: root.picking
width: parent.width
text: "Tap apps to add them to the home screen or take them off."
color: "white"
opacity: .8
font.pixelSize: 14
wrapMode: Text.Wrap
horizontalAlignment: Text.AlignHCenter
}
}
GridView {
id: grid
objectName: "drawerGrid"
x: head.x
width: head.width
anchors.top: head.bottom
anchors.topMargin: 16
anchors.bottom: parent.bottom
readonly property int cols: root.width >= 480 ? 5 : 4
cellWidth: width / cols
cellHeight: 104
clip: true
bottomMargin: root.insetBottom + 24
boundsBehavior: Flickable.DragOverBounds
model: root.warm || root.visible ? root.shown : []
// Swiping up once the list is at its end puts the drawer away.
onDragEnded: if (verticalOvershoot > 48) root.closeRequested()
delegate: Item {
id: cell
required property int index
required property var modelData
readonly property var app: root.apps[modelData] || ({})
width: grid.cellWidth
height: grid.cellHeight
Tile {
width: parent.width
height: 84
key: "a:" + (cell.app.component || "")
label: cell.app.label || ""
generation: root.iconGen[(cell.app.component || "").split("/")[0]] || 0
iconSize: 52
fontSize: 12
spacing: 6
checkable: root.picking
checked: root.picking && root.homeSet[cell.app.component] === true
pressed: area.pressed
}
MouseArea {
id: area
width: parent.width
height: 84
pressAndHoldInterval: 450
onClicked: root.picking ? root.toggleApp(cell.modelData) : root.openApp(cell.modelData)
onPressAndHold: if (!root.picking) root.appMenu(cell.modelData)
}
}
}
Text {
anchors.centerIn: grid
visible: root.loading || root.shown.length === 0
text: root.loading ? "Loading apps…" : "No apps match."
color: "white"
opacity: .85
font.pixelSize: 15
}
}
+161
View File
@@ -0,0 +1,161 @@
.pragma library
// The home grid, as plain functions over the home list so they can be tested on their
// own (tests/layout.test.mjs). A slot is
// {kind: "app", str: COMPONENT, x, y}
// {kind: "widget", str: LABEL, wid: HOST_ID, w: COLUMNS (0: whole row), rows, x, y}
// where x, y is the cell it was dropped into (column, row from 0), or -1, -1: placed in
// order into the first free cells that fit it ("dense" packing, so apps fill the cells
// beside a widget and the grid has no holes).
var CELL = 64; // row height, px
var RGAP = 8; // gap between rows
var CGAP = 8; // gap between columns
// Rows of app tiles nearest to a widget height in px, at least one.
function widgetRows(px) {
return Math.max(1, Math.floor((px + RGAP + (CELL + RGAP) / 2) / (CELL + RGAP)));
}
function slotW(s, cols) {
if (s.kind !== "widget") return 1;
return (s.w <= 0 || s.w > cols) ? cols : s.w;
}
function slotH(s) {
return s.kind === "widget" ? Math.max(1, s.rows | 0) : 1;
}
function pinned(s, cols) {
return s.x >= 0 && s.y >= 0 && s.x + slotW(s, cols) <= cols;
}
// Where each slot goes: [{col, row, w, h}] (null for a hidden slot), and the rows used,
// at least nrows (the rows that fill the screen).
function pack(home, cols, nrows, hidden) {
var occ = [];
function taken(c, r) { return occ[r] !== undefined && occ[r][c] === true; }
function fits(c, r, w, h) {
if (c < 0 || c + w > cols) return false;
for (var y = r; y < r + h; y++)
for (var x = c; x < c + w; x++)
if (taken(x, y)) return false;
return true;
}
function mark(c, r, w, h) {
for (var y = r; y < r + h; y++) {
if (occ[y] === undefined) occ[y] = [];
for (var x = c; x < c + w; x++) occ[y][x] = true;
}
}
var cells = new Array(home.length);
var rows = Math.max(0, nrows | 0);
var i, s, w, h;
// Pinned slots first, where they were put (they may overlap each other).
for (i = 0; i < home.length; i++) {
s = home[i];
cells[i] = null;
if ((hidden && hidden[i]) || !pinned(s, cols)) continue;
w = slotW(s, cols); h = slotH(s);
cells[i] = {col: s.x, row: s.y, w: w, h: h};
mark(s.x, s.y, w, h);
rows = Math.max(rows, s.y + h);
}
// The rest in order, each into the first free cells that fit it.
for (i = 0; i < home.length; i++) {
s = home[i];
if ((hidden && hidden[i]) || cells[i] !== null) continue;
w = slotW(s, cols); h = slotH(s);
for (var r = 0; cells[i] === null; r++) {
for (var c = 0; c + w <= cols; c++) {
if (fits(c, r, w, h)) {
cells[i] = {col: c, row: r, w: w, h: h};
mark(c, r, w, h);
rows = Math.max(rows, r + h);
break;
}
}
}
}
return {cells: cells, rows: rows};
}
// A cell's box in px, given the column width.
function box(cell, colW) {
return {x: cell.col * (colW + CGAP), y: cell.row * (CELL + RGAP),
w: cell.w * colW + (cell.w - 1) * CGAP, h: cell.h * CELL + (cell.h - 1) * RGAP};
}
// The cell nearest to the top left of a box at x, y (px in the grid).
function cellAt(x, y, colW) {
return [Math.max(0, Math.round(x / (colW + CGAP))), Math.max(0, Math.round(y / (CELL + RGAP)))];
}
// Slot i pinned with its top left at col, row (kept on the screen's grid).
function pin(home, i, col, row, cols, nrows) {
var s = home[i];
var x = col, y = row;
if (x + slotW(s, cols) > cols) x = cols - slotW(s, cols);
if (nrows > 0 && y + slotH(s) > nrows) y = nrows - slotH(s);
s.x = Math.max(0, x);
s.y = Math.max(0, y);
}
// Unpin the slots under pinned slot i, so they flow into free cells.
function clearCells(home, i, cols) {
var a = home[i];
for (var j = 0; j < home.length; j++) {
var b = home[j];
if (j === i || b.x < 0) continue;
if (b.x < a.x + slotW(a, cols) && a.x < b.x + slotW(b, cols)
&& b.y < a.y + slotH(a) && a.y < b.y + slotH(b)) {
b.x = -1;
b.y = -1;
}
}
}
// Take slot a out and put it back at b, shifting the slots between.
function move(home, a, b) {
var s = home.splice(a, 1)[0];
home.splice(b, 0, s);
}
// Resize steps: the number of cells (of size px, gap apart) nearest to want px, kept
// within [min, max] px where it can be (max 0: no limit), and within [lo, hi] cells.
function span(k, size, gap) { return k * size + (k - 1) * gap; }
function fit(want, lo, hi, size, gap, min, max) {
var k = Math.round((want + gap) / (size + gap));
while (k < hi && span(k, size, gap) < min - 8) k++;
while (k > lo && max > 0 && span(k, size, gap) > max + 8) k--;
return Math.max(lo, Math.min(hi, k));
}
// Columns a new widget of natural width px starts at (0: the whole row).
function widgetCols(px, colW, cols) {
if (!px) return 0;
var k = Math.max(1, Math.ceil((px + CGAP - 8) / (colW + CGAP)));
return k >= cols ? 0 : k;
}
// The WebView build's saved home (its ultra.home.* localStorage keys) as Qt slots.
// Widget heights were px; they become whole rows.
function legacy(kv) {
var out = [];
var n = parseInt(kv["ultra.home.n"], 10) || 0;
var num = function (k, i, d) {
var v = parseInt(kv["ultra.home." + k + "." + i], 10);
return isNaN(v) ? d : v;
};
for (var i = 0; i < n; i++) {
var str = kv["ultra.home.str." + i];
if (typeof str !== "string" || !str) continue;
var x = num("cx", i, -1), y = num("cy", i, -1);
if (num("kind", i, 0) === 1)
out.push({kind: "widget", str: str, wid: num("wid", i, 0), w: Math.max(0, num("w", i, 0)),
rows: widgetRows(num("h", i, 120)), x: x, y: y});
else
out.push({kind: "app", str: str, x: x, y: y});
}
return out;
}
File diff suppressed because it is too large. Load diff
+27
View File
@@ -0,0 +1,27 @@
import QtQuick
// A rounded text button: "ghost" (clear until pressed) or "primary" (filled).
Rectangle {
id: root
property alias text: label.text
property bool primary: false
property real fontSize: 14
signal clicked()
implicitWidth: label.implicitWidth + 28
implicitHeight: 36
radius: height / 2
color: primary ? (area.pressed ? "#d4d4d8" : "white")
: (area.pressed ? Qt.rgba(1, 1, 1, .18) : "transparent")
Text {
id: label
anchors.centerIn: parent
color: root.primary ? "#111" : "white"
font.pixelSize: root.fontSize
font.weight: Font.Medium
}
MouseArea {
id: area
anchors.fill: parent
onClicked: root.clicked()
}
}
+89
View File
@@ -0,0 +1,89 @@
import QtQuick
// A rounded search box. Enter is "accepted"; the text is "text", and "shown" is what
// the box shows, including a word the keyboard is still composing (Android keyboards
// keep it out of "text" until it is committed).
Rectangle {
id: root
property alias text: input.text
property alias placeholder: hint.text
property alias input: input
readonly property string shown: input.displayText
property real fontSize: 16
signal accepted()
signal escaped()
implicitHeight: 44
radius: height / 2
color: Qt.rgba(1, 1, 1, .1)
border.color: Qt.rgba(1, 1, 1, .15)
border.width: 1
function focusNow() { input.forceActiveFocus(); Qt.inputMethod.show() }
// Empty the box, including a word still being composed, and keep typing in it.
// Android commits a composing word asynchronously, so it can land after the clear:
// clear again once it has.
function clearText() {
Qt.inputMethod.commit();
input.clear();
input.forceActiveFocus();
clearAgain.restart();
}
Timer { id: clearAgain; interval: 120; onTriggered: input.clear() }
TextInput {
id: input
anchors.left: parent.left
anchors.right: clear.left
anchors.leftMargin: 20
anchors.rightMargin: 0
anchors.verticalCenter: parent.verticalCenter
color: "white"
selectionColor: Qt.rgba(1, 1, 1, .35)
font.pixelSize: root.fontSize
clip: true
// No suggestions: Android keyboards then type straight into the box rather than
// composing words, so the list filters on every key.
inputMethodHints: Qt.ImhNoPredictiveText | Qt.ImhSensitiveData | Qt.ImhNoAutoUppercase
onAccepted: root.accepted()
Keys.onEscapePressed: root.escaped()
Text {
id: hint
anchors.fill: parent
verticalAlignment: Text.AlignVCenter
color: Qt.rgba(1, 1, 1, .6)
font.pixelSize: root.fontSize
visible: input.displayText.length === 0
}
}
// The clear button: a finger-sized target at the right end of the box.
Item {
id: clear
objectName: "searchClear"
anchors.right: parent.right
anchors.top: parent.top
anchors.bottom: parent.bottom
width: visible ? 44 : 0
visible: input.displayText.length > 0
z: 1
// Drawn, not a glyph: phone fonts may have no ✕.
Repeater {
model: [45, -45]
Rectangle {
required property var modelData
anchors.centerIn: parent
width: 14
height: 2
radius: 1
rotation: modelData
antialiasing: true
color: Qt.rgba(1, 1, 1, .7)
}
}
MouseArea {
anchors.fill: parent
preventStealing: true
onPressed: (m) => m.accepted = true
onClicked: { root.clearText(); root.escaped() }
}
}
}
+71
View File
@@ -0,0 +1,71 @@
import QtQuick
// A panel that rises from the bottom over a dimmed screen (long-press menus, the
// widget picker). Its children go in a column; tapping outside closes it.
Item {
id: root
property bool open: false
property string title: ""
property real bottomInset: 0
property real maxWidth: 560
default property alias content: column.data
// Where the panel's top edge is, for hiding native widgets under it.
readonly property real edge: panel.y
signal closeRequested()
anchors.fill: parent
visible: open || panel.y < height
enabled: open
Rectangle {
anchors.fill: parent
color: "black"
opacity: root.open ? .45 : 0
Behavior on opacity { NumberAnimation { duration: 150 } }
MouseArea { anchors.fill: parent; onClicked: root.closeRequested() }
}
Rectangle {
id: panel
width: Math.min(root.width, root.maxWidth)
anchors.horizontalCenter: parent.horizontalCenter
height: Math.min(root.height * .7, column.implicitHeight + 36 + root.bottomInset + 16)
y: root.open ? root.height - height : root.height
Behavior on y { NumberAnimation { duration: 200; easing.type: Easing.OutCubic } }
radius: 20
color: "#18181b"
MouseArea { anchors.fill: parent } // keep taps on the sheet off the overlay
// square off the bottom corners
Rectangle { anchors.bottom: parent.bottom; width: parent.width; height: 20; color: parent.color }
Rectangle {
width: 36; height: 5; radius: 3
anchors.horizontalCenter: parent.horizontalCenter
y: 12
color: "#3f3f46"
}
Flickable {
id: flick
anchors.fill: parent
anchors.topMargin: 28
anchors.leftMargin: 16
anchors.rightMargin: 16
anchors.bottomMargin: root.bottomInset + 16
contentHeight: column.implicitHeight
clip: true
boundsBehavior: Flickable.StopAtBounds
Column {
id: column
width: flick.width
Text {
visible: root.title.length > 0
text: root.title
color: "#fafafa"
font.pixelSize: 16
font.weight: Font.DemiBold
leftPadding: 8
bottomPadding: 8
width: parent.width
elide: Text.ElideRight
}
}
}
}
}
+25
View File
@@ -0,0 +1,25 @@
import QtQuick
// A row in a sheet's menu.
Rectangle {
id: root
property alias text: label.text
signal clicked()
width: parent ? parent.width : 0
height: 48
radius: 8
color: area.pressed ? "#2e2e36" : "transparent"
Text {
id: label
anchors.left: parent.left
anchors.leftMargin: 8
anchors.verticalCenter: parent.verticalCenter
color: "#fafafa"
font.pixelSize: 16
}
MouseArea {
id: area
anchors.fill: parent
onClicked: root.clicked()
}
}
+61
View File
@@ -0,0 +1,61 @@
import QtQuick
// An app: its icon over its name.
Item {
id: root
property string key: ""
property string label: ""
property int generation: 0
property real iconSize: 40
property real fontSize: 11
property real spacing: 4
property bool checkable: false // the drawer's pick mode: a check circle in the corner
property bool checked: false
property bool pressed: false
Rectangle {
anchors.fill: parent
radius: 12
color: Qt.rgba(1, 1, 1, .12)
visible: root.pressed
}
Column {
anchors.centerIn: parent
width: parent.width
spacing: root.spacing
AppIcon {
anchors.horizontalCenter: parent.horizontalCenter
key: root.key
generation: root.generation
size: root.iconSize
}
Text {
width: parent.width - 4
anchors.horizontalCenter: parent.horizontalCenter
text: root.label
color: "white"
font.pixelSize: root.fontSize
horizontalAlignment: Text.AlignHCenter
elide: Text.ElideRight
style: Text.Raised
styleColor: Qt.rgba(0, 0, 0, .55)
}
}
Rectangle {
visible: root.checkable
width: 20; height: 20; radius: 10
x: parent.width / 2 + root.iconSize / 2 - 12
y: 2
color: root.checked ? "white" : Qt.rgba(0, 0, 0, .35)
border.color: "white"
border.width: 2
Text {
anchors.centerIn: parent
visible: root.checked
text: "✓"
color: "#111"
font.pixelSize: 12
font.bold: true
}
}
}