@@ -70,10 +70,8 @@ public class MainActivity extends AppCompatActivity implements TerminalControlle
7070 private TabLayout tabLayout ;
7171 private ViewPager2 viewPager ;
7272 private TextView versionFooter ;
73- public boolean isServerAlive = false ;
7473 private long serverUpSinceMs = 0L ; // ADFA-4466: for server_stopped uptime bucket
7574 public boolean isNegotiating = false ;
76- public DashboardFragment .SystemState currentSystemState = DashboardFragment .SystemState .NONE ;
7775 public Boolean targetServerState = null ;
7876 public String serverTransitionText = "" ;
7977 public UsageFragment usageFragment ;
@@ -134,15 +132,16 @@ public void invalidateModuleStateTrust() {
134132 * otherwise). server_stopped carries a coarse uptime bucket, never an exact duration.
135133 */
136134 private void updateServerAlive (boolean nowAlive ) {
137- if (nowAlive && !isServerAlive ) {
135+ boolean wasAlive = ServerStateRepository .get ().current ().alive ;
136+ if (nowAlive && !wasAlive ) {
138137 serverUpSinceMs = System .currentTimeMillis ();
139138 org .iiab .controller .analytics .AnalyticsClient .with (this ).logServerStarted ();
140- } else if (!nowAlive && isServerAlive ) {
139+ } else if (!nowAlive && wasAlive ) {
141140 long uptime = serverUpSinceMs > 0L ? System .currentTimeMillis () - serverUpSinceMs : -1L ;
142141 serverUpSinceMs = 0L ;
143142 org .iiab .controller .analytics .AnalyticsClient .with (this ).logServerStopped (uptime );
144143 }
145- isServerAlive = nowAlive ;
144+ // The repository is updated by the poll (checkServerStatus) right after this.
146145 }
147146
148147 public boolean isModuleStateTrusted () {
@@ -408,7 +407,7 @@ public boolean onTouch(View v, MotionEvent event) {
408407
409408 // --- QR Share Button Logic ---
410409 btnShareQr .setOnClickListener (v -> {
411- if (!isServerAlive ) {
410+ if (!ServerStateRepository . get (). current (). alive ) {
412411 if (viewPager != null ) {
413412 viewPager .setCurrentItem (1 , true );
414413 }
@@ -617,7 +616,7 @@ public void onClick(View view) {
617616 }
618617
619618 public void handleBrowseContentClick (View v ) {
620- if (!isServerAlive ) {
619+ if (!ServerStateRepository . get (). current (). alive ) {
621620 Snackbar .make (v , R .string .qr_error_no_server , Snackbar .LENGTH_LONG ).show ();
622621 return ;
623622 }
@@ -689,7 +688,7 @@ public void handleServerLaunchClick(View v) {
689688
690689 File rootfsDir = new File (getFilesDir (), "rootfs/installed-rootfs/iiab" );
691690
692- if (!isServerAlive ) {
691+ if (!ServerStateRepository . get (). current (). alive ) {
693692 addToLog (getString (R .string .log_server_booting_native ));
694693 // kernel & uptime
695694 createFakeSysData (rootfsDir );
@@ -727,7 +726,7 @@ public void onError(String error) {
727726
728727 // Fallback for Oppo/Xiaomi: Notify user if server fails to start
729728 new Handler (android .os .Looper .getMainLooper ()).postDelayed (() -> {
730- if (targetServerState != null && !isServerAlive ) {
729+ if (targetServerState != null && !ServerStateRepository . get (). current (). alive ) {
731730 Snackbar .make (v , R .string .termux_stuck_warning , Snackbar .LENGTH_LONG ).show ();
732731 }
733732 }, getResources ().getInteger (R .integer .server_snackbar_delay_ms ));
@@ -795,23 +794,19 @@ private void checkServerStatus() {
795794
796795 // ADFA-4578: evaluate + publish the SystemState at app level (every poll),
797796 // so every tab reflects the server live instead of only after visiting the
798- // Dashboard. Mirror it onto currentSystemState for the current (field) readers.
799797 final DashboardFragment .SystemState sysState = SystemStateEvaluator .evaluate (MainActivity .this , localAlive );
800798 ServerStateRepository .get ().post (ServerState .of (localAlive , sysState ));
801799
802800 // STATE MACHINE: Has the target state been reached?
803- if (targetServerState != null && isServerAlive == targetServerState ) {
801+ if (targetServerState != null && ServerStateRepository . get (). current (). alive == targetServerState ) {
804802 targetServerState = null ; // Transition complete!
805803 timeoutHandler .removeCallbacks (timeoutRunnable ); // Cancel safety net
806804 if (usageFragment != null ) runOnUiThread (() -> usageFragment .stopBtnProgress ());
807805 }
808806
809807 currentTargetUrl = localAlive ? "http://localhost:8085/home" : null ;
810808
811- runOnUiThread (() -> {
812- currentSystemState = sysState ;
813- updateUIColorsAndVisibility ();
814- });
809+ runOnUiThread (this ::updateUIColorsAndVisibility );
815810 });
816811 }
817812
0 commit comments