Add the pure MoonBit core: grid, gestures, updater, vdom, app
grid: packing, pinning, resize steps (port of Layout.js and app.py's grid logic). gesture: pointer state machine (tap, long press, drag, release, swipe). updater: release/version parsing and the update decision. vdom: pure virtual DOM with an HTML-text renderer for tests. app: Elm-style Model/Msg/update/view with effects as data, persistence (JSON layout, import of the old WebView build's localStorage), drawer/search, menus, drag and resize. 60 headless tests drive it through pointer input. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
66e8e90da1
commit
28e0284d9b
28 files changed
+4278
No files matched your search
+307
@@ -0,0 +1,307 @@
|
||||
///|
|
||||
/// The launcher as an Elm-style program, pure: `Model`, `Msg`, `update` (returns the
|
||||
/// `Effect`s for the platform to run) and `view` (returns a `vdom` tree). It ports
|
||||
/// legacy/web/app.py, the LPython app, and the gesture handling that lived in its
|
||||
/// index.html. Nothing here touches a platform: the web/ package runs the effects and
|
||||
/// renders the tree, and the tests below drive the whole thing headlessly.
|
||||
|
||||
///|
|
||||
pub(all) struct AppInfo {
|
||||
label : String
|
||||
component : String
|
||||
icon : String
|
||||
/// A system app: it has no Uninstall.
|
||||
system : Bool
|
||||
}
|
||||
|
||||
///|
|
||||
pub(all) struct WidgetInfo {
|
||||
label : String
|
||||
provider : String
|
||||
icon : String
|
||||
/// The label of the app the widget comes from (for the picker's search).
|
||||
app : String
|
||||
/// Natural height in CSS px.
|
||||
h : Int
|
||||
}
|
||||
|
||||
///|
|
||||
/// How a widget may be resized, in CSS px (the shell's `widgetLimits`): its natural
|
||||
/// width, min/max size (0: no max), and whether it resizes horizontally / vertically.
|
||||
pub(all) struct Limits {
|
||||
w : Int
|
||||
min_w : Int
|
||||
min_h : Int
|
||||
max_w : Int
|
||||
max_h : Int
|
||||
h : Bool
|
||||
v : Bool
|
||||
}
|
||||
|
||||
///|
|
||||
pub let default_limits : Limits = {
|
||||
w: 0,
|
||||
min_w: 120,
|
||||
min_h: 80,
|
||||
max_w: 0,
|
||||
max_h: 0,
|
||||
h: true,
|
||||
v: true,
|
||||
}
|
||||
|
||||
///|
|
||||
#derive(Eq, Debug)
|
||||
pub(all) enum Sheet {
|
||||
NoSheet
|
||||
/// The menu of the empty home.
|
||||
HomeMenu
|
||||
/// The menu of a home slot.
|
||||
Item(Int)
|
||||
/// The menu of a drawer app (row in the app list).
|
||||
DrawerApp(Int)
|
||||
WidgetPicker
|
||||
}
|
||||
|
||||
///|
|
||||
#derive(Eq, Debug)
|
||||
pub(all) enum Edge {
|
||||
Right
|
||||
Bottom
|
||||
Corner
|
||||
}
|
||||
|
||||
///|
|
||||
/// A resize in progress: a handle was pressed on the widget whose box (px, viewport) was
|
||||
/// at `left`, `top`.
|
||||
pub(all) struct ResizeDrag {
|
||||
edge : Edge
|
||||
slot : Int
|
||||
left : Double
|
||||
top : Double
|
||||
mut cols : Int
|
||||
mut rows : Int
|
||||
}
|
||||
|
||||
///|
|
||||
/// Where the lifted slot was held, and the cell it was last sent to.
|
||||
pub(all) struct Carry {
|
||||
dx : Double
|
||||
dy : Double
|
||||
mut cell : Int
|
||||
}
|
||||
|
||||
///|
|
||||
pub(all) struct Model {
|
||||
mut apps : Array[AppInfo]
|
||||
mut loading : Bool
|
||||
mut load_error : String
|
||||
mut widgets : Array[WidgetInfo]
|
||||
mut wloading : Bool
|
||||
/// The home screen, in order.
|
||||
mut home : Array[@grid.Slot]
|
||||
mut next_key : Int
|
||||
/// Grid columns, and rows that fill the screen (0 until the page has measured).
|
||||
mut cols : Int
|
||||
mut nrows : Int
|
||||
/// Where the grid is on the screen (px, viewport) and how wide a column is.
|
||||
mut grid_left : Double
|
||||
mut grid_top : Double
|
||||
mut col_w : Double
|
||||
mut query : String
|
||||
mut wquery : String
|
||||
mut drawer : Bool
|
||||
/// The drawer is in "add apps" mode: taps toggle home slots.
|
||||
mut picking : Bool
|
||||
mut sheet : Sheet
|
||||
/// The package being uninstalled: its home slot goes when it leaves the app list.
|
||||
mut gone : String
|
||||
/// Home slot picked up by a long press, being dragged.
|
||||
mut lifted : Int
|
||||
/// Widget slot showing resize handles.
|
||||
mut resizing : Int
|
||||
/// The lifted slot was grabbed while showing handles: drop it back into them.
|
||||
mut regrab : Bool
|
||||
mut carry : Carry?
|
||||
mut resize : ResizeDrag?
|
||||
/// Native widget views report their drags through `NativeDrag`; where it began.
|
||||
mut native_from : (Double, Double)?
|
||||
/// Widget row being added.
|
||||
mut chosen : Int
|
||||
mut limits : Map[Int, Limits]
|
||||
mut notice : String
|
||||
mut notice_gen : Int
|
||||
// ---- self-update
|
||||
mut installed : Int
|
||||
mut declined : Int
|
||||
mut checking : Bool
|
||||
mut manual_check : Bool
|
||||
mut apk_url : String?
|
||||
mut release_tag : String
|
||||
/// The layout JSON last handed to `SaveHome`.
|
||||
mut saved : String
|
||||
/// A pointer drag (lift or resize) happened since the pointer went down: the swipe
|
||||
/// check that follows the touch ignores it.
|
||||
mut dragged : Bool
|
||||
/// A widget just added whose limits will set its starting width.
|
||||
mut fresh : Int
|
||||
mut gesture : @gesture.State
|
||||
}
|
||||
|
||||
///|
|
||||
pub fn Model::new() -> Model {
|
||||
{
|
||||
apps: [],
|
||||
loading: true,
|
||||
load_error: "",
|
||||
widgets: [],
|
||||
wloading: false,
|
||||
home: [],
|
||||
next_key: 1,
|
||||
cols: 5,
|
||||
nrows: 0,
|
||||
grid_left: 0.0,
|
||||
grid_top: 0.0,
|
||||
col_w: 0.0,
|
||||
query: "",
|
||||
wquery: "",
|
||||
drawer: false,
|
||||
picking: false,
|
||||
sheet: NoSheet,
|
||||
gone: "",
|
||||
lifted: -1,
|
||||
resizing: -1,
|
||||
regrab: false,
|
||||
carry: None,
|
||||
resize: None,
|
||||
native_from: None,
|
||||
chosen: -1,
|
||||
limits: {},
|
||||
notice: "",
|
||||
notice_gen: 0,
|
||||
installed: 0,
|
||||
declined: -1,
|
||||
checking: false,
|
||||
manual_check: false,
|
||||
apk_url: None,
|
||||
release_tag: "",
|
||||
saved: "",
|
||||
dragged: false,
|
||||
fresh: -1,
|
||||
gesture: @gesture.State::new(),
|
||||
}
|
||||
}
|
||||
|
||||
///|
|
||||
/// The most slots the home screen holds.
|
||||
pub let home_cap : Int = 200
|
||||
|
||||
///|
|
||||
pub let app_cap : Int = 512
|
||||
|
||||
///|
|
||||
#derive(Eq, Debug)
|
||||
/// What a view node can send. Raw pointer input goes through `Input` and the gesture
|
||||
/// recogniser first; everything else is a Msg a handler or the shell sends directly.
|
||||
pub(all) enum Msg {
|
||||
// ---- from the platform
|
||||
/// Boot: the saved layout (this app's JSON, and the old WebView build's
|
||||
/// `ultra.home.*` localStorage as a JSON object), the clock, and the self-update state.
|
||||
Restore(saved~ : String?, legacy~ : String?)
|
||||
Started(now~ : Int64, last_check~ : Int64, declined~ : Int, installed~ : Int)
|
||||
/// The page measured itself: viewport size, and where the home grid is.
|
||||
Measured(vw~ : Int, vh~ : Int, grid_left~ : Double, grid_top~ : Double, grid_w~ : Double, bottom_pad~ : Double)
|
||||
AppsLoaded(String?)
|
||||
WidgetsLoaded(String?)
|
||||
/// The shell's answer to `QueryLimits`.
|
||||
LimitsKnown(Int, String?)
|
||||
/// A package changed: look at the app list again.
|
||||
Reload
|
||||
/// The Home button or intent.
|
||||
GoHome
|
||||
Back
|
||||
WidgetAdded(Int)
|
||||
/// A long press on a native widget view lifts its slot.
|
||||
WidgetMenu(Int)
|
||||
/// A press on the native view of the widget showing handles picks it up.
|
||||
WidgetGrab(Int)
|
||||
NativeDrag(Double, Double)
|
||||
NativeDrop(Bool)
|
||||
/// The swipe the page saw: dx, dy, ms, whether the home is scrolled to the top, and
|
||||
/// whether the drawer's list is at its end.
|
||||
Touch(dx~ : Double, dy~ : Double, ms~ : Int, home_top~ : Bool, list_end~ : Bool)
|
||||
ReleaseFetched(String?)
|
||||
VersionFetched(String?)
|
||||
UpdateDeclined(Int)
|
||||
NoticeDone(Int)
|
||||
// ---- from handlers
|
||||
Query(String)
|
||||
Clear
|
||||
WQuery(String)
|
||||
WClear
|
||||
OpenDrawer
|
||||
CloseDrawer
|
||||
OpenApp(Int)
|
||||
OpenFirst
|
||||
OpenHome(Int)
|
||||
AddHome(Int)
|
||||
ToggleHome(Int)
|
||||
AppMenu(Int)
|
||||
AppInfoOf(Int)
|
||||
UninstallOf(Int)
|
||||
Menu
|
||||
CloseSheet
|
||||
PickApps
|
||||
PickWidget
|
||||
ChooseWidget(Int)
|
||||
ChooseFirstWidget
|
||||
Remove(Int)
|
||||
/// Swap the slot with the one before it.
|
||||
MoveEarlier(Int)
|
||||
InfoOf(Int)
|
||||
Settings
|
||||
Wallpaper
|
||||
Recents
|
||||
CheckUpdates
|
||||
Lift(Int)
|
||||
Grab(Int)
|
||||
ResizeBegin(Edge)
|
||||
ResizeDone
|
||||
/// Does nothing; stands in a chain to stop a tap reaching an element below.
|
||||
Nop
|
||||
/// The recogniser saw a drag / the pointer lift (see `input`).
|
||||
Dragged(x~ : Double, y~ : Double, x0~ : Double, y0~ : Double)
|
||||
Released(moved~ : Bool, held~ : Bool)
|
||||
}
|
||||
|
||||
///|
|
||||
#derive(Eq, Debug)
|
||||
pub(all) enum Effect {
|
||||
Launch(String)
|
||||
AppInfo(String)
|
||||
Uninstall(String)
|
||||
AddWidget(String)
|
||||
RemoveWidget(Int)
|
||||
OpenSettings
|
||||
PickWallpaper
|
||||
OpenRecents
|
||||
Haptic
|
||||
/// Fetch apps.json / widgets.json and answer `AppsLoaded` / `WidgetsLoaded`.
|
||||
LoadApps
|
||||
LoadWidgets
|
||||
/// Ask the shell for a widget's limits and answer `LimitsKnown`.
|
||||
QueryLimits(Int)
|
||||
SaveHome(String)
|
||||
SaveLastCheck(Int64)
|
||||
SaveDeclined(Int)
|
||||
/// Send the message after this many ms.
|
||||
Delay(Int, Msg)
|
||||
/// After this many ms, feed `Hold(token)` to `input` (the long-press timer).
|
||||
HoldTimer(Int, Int)
|
||||
FetchRelease(String)
|
||||
FetchVersion(String)
|
||||
InstallApk(String, Int)
|
||||
/// The drawer opened with its search in front: focus it and raise the keyboard.
|
||||
FocusSearch
|
||||
HideKeyboard
|
||||
ScrollTop
|
||||
}
|
||||
Reference in new issue
Block a user