1 parent
dccbfd7d86
commit
17f81c60c8
20 files changed
+636
-447
No files matched your search
+29
-18
@@ -43,7 +43,12 @@ extern "js" fn dom_class(d : Dom, v : String) -> Unit =
|
||||
///|
|
||||
/// Put `d` into `parent` right before `before` (or last when `before` is not a node),
|
||||
/// unless it is already there.
|
||||
extern "js" fn dom_place(parent : Dom, d : Dom, before : Dom, has_before : Bool) -> Unit =
|
||||
extern "js" fn dom_place(
|
||||
parent : Dom,
|
||||
d : Dom,
|
||||
before : Dom,
|
||||
has_before : Bool,
|
||||
) -> Unit =
|
||||
#|(p, d, b, has) => { const next = has ? b : null; if (d.parentNode !== p || d.nextSibling !== next) p.insertBefore(d, next); }
|
||||
|
||||
///|
|
||||
@@ -102,7 +107,7 @@ extern "js" fn ev_touch_y(e : Ev) -> Double =
|
||||
#|(e) => (e.changedTouches && e.changedTouches[0] ? e.changedTouches[0].clientY : 0)
|
||||
|
||||
///|
|
||||
extern "js" fn ev_touches(e : Ev) -> Int =
|
||||
extern "js" fn ev_touches(e : Ev) -> Int32 =
|
||||
#|(e) => (e.touches ? e.touches.length : 0)
|
||||
|
||||
///|
|
||||
@@ -111,7 +116,7 @@ extern "js" fn ev_chain(e : Ev) -> String =
|
||||
#|(e) => { const out = []; for (let n = e.target; n && n.getAttribute; n = n.parentNode) { const v = n.getAttribute("data-n"); if (v !== null) out.push(v); } return out.join(","); }
|
||||
|
||||
///|
|
||||
extern "js" fn set_timeout(ms : Int, f : () -> Unit) -> Unit =
|
||||
extern "js" fn set_timeout(ms : Int32, f : () -> Unit) -> Unit =
|
||||
#|(ms, f) => { setTimeout(f, ms) }
|
||||
|
||||
///|
|
||||
@@ -154,7 +159,7 @@ extern "js" fn measure() -> Bool =
|
||||
|
||||
///|
|
||||
/// Measurement i: viewport width, height, grid left, top, width, the home's bottom padding.
|
||||
extern "js" fn measured(i : Int) -> Double =
|
||||
extern "js" fn measured(i : Int32) -> Double =
|
||||
#|(i) => window.__m[i]
|
||||
|
||||
///|
|
||||
@@ -211,20 +216,20 @@ extern "js" fn toast(s : String) -> Unit =
|
||||
|
||||
///|
|
||||
/// Snapshot the page's icon images; returns how many.
|
||||
extern "js" fn icons_scan() -> Int =
|
||||
extern "js" fn icons_scan() -> Int32 =
|
||||
#|() => { window.__imgs = [...document.querySelectorAll("img.icon[data-icon]")]; return window.__imgs.length; }
|
||||
|
||||
///|
|
||||
extern "js" fn icon_key(i : Int) -> String =
|
||||
extern "js" fn icon_key(i : Int32) -> String =
|
||||
#|(i) => window.__imgs[i].dataset.icon
|
||||
|
||||
///|
|
||||
/// Whether image i already shows the icon for its key.
|
||||
extern "js" fn icon_done(i : Int) -> Bool =
|
||||
extern "js" fn icon_done(i : Int32) -> Bool =
|
||||
#|(i) => window.__imgs[i].__icon === window.__imgs[i].dataset.icon
|
||||
|
||||
///|
|
||||
extern "js" fn icon_set(i : Int, src : String) -> Unit =
|
||||
extern "js" fn icon_set(i : Int32, src : String) -> Unit =
|
||||
#|(i, src) => { const img = window.__imgs[i]; img.__icon = img.dataset.icon; if (src) { img.src = src; img.classList.remove("missing"); } else img.classList.add("missing"); }
|
||||
|
||||
///|
|
||||
@@ -255,7 +260,7 @@ extern "js" fn h_add_widget(p : String) -> Unit =
|
||||
#|(p) => window.Android.addWidget(p)
|
||||
|
||||
///|
|
||||
extern "js" fn h_remove_widget(id : Int) -> Unit =
|
||||
extern "js" fn h_remove_widget(id : Int32) -> Unit =
|
||||
#|(id) => window.Android.removeWidget(id)
|
||||
|
||||
///|
|
||||
@@ -263,7 +268,7 @@ extern "js" fn h_place_widgets(json : String) -> Unit =
|
||||
#|(j) => window.Android.placeWidgets(j)
|
||||
|
||||
///|
|
||||
extern "js" fn h_cover_widgets(y : Int) -> Unit =
|
||||
extern "js" fn h_cover_widgets(y : Int32) -> Unit =
|
||||
#|(y) => window.Android.coverWidgets(y)
|
||||
|
||||
///|
|
||||
@@ -271,7 +276,7 @@ extern "js" fn h_exclude_gestures(json : String) -> Unit =
|
||||
#|(j) => window.Android.excludeGestures && window.Android.excludeGestures(j)
|
||||
|
||||
///|
|
||||
extern "js" fn h_widget_limits(id : Int) -> String =
|
||||
extern "js" fn h_widget_limits(id : Int32) -> String =
|
||||
#|(id) => window.Android.widgetLimits(id)
|
||||
|
||||
///|
|
||||
@@ -307,19 +312,19 @@ extern "js" fn h_open_recents() -> Unit =
|
||||
#|() => window.Android.openRecents()
|
||||
|
||||
///|
|
||||
extern "js" fn h_http_get(url : String, tag : Int) -> Unit =
|
||||
extern "js" fn h_http_get(url : String, tag : Int32) -> Unit =
|
||||
#|(url, tag) => window.Android.httpGet(url, tag)
|
||||
|
||||
///|
|
||||
extern "js" fn h_install_apk(url : String, version : Int) -> Unit =
|
||||
extern "js" fn h_install_apk(url : String, version : Int32) -> Unit =
|
||||
#|(url, v) => window.Android.installApk(url, v)
|
||||
|
||||
///|
|
||||
extern "js" fn h_declined_version() -> Int =
|
||||
extern "js" fn h_declined_version() -> Int32 =
|
||||
#|() => window.Android.declinedVersion()
|
||||
|
||||
///|
|
||||
extern "js" fn h_installed_version() -> Int =
|
||||
extern "js" fn h_installed_version() -> Int32 =
|
||||
#|() => window.Android.installedVersion()
|
||||
|
||||
// ---- what the shell calls on the page -----------------------------------------------
|
||||
@@ -333,7 +338,7 @@ extern "js" fn expose0(name : String, f : () -> Unit) -> Unit =
|
||||
#|(n, f) => { window.launcher[n] = f }
|
||||
|
||||
///|
|
||||
extern "js" fn expose1(name : String, f : (Int) -> Unit) -> Unit =
|
||||
extern "js" fn expose1(name : String, f : (Int32) -> Unit) -> Unit =
|
||||
#|(n, f) => { window.launcher[n] = f }
|
||||
|
||||
///|
|
||||
@@ -346,7 +351,10 @@ extern "js" fn expose_dd(name : String, f : (Double, Double) -> Unit) -> Unit =
|
||||
|
||||
///|
|
||||
/// `f(tag, ok, text)`: a finished `httpGet`.
|
||||
extern "js" fn expose_result(name : String, f : (Int, Bool, String) -> Unit) -> Unit =
|
||||
extern "js" fn expose_result(
|
||||
name : String,
|
||||
f : (Int32, Bool, String) -> Unit,
|
||||
) -> Unit =
|
||||
#|(n, f) => { window.launcher[n] = f }
|
||||
|
||||
///|
|
||||
@@ -356,7 +364,10 @@ extern "js" fn expose_json(name : String, f : (String) -> Unit) -> Unit =
|
||||
|
||||
///|
|
||||
/// Run `f` for each `key\nsrc` pair of a JSON object (flattened, so no arrays cross).
|
||||
extern "js" fn json_entries(json : String, f : (String, String) -> Unit) -> Unit =
|
||||
extern "js" fn json_entries(
|
||||
json : String,
|
||||
f : (String, String) -> Unit,
|
||||
) -> Unit =
|
||||
#|(j, f) => { const o = JSON.parse(j); for (const k in o) f(k, o[k] ?? "") }
|
||||
|
||||
///|
|
||||
|
||||
+57
-22
@@ -19,17 +19,17 @@ priv struct PageState {
|
||||
mut focus_pending : Bool
|
||||
mut placed : String
|
||||
mut excluded : String
|
||||
mut cover_y : Int
|
||||
mut cover_y : Int32
|
||||
mut cover_last : Double
|
||||
mut cover_loop : Bool
|
||||
mut measured : String
|
||||
mut touch : (Double, Double, Double)?
|
||||
mut demo_widget : Int
|
||||
mut http_tag : Int
|
||||
http : Map[Int, (Bool, String) -> Unit]
|
||||
mut demo_widget : Int32
|
||||
mut http_tag : Int32
|
||||
http : Map[Int32, (Bool, String) -> Unit]
|
||||
icon_src : Map[String, String]
|
||||
icon_asked : Map[String, Bool]
|
||||
icon_tries : Map[String, Int]
|
||||
icon_tries : Map[String, Int32]
|
||||
}
|
||||
|
||||
///|
|
||||
@@ -100,8 +100,18 @@ fn exec(e : @app.Effect) -> Unit {
|
||||
let android = is_android()
|
||||
match e {
|
||||
Launch(c) => if android { h_launch(c) } else { toast("Open " + c) }
|
||||
AppInfo(c) => if android { h_app_info(c) } else { toast("App info for " + c) }
|
||||
Uninstall(c) => if android { h_uninstall(c) } else { toast("Uninstall " + c) }
|
||||
AppInfo(c) =>
|
||||
if android {
|
||||
h_app_info(c)
|
||||
} else {
|
||||
toast("App info for " + c)
|
||||
}
|
||||
Uninstall(c) =>
|
||||
if android {
|
||||
h_uninstall(c)
|
||||
} else {
|
||||
toast("Uninstall " + c)
|
||||
}
|
||||
AddWidget(p) =>
|
||||
if android {
|
||||
h_add_widget(p)
|
||||
@@ -111,9 +121,24 @@ fn exec(e : @app.Effect) -> Unit {
|
||||
set_timeout(0, fn() { dispatch(WidgetAdded(id)) })
|
||||
}
|
||||
RemoveWidget(id) => if android { h_remove_widget(id) }
|
||||
OpenSettings => if android { h_open_settings() } else { toast("Open system settings") }
|
||||
PickWallpaper => if android { h_pick_wallpaper() } else { toast("Pick a wallpaper") }
|
||||
OpenRecents => if android { h_open_recents() } else { toast("Show open windows") }
|
||||
OpenSettings =>
|
||||
if android {
|
||||
h_open_settings()
|
||||
} else {
|
||||
toast("Open system settings")
|
||||
}
|
||||
PickWallpaper =>
|
||||
if android {
|
||||
h_pick_wallpaper()
|
||||
} else {
|
||||
toast("Pick a wallpaper")
|
||||
}
|
||||
OpenRecents =>
|
||||
if android {
|
||||
h_open_recents()
|
||||
} else {
|
||||
toast("Show open windows")
|
||||
}
|
||||
Haptic => h_haptic()
|
||||
LoadApps =>
|
||||
fetch_text("apps.json", fn(ok, text) {
|
||||
@@ -149,7 +174,11 @@ fn exec(e : @app.Effect) -> Unit {
|
||||
dispatch(VersionFetched(if ok { Some(text) } else { None }))
|
||||
})
|
||||
InstallApk(url, n) =>
|
||||
if android { h_install_apk(url, n) } else { toast("Install update \{n}") }
|
||||
if android {
|
||||
h_install_apk(url, n)
|
||||
} else {
|
||||
toast("Install update \{n}")
|
||||
}
|
||||
FocusSearch => state.val.focus_pending = true
|
||||
HideKeyboard => {
|
||||
blur_active()
|
||||
@@ -309,17 +338,13 @@ fn got_icons(json : String) -> Unit {
|
||||
// ---- input -------------------------------------------------------------------------
|
||||
|
||||
///|
|
||||
fn parse_chain(s : String) -> Array[Int] {
|
||||
fn parse_chain(s : String) -> Array[Int32] {
|
||||
if s == "" {
|
||||
return []
|
||||
}
|
||||
let out : Array[Int] = []
|
||||
let out : Array[Int32] = []
|
||||
for part in s.split(",") {
|
||||
out.push(
|
||||
try @string.parse_int(part) catch {
|
||||
_ => -1
|
||||
},
|
||||
)
|
||||
out.push(@string.parse_int(part) catch { _ => -1 })
|
||||
}
|
||||
out
|
||||
}
|
||||
@@ -342,10 +367,16 @@ fn wire_events() -> Unit {
|
||||
listen("document", "pointerup", true, fn(e) { feed(Up(x=ev_x(e), y=ev_y(e))) })
|
||||
listen("document", "pointercancel", true, fn(_) { feed(Cancel) })
|
||||
// keep the page from scrolling under a lifted slot or a handle being dragged
|
||||
listen("document", "touchmove", false, fn(e) { if is_dragging() { ev_prevent(e) } })
|
||||
listen("document", "touchmove", false, fn(e) {
|
||||
if is_dragging() {
|
||||
ev_prevent(e)
|
||||
}
|
||||
})
|
||||
listen("document", "contextmenu", false, fn(e) { ev_prevent(e) })
|
||||
listen("document", "input", true, fn(e) {
|
||||
run(@app.typed(model, state.val.table, parse_chain(ev_chain(e)), ev_value(e)))
|
||||
run(
|
||||
@app.typed(model, state.val.table, parse_chain(ev_chain(e)), ev_value(e)),
|
||||
)
|
||||
})
|
||||
listen("document", "keydown", true, fn(e) {
|
||||
if ev_composing(e) {
|
||||
@@ -428,7 +459,7 @@ fn num(key : String) -> Int64 {
|
||||
if s == "" {
|
||||
0L
|
||||
} else {
|
||||
try @string.parse_int64(s) catch {
|
||||
@string.parse_int64(s) catch {
|
||||
_ => 0L
|
||||
}
|
||||
}
|
||||
@@ -441,7 +472,11 @@ fn main {
|
||||
}
|
||||
expose_api()
|
||||
wire_events()
|
||||
let saved = if storage_has("launcher.home") { Some(storage_get("launcher.home")) } else { None }
|
||||
let saved = if storage_has("launcher.home") {
|
||||
Some(storage_get("launcher.home"))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
let legacy = if saved is None { Some(storage_legacy()) } else { None }
|
||||
dispatch(Restore(saved~, legacy~))
|
||||
if is_android() {
|
||||
|
||||
+1
-3
@@ -6,8 +6,6 @@ import {
|
||||
"moonbitlang/core/string",
|
||||
}
|
||||
|
||||
options(
|
||||
is_main: true,
|
||||
)
|
||||
pkgtype(kind: "executable")
|
||||
|
||||
supported_targets = "js"
|
||||
+9
-5
@@ -9,9 +9,9 @@ priv struct RNode {
|
||||
dom : Dom
|
||||
is_text : Bool
|
||||
tag : String
|
||||
key : Int
|
||||
key : Int32
|
||||
mut text : String
|
||||
mut n : Int
|
||||
mut n : Int32
|
||||
mut classes : String
|
||||
mut attrs : Map[String, String]
|
||||
mut props : Map[String, String]
|
||||
@@ -54,7 +54,11 @@ fn new_rnode(n : @vdom.Node[@app.Msg]) -> RNode {
|
||||
}
|
||||
|
||||
///|
|
||||
fn update_rnode(r : RNode, n : @vdom.Node[@app.Msg], counter : Ref[Int]) -> Unit {
|
||||
fn update_rnode(
|
||||
r : RNode,
|
||||
n : @vdom.Node[@app.Msg],
|
||||
counter : Ref[Int32],
|
||||
) -> Unit {
|
||||
match n {
|
||||
Text(s) =>
|
||||
if s != r.text {
|
||||
@@ -127,10 +131,10 @@ fn patch_children(
|
||||
parent : Dom,
|
||||
old : Array[RNode],
|
||||
new : Array[@vdom.Node[@app.Msg]],
|
||||
counter : Ref[Int],
|
||||
counter : Ref[Int32],
|
||||
) -> Array[RNode] {
|
||||
let used : Array[Bool] = Array::make(old.length(), false)
|
||||
let by_key : Map[Int, Int] = {}
|
||||
let by_key : Map[Int32, Int32] = {}
|
||||
for i in 0..<old.length() {
|
||||
if old[i].key != 0 {
|
||||
by_key[old[i].key] = i
|
||||
|
||||
Reference in new issue
Block a user