@@ -4,23 +4,34 @@ import {
44 type EnvironmentId ,
55 type PluginInstallation ,
66 type PluginInstallationId ,
7+ type PluginNpmPackage ,
78 resolveEnvironmentMachineKind ,
89} from "@t3tools/contracts" ;
10+ import {
11+ describePluginNpmSource ,
12+ PLUGIN_NPM_INTEGRITY_STATEMENT ,
13+ pluginNpmListKey ,
14+ pluginNpmRowLabel ,
15+ resolvePluginNpmPackagesState ,
16+ resolvePluginNpmProvenance ,
17+ supportsPluginNpm ,
18+ } from "@t3tools/client-runtime/state/pluginNpmPresentation" ;
919import {
1020 describePluginSource ,
1121 presentPluginInstallation ,
1222 resolvePluginCatalogState ,
1323 resolvePluginDetail ,
1424 type PluginStateTone ,
1525} from "@t3tools/client-runtime/state/pluginPresentation" ;
26+ import { useEffect , useRef } from "react" ;
1627import { Platform , Pressable , View } from "react-native" ;
1728import { useSafeAreaInsets } from "react-native-safe-area-context" ;
1829
1930import { AppText as Text } from "../../components/AppText" ;
2031import { SymbolView } from "../../components/AppSymbol" ;
2132import { EnvironmentMachineSymbol } from "../../components/EnvironmentMachineSymbol" ;
2233import { ScreenScrollView as ScrollView } from "../../components/ScreenScrollView" ;
23- import { pluginEnvironment } from "../../state/plugins" ;
34+ import { pluginEnvironment , pluginNpmEnvironment } from "../../state/plugins" ;
2435import { useEnvironmentQuery } from "../../state/query" ;
2536import { SettingsActionRow } from "./components/SettingsActionRow" ;
2637import {
@@ -56,7 +67,7 @@ export function supportsPlugins(target: SettingsTarget): boolean {
5667 * plugin management needs; it shows plugins without controls.
5768 */
5869const PLUGINS_VIEW_ONLY =
59- "Plugins are view-only on mobile. Add, approve, enable, or remove them from an administrative web or desktop connection." ;
70+ "Plugins are view-only on mobile. Add, install, approve, enable, update , or remove them from an administrative web or desktop connection." ;
6071
6172function ViewOnlyNotice ( ) {
6273 return < Text className = "px-2 text-sm text-foreground-muted" > { PLUGINS_VIEW_ONLY } </ Text > ;
@@ -76,6 +87,41 @@ function usePluginCatalog(environmentId: EnvironmentId, environment: SettingsTar
7687 return { state, retry : catalog . refresh } ;
7788}
7889
90+ /** Calls `refresh` when `key` changes from one known value to another; never on a timer. */
91+ function useRefreshOnChange ( key : string | null , refresh : ( ) => void ) {
92+ const last = useRef ( key ) ;
93+ useEffect ( ( ) => {
94+ const previous = last . current ;
95+ last . current = key ;
96+ if ( previous !== null && key !== null && previous !== key ) refresh ( ) ;
97+ } , [ key , refresh ] ) ;
98+ }
99+
100+ /**
101+ * Where an environment's plugins came from on npm. An older server gets no call.
102+ * The list is a query, so it is read again when installations or their files change.
103+ */
104+ function usePluginNpmPackages (
105+ environmentId : EnvironmentId ,
106+ environment : SettingsTarget | undefined ,
107+ installations : ReadonlyArray < PluginInstallation > | null ,
108+ ) {
109+ const supported =
110+ environment !== undefined &&
111+ supportsPluginNpm ( environment . serverConfig . environment . capabilities ) ;
112+ const query = useEnvironmentQuery (
113+ supported ? pluginNpmEnvironment . packages ( { environmentId, input : { } } ) : null ,
114+ ) ;
115+ useRefreshOnChange (
116+ supported && installations !== null ? pluginNpmListKey ( installations ) : null ,
117+ query . refresh ,
118+ ) ;
119+ return {
120+ state : resolvePluginNpmPackagesState ( { supported, data : query . data , error : query . error } ) ,
121+ refresh : query . refresh ,
122+ } ;
123+ }
124+
79125const SCROLL_PROPS = {
80126 keyboardShouldPersistTaps : "handled" ,
81127 contentInsetAdjustmentBehavior : "automatic" ,
@@ -117,9 +163,10 @@ function EnvironmentPlugins({ environment }: { readonly environment: SettingsTar
117163 const navigation = useNavigation < NativeStackNavigationProp < PluginRoutes > > ( ) ;
118164 const environmentId = environment . environmentId ;
119165 const catalog = usePluginCatalog ( environmentId , environment ) ;
120- if ( catalog . state . _tag === "unsupported" ) return null ;
121166 const installations =
122167 catalog . state . _tag === "available" ? catalog . state . view . installations : null ;
168+ const npm = usePluginNpmPackages ( environmentId , environment , installations ) ;
169+ if ( catalog . state . _tag === "unsupported" ) return null ;
123170 return (
124171 < View className = "gap-2" >
125172 < SettingsSection
@@ -150,6 +197,7 @@ function EnvironmentPlugins({ environment }: { readonly environment: SettingsTar
150197 < PluginListRow
151198 key = { installation . installationId }
152199 installation = { installation }
200+ npmPackage = { npmPackageOf ( npm . state , installation . installationId ) }
153201 first = { index === 0 }
154202 onPress = { ( ) =>
155203 navigation . navigate ( "SettingsPlugin" , {
@@ -166,12 +214,23 @@ function EnvironmentPlugins({ environment }: { readonly environment: SettingsTar
166214 ) ;
167215}
168216
217+ /** The npm package behind a listed installation, from the list alone. */
218+ function npmPackageOf (
219+ state : ReturnType < typeof resolvePluginNpmPackagesState > ,
220+ installationId : PluginInstallationId ,
221+ ) : PluginNpmPackage | null {
222+ const provenance = resolvePluginNpmProvenance ( { state, installationId, step : null } ) ;
223+ return provenance . _tag === "found" ? provenance . package : null ;
224+ }
225+
169226function PluginListRow ( {
170227 installation,
228+ npmPackage,
171229 first,
172230 onPress,
173231} : {
174232 readonly installation : PluginInstallation ;
233+ readonly npmPackage : PluginNpmPackage | null ;
175234 readonly first : boolean ;
176235 readonly onPress : ( ) => void ;
177236} ) {
@@ -204,6 +263,11 @@ function PluginListRow({
204263 { view . delivery . detail ? ` · ${ view . delivery . detail } ` : "" }
205264 </ Text >
206265 ) : null }
266+ { npmPackage ? (
267+ < Text className = "text-sm text-foreground-muted" numberOfLines = { 2 } >
268+ { pluginNpmRowLabel ( npmPackage ) }
269+ </ Text >
270+ ) : null }
207271 < Text className = "font-mono text-xs text-foreground-muted" numberOfLines = { 1 } >
208272 { installation . directory }
209273 </ Text >
@@ -262,6 +326,11 @@ function PluginDetail({
262326 const label = environment ?. label ?? "this environment" ;
263327 const catalog = usePluginCatalog ( environmentId , environment ) ;
264328 const detail = resolvePluginDetail ( { catalog : catalog . state , installationId, added : null } ) ;
329+ const npm = usePluginNpmPackages (
330+ environmentId ,
331+ environment ,
332+ catalog . state . _tag === "available" ? catalog . state . view . installations : null ,
333+ ) ;
265334
266335 if ( detail . _tag !== "found" ) {
267336 return (
@@ -296,6 +365,8 @@ function PluginDetail({
296365 const view = presentPluginInstallation ( installation ) ;
297366 const manifest = installation . manifest ;
298367 const digest = installation . source ?. digest ?? null ;
368+ const provenance = resolvePluginNpmProvenance ( { state : npm . state , installationId, step : null } ) ;
369+ const npmPackage = provenance . _tag === "found" ? provenance . package : null ;
299370
300371 return (
301372 < SettingsScreen title = { view . title } >
@@ -333,6 +404,30 @@ function PluginDetail({
333404 ) : null }
334405 </ >
335406 ) : null }
407+ { npmPackage ? (
408+ < >
409+ < DetailField
410+ first = { manifest === null }
411+ label = "Package"
412+ value = { describePluginNpmSource ( npmPackage ) }
413+ />
414+ < DetailField
415+ label = "Integrity"
416+ value = { `${ npmPackage . source . integrity } \n${ PLUGIN_NPM_INTEGRITY_STATEMENT } ` }
417+ mono
418+ />
419+ </ >
420+ ) : provenance . _tag === "unknown" ? (
421+ < DetailField
422+ first = { manifest === null }
423+ label = "Package"
424+ value = {
425+ npm . state . _tag === "failed"
426+ ? "Not known: where it came from did not load"
427+ : "Checking where it came from…"
428+ }
429+ />
430+ ) : null }
336431 < DetailField
337432 first = { manifest === null }
338433 label = { `Directory on ${ label } ` }
@@ -361,6 +456,17 @@ function PluginDetail({
361456 < DetailField label = "Problem" value = { installation . problem } />
362457 ) : null }
363458 </ SettingsSection >
459+ { npm . state . _tag === "failed" ? (
460+ < SettingsSection title = "npm package" >
461+ < Text selectable className = "p-4 text-base text-danger-foreground" >
462+ { npm . state . message }
463+ </ Text >
464+ < View className = "border-t border-border-subtle" >
465+ < SettingsActionRow icon = "arrow.clockwise" label = "Retry" onPress = { npm . refresh } />
466+ </ View >
467+ </ SettingsSection >
468+ ) : null }
469+
364470 < ViewOnlyNotice />
365471 </ ScrollView >
366472 </ SettingsScreen >
0 commit comments