CH-J SM Mobileupravljanje strežnikov prek SSH
Meni
Objavljen vir

CH-J SM Mobile

Brskajte po imenikih in datotekah za določeno izdajo programa.

Prenos vir ZIP
CH-J / SM Mobile 134 datoteke
sm-mobile-20261016T050549Z-3678f2a05fa9 Dodano: · Zgrajena:
Datoteke
monitor_page.dart Dodano: Datum, ki ni zabeležen 2,9 KB · 116 vrstice
Prenesi datoteko
1import 'dart:async';
2import 'package:flutter/material.dart';
3import '../core/app_controller.dart';
4import '../l10n/strings.dart';
5import '../services/monitor.dart';
6import '../services/ssh_service.dart';
7import 'common.dart';
9class MonitorPage extends StatefulWidget {
10 final AppController controller;
11 const MonitorPage(this.controller, {super.key});
12 @override
13 State<MonitorPage> createState() => _MonitorPageState();
16class _MonitorPageState extends State<MonitorPage> {
17 final adapter = LinuxMonitor();
18 Map<String, String> metrics = {};
19 Timer? timer;
20 bool busy = false;
21 String? error;
22 @override
23 void initState() {
24 super.initState();
25 widget.controller.addListener(schedule);
26 schedule();
27 }
29 void schedule() {
30 timer?.cancel();
31 if (!widget.controller.foreground || !widget.controller.ssh.connected) {
32 adapter.cancel();
33 return;
34 }
35 refresh();
36 timer = Timer.periodic(
37 Duration(seconds: widget.controller.monitorSeconds),
38 (_) => refresh(),
39 );
40 }
42 Future<void> refresh() async {
43 if (busy ||
44 !widget.controller.foreground ||
45 !widget.controller.ssh.connected) {
46 return;
47 }
48 setState(() => busy = true);
49 try {
50 final result = await adapter.sample(widget.controller.ssh.client);
51 if (mounted && widget.controller.foreground) {
52 setState(() {
53 metrics = result;
54 error = null;
55 });
56 }
57 } catch (e) {
58 if (mounted) setState(() => error = failureCode(e));
59 } finally {
60 if (mounted) setState(() => busy = false);
61 }
62 }
64 @override
65 void dispose() {
66 timer?.cancel();
67 adapter.cancel();
68 widget.controller.removeListener(schedule);
69 super.dispose();
70 }
72 @override
73 Widget build(BuildContext context) {
74 if (!widget.controller.ssh.connected) {
75 return const PageMessage(
76 'selectServer',
77 icon: Icons.monitor_heart_outlined,
78 );
79 }
80 return ListView(
81 padding: const EdgeInsets.all(20),
82 children: [
83 Text(context.tr('backgroundNote')),
84 const SizedBox(height: 16),
85 if (busy) const LinearProgressIndicator(),
86 if (error != null) Text(context.tr(error!)),
87 for (final key in [
88 'cpu',
89 'ram',
90 'disk',
91 'uptime',
92 'load',
93 'system',
94 'release',
95 'rtt',
96 ])
97 Card(
98 child: ListTile(
99 title: Text(context.tr(key)),
100 subtitle: SelectableText(metrics[key] ?? '—'),
101 ),
102 ),
103 if (widget.controller.ssh.handshakeMs != null)
104 ListTile(
105 title: Text(context.tr('handshake')),
106 subtitle: Text('${widget.controller.ssh.handshakeMs} ms'),
107 ),
108 OutlinedButton.icon(
109 onPressed: busy ? null : refresh,
110 icon: const Icon(Icons.refresh),
111 label: Text(context.tr('refresh')),
112 ),
113 ],
114 );
115 }
SHA-256da10cb0019b1d17daf71cf709d1dff636dfe164a770677d7433dd63c18526976

CH-J Proprietary Software License 1.14 · Vir je na voljo pod CH-J Proprietary Software License 1.14. Njena razpoložljivost ne spreminja pogojev licence ali dodeljuje dodatnih pravic.

Arhiv SHA-256c486a807e4828998b9c57ab0f2e760f7980b31965fe118e89d3e1a5a2b65be65