@@ -127,6 +127,8 @@ const PersistedComposerDraftsSchema = Schema.Struct({
127127 schemaVersion : Schema . Literal ( COMPOSER_DRAFTS_SCHEMA_VERSION ) ,
128128 drafts : Schema . Record ( Schema . String , ComposerDraftSchema ) ,
129129 stickyModelSelection : Schema . optional ( ModelSelectionSchema ) ,
130+ lastUsedRuntimeModeByProjectKey : Schema . optional ( Schema . Record ( Schema . String , RuntimeModeSchema ) ) ,
131+ /** @deprecated Renamed to lastUsedRuntimeModeByProjectKey. */
130132 stickyRuntimeModeByProjectKey : Schema . optional ( Schema . Record ( Schema . String , RuntimeModeSchema ) ) ,
131133 cloudAccountId : Schema . optional ( Schema . String ) ,
132134 signedOutDrafts : Schema . optional (
@@ -159,9 +161,9 @@ export const stickyComposerModelSelectionAtom = Atom.make<ModelSelection | null>
159161 Atom . withLabel ( "mobile:sticky-composer-model-selection" ) ,
160162) ;
161163
162- export const stickyComposerRuntimeModeByProjectKeyAtom = Atom . make <
164+ export const lastUsedComposerRuntimeModeByProjectKeyAtom = Atom . make <
163165 Partial < Record < string , RuntimeMode > >
164- > ( { } ) . pipe ( Atom . keepAlive , Atom . withLabel ( "mobile:sticky -composer-runtime-mode-by-project" ) ) ;
166+ > ( { } ) . pipe ( Atom . keepAlive , Atom . withLabel ( "mobile:last-used -composer-runtime-mode-by-project" ) ) ;
165167
166168interface SignedOutDrafts {
167169 readonly drafts : Record < string , ComposerDraft > ;
@@ -278,7 +280,7 @@ export function migrateLegacyNewTaskDraft(
278280export function decodePersistedComposerState ( value : unknown ) : {
279281 readonly drafts : Record < string , ComposerDraft > ;
280282 readonly stickyModelSelection : ModelSelection | null ;
281- readonly stickyRuntimeModeByProjectKey : Partial < Record < string , RuntimeMode > > ;
283+ readonly lastUsedRuntimeModeByProjectKey : Partial < Record < string , RuntimeMode > > ;
282284 readonly cloudDrafts : ComposerCloudDraftState ;
283285} {
284286 const parsed = decodePersistedComposerDraftsDocument ( value ) ;
@@ -313,8 +315,8 @@ export function decodePersistedComposerState(value: unknown): {
313315 . filter ( ( [ , draft ] ) => ! isEmptyDraft ( draft ) || ( draft . importedShareIds ?. length ?? 0 ) > 0 ) ,
314316 ) ,
315317 stickyModelSelection : parsed . stickyModelSelection ?? null ,
316- stickyRuntimeModeByProjectKey : normalizeStickyRuntimeModeByProjectKey (
317- parsed . stickyRuntimeModeByProjectKey ,
318+ lastUsedRuntimeModeByProjectKey : normalizeLastUsedRuntimeModeByProjectKey (
319+ parsed . lastUsedRuntimeModeByProjectKey ?? parsed . stickyRuntimeModeByProjectKey ,
318320 ) ,
319321 cloudDrafts : {
320322 accountId : parsed . cloudAccountId ?? null ,
@@ -337,7 +339,7 @@ export function decodePersistedComposerState(value: unknown): {
337339 } ;
338340}
339341
340- function normalizeStickyRuntimeModeByProjectKey (
342+ function normalizeLastUsedRuntimeModeByProjectKey (
341343 value : Partial < Record < string , RuntimeMode > > | undefined ,
342344) : Partial < Record < string , RuntimeMode > > {
343345 if ( ! value ) {
@@ -371,7 +373,7 @@ async function loadPersistedComposerState(): Promise<
371373 return {
372374 drafts : { } ,
373375 stickyModelSelection : null ,
374- stickyRuntimeModeByProjectKey : { } ,
376+ lastUsedRuntimeModeByProjectKey : { } ,
375377 cloudDrafts : { accountId : null , signedOut : { } } ,
376378 } ;
377379 }
@@ -392,8 +394,8 @@ async function loadPersistedComposerState(): Promise<
392394async function writePersistedComposerState (
393395 drafts : Record < string , ComposerDraft > ,
394396 stickyModelSelection : ModelSelection | null ,
395- stickyRuntimeModeByProjectKey : Partial < Record < string , RuntimeMode > > = appAtomRegistry . get (
396- stickyComposerRuntimeModeByProjectKeyAtom ,
397+ lastUsedRuntimeModeByProjectKey : Partial < Record < string , RuntimeMode > > = appAtomRegistry . get (
398+ lastUsedComposerRuntimeModeByProjectKeyAtom ,
397399 ) ,
398400 cloudDrafts = appAtomRegistry . get ( composerCloudDraftsAtom ) ,
399401) : Promise < void > {
@@ -404,17 +406,17 @@ async function writePersistedComposerState(
404406 const nonEmptyDrafts = Object . fromEntries (
405407 Object . entries ( drafts ) . filter ( ( [ , draft ] ) => ! isEmptyDraft ( draft ) ) ,
406408 ) ;
407- const stickyRuntimeModes = Object . fromEntries (
408- Object . entries ( stickyRuntimeModeByProjectKey ) . filter (
409+ const lastUsedRuntimeModes = Object . fromEntries (
410+ Object . entries ( lastUsedRuntimeModeByProjectKey ) . filter (
409411 ( entry ) : entry is [ string , RuntimeMode ] => entry [ 1 ] !== undefined ,
410412 ) ,
411413 ) ;
412414 const document = {
413415 schemaVersion : COMPOSER_DRAFTS_SCHEMA_VERSION ,
414416 drafts : nonEmptyDrafts ,
415417 ...( stickyModelSelection ? { stickyModelSelection } : { } ) ,
416- ...( Object . keys ( stickyRuntimeModes ) . length > 0
417- ? { stickyRuntimeModeByProjectKey : stickyRuntimeModes }
418+ ...( Object . keys ( lastUsedRuntimeModes ) . length > 0
419+ ? { lastUsedRuntimeModeByProjectKey : lastUsedRuntimeModes }
418420 : { } ) ,
419421 ...( cloudDrafts . accountId ? { cloudAccountId : cloudDrafts . accountId } : { } ) ,
420422 ...( Object . keys ( cloudDrafts . signedOut ) . length > 0
@@ -667,7 +669,7 @@ function schedulePersistComposerState(): void {
667669 await writePersistedComposerState (
668670 appAtomRegistry . get ( composerDraftsAtom ) ,
669671 appAtomRegistry . get ( stickyComposerModelSelectionAtom ) ,
670- appAtomRegistry . get ( stickyComposerRuntimeModeByProjectKeyAtom ) ,
672+ appAtomRegistry . get ( lastUsedComposerRuntimeModeByProjectKeyAtom ) ,
671673 ) ;
672674 persistRetryNeeded = false ;
673675 } catch ( error ) {
@@ -700,10 +702,10 @@ export function ensureComposerDraftsLoaded(): void {
700702 ) {
701703 appAtomRegistry . set ( stickyComposerModelSelectionAtom , persisted . stickyModelSelection ) ;
702704 }
703- if ( Object . keys ( persisted . stickyRuntimeModeByProjectKey ) . length > 0 ) {
704- const current = appAtomRegistry . get ( stickyComposerRuntimeModeByProjectKeyAtom ) ;
705- appAtomRegistry . set ( stickyComposerRuntimeModeByProjectKeyAtom , {
706- ...persisted . stickyRuntimeModeByProjectKey ,
705+ if ( Object . keys ( persisted . lastUsedRuntimeModeByProjectKey ) . length > 0 ) {
706+ const current = appAtomRegistry . get ( lastUsedComposerRuntimeModeByProjectKeyAtom ) ;
707+ appAtomRegistry . set ( lastUsedComposerRuntimeModeByProjectKeyAtom , {
708+ ...persisted . lastUsedRuntimeModeByProjectKey ,
707709 ...current ,
708710 } ) ;
709711 }
@@ -938,23 +940,23 @@ export function setStickyComposerModelSelection(modelSelection: ModelSelection):
938940 schedulePersistComposerState ( ) ;
939941}
940942
941- export function getStickyComposerRuntimeMode ( projectKey : string ) : RuntimeMode | null {
943+ export function getLastUsedComposerRuntimeMode ( projectKey : string ) : RuntimeMode | null {
942944 const key = projectKey . trim ( ) ;
943945 if ( key . length === 0 ) {
944946 return null ;
945947 }
946- return appAtomRegistry . get ( stickyComposerRuntimeModeByProjectKeyAtom ) [ key ] ?? null ;
948+ return appAtomRegistry . get ( lastUsedComposerRuntimeModeByProjectKeyAtom ) [ key ] ?? null ;
947949}
948950
949- export function setStickyComposerRuntimeMode (
951+ export function setLastUsedComposerRuntimeMode (
950952 projectKey : string ,
951953 runtimeMode : RuntimeMode | null | undefined ,
952954) : void {
953955 const key = projectKey . trim ( ) ;
954956 if ( key . length === 0 ) {
955957 return ;
956958 }
957- const current = appAtomRegistry . get ( stickyComposerRuntimeModeByProjectKeyAtom ) ;
959+ const current = appAtomRegistry . get ( lastUsedComposerRuntimeModeByProjectKeyAtom ) ;
958960 const nextMode = runtimeMode ?? null ;
959961 if ( ( current [ key ] ?? null ) === nextMode ) {
960962 return ;
@@ -965,7 +967,7 @@ export function setStickyComposerRuntimeMode(
965967 } else {
966968 next [ key ] = nextMode ;
967969 }
968- appAtomRegistry . set ( stickyComposerRuntimeModeByProjectKeyAtom , next ) ;
970+ appAtomRegistry . set ( lastUsedComposerRuntimeModeByProjectKeyAtom , next ) ;
969971 schedulePersistComposerState ( ) ;
970972}
971973
@@ -1569,13 +1571,13 @@ export function useStickyComposerModelSelection(): ModelSelection | null {
15691571 return selection ;
15701572}
15711573
1572- export function useStickyComposerRuntimeMode ( projectKey : string | null ) : RuntimeMode | null {
1573- const stickyByProject = useAtomValue ( stickyComposerRuntimeModeByProjectKeyAtom ) ;
1574+ export function useLastUsedComposerRuntimeMode ( projectKey : string | null ) : RuntimeMode | null {
1575+ const lastUsedByProject = useAtomValue ( lastUsedComposerRuntimeModeByProjectKeyAtom ) ;
15741576 useEffect ( ( ) => {
15751577 ensureComposerDraftsLoaded ( ) ;
15761578 } , [ ] ) ;
15771579 if ( ! projectKey ) {
15781580 return null ;
15791581 }
1580- return stickyByProject [ projectKey ] ?? null ;
1582+ return lastUsedByProject [ projectKey ] ?? null ;
15811583}
0 commit comments