@glassly/miniapp-cli 0.1.12-dev.0 → 0.1.13-dev.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/sim/client/app.css +8 -5
- package/src/sim/client/index.html +10 -5
- package/src/sim/client/main.ts +25 -6
- package/src/sim/host.test.ts +11 -0
- package/src/sim/host.ts +8 -0
- package/src/sim/phone.test.ts +27 -0
- package/src/sim/phone.ts +51 -0
- package/src/sim/server.ts +76 -25
- package/src/sim/sim.ts +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@glassly/miniapp-cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.13-dev.0",
|
|
4
4
|
"description": "Build tooling for Glassly miniapps: dev server, packer, manifest validation, and JSON Schema. The `glassly` command that drives it ships in @glassly/cli.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"publishConfig": {
|
package/src/sim/client/app.css
CHANGED
|
@@ -540,10 +540,13 @@ output {
|
|
|
540
540
|
|
|
541
541
|
.phone-body {
|
|
542
542
|
--scale: 0.7;
|
|
543
|
+
--phone-width: 393px;
|
|
544
|
+
--phone-height: 852px;
|
|
545
|
+
--phone-radius: 44px;
|
|
543
546
|
position: relative;
|
|
544
|
-
width: calc(
|
|
545
|
-
height: calc(
|
|
546
|
-
border-radius: calc(
|
|
547
|
+
width: calc(var(--phone-width) * var(--scale));
|
|
548
|
+
height: calc(var(--phone-height) * var(--scale));
|
|
549
|
+
border-radius: calc(var(--phone-radius) * var(--scale));
|
|
547
550
|
box-shadow: 0 0 0 calc(7px * var(--scale)) var(--bezel);
|
|
548
551
|
background: #000;
|
|
549
552
|
overflow: hidden;
|
|
@@ -551,8 +554,8 @@ output {
|
|
|
551
554
|
|
|
552
555
|
.phone-body iframe {
|
|
553
556
|
display: block;
|
|
554
|
-
width:
|
|
555
|
-
height:
|
|
557
|
+
width: var(--phone-width);
|
|
558
|
+
height: var(--phone-height);
|
|
556
559
|
border: 0;
|
|
557
560
|
transform: scale(var(--scale));
|
|
558
561
|
transform-origin: 0 0;
|
|
@@ -54,9 +54,9 @@
|
|
|
54
54
|
<section>
|
|
55
55
|
<h2>Touch bar</h2>
|
|
56
56
|
<div class="keys">
|
|
57
|
-
<button type="button" class="key" data-touch="single_tap">Tap <kbd>T</kbd></button>
|
|
57
|
+
<button type="button" class="key" data-touch="single_tap" data-index="0">Tap (A) <kbd>T</kbd></button>
|
|
58
|
+
<button type="button" class="key" data-touch="single_tap" data-index="1">Tap (B) <kbd>Y</kbd></button>
|
|
58
59
|
<button type="button" class="key" data-touch="double_tap">Double tap <kbd>D</kbd></button>
|
|
59
|
-
<button type="button" class="key" data-touch="triple_tap">Triple tap</button>
|
|
60
60
|
<button type="button" class="key" data-touch="long_press">Hold <kbd>H</kbd></button>
|
|
61
61
|
<button type="button" class="key" data-touch="swipe_up">Swipe up <kbd>↑</kbd></button>
|
|
62
62
|
<button type="button" class="key" data-touch="swipe_down">Swipe down <kbd>↓</kbd></button>
|
|
@@ -64,12 +64,10 @@
|
|
|
64
64
|
</section>
|
|
65
65
|
|
|
66
66
|
<section>
|
|
67
|
-
<h2>Head
|
|
67
|
+
<h2>Head gestures</h2>
|
|
68
68
|
<div class="keys">
|
|
69
69
|
<button type="button" class="key" data-touch="head_up">Look up <kbd>U</kbd></button>
|
|
70
70
|
<button type="button" class="key" data-touch="head_down">Look down <kbd>J</kbd></button>
|
|
71
|
-
<button type="button" class="key" data-button="short">Button <kbd>B</kbd></button>
|
|
72
|
-
<button type="button" class="key" data-button="long">Long press</button>
|
|
73
71
|
</div>
|
|
74
72
|
</section>
|
|
75
73
|
|
|
@@ -144,6 +142,13 @@
|
|
|
144
142
|
<button type="button" data-scheme="dark" aria-pressed="true">Dark</button>
|
|
145
143
|
</div>
|
|
146
144
|
</div>
|
|
145
|
+
<div class="row">
|
|
146
|
+
<span class="label">Phone</span>
|
|
147
|
+
<div class="seg" role="group" aria-label="Phone">
|
|
148
|
+
<button type="button" data-phone="iphone" aria-pressed="true">iPhone</button>
|
|
149
|
+
<button type="button" data-phone="duo" aria-pressed="false">iPhone Duo</button>
|
|
150
|
+
</div>
|
|
151
|
+
</div>
|
|
147
152
|
<label class="row">
|
|
148
153
|
<span class="label">Read speech aloud<small>Speaks what the miniapp says</small></span>
|
|
149
154
|
<input id="aloud" type="checkbox" class="switch" />
|
package/src/sim/client/main.ts
CHANGED
|
@@ -24,6 +24,7 @@ interface Status {
|
|
|
24
24
|
speaker: string
|
|
25
25
|
sensors: {glassesBattery: {level: number}; location: {lat: number; lng: number}; glassesConnected: boolean}
|
|
26
26
|
colorScheme: string
|
|
27
|
+
phone: "iphone" | "duo"
|
|
27
28
|
unsimulated: string[]
|
|
28
29
|
}
|
|
29
30
|
|
|
@@ -119,6 +120,10 @@ function showStatus(status: Status): void {
|
|
|
119
120
|
document.querySelectorAll<HTMLButtonElement>("[data-scheme]").forEach((button) => {
|
|
120
121
|
button.setAttribute("aria-pressed", String(button.dataset.scheme === status.colorScheme))
|
|
121
122
|
})
|
|
123
|
+
document.querySelectorAll<HTMLButtonElement>("[data-phone]").forEach((button) => {
|
|
124
|
+
button.setAttribute("aria-pressed", String(button.dataset.phone === status.phone))
|
|
125
|
+
})
|
|
126
|
+
showPhone(status.phone)
|
|
122
127
|
|
|
123
128
|
const rows: [string, string, boolean?][] = [
|
|
124
129
|
["subscriptions", status.subscriptions.join(", ") || "none"],
|
|
@@ -178,21 +183,19 @@ function flash(button: Element | null): void {
|
|
|
178
183
|
}
|
|
179
184
|
|
|
180
185
|
document.querySelectorAll<HTMLButtonElement>("[data-touch]").forEach((button) => {
|
|
181
|
-
button.
|
|
182
|
-
})
|
|
183
|
-
document.querySelectorAll<HTMLButtonElement>("[data-button]").forEach((button) => {
|
|
184
|
-
button.addEventListener("click", () => void post("button", {pressType: button.dataset.button}))
|
|
186
|
+
const index = button.dataset.index === undefined ? {} : {index: Number(button.dataset.index)}
|
|
187
|
+
button.addEventListener("click", () => void post("touch", {gesture: button.dataset.touch, ...index}))
|
|
185
188
|
})
|
|
186
189
|
|
|
187
190
|
const KEYS: Record<string, string> = {
|
|
188
|
-
t: '[data-touch="single_tap"]',
|
|
191
|
+
t: '[data-touch="single_tap"][data-index="0"]',
|
|
192
|
+
y: '[data-touch="single_tap"][data-index="1"]',
|
|
189
193
|
d: '[data-touch="double_tap"]',
|
|
190
194
|
h: '[data-touch="long_press"]',
|
|
191
195
|
ArrowUp: '[data-touch="swipe_up"]',
|
|
192
196
|
ArrowDown: '[data-touch="swipe_down"]',
|
|
193
197
|
u: '[data-touch="head_up"]',
|
|
194
198
|
j: '[data-touch="head_down"]',
|
|
195
|
-
b: '[data-button="short"]',
|
|
196
199
|
}
|
|
197
200
|
window.addEventListener("keydown", (event) => {
|
|
198
201
|
const target = event.target as HTMLElement | null
|
|
@@ -239,6 +242,9 @@ $("connected").addEventListener("change", (event) => {
|
|
|
239
242
|
document.querySelectorAll<HTMLButtonElement>("[data-scheme]").forEach((button) => {
|
|
240
243
|
button.addEventListener("click", () => void post("color-scheme", {colorScheme: button.dataset.scheme}))
|
|
241
244
|
})
|
|
245
|
+
document.querySelectorAll<HTMLButtonElement>("[data-phone]").forEach((button) => {
|
|
246
|
+
button.addEventListener("click", () => void post("phone", {phone: button.dataset.phone}))
|
|
247
|
+
})
|
|
242
248
|
$("restart").addEventListener("click", () => void post("restart"))
|
|
243
249
|
$("clear-log").addEventListener("click", () => logPane.replaceChildren())
|
|
244
250
|
|
|
@@ -249,8 +255,21 @@ document.querySelectorAll<HTMLButtonElement>('[role="tab"]').forEach((tab) => {
|
|
|
249
255
|
})
|
|
250
256
|
})
|
|
251
257
|
|
|
258
|
+
const PHONE_SIZES = {iphone: {width: 393, height: 852, radius: 44}, duo: {width: 466, height: 678, radius: 40}}
|
|
259
|
+
let phoneSize = PHONE_SIZES.iphone
|
|
260
|
+
|
|
261
|
+
function showPhone(phone: keyof typeof PHONE_SIZES): void {
|
|
262
|
+
const size = PHONE_SIZES[phone] ?? PHONE_SIZES.iphone
|
|
263
|
+
if (size === phoneSize) return
|
|
264
|
+
phoneSize = size
|
|
265
|
+
fitPhone()
|
|
266
|
+
}
|
|
267
|
+
|
|
252
268
|
function fitPhone(): void {
|
|
253
269
|
const body = $("phone-body")
|
|
270
|
+
body.style.setProperty("--phone-width", `${phoneSize.width}px`)
|
|
271
|
+
body.style.setProperty("--phone-height", `${phoneSize.height}px`)
|
|
272
|
+
body.style.setProperty("--phone-radius", `${phoneSize.radius}px`)
|
|
254
273
|
const wide = window.matchMedia("(min-width: 1200px)").matches
|
|
255
274
|
const room = wide ? body.parentElement!.clientHeight - 40 : window.innerHeight - 96
|
|
256
275
|
body.style.setProperty("--scale", String(Math.max(0.5, Math.min(1, room / 852))))
|
package/src/sim/host.test.ts
CHANGED
|
@@ -112,6 +112,17 @@ describe("input", () => {
|
|
|
112
112
|
expect(head).toEqual(["up"])
|
|
113
113
|
})
|
|
114
114
|
|
|
115
|
+
test("tap A and tap B carry the finger index", async () => {
|
|
116
|
+
const {session, host} = await connect()
|
|
117
|
+
const indexes: (number | undefined)[] = []
|
|
118
|
+
session.input.onTouch("single_tap", (touch) => indexes.push(touch.index))
|
|
119
|
+
await settle()
|
|
120
|
+
host.touch("single_tap", {index: 0})
|
|
121
|
+
host.touch("single_tap", {index: 1})
|
|
122
|
+
await settle()
|
|
123
|
+
expect(indexes).toEqual([0, 1])
|
|
124
|
+
})
|
|
125
|
+
|
|
115
126
|
test("button presses carry their press type", async () => {
|
|
116
127
|
const {session, host} = await connect()
|
|
117
128
|
const presses: string[] = []
|
package/src/sim/host.ts
CHANGED
|
@@ -16,6 +16,7 @@ import {
|
|
|
16
16
|
} from "@glassly/miniapp/protocol"
|
|
17
17
|
|
|
18
18
|
import type {SimDevice} from "./device.js"
|
|
19
|
+
import type {PhoneKind} from "./phone.js"
|
|
19
20
|
import type {SimStorage} from "./storage.js"
|
|
20
21
|
|
|
21
22
|
export type SimLogSource = "background" | "ui" | "host" | "bridge"
|
|
@@ -179,6 +180,7 @@ export class SimHost {
|
|
|
179
180
|
private location: SimLocation = {lat: 37.7749, lng: -122.4194, accuracy: 5, timestamp: Date.now()}
|
|
180
181
|
private visibility: "foreground" | "background" = "foreground"
|
|
181
182
|
private colorScheme: "light" | "dark" = "dark"
|
|
183
|
+
private phone: PhoneKind = "iphone"
|
|
182
184
|
private notificationSeq = 0
|
|
183
185
|
|
|
184
186
|
constructor(options: SimHostOptions) {
|
|
@@ -835,6 +837,11 @@ export class SimHost {
|
|
|
835
837
|
this.emit({type: "status"})
|
|
836
838
|
}
|
|
837
839
|
|
|
840
|
+
setPhone(phone: PhoneKind): void {
|
|
841
|
+
this.phone = phone
|
|
842
|
+
this.emit({type: "status"})
|
|
843
|
+
}
|
|
844
|
+
|
|
838
845
|
event(stream: string, data: unknown): void {
|
|
839
846
|
this.inject([stream], data)
|
|
840
847
|
}
|
|
@@ -945,6 +952,7 @@ export class SimHost {
|
|
|
945
952
|
},
|
|
946
953
|
visibility: this.visibility,
|
|
947
954
|
colorScheme: this.colorScheme,
|
|
955
|
+
phone: this.phone,
|
|
948
956
|
unsimulated: [...this.unsimulated],
|
|
949
957
|
logSeq: this.logSeq,
|
|
950
958
|
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import {describe, expect, test} from "bun:test"
|
|
2
|
+
|
|
3
|
+
import {parsePhone, phoneLayout} from "./phone"
|
|
4
|
+
|
|
5
|
+
describe("phoneLayout", () => {
|
|
6
|
+
test("iPhone keeps the corner capsule under the status bar", () => {
|
|
7
|
+
const layout = phoneLayout("iphone")
|
|
8
|
+
expect(layout.insets).toEqual({top: 59, bottom: 34, left: 0, right: 0})
|
|
9
|
+
expect(layout.capsuleMenu).toEqual({top: 67, right: 16, bottom: 99, left: 297, width: 80, height: 32, placement: "corner"})
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
test("folded Duo puts the capsule in the right rail, centered 48 pt from the edge", () => {
|
|
13
|
+
const layout = phoneLayout("duo")
|
|
14
|
+
expect([layout.width, layout.height]).toEqual([466, 678])
|
|
15
|
+
expect(layout.insets).toEqual({top: 0, bottom: 34, left: 0, right: 84})
|
|
16
|
+
const capsule = layout.capsuleMenu
|
|
17
|
+
expect(capsule.placement).toBe("rail")
|
|
18
|
+
expect(capsule.left).toBeGreaterThanOrEqual(layout.width - layout.insets.right)
|
|
19
|
+
expect(layout.width - (capsule.left + capsule.width / 2)).toBe(48)
|
|
20
|
+
expect([capsule.top, capsule.bottom]).toEqual([174, 262])
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
test("parsePhone falls back to iphone", () => {
|
|
24
|
+
expect(parsePhone("duo")).toBe("duo")
|
|
25
|
+
expect(parsePhone("pixel")).toBe("iphone")
|
|
26
|
+
})
|
|
27
|
+
})
|
package/src/sim/phone.ts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type {CapsuleMenuRect, MiniappSafeArea} from "@glassly/miniapp/host"
|
|
2
|
+
|
|
3
|
+
export type PhoneKind = "iphone" | "duo"
|
|
4
|
+
|
|
5
|
+
export interface PhoneLayout {
|
|
6
|
+
kind: PhoneKind
|
|
7
|
+
width: number
|
|
8
|
+
height: number
|
|
9
|
+
insets: MiniappSafeArea
|
|
10
|
+
capsuleMenu: CapsuleMenuRect
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// Folded iPhone Duo, measured on the iOS 27.1 simulator: the camera/status
|
|
14
|
+
// rail is an 84 pt right inset with no top inset, and the Glassly App puts a
|
|
15
|
+
// 44×88 capsule 48 pt (its center) in from the outer edge, under the 174 pt
|
|
16
|
+
// column the system reserves for the status bar and the Dynamic Island.
|
|
17
|
+
const PHONES: Record<PhoneKind, {width: number; height: number; insets: MiniappSafeArea; capsule: Omit<CapsuleMenuRect, "left" | "bottom">}> = {
|
|
18
|
+
iphone: {
|
|
19
|
+
width: 393,
|
|
20
|
+
height: 852,
|
|
21
|
+
insets: {top: 59, bottom: 34, left: 0, right: 0},
|
|
22
|
+
capsule: {top: 67, right: 16, width: 80, height: 32, placement: "corner"},
|
|
23
|
+
},
|
|
24
|
+
duo: {
|
|
25
|
+
width: 466,
|
|
26
|
+
height: 678,
|
|
27
|
+
insets: {top: 0, bottom: 34, left: 0, right: 84},
|
|
28
|
+
capsule: {top: 174, right: 26, width: 44, height: 88, placement: "rail"},
|
|
29
|
+
},
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export const RAIL_BACK = {top: 174 + 88 + 12, size: 44}
|
|
33
|
+
|
|
34
|
+
export function parsePhone(value: unknown): PhoneKind {
|
|
35
|
+
return value === "duo" ? "duo" : "iphone"
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function phoneLayout(kind: PhoneKind): PhoneLayout {
|
|
39
|
+
const {width, height, insets, capsule} = PHONES[kind]
|
|
40
|
+
return {
|
|
41
|
+
kind,
|
|
42
|
+
width,
|
|
43
|
+
height,
|
|
44
|
+
insets: {...insets},
|
|
45
|
+
capsuleMenu: {
|
|
46
|
+
...capsule,
|
|
47
|
+
left: width - capsule.right - capsule.width,
|
|
48
|
+
bottom: capsule.top + capsule.height,
|
|
49
|
+
},
|
|
50
|
+
}
|
|
51
|
+
}
|
package/src/sim/server.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import {existsSync, readFileSync, statSync} from "fs"
|
|
2
2
|
import {join, normalize, sep} from "path"
|
|
3
3
|
import type {ServerWebSocket} from "bun"
|
|
4
|
-
import {buildUiShim, buildWebviewGlobalsScript} from "@glassly/miniapp/host"
|
|
4
|
+
import {buildSafeAreaUpdateScript, buildUiShim, buildWebviewGlobalsScript} from "@glassly/miniapp/host"
|
|
5
5
|
import type {MirrorSnapshot} from "@glassly/miniapp/mirror"
|
|
6
6
|
|
|
7
7
|
import type {SimHost, SimHostEvent} from "./host.js"
|
|
8
|
+
import {parsePhone, phoneLayout, RAIL_BACK, type PhoneLayout} from "./phone.js"
|
|
8
9
|
import type {ScreenRenderer} from "./screenshot.js"
|
|
9
10
|
|
|
10
11
|
export interface SimServerOptions {
|
|
@@ -30,9 +31,6 @@ interface SocketData {
|
|
|
30
31
|
id: string
|
|
31
32
|
}
|
|
32
33
|
|
|
33
|
-
const SAFE_AREA = {top: 59, bottom: 34, left: 0, right: 0}
|
|
34
|
-
const CAPSULE = {top: 67, right: 16, width: 80, height: 32}
|
|
35
|
-
|
|
36
34
|
const CONTENT_TYPES: Record<string, string> = {
|
|
37
35
|
html: "text/html; charset=utf-8",
|
|
38
36
|
js: "application/javascript; charset=utf-8",
|
|
@@ -92,24 +90,21 @@ export function describeScreen(snapshot: MirrorSnapshot): string {
|
|
|
92
90
|
* Must run before the page's own scripts: it installs the WebView bridge the
|
|
93
91
|
* Glassly App provides (carried over a WebSocket) and the phone chrome.
|
|
94
92
|
*/
|
|
95
|
-
function uiBootstrap(packageName: string, colorScheme: "light" | "dark"): string {
|
|
93
|
+
function uiBootstrap(packageName: string, colorScheme: "light" | "dark", layout: PhoneLayout): string {
|
|
96
94
|
const globals = buildWebviewGlobalsScript({
|
|
97
95
|
platform: "simulator",
|
|
98
96
|
packageName,
|
|
99
97
|
miniappLocal: true,
|
|
100
98
|
miniappDeveloperMode: true,
|
|
101
|
-
safeAreaInsets:
|
|
102
|
-
capsuleMenu:
|
|
103
|
-
...CAPSULE,
|
|
104
|
-
bottom: CAPSULE.top + CAPSULE.height,
|
|
105
|
-
left: 393 - CAPSULE.right - CAPSULE.width,
|
|
106
|
-
placement: "corner",
|
|
107
|
-
},
|
|
99
|
+
safeAreaInsets: layout.insets,
|
|
100
|
+
capsuleMenu: layout.capsuleMenu,
|
|
108
101
|
colorScheme,
|
|
109
102
|
})
|
|
110
103
|
const bridge = `
|
|
111
104
|
(function () {
|
|
112
105
|
var queue = [], socket = null, open = false, dropped = false;
|
|
106
|
+
var layout = ${JSON.stringify({kind: layout.kind, width: layout.width})};
|
|
107
|
+
var backShown = false;
|
|
113
108
|
function connect() {
|
|
114
109
|
socket = new WebSocket((location.protocol === "https:" ? "wss://" : "ws://") + location.host + "/sim/ui-socket");
|
|
115
110
|
socket.onopen = function () {
|
|
@@ -126,12 +121,26 @@ function uiBootstrap(packageName: string, colorScheme: "light" | "dark"): string
|
|
|
126
121
|
window.dispatchEvent(new Event("glassly:color-scheme-change"));
|
|
127
122
|
paintChrome();
|
|
128
123
|
}
|
|
124
|
+
else if (message.type === "layout") {
|
|
125
|
+
layout = {kind: message.kind, width: message.width};
|
|
126
|
+
(0, eval)(message.script);
|
|
127
|
+
renderChrome();
|
|
128
|
+
}
|
|
129
129
|
};
|
|
130
130
|
socket.onclose = function () { open = false; dropped = true; setTimeout(connect, 600); };
|
|
131
131
|
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
132
|
+
// The Glassly App draws the page's back button in the Duo rail; the
|
|
133
|
+
// simulator does the same here instead of passing it to the host.
|
|
134
|
+
function post(raw) {
|
|
135
|
+
var envelope = null; try { envelope = JSON.parse(raw); } catch (e) {}
|
|
136
|
+
if (envelope && envelope.type === "set_back_action") {
|
|
137
|
+
backShown = envelope.shown === true;
|
|
138
|
+
renderChrome();
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
if (open) socket.send(raw); else queue.push(raw);
|
|
142
|
+
}
|
|
143
|
+
window.ReactNativeWebView = {postMessage: post};
|
|
135
144
|
connect();
|
|
136
145
|
|
|
137
146
|
function placeCapsule() {
|
|
@@ -143,7 +152,7 @@ function uiBootstrap(packageName: string, colorScheme: "light" | "dark"): string
|
|
|
143
152
|
document.documentElement.style.setProperty("--glassly-capsule-left", left + "px");
|
|
144
153
|
window.dispatchEvent(new Event("glassly:safe-area-change"));
|
|
145
154
|
}
|
|
146
|
-
var chrome = null;
|
|
155
|
+
var chrome = null, root = null;
|
|
147
156
|
function paintChrome() {
|
|
148
157
|
if (!chrome) return;
|
|
149
158
|
var dark = window.Glassly.colorScheme === "dark";
|
|
@@ -151,20 +160,46 @@ function uiBootstrap(packageName: string, colorScheme: "light" | "dark"): string
|
|
|
151
160
|
chrome.style.setProperty("--pill", dark ? "rgba(63,63,70,.72)" : "rgba(255,255,255,.78)");
|
|
152
161
|
chrome.style.setProperty("--edge", dark ? "rgba(255,255,255,.14)" : "rgba(0,0,0,.1)");
|
|
153
162
|
}
|
|
163
|
+
function box(top, right, width, height, extra) {
|
|
164
|
+
return 'position:absolute;top:' + top + 'px;right:' + right + 'px;width:' + width + 'px;height:' + height + 'px;box-sizing:border-box;' + (extra || "");
|
|
165
|
+
}
|
|
166
|
+
var PILL = "background:var(--pill);border:1px solid var(--edge);backdrop-filter:blur(12px);display:flex;align-items:center;justify-content:space-evenly;line-height:1;";
|
|
167
|
+
function renderChrome() {
|
|
168
|
+
if (!root) return;
|
|
169
|
+
var c = window.Glassly.capsuleMenu, html = "";
|
|
170
|
+
if (layout.kind === "duo") {
|
|
171
|
+
html +=
|
|
172
|
+
'<div style="' + box(29, 48 - 18.5, 37, 37, "border-radius:50%;background:#000") + '"></div>' +
|
|
173
|
+
'<div style="' + box(80, 18, 60, 20, "text-align:center") + '">9:41</div>' +
|
|
174
|
+
'<div style="' + box(104, 18, 60, 16, "text-align:center;font-size:10px;opacity:.7") + '">Simulator</div>' +
|
|
175
|
+
'<div style="' + box(c.top, c.right, c.width, c.height, "border-radius:" + c.width / 2 + "px;flex-direction:column;" + PILL) + '">' +
|
|
176
|
+
'<span style="font-size:14px;letter-spacing:1px">•••</span><span style="width:16px;height:1px;background:var(--edge)"></span><span style="font-size:13px">✕</span></div>';
|
|
177
|
+
if (backShown) {
|
|
178
|
+
html += '<button id="back" type="button" aria-label="Back" style="' +
|
|
179
|
+
box(${RAIL_BACK.top}, c.right, ${RAIL_BACK.size}, ${RAIL_BACK.size}, "border-radius:50%;pointer-events:auto;cursor:pointer;color:var(--ink);font:400 26px/1 -apple-system,system-ui,sans-serif;padding:0 0 3px;" + PILL) +
|
|
180
|
+
'">‹</button>';
|
|
181
|
+
}
|
|
182
|
+
} else {
|
|
183
|
+
html +=
|
|
184
|
+
'<div style="position:absolute;top:18px;left:30px">9:41</div>' +
|
|
185
|
+
'<div style="position:absolute;top:19px;right:28px;font-size:12px;letter-spacing:.02em;opacity:.7">Simulator</div>' +
|
|
186
|
+
'<div style="' + box(c.top, c.right, c.width, c.height, "border-radius:16px;font-size:16px;" + PILL) + '">' +
|
|
187
|
+
'<span style="letter-spacing:1px">•••</span><span style="width:1px;height:14px;background:var(--edge)"></span><span style="font-size:13px">✕</span></div>';
|
|
188
|
+
}
|
|
189
|
+
html += '<div style="position:absolute;bottom:8px;left:50%;width:134px;height:5px;margin-left:-67px;border-radius:3px;background:var(--ink);opacity:.85"></div>';
|
|
190
|
+
root.innerHTML = html;
|
|
191
|
+
var back = root.getElementById("back");
|
|
192
|
+
if (back) back.addEventListener("click", function () { window.__host.recv({type: "back"}); });
|
|
193
|
+
}
|
|
154
194
|
function mountChrome() {
|
|
155
195
|
if (chrome || !document.documentElement) return;
|
|
156
196
|
chrome = document.createElement("div");
|
|
157
197
|
chrome.setAttribute("data-glassly-sim-chrome", "");
|
|
158
198
|
chrome.style.cssText = "position:fixed;inset:0;pointer-events:none;z-index:2147483647;font:600 15px -apple-system,system-ui,sans-serif;color:var(--ink)";
|
|
159
|
-
|
|
160
|
-
root.innerHTML =
|
|
161
|
-
'<div style="position:absolute;top:18px;left:30px">9:41</div>' +
|
|
162
|
-
'<div style="position:absolute;top:19px;right:28px;font-size:12px;letter-spacing:.02em;opacity:.7">Simulator</div>' +
|
|
163
|
-
'<div style="position:absolute;top:${CAPSULE.top}px;right:${CAPSULE.right}px;width:${CAPSULE.width}px;height:${CAPSULE.height}px;box-sizing:border-box;border-radius:16px;background:var(--pill);border:1px solid var(--edge);backdrop-filter:blur(12px);display:flex;align-items:center;justify-content:space-evenly;font-size:16px;line-height:1">' +
|
|
164
|
-
'<span style="letter-spacing:1px">•••</span><span style="width:1px;height:14px;background:var(--edge)"></span><span style="font-size:13px">✕</span></div>' +
|
|
165
|
-
'<div style="position:absolute;bottom:8px;left:50%;width:134px;height:5px;margin-left:-67px;border-radius:3px;background:var(--ink);opacity:.85"></div>';
|
|
199
|
+
root = chrome.attachShadow({mode: "open"});
|
|
166
200
|
document.documentElement.appendChild(chrome);
|
|
167
201
|
paintChrome();
|
|
202
|
+
renderChrome();
|
|
168
203
|
}
|
|
169
204
|
placeCapsule();
|
|
170
205
|
window.addEventListener("resize", placeCapsule);
|
|
@@ -174,6 +209,15 @@ function uiBootstrap(packageName: string, colorScheme: "light" | "dark"): string
|
|
|
174
209
|
return `<script>${globals}\n${bridge}\n${buildUiShim({packageName})}</script>`
|
|
175
210
|
}
|
|
176
211
|
|
|
212
|
+
export function layoutMessage(layout: PhoneLayout): Record<string, unknown> {
|
|
213
|
+
return {
|
|
214
|
+
type: "layout",
|
|
215
|
+
kind: layout.kind,
|
|
216
|
+
width: layout.width,
|
|
217
|
+
script: buildSafeAreaUpdateScript(layout.insets, layout.capsuleMenu),
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
177
221
|
function injectBootstrap(html: string, bootstrap: string): string {
|
|
178
222
|
const head = html.match(/<head[^>]*>/i)
|
|
179
223
|
if (head?.index !== undefined) {
|
|
@@ -210,7 +254,8 @@ export function startSimServer(options: SimServerOptions): SimServer {
|
|
|
210
254
|
const headers = {"content-type": contentType(file), "cache-control": "no-store"}
|
|
211
255
|
if (!file.endsWith(".html")) return new Response(readFileSync(file), {headers})
|
|
212
256
|
const scheme = host.status().colorScheme === "light" ? "light" : "dark"
|
|
213
|
-
|
|
257
|
+
const layout = phoneLayout(parsePhone(host.status().phone))
|
|
258
|
+
return new Response(injectBootstrap(readFileSync(file, "utf-8"), uiBootstrap(options.packageName, scheme, layout)), {
|
|
214
259
|
headers,
|
|
215
260
|
})
|
|
216
261
|
}
|
|
@@ -266,7 +311,7 @@ export function startSimServer(options: SimServerOptions): SimServer {
|
|
|
266
311
|
try {
|
|
267
312
|
switch (route) {
|
|
268
313
|
case "touch":
|
|
269
|
-
host.touch(text("gesture") ?? "single_tap")
|
|
314
|
+
host.touch(text("gesture") ?? "single_tap", body.index === undefined ? {} : {index: number("index")})
|
|
270
315
|
break
|
|
271
316
|
case "button":
|
|
272
317
|
host.button(body.pressType === "long" ? "long" : "short", text("buttonId"))
|
|
@@ -309,6 +354,12 @@ export function startSimServer(options: SimServerOptions): SimServer {
|
|
|
309
354
|
broadcast(uiSockets, {type: "color-scheme", colorScheme})
|
|
310
355
|
break
|
|
311
356
|
}
|
|
357
|
+
case "phone": {
|
|
358
|
+
const layout = phoneLayout(parsePhone(body.phone))
|
|
359
|
+
host.setPhone(layout.kind)
|
|
360
|
+
broadcast(uiSockets, layoutMessage(layout))
|
|
361
|
+
break
|
|
362
|
+
}
|
|
312
363
|
case "event":
|
|
313
364
|
host.event(text("stream") ?? "", body.data)
|
|
314
365
|
break
|
package/src/sim/sim.ts
CHANGED
|
@@ -171,7 +171,7 @@ async function loadHostModules() {
|
|
|
171
171
|
}
|
|
172
172
|
throw new Error(
|
|
173
173
|
`glassly sim needs a newer @glassly/miniapp than this project has (${found}). ` +
|
|
174
|
-
`
|
|
174
|
+
`Run \`glassly update\` and try again.`,
|
|
175
175
|
)
|
|
176
176
|
}
|
|
177
177
|
const [host, server, background, device, storage, screenshot] = await Promise.all([
|