@@ -409,6 +409,30 @@ function resolveRuntimeState(input: {
409409 } ;
410410}
411411
412+ // A network-accessible backend binds every interface, so a new Wi-Fi network
413+ // or DHCP lease changes only the address worth advertising, not the binding.
414+ const withCurrentAdvertisedHost = (
415+ state : RuntimeState ,
416+ networkInterfaces : DesktopNetworkInterfaces . NetworkInterfaces ,
417+ advertisedHostOverride : Option . Option < string > ,
418+ ) : RuntimeState => {
419+ if ( state . mode !== "network-accessible" ) {
420+ return state ;
421+ }
422+ const override = Option . getOrUndefined ( advertisedHostOverride ) ;
423+ const exposure = resolveDesktopServerExposure ( {
424+ mode : state . mode ,
425+ port : state . port ,
426+ networkInterfaces,
427+ ...( override ? { advertisedHostOverride : override } : { } ) ,
428+ } ) ;
429+ return {
430+ ...state ,
431+ endpointUrl : Option . fromNullishOr ( exposure . endpointUrl ) ,
432+ advertisedHost : Option . fromNullishOr ( exposure . advertisedHost ) ,
433+ } ;
434+ } ;
435+
412436const tailscaleIpv4AddressKey = (
413437 networkInterfaces : DesktopNetworkInterfaces . NetworkInterfaces ,
414438) : string =>
@@ -458,7 +482,17 @@ export const make = Effect.gen(function* () {
458482
459483 const readNetworkInterfaces = networkInterfaces . read ;
460484
461- const getState = Ref . get ( stateRef ) . pipe ( Effect . map ( toContractState ) ) ;
485+ const readCurrentState = ( currentNetworkInterfaces : DesktopNetworkInterfaces . NetworkInterfaces ) =>
486+ Ref . get ( stateRef ) . pipe (
487+ Effect . map ( ( state ) =>
488+ withCurrentAdvertisedHost ( state , currentNetworkInterfaces , config . desktopLanHostOverride ) ,
489+ ) ,
490+ ) ;
491+
492+ const getState = readNetworkInterfaces . pipe (
493+ Effect . flatMap ( readCurrentState ) ,
494+ Effect . map ( toContractState ) ,
495+ ) ;
462496 const backendConfig = Ref . get ( stateRef ) . pipe ( Effect . map ( toBackendConfig ) ) ;
463497
464498 const configureFromSettings = Effect . fn ( "desktop.serverExposure.configureFromSettings" ) (
@@ -555,8 +589,8 @@ export const make = Effect.gen(function* () {
555589 ) ;
556590
557591 const getAdvertisedEndpoints = Effect . gen ( function * ( ) {
558- const state = yield * Ref . get ( stateRef ) ;
559592 const currentNetworkInterfaces = yield * readNetworkInterfaces ;
593+ const state = yield * readCurrentState ( currentNetworkInterfaces ) ;
560594 const coreEndpoints = resolveDesktopCoreAdvertisedEndpoints ( {
561595 port : state . port ,
562596 exposure : toResolvedExposure ( state ) ,
0 commit comments