11import 'dart:async' ;
2+
23import 'package:flutter/foundation.dart' ;
34import 'package:flutter_riverpod/flutter_riverpod.dart' ;
45import 'package:sysadmin/providers/ssh_state.dart' ;
@@ -139,14 +140,15 @@ class ProcessMonitorNotifier extends StateNotifier<ProcessMonitorState> {
139140 final memOutput = String .fromCharCodes (memResult).trim ();
140141
141142 // For swap, we use a more efficient command
142- final swapResult = await sshClient
143- .run ('grep VmSwap /proc/[0-9]*/status 2>/dev/null | ' +
144- 'sort -nr -k2 | head -n 5 | ' +
145- 'sed -e "s/[^0-9]\\ +\\ ([0-9]\\ +\\ )[^0-9]\\ +\\ ([0-9]\\ +\\ ).*/\\ 1 \\ 2/" | ' +
146- 'while read pid swap; do comm=`cat /proc/\$ pid/comm 2>/dev/null`; echo "\$ pid \$ swap \$ comm"; done' )
147- .timeout (const Duration (seconds: 5 ), onTimeout: () {
148- throw TimeoutException ('Command timed out' );
149- });
143+ final swapResult = await sshClient.run (
144+ 'grep VmSwap /proc/[0-9]*/status 2>/dev/null | '
145+ 'sort -nr -k2 | head -n 5 | '
146+ 'sed -e "s/[^0-9]\\ +\\ ([0-9]\\ +\\ )[^0-9]\\ +\\ ([0-9]\\ +\\ ).*/\\ 1 \\ 2/" | '
147+ 'while read pid swap; do comm=`cat /proc/\$ pid/comm 2>/dev/null`; echo "\$ pid \$ swap \$ comm"; done'
148+ ).timeout (
149+ const Duration (seconds: 5 ),
150+ onTimeout: () => throw TimeoutException ('Command timed out' )
151+ );
150152
151153 if (_disposed) {
152154 _isRefreshing = false ;
@@ -170,15 +172,17 @@ class ProcessMonitorNotifier extends StateNotifier<ProcessMonitorState> {
170172 error: null ,
171173 );
172174 }
173- } catch (e) {
175+ }
176+ catch (e) {
174177 if (! _disposed) {
175178 debugPrint ('Error fetching process data: $e ' );
176179 state = state.copyWith (
177180 isLoading: false ,
178181 error: 'Failed to fetch process data' ,
179182 );
180183 }
181- } finally {
184+ }
185+ finally {
182186 _isRefreshing = false ;
183187 }
184188 }
@@ -213,7 +217,8 @@ class ProcessMonitorNotifier extends StateNotifier<ProcessMonitorState> {
213217 memoryMB: memoryMB,
214218 swapMB: 0 , // We don't have swap info here
215219 ));
216- } catch (e) {
220+ }
221+ catch (e) {
217222 debugPrint ('Error parsing process line: $line - $e ' );
218223 }
219224 }
@@ -247,7 +252,8 @@ class ProcessMonitorNotifier extends StateNotifier<ProcessMonitorState> {
247252 memoryMB: 0 , // We don't have memory info here
248253 swapMB: swapMB,
249254 ));
250- } catch (e) {
255+ }
256+ catch (e) {
251257 debugPrint ('Error parsing swap process line: $line - $e ' );
252258 }
253259 }
0 commit comments