@marktiderman/genesis-native 0.11.0 → 0.13.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/README.md +13 -3
- package/dist/{block-Iga-mCeC.d.ts → block-BfJT3F6B.d.ts} +3 -3
- package/dist/{blocks-BQY_df3j.d.ts → blocks-DoY_Z-Lh.d.ts} +69 -7
- package/dist/{chunk-6BT4PTGH.js → chunk-6UVWYJPZ.js} +15 -5
- package/dist/chunk-6UVWYJPZ.js.map +1 -0
- package/dist/{chunk-EWHO5WQU.js → chunk-JWIBRHDE.js} +21 -9
- package/dist/chunk-JWIBRHDE.js.map +1 -0
- package/dist/{chunk-YIF4BFQH.js → chunk-JZHDEU4Q.js} +130 -13
- package/dist/chunk-JZHDEU4Q.js.map +1 -0
- package/dist/devtools.d.ts +101 -8
- package/dist/devtools.js +180 -104
- package/dist/devtools.js.map +1 -1
- package/dist/index.d.ts +5 -5
- package/dist/index.js +4 -5
- package/dist/index.js.map +1 -1
- package/dist/observability.d.ts +14 -8
- package/dist/observability.js +3 -3
- package/dist/persist.d.ts +1 -1
- package/dist/push.d.ts +4 -4
- package/dist/push.js +1 -1
- package/dist/push.js.map +1 -1
- package/dist/{query--ihYsJWC.d.ts → query-DJFrykK_.d.ts} +38 -2
- package/dist/{screen-boundary-B8DlsLwb.d.ts → screen-boundary-Da3qleNz.d.ts} +5 -1
- package/dist/updates.d.ts +3 -3
- package/dist/updates.js +6 -6
- package/dist/updates.js.map +1 -1
- package/package.json +50 -8
- package/src/app.tsx +2 -1
- package/src/blocks.tsx +20 -5
- package/src/devtools/block.tsx +281 -152
- package/src/devtools/index.ts +4 -3
- package/src/devtools/settings.ts +50 -0
- package/src/devtools/slots.ts +15 -0
- package/src/errors.tsx +144 -13
- package/src/index.ts +4 -0
- package/src/observability/block.tsx +1 -1
- package/src/observability/index.ts +1 -1
- package/src/observability/scrub.ts +22 -4
- package/src/push/block.tsx +1 -1
- package/src/screen-boundary.tsx +13 -2
- package/src/updates/block.tsx +7 -5
- package/src/updates/index.ts +1 -1
- package/src/updates/signature.ts +52 -3
- package/dist/chunk-65P7RU4V.js +0 -49
- package/dist/chunk-65P7RU4V.js.map +0 -1
- package/dist/chunk-6BT4PTGH.js.map +0 -1
- package/dist/chunk-EWHO5WQU.js.map +0 -1
- package/dist/chunk-YIF4BFQH.js.map +0 -1
package/src/devtools/block.tsx
CHANGED
|
@@ -10,9 +10,12 @@
|
|
|
10
10
|
* app's flags;
|
|
11
11
|
* - the recent breadcrumbs and errors (the observability block's, scrubbed);
|
|
12
12
|
* - the server's base URL;
|
|
13
|
+
* - the health checks (`checks`: genesis-support's `healthChecks` registry), run when the sheet
|
|
14
|
+
* opens and again on "Run checks", each in words (`checkLabels`) with its own "Try again";
|
|
13
15
|
* - "Copy debug info", "Crash test", "Clear cache" and "Sign out";
|
|
14
16
|
* - the `devtoolsFeedback` slot, which the support block fills with
|
|
15
|
-
* "Send feedback"
|
|
17
|
+
* "Send feedback", and the `devtoolsDiagnostics` slot beside "Copy debug
|
|
18
|
+
* info", which it fills with "Send diagnostics" (the context dump).
|
|
16
19
|
*
|
|
17
20
|
* Keep it out of production bundles: import this entry only behind a
|
|
18
21
|
* condition Metro can fold at build time (see the README), and pass
|
|
@@ -20,12 +23,24 @@
|
|
|
20
23
|
* false the block mounts nothing and listens to nothing.
|
|
21
24
|
*/
|
|
22
25
|
import { useEffect, useMemo, useRef, useState, useSyncExternalStore, type ComponentType, type ReactNode } from "react";
|
|
23
|
-
import {
|
|
26
|
+
import type { ResolvedSettings } from "@marktiderman/genesis-config/settings";
|
|
27
|
+
import { devtoolsSettingValues } from "./settings";
|
|
28
|
+
import { Alert, Share, View, type GestureResponderEvent } from "react-native";
|
|
24
29
|
import { useQueryClient } from "@tanstack/react-query";
|
|
25
30
|
import { renderSlot } from "@marktiderman/genesis-core/slots";
|
|
26
|
-
import {
|
|
27
|
-
|
|
28
|
-
|
|
31
|
+
import {
|
|
32
|
+
Box,
|
|
33
|
+
Inline,
|
|
34
|
+
NativeButton,
|
|
35
|
+
NativeInput,
|
|
36
|
+
NativeSectionListHeader,
|
|
37
|
+
NativeSettingsRow,
|
|
38
|
+
NativeSheet,
|
|
39
|
+
NativeSheetScrollView,
|
|
40
|
+
NativeText,
|
|
41
|
+
Stack,
|
|
42
|
+
} from "@marktiderman/genesis-ui-native/components";
|
|
43
|
+
import { defineBlock } from "@marktiderman/genesis-config/blocks";
|
|
29
44
|
import { useSession } from "../auth";
|
|
30
45
|
import { useBlocks, type NativeBlock, type NativeBlockRootProps } from "../blocks";
|
|
31
46
|
import { useRecentActivity, type ObservabilityBlock } from "../observability/block";
|
|
@@ -35,7 +50,7 @@ import type { ChannelSwitchResult } from "../updates/channels";
|
|
|
35
50
|
import { versionSignature, type VersionSignature } from "../updates/signature";
|
|
36
51
|
import { createHoldDetector, createShakeDetector, type AccelerometerLike } from "./gestures";
|
|
37
52
|
import { buildDebugInfo } from "./info";
|
|
38
|
-
import type { DevtoolsFeedbackProps } from "./slots";
|
|
53
|
+
import type { DevtoolsDiagnosticsProps, DevtoolsFeedbackProps } from "./slots";
|
|
39
54
|
|
|
40
55
|
/** The FeatureId of the devtools overlay. */
|
|
41
56
|
export const DEVTOOLS_BLOCK_ID = "devtools-overlay";
|
|
@@ -45,6 +60,42 @@ export interface DevSettingsLike {
|
|
|
45
60
|
addMenuItem(title: string, handler: () => void): void;
|
|
46
61
|
}
|
|
47
62
|
|
|
63
|
+
/** One health check's result, as genesis-support's `healthChecks` gives it. */
|
|
64
|
+
export interface DevtoolsCheckResult {
|
|
65
|
+
name: string;
|
|
66
|
+
status: "ok" | "warn" | "fail";
|
|
67
|
+
message: string | null;
|
|
68
|
+
ms: number;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** A health-check registry (genesis-support's `healthChecks`): the overlay runs it and shows the results. */
|
|
72
|
+
export interface DevtoolsChecksLike {
|
|
73
|
+
list(): readonly unknown[];
|
|
74
|
+
run(): Promise<readonly DevtoolsCheckResult[]>;
|
|
75
|
+
latest(): readonly DevtoolsCheckResult[];
|
|
76
|
+
/** Run one check again (a check's "Try again"); null when none has that name. Without it, no check has "Try again". */
|
|
77
|
+
runCheck?(name: string): Promise<DevtoolsCheckResult | null>;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** The health checks' words: each status, and the actions. */
|
|
81
|
+
export interface DevtoolsCheckLabels {
|
|
82
|
+
ok: string;
|
|
83
|
+
warn: string;
|
|
84
|
+
fail: string;
|
|
85
|
+
/** Run one check again. */
|
|
86
|
+
retry: string;
|
|
87
|
+
/** Run every check. */
|
|
88
|
+
runAll: string;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export const DEFAULT_DEVTOOLS_CHECK_LABELS: DevtoolsCheckLabels = {
|
|
92
|
+
ok: "Working",
|
|
93
|
+
warn: "Needs a look",
|
|
94
|
+
fail: "Not working",
|
|
95
|
+
retry: "Try again",
|
|
96
|
+
runAll: "Run checks",
|
|
97
|
+
};
|
|
98
|
+
|
|
48
99
|
export interface DevtoolsOptions {
|
|
49
100
|
/**
|
|
50
101
|
* Must be explicitly true: `__DEV__` or a fact of the binary (a `.dev` or
|
|
@@ -61,6 +112,10 @@ export interface DevtoolsOptions {
|
|
|
61
112
|
baseUrl?: string;
|
|
62
113
|
/** The app's switches and flags, shown by name and value. */
|
|
63
114
|
flags?: Readonly<Record<string, unknown>>;
|
|
115
|
+
/** The health checks to run and show (genesis-support's `healthChecks`). */
|
|
116
|
+
checks?: DevtoolsChecksLike;
|
|
117
|
+
/** The health checks' words, in English by default. */
|
|
118
|
+
checkLabels?: Partial<DevtoolsCheckLabels>;
|
|
64
119
|
/** `Accelerometer` from expo-sensors: shake to open. Without it, the hold and the dev menu still work. */
|
|
65
120
|
accelerometer?: AccelerometerLike;
|
|
66
121
|
/** `DevSettings` from react-native: "Open devtools" in the dev menu (development builds). */
|
|
@@ -73,6 +128,13 @@ export interface DevtoolsOptions {
|
|
|
73
128
|
clearCache?: () => unknown;
|
|
74
129
|
/** Sign out (`supabase.auth.signOut()`). Without it, the action is hidden. */
|
|
75
130
|
signOut?: () => unknown;
|
|
131
|
+
/**
|
|
132
|
+
* Genesis settings (`resolveSettings`' result, or the values alone): `devtools.overlay` off
|
|
133
|
+
* mounts nothing (it never turns the overlay on: `enabled` does); `devtools.shakeToOpen`,
|
|
134
|
+
* `devtools.hold`, `devtools.flags` and `devtools.signOut` off take that part away. Without
|
|
135
|
+
* them, everything the options give.
|
|
136
|
+
*/
|
|
137
|
+
appSettings?: Pick<ResolvedSettings, "values"> | { readonly [key: string]: unknown } | null;
|
|
76
138
|
}
|
|
77
139
|
|
|
78
140
|
export interface DevtoolsState {
|
|
@@ -90,8 +152,17 @@ export interface DevtoolsBlock extends NativeBlock<typeof DEVTOOLS_BLOCK_ID> {
|
|
|
90
152
|
}
|
|
91
153
|
|
|
92
154
|
/** Build the overlay once, at module scope. @stability Beta */
|
|
93
|
-
export function createDevtools(
|
|
94
|
-
const
|
|
155
|
+
export function createDevtools(given: DevtoolsOptions): DevtoolsBlock {
|
|
156
|
+
const settings = devtoolsSettingValues(given.appSettings);
|
|
157
|
+
// The settings only take away: what they switch off is left out of the options everything reads.
|
|
158
|
+
const options: DevtoolsOptions = {
|
|
159
|
+
...given,
|
|
160
|
+
...(settings.shakeToOpen ? {} : { accelerometer: undefined }),
|
|
161
|
+
...(settings.hold ? {} : { hold: false as const }),
|
|
162
|
+
...(settings.flags ? {} : { flags: undefined }),
|
|
163
|
+
...(settings.signOut ? {} : { signOut: undefined }),
|
|
164
|
+
};
|
|
165
|
+
const enabled = given.enabled === true && settings.overlay;
|
|
95
166
|
let state: DevtoolsState = { open: false };
|
|
96
167
|
const listeners = new Set<() => void>();
|
|
97
168
|
const set = (next: DevtoolsState) => {
|
|
@@ -214,6 +285,8 @@ export function createDevtools(options: DevtoolsOptions): DevtoolsBlock {
|
|
|
214
285
|
block={block}
|
|
215
286
|
Feedback={slots?.devtoolsFeedback}
|
|
216
287
|
feedbackProps={slotProps?.devtoolsFeedback}
|
|
288
|
+
Diagnostics={slots?.devtoolsDiagnostics}
|
|
289
|
+
diagnosticsProps={slotProps?.devtoolsDiagnostics}
|
|
217
290
|
onCrash={() => {
|
|
218
291
|
set({ open: false });
|
|
219
292
|
setCrash(true);
|
|
@@ -241,6 +314,10 @@ function NoFeedback(_props: DevtoolsFeedbackProps) {
|
|
|
241
314
|
return null;
|
|
242
315
|
}
|
|
243
316
|
|
|
317
|
+
function NoDiagnostics(_props: DevtoolsDiagnosticsProps) {
|
|
318
|
+
return null;
|
|
319
|
+
}
|
|
320
|
+
|
|
244
321
|
function useSignature(options: DevtoolsOptions): VersionSignature | null {
|
|
245
322
|
const updates = options.updates;
|
|
246
323
|
const [requested, setRequested] = useState<string | null>(null);
|
|
@@ -255,8 +332,8 @@ function useSignature(options: DevtoolsOptions): VersionSignature | null {
|
|
|
255
332
|
return useMemo(() => {
|
|
256
333
|
if (!updates) return options.signature ?? null;
|
|
257
334
|
if (!requested) return updates.signature;
|
|
258
|
-
const { application, updates: modules, platform } = updates.options;
|
|
259
|
-
return versionSignature({ application, updates: modules, platform, requestedChannel: requested });
|
|
335
|
+
const { application, updates: modules, platform, buildMetadata } = updates.options;
|
|
336
|
+
return versionSignature({ application, updates: modules, platform, requestedChannel: requested, buildMetadata: buildMetadata ?? null });
|
|
260
337
|
}, [updates, requested, options.signature]);
|
|
261
338
|
}
|
|
262
339
|
|
|
@@ -276,37 +353,87 @@ interface SheetProps {
|
|
|
276
353
|
block: DevtoolsBlock;
|
|
277
354
|
Feedback: ComponentType<DevtoolsFeedbackProps> | null | undefined;
|
|
278
355
|
feedbackProps: Partial<DevtoolsFeedbackProps> | undefined;
|
|
356
|
+
Diagnostics: ComponentType<DevtoolsDiagnosticsProps> | null | undefined;
|
|
357
|
+
diagnosticsProps: Partial<DevtoolsDiagnosticsProps> | undefined;
|
|
279
358
|
onCrash: () => void;
|
|
280
359
|
}
|
|
281
360
|
|
|
282
|
-
|
|
283
|
-
// transform runs, so a class on React Native's own View would do nothing.
|
|
361
|
+
/** A label and its value, as a settings row: the value wraps whole and can be selected (an id, a URL). */
|
|
284
362
|
function Row({ label, value, testID }: { label: string; value: string; testID?: string }) {
|
|
285
|
-
return (
|
|
286
|
-
<View style={{ flexDirection: "row", justifyContent: "space-between", gap: 12, paddingVertical: 4 }} testID={testID}>
|
|
287
|
-
<NativeText preset="label">{label}</NativeText>
|
|
288
|
-
<NativeText preset="body-sm" className="text-right text-muted-foreground" style={{ flex: 1 }} selectable>
|
|
289
|
-
{value}
|
|
290
|
-
</NativeText>
|
|
291
|
-
</View>
|
|
292
|
-
);
|
|
363
|
+
return <NativeSettingsRow label={label} description={value} descriptionLines={null} selectable {...(testID ? { testID } : {})} />;
|
|
293
364
|
}
|
|
294
365
|
|
|
295
366
|
function Section({ title, children }: { title: string; children: ReactNode }) {
|
|
296
|
-
const roles = useThemeRoles();
|
|
297
367
|
return (
|
|
298
|
-
<
|
|
299
|
-
<
|
|
300
|
-
{title}
|
|
301
|
-
</NativeText>
|
|
368
|
+
<Stack gap="xs">
|
|
369
|
+
<NativeSectionListHeader title={title} />
|
|
302
370
|
{children}
|
|
303
|
-
</
|
|
371
|
+
</Stack>
|
|
372
|
+
);
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
function HealthChecksSection({ checks, labels }: { checks: DevtoolsChecksLike; labels: DevtoolsCheckLabels }) {
|
|
376
|
+
const [results, setResults] = useState<readonly DevtoolsCheckResult[]>(() => checks.latest());
|
|
377
|
+
const [running, setRunning] = useState(false);
|
|
378
|
+
const [retrying, setRetrying] = useState<string | null>(null);
|
|
379
|
+
const run = () => {
|
|
380
|
+
setRunning(true);
|
|
381
|
+
checks
|
|
382
|
+
.run()
|
|
383
|
+
.then(setResults, () => undefined)
|
|
384
|
+
.finally(() => setRunning(false));
|
|
385
|
+
};
|
|
386
|
+
const runCheck = checks.runCheck?.bind(checks);
|
|
387
|
+
const retry = (again: NonNullable<typeof runCheck>, name: string) => {
|
|
388
|
+
setRetrying(name);
|
|
389
|
+
again(name)
|
|
390
|
+
.then((next) => {
|
|
391
|
+
if (next) setResults((all) => all.map((r) => (r.name === name ? next : r)));
|
|
392
|
+
}, () => undefined)
|
|
393
|
+
.finally(() => setRetrying(null));
|
|
394
|
+
};
|
|
395
|
+
// Run when the sheet opens.
|
|
396
|
+
useEffect(run, [checks]);
|
|
397
|
+
const failed = results.filter((r) => r.status === "fail").length;
|
|
398
|
+
const warned = results.filter((r) => r.status === "warn").length;
|
|
399
|
+
const verdict = running ? "running" : !results.length ? "not run" : failed ? `${failed} failed` : warned ? `${warned} warnings` : "all good";
|
|
400
|
+
const word: Record<DevtoolsCheckResult["status"], string> = { ok: labels.ok, warn: labels.warn, fail: labels.fail };
|
|
401
|
+
return (
|
|
402
|
+
<Section title={`Health checks (${verdict})`}>
|
|
403
|
+
{checks.list().length === 0 ? <NativeText preset="body-sm">None registered</NativeText> : null}
|
|
404
|
+
{results.map((r) => (
|
|
405
|
+
<NativeSettingsRow
|
|
406
|
+
key={r.name}
|
|
407
|
+
label={r.name}
|
|
408
|
+
description={`${word[r.status]}${r.message ? ` · ${r.message}` : ""} · ${r.ms} ms`}
|
|
409
|
+
descriptionLines={null}
|
|
410
|
+
selectable
|
|
411
|
+
testID={`genesis-devtools-check-${r.name}`}
|
|
412
|
+
>
|
|
413
|
+
{runCheck ? (
|
|
414
|
+
<NativeButton
|
|
415
|
+
size="sm"
|
|
416
|
+
variant="ghost"
|
|
417
|
+
onPress={() => retry(runCheck, r.name)}
|
|
418
|
+
disabled={running || retrying !== null}
|
|
419
|
+
loading={retrying === r.name}
|
|
420
|
+
accessibilityLabel={`${labels.retry}: ${r.name}`}
|
|
421
|
+
testID={`genesis-devtools-check-${r.name}-retry`}
|
|
422
|
+
>
|
|
423
|
+
{labels.retry}
|
|
424
|
+
</NativeButton>
|
|
425
|
+
) : null}
|
|
426
|
+
</NativeSettingsRow>
|
|
427
|
+
))}
|
|
428
|
+
<NativeButton size="sm" variant="outline" onPress={run} disabled={running} testID="genesis-devtools-run-checks">
|
|
429
|
+
{labels.runAll}
|
|
430
|
+
</NativeButton>
|
|
431
|
+
</Section>
|
|
304
432
|
);
|
|
305
433
|
}
|
|
306
434
|
|
|
307
|
-
function DevtoolsSheet({ visible, onDismissed, block, Feedback, feedbackProps, onCrash }: SheetProps) {
|
|
435
|
+
function DevtoolsSheet({ visible, onDismissed, block, Feedback, feedbackProps, Diagnostics, diagnosticsProps, onCrash }: SheetProps) {
|
|
308
436
|
const { options } = block;
|
|
309
|
-
const roles = useThemeRoles();
|
|
310
437
|
const { userId } = useSession();
|
|
311
438
|
const blocks = useBlocks();
|
|
312
439
|
const recent = useRecentActivity(options.observability ?? null);
|
|
@@ -329,7 +456,8 @@ function DevtoolsSheet({ visible, onDismissed, block, Feedback, feedbackProps, o
|
|
|
329
456
|
);
|
|
330
457
|
};
|
|
331
458
|
|
|
332
|
-
const
|
|
459
|
+
const copyText = (text: string) => (options.copy ? options.copy(text) : Share.share({ message: text }));
|
|
460
|
+
const copy = () => run("Copy debug info", () => copyText(info()));
|
|
333
461
|
const clearCache = () =>
|
|
334
462
|
run("Clear cache", async () => {
|
|
335
463
|
queryClient.clear();
|
|
@@ -357,132 +485,133 @@ function DevtoolsSheet({ visible, onDismissed, block, Feedback, feedbackProps, o
|
|
|
357
485
|
|
|
358
486
|
const flags = Object.entries(options.flags ?? {});
|
|
359
487
|
return (
|
|
360
|
-
//
|
|
361
|
-
// library's
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
<ScrollView style={{ flex: 1, backgroundColor: roles.background }} contentContainerStyle={{ gap: 12, padding: 16, paddingBottom: 48 }}>
|
|
371
|
-
<View style={{ flexDirection: "row", alignItems: "center", justifyContent: "space-between" }}>
|
|
372
|
-
<NativeText preset="h3" accessibilityRole="header">
|
|
373
|
-
Devtools
|
|
374
|
-
</NativeText>
|
|
375
|
-
<NativeButton variant="ghost" size="sm" onPress={() => void close()} testID="genesis-devtools-close">
|
|
376
|
-
Close
|
|
377
|
-
</NativeButton>
|
|
378
|
-
</View>
|
|
379
|
-
{status ? (
|
|
380
|
-
<NativeText preset="body-sm" testID="genesis-devtools-status">
|
|
381
|
-
{status}
|
|
382
|
-
</NativeText>
|
|
383
|
-
) : null}
|
|
384
|
-
|
|
385
|
-
<Section title="Build">
|
|
386
|
-
<NativeText preset="body-sm" selectable testID="genesis-devtools-signature">
|
|
387
|
-
{signature?.text ?? "Version unknown (no updates block)"}
|
|
388
|
-
</NativeText>
|
|
389
|
-
</Section>
|
|
390
|
-
|
|
391
|
-
{channels ? (
|
|
392
|
-
<Section title="Update channel">
|
|
393
|
-
<Row label="Channel" value={signature?.requestedChannel ?? signature?.channel ?? "none"} testID="genesis-devtools-channel" />
|
|
394
|
-
{channels.enabled ? (
|
|
395
|
-
<>
|
|
396
|
-
<NativeInput
|
|
397
|
-
value={channel}
|
|
398
|
-
onChangeText={setChannel}
|
|
399
|
-
placeholder="pr-42"
|
|
400
|
-
autoCapitalize="none"
|
|
401
|
-
autoCorrect={false}
|
|
402
|
-
accessibilityLabel="Channel to switch to"
|
|
403
|
-
testID="genesis-devtools-channel-input"
|
|
404
|
-
/>
|
|
405
|
-
<NativeButton size="sm" onPress={switchChannel} disabled={!channel.trim()} testID="genesis-devtools-channel-switch">
|
|
406
|
-
Switch and reload
|
|
407
|
-
</NativeButton>
|
|
408
|
-
</>
|
|
409
|
-
) : (
|
|
410
|
-
<NativeText preset="body-sm" className="text-muted-foreground">
|
|
411
|
-
Switching is off in this build.
|
|
412
|
-
</NativeText>
|
|
413
|
-
)}
|
|
414
|
-
<NativeButton size="sm" variant="ghost" onPress={resetChannel} testID="genesis-devtools-channel-reset">
|
|
415
|
-
Back to the build's channel
|
|
416
|
-
</NativeButton>
|
|
417
|
-
</Section>
|
|
418
|
-
) : null}
|
|
419
|
-
|
|
420
|
-
<Section title="Session">
|
|
421
|
-
<Row label="User id" value={userId ?? "signed out"} testID="genesis-devtools-user" />
|
|
422
|
-
<Row label="Server" value={options.baseUrl ? scrubUrl(options.baseUrl) : "unknown"} testID="genesis-devtools-server" />
|
|
423
|
-
</Section>
|
|
424
|
-
|
|
425
|
-
<Section title="Blocks and flags">
|
|
426
|
-
<Row label="Blocks" value={blocks.ids.size > 0 ? [...blocks.ids].join(", ") : "none"} testID="genesis-devtools-blocks" />
|
|
427
|
-
{flags.map(([name, value]) => (
|
|
428
|
-
<Row key={name} label={name} value={typeof value === "string" ? scrubString(value) : String(value)} testID={`genesis-devtools-flag-${name}`} />
|
|
429
|
-
))}
|
|
430
|
-
</Section>
|
|
431
|
-
|
|
432
|
-
<Section title={`Errors (${recent.errors.length})`}>
|
|
433
|
-
{recent.errors.length === 0 ? <NativeText preset="body-sm">None</NativeText> : null}
|
|
434
|
-
{recent.errors
|
|
435
|
-
.slice(-10)
|
|
436
|
-
.reverse()
|
|
437
|
-
.map((e) => (
|
|
438
|
-
<NativeText key={`${e.at}-${e.message}`} preset="body-sm" testID="genesis-devtools-error">
|
|
439
|
-
{`${e.fatal ? "fatal " : ""}${e.source} · ${e.name}: ${e.message}`}
|
|
488
|
+
// The sheet primitive: a page sheet on iOS (React Native's modal, needing no provider above it),
|
|
489
|
+
// or the bottom-sheet library's under NativeSheetProvider; it brings the escape gesture, reduced
|
|
490
|
+
// motion and the safe area.
|
|
491
|
+
<NativeSheet open={visible} onOpenChange={(open) => (open ? undefined : void close())} onDismissed={onDismissed} testID="genesis-devtools">
|
|
492
|
+
<NativeSheetScrollView>
|
|
493
|
+
<Box p="lg" pb="3xl">
|
|
494
|
+
<Stack gap="md">
|
|
495
|
+
<Inline justify="between">
|
|
496
|
+
<NativeText preset="h3" accessibilityRole="header">
|
|
497
|
+
Devtools
|
|
440
498
|
</NativeText>
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
.reverse()
|
|
449
|
-
.map((c, i) => (
|
|
450
|
-
<NativeText key={`${c.timestamp ?? 0}-${i}`} preset="body-sm" testID="genesis-devtools-breadcrumb">
|
|
451
|
-
{`${c.category} · ${c.message ?? ""}`}
|
|
499
|
+
<NativeButton variant="ghost" size="sm" onPress={() => void close()} testID="genesis-devtools-close">
|
|
500
|
+
Close
|
|
501
|
+
</NativeButton>
|
|
502
|
+
</Inline>
|
|
503
|
+
{status ? (
|
|
504
|
+
<NativeText preset="body-sm" testID="genesis-devtools-status">
|
|
505
|
+
{status}
|
|
452
506
|
</NativeText>
|
|
453
|
-
)
|
|
454
|
-
</Section>
|
|
507
|
+
) : null}
|
|
455
508
|
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
</
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
509
|
+
<Section title="Build">
|
|
510
|
+
<NativeText preset="body-sm" selectable testID="genesis-devtools-signature">
|
|
511
|
+
{signature?.text ?? "Version unknown (no updates block)"}
|
|
512
|
+
</NativeText>
|
|
513
|
+
</Section>
|
|
514
|
+
|
|
515
|
+
{channels ? (
|
|
516
|
+
<Section title="Update channel">
|
|
517
|
+
<Row label="Channel" value={signature?.requestedChannel ?? signature?.channel ?? "none"} testID="genesis-devtools-channel" />
|
|
518
|
+
{channels.enabled ? (
|
|
519
|
+
<>
|
|
520
|
+
<NativeInput
|
|
521
|
+
value={channel}
|
|
522
|
+
onChangeText={setChannel}
|
|
523
|
+
placeholder="pr-42"
|
|
524
|
+
autoCapitalize="none"
|
|
525
|
+
autoCorrect={false}
|
|
526
|
+
accessibilityLabel="Channel to switch to"
|
|
527
|
+
testID="genesis-devtools-channel-input"
|
|
528
|
+
/>
|
|
529
|
+
<NativeButton size="sm" onPress={switchChannel} disabled={!channel.trim()} testID="genesis-devtools-channel-switch">
|
|
530
|
+
Switch and reload
|
|
531
|
+
</NativeButton>
|
|
532
|
+
</>
|
|
533
|
+
) : (
|
|
534
|
+
<NativeText preset="body-sm" className="text-muted-foreground">
|
|
535
|
+
Switching is off in this build.
|
|
536
|
+
</NativeText>
|
|
537
|
+
)}
|
|
538
|
+
<NativeButton size="sm" variant="ghost" onPress={resetChannel} testID="genesis-devtools-channel-reset">
|
|
539
|
+
Back to the build's channel
|
|
540
|
+
</NativeButton>
|
|
541
|
+
</Section>
|
|
482
542
|
) : null}
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
543
|
+
|
|
544
|
+
<Section title="Session">
|
|
545
|
+
<Row label="User id" value={userId ?? "signed out"} testID="genesis-devtools-user" />
|
|
546
|
+
<Row label="Server" value={options.baseUrl ? scrubUrl(options.baseUrl) : "unknown"} testID="genesis-devtools-server" />
|
|
547
|
+
</Section>
|
|
548
|
+
|
|
549
|
+
{options.checks ? <HealthChecksSection checks={options.checks} labels={{ ...DEFAULT_DEVTOOLS_CHECK_LABELS, ...options.checkLabels }} /> : null}
|
|
550
|
+
|
|
551
|
+
<Section title="Blocks and flags">
|
|
552
|
+
<Row label="Blocks" value={blocks.ids.size > 0 ? [...blocks.ids].join(", ") : "none"} testID="genesis-devtools-blocks" />
|
|
553
|
+
{flags.map(([name, value]) => (
|
|
554
|
+
<Row key={name} label={name} value={typeof value === "string" ? scrubString(value) : String(value)} testID={`genesis-devtools-flag-${name}`} />
|
|
555
|
+
))}
|
|
556
|
+
</Section>
|
|
557
|
+
|
|
558
|
+
<Section title={`Errors (${recent.errors.length})`}>
|
|
559
|
+
{recent.errors.length === 0 ? <NativeText preset="body-sm">None</NativeText> : null}
|
|
560
|
+
{recent.errors
|
|
561
|
+
.slice(-10)
|
|
562
|
+
.reverse()
|
|
563
|
+
.map((e) => (
|
|
564
|
+
<NativeText key={`${e.at}-${e.message}`} preset="body-sm" testID="genesis-devtools-error">
|
|
565
|
+
{`${e.fatal ? "fatal " : ""}${e.source} · ${e.name}: ${e.message}`}
|
|
566
|
+
</NativeText>
|
|
567
|
+
))}
|
|
568
|
+
</Section>
|
|
569
|
+
|
|
570
|
+
<Section title={`Breadcrumbs (${recent.breadcrumbs.length})`}>
|
|
571
|
+
{recent.breadcrumbs.length === 0 ? <NativeText preset="body-sm">None</NativeText> : null}
|
|
572
|
+
{recent.breadcrumbs
|
|
573
|
+
.slice(-15)
|
|
574
|
+
.reverse()
|
|
575
|
+
.map((c, i) => (
|
|
576
|
+
<NativeText key={`${c.timestamp ?? 0}-${i}`} preset="body-sm" testID="genesis-devtools-breadcrumb">
|
|
577
|
+
{`${c.category} · ${c.message ?? ""}`}
|
|
578
|
+
</NativeText>
|
|
579
|
+
))}
|
|
580
|
+
</Section>
|
|
581
|
+
|
|
582
|
+
<Section title="Actions">
|
|
583
|
+
<Stack gap="sm">
|
|
584
|
+
<NativeButton size="sm" variant="outline" onPress={copy} testID="genesis-devtools-copy">
|
|
585
|
+
Copy debug info
|
|
586
|
+
</NativeButton>
|
|
587
|
+
{renderSlot(NoDiagnostics, Diagnostics, { debugInfo: info(), close, copy: copyText }, diagnosticsProps)}
|
|
588
|
+
{renderSlot(NoFeedback, Feedback, { debugInfo: info(), close }, feedbackProps)}
|
|
589
|
+
<NativeButton size="sm" variant="outline" onPress={clearCache} testID="genesis-devtools-clear-cache">
|
|
590
|
+
Clear cache
|
|
591
|
+
</NativeButton>
|
|
592
|
+
<NativeButton
|
|
593
|
+
size="sm"
|
|
594
|
+
variant="outline"
|
|
595
|
+
onPress={() => confirm("Crash test", "This throws a render error: the fatal screen shows and the error is reported.", "Crash", onCrash)}
|
|
596
|
+
testID="genesis-devtools-crash"
|
|
597
|
+
>
|
|
598
|
+
Crash test
|
|
599
|
+
</NativeButton>
|
|
600
|
+
{options.signOut ? (
|
|
601
|
+
<NativeButton
|
|
602
|
+
size="sm"
|
|
603
|
+
variant="destructive"
|
|
604
|
+
onPress={() => confirm("Sign out", "Sign out of this device?", "Sign out", () => run("Sign out", options.signOut as () => unknown))}
|
|
605
|
+
testID="genesis-devtools-sign-out"
|
|
606
|
+
>
|
|
607
|
+
Sign out
|
|
608
|
+
</NativeButton>
|
|
609
|
+
) : null}
|
|
610
|
+
</Stack>
|
|
611
|
+
</Section>
|
|
612
|
+
</Stack>
|
|
613
|
+
</Box>
|
|
614
|
+
</NativeSheetScrollView>
|
|
615
|
+
</NativeSheet>
|
|
487
616
|
);
|
|
488
617
|
}
|
package/src/devtools/index.ts
CHANGED
|
@@ -11,12 +11,13 @@
|
|
|
11
11
|
* ```
|
|
12
12
|
*
|
|
13
13
|
* Rung 1: `<GenesisNativeApp blocks={[devtools]}>`. Rung 2: the
|
|
14
|
-
* `devtoolsFeedback`
|
|
14
|
+
* `devtoolsFeedback` and `devtoolsDiagnostics` slots. Rung 3: `createHoldDetector`,
|
|
15
15
|
* `createShakeDetector`, `buildDebugInfo`.
|
|
16
16
|
*
|
|
17
17
|
* @stability Beta
|
|
18
18
|
*/
|
|
19
|
-
export { createDevtools, DEVTOOLS_BLOCK_ID, type DevSettingsLike, type DevtoolsBlock, type DevtoolsOptions, type DevtoolsState } from "./block";
|
|
19
|
+
export { createDevtools, DEFAULT_DEVTOOLS_CHECK_LABELS, DEVTOOLS_BLOCK_ID, type DevSettingsLike, type DevtoolsCheckLabels, type DevtoolsCheckResult, type DevtoolsChecksLike, type DevtoolsBlock, type DevtoolsOptions, type DevtoolsState } from "./block";
|
|
20
20
|
export { createHoldDetector, createShakeDetector, type AccelerometerLike, type HoldDetector, type HoldDetectorOptions, type ShakeDetector, type ShakeDetectorOptions } from "./gestures";
|
|
21
21
|
export { buildDebugInfo, type DebugInfoInput } from "./info";
|
|
22
|
-
export type { DevtoolsFeedbackProps, DevtoolsSlots } from "./slots";
|
|
22
|
+
export type { DevtoolsDiagnosticsProps, DevtoolsFeedbackProps, DevtoolsSlots } from "./slots";
|
|
23
|
+
export { DEVTOOLS_SETTING_SPECS, devtoolsSettings, devtoolsSettingValues, type DevtoolsSettingValues } from "./settings";
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The devtools overlay's settings (`devtools.*`), declared with genesis-config. The same
|
|
3
|
+
* declaration is in this package's package.json (`genesis.settings`) for the CLI's doctor; a test
|
|
4
|
+
* keeps the two the same.
|
|
5
|
+
*
|
|
6
|
+
* A setting can only take things away: `devtools.overlay` off hides the overlay, but nothing here
|
|
7
|
+
* turns it on in a production build (`createDevtools({ enabled })` stays a fact of the binary).
|
|
8
|
+
*
|
|
9
|
+
* @stability Beta
|
|
10
|
+
*/
|
|
11
|
+
import { defineSettings, settingValueProblem, type ResolvedSettings, type SettingSpec } from "@marktiderman/genesis-config/settings";
|
|
12
|
+
|
|
13
|
+
/** `devtools.*`, as declared. @stability Beta */
|
|
14
|
+
export const DEVTOOLS_SETTING_SPECS = {
|
|
15
|
+
overlay: { type: "boolean", default: true, summary: "The Development overlay in development and preview builds. Off hides it; no setting turns it on in a production build." },
|
|
16
|
+
shakeToOpen: { type: "boolean", default: true, requires: ["devtools.overlay"], summary: "Shake to open the overlay (development and preview builds)." },
|
|
17
|
+
hold: { type: "boolean", default: true, requires: ["devtools.overlay"], summary: "A three-finger hold opens the overlay." },
|
|
18
|
+
flags: { type: "boolean", default: true, requires: ["devtools.overlay"], summary: "Show the app's switches and flags in the overlay." },
|
|
19
|
+
signOut: { type: "boolean", default: true, requires: ["devtools.overlay"], summary: "Offer Sign out in the overlay." },
|
|
20
|
+
} as const satisfies Record<string, SettingSpec>;
|
|
21
|
+
|
|
22
|
+
/** @stability Beta */
|
|
23
|
+
export const devtoolsSettings = defineSettings("devtools", DEVTOOLS_SETTING_SPECS);
|
|
24
|
+
|
|
25
|
+
/** The devtools overlay's settings, typed. @stability Beta */
|
|
26
|
+
export interface DevtoolsSettingValues {
|
|
27
|
+
overlay: boolean;
|
|
28
|
+
shakeToOpen: boolean;
|
|
29
|
+
hold: boolean;
|
|
30
|
+
flags: boolean;
|
|
31
|
+
signOut: boolean;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* The overlay's settings from `resolveSettings`' result (or the values alone, by full key). A key
|
|
36
|
+
* that's missing, or whose value doesn't fit, takes its default (every one on).
|
|
37
|
+
*
|
|
38
|
+
* @stability Beta
|
|
39
|
+
*/
|
|
40
|
+
export function devtoolsSettingValues(input?: Pick<ResolvedSettings, "values"> | { readonly [key: string]: unknown } | null): DevtoolsSettingValues {
|
|
41
|
+
const raw = (input ?? {}) as { readonly [key: string]: unknown };
|
|
42
|
+
const nested = Object.prototype.hasOwnProperty.call(raw, "values") ? raw.values : undefined;
|
|
43
|
+
const values = (typeof nested === "object" && nested !== null && !Array.isArray(nested) ? nested : raw) as { readonly [key: string]: unknown };
|
|
44
|
+
const out: Record<string, unknown> = {};
|
|
45
|
+
for (const def of Object.values(devtoolsSettings.keys)) {
|
|
46
|
+
const v = Object.prototype.hasOwnProperty.call(values, def.key) ? values[def.key] : undefined;
|
|
47
|
+
out[def.key.slice("devtools.".length)] = v !== undefined && settingValueProblem(def, v) === null ? v : def.defaults.max;
|
|
48
|
+
}
|
|
49
|
+
return out as unknown as DevtoolsSettingValues;
|
|
50
|
+
}
|
package/src/devtools/slots.ts
CHANGED
|
@@ -14,8 +14,23 @@ export interface DevtoolsFeedbackProps {
|
|
|
14
14
|
close: () => Promise<void> | void;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
+
/** What the `devtoolsDiagnostics` slot is given: the support block's "Send diagnostics" fills it. */
|
|
18
|
+
export interface DevtoolsDiagnosticsProps {
|
|
19
|
+
/** The overlay's debug report, as text (what "Copy debug info" copies). */
|
|
20
|
+
debugInfo: string;
|
|
21
|
+
/** Closes the overlay. */
|
|
22
|
+
close: () => Promise<void> | void;
|
|
23
|
+
/** Copies text, as the overlay's own "Copy debug info" does (the app's `copy` option, or the share sheet). */
|
|
24
|
+
copy: (text: string) => unknown;
|
|
25
|
+
}
|
|
26
|
+
|
|
17
27
|
// A type, not an interface, so it fits the slots contract's Record constraint.
|
|
18
28
|
export type DevtoolsSlots = {
|
|
19
29
|
/** A "send feedback" action in the devtools overlay. Default nothing; the support block fills it. */
|
|
20
30
|
devtoolsFeedback: DevtoolsFeedbackProps;
|
|
31
|
+
/**
|
|
32
|
+
* A "Send diagnostics" action beside "Copy debug info": sends the context dump and shows its
|
|
33
|
+
* short id. Default nothing; the support block fills it when it has `diagnostics`.
|
|
34
|
+
*/
|
|
35
|
+
devtoolsDiagnostics: DevtoolsDiagnosticsProps;
|
|
21
36
|
};
|