mirror of
https://github.com/lollipopkit/flutter_server_box.git
synced 2025-12-17 07:14:28 +01:00
feat: Windows compatibility (#836)
* feat: win compatibility * fix * fix: uptime parse * opt.: linux uptime accuracy * fix: windows temperature fetching * opt. * opt.: powershell exec * refactor: address PR review feedback and improve code quality ### Major Improvements: - **Refactored Windows status parsing**: Broke down large `_getWindowsStatus` method into 13 smaller, focused helper methods for better maintainability and readability - **Extracted system detection logic**: Created dedicated `SystemDetector` helper class to separate OS detection concerns from ServerProvider - **Improved concurrency handling**: Implemented proper synchronization for server updates using Future-based locks to prevent race conditions ### Bug Fixes: - **Fixed CPU percentage parsing**: Removed incorrect '*100' multiplication in BSD CPU parsing (values were already percentages) - **Enhanced memory parsing**: Added validation and error handling to BSD memory fallback parsing with proper logging - **Improved uptime parsing**: Added support for multiple Windows date formats and robust error handling with validation - **Fixed division by zero**: Added safety checks in Swap.usedPercent getter ### Code Quality Enhancements: - **Added comprehensive documentation**: Documented Windows CPU counter limitations and approach - **Strengthened error handling**: Added detailed logging and validation throughout parsing methods - **Improved robustness**: Enhanced BSD CPU parsing with percentage validation and warnings - **Better separation of concerns**: Each parsing method now has single responsibility ### Files Changed: - `lib/data/helper/system_detector.dart` (new): System detection helper - `lib/data/model/server/cpu.dart`: Fixed percentage parsing and added validation - `lib/data/model/server/memory.dart`: Enhanced fallback parsing and division-by-zero protection - `lib/data/model/server/server_status_update_req.dart`: Refactored into 13 focused parsing methods - `lib/data/provider/server.dart`: Improved synchronization and extracted system detection 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * refactor: parse & shell fn struct --------- Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -9,15 +9,9 @@ import 'package:server_box/view/page/ssh/page/page.dart';
|
||||
final class SystemdPage extends StatefulWidget {
|
||||
final SpiRequiredArgs args;
|
||||
|
||||
const SystemdPage({
|
||||
super.key,
|
||||
required this.args,
|
||||
});
|
||||
const SystemdPage({super.key, required this.args});
|
||||
|
||||
static const route = AppRouteArg<void, SpiRequiredArgs>(
|
||||
page: SystemdPage.new,
|
||||
path: '/systemd',
|
||||
);
|
||||
static const route = AppRouteArg<void, SpiRequiredArgs>(page: SystemdPage.new, path: '/systemd');
|
||||
|
||||
@override
|
||||
State<SystemdPage> createState() => _SystemdPageState();
|
||||
@@ -37,9 +31,7 @@ final class _SystemdPageState extends State<SystemdPage> {
|
||||
return Scaffold(
|
||||
appBar: CustomAppBar(
|
||||
title: const Text('Systemd'),
|
||||
actions: isDesktop
|
||||
? [Btn.icon(icon: const Icon(Icons.refresh), onTap: _pro.getUnits)]
|
||||
: null,
|
||||
actions: isDesktop ? [Btn.icon(icon: const Icon(Icons.refresh), onTap: _pro.getUnits)] : null,
|
||||
),
|
||||
body: RefreshIndicator(onRefresh: _pro.getUnits, child: _buildBody()),
|
||||
);
|
||||
@@ -54,9 +46,7 @@ final class _SystemdPageState extends State<SystemdPage> {
|
||||
duration: Durations.medium1,
|
||||
curve: Curves.fastEaseInToSlowEaseOut,
|
||||
height: isBusy ? SizedLoading.medium.size : 0,
|
||||
child: isBusy
|
||||
? SizedLoading.medium
|
||||
: const SizedBox.shrink(),
|
||||
child: isBusy ? SizedLoading.medium : const SizedBox.shrink(),
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -66,35 +56,24 @@ final class _SystemdPageState extends State<SystemdPage> {
|
||||
}
|
||||
|
||||
Widget _buildUnitList(VNode<List<SystemdUnit>> units) {
|
||||
return units.listenVal(
|
||||
(units) {
|
||||
if (units.isEmpty) {
|
||||
return SliverToBoxAdapter(
|
||||
child:
|
||||
CenterGreyTitle(libL10n.empty).paddingSymmetric(horizontal: 13),
|
||||
);
|
||||
}
|
||||
return SliverList(
|
||||
delegate: SliverChildBuilderDelegate(
|
||||
(context, index) {
|
||||
final unit = units[index];
|
||||
return ListTile(
|
||||
leading: _buildScopeTag(unit.scope),
|
||||
title: unit.description != null
|
||||
? TipText(unit.name, unit.description!)
|
||||
: Text(unit.name),
|
||||
subtitle: Wrap(children: [
|
||||
_buildStateTag(unit.state),
|
||||
_buildTypeTag(unit.type),
|
||||
]).paddingOnly(top: 7),
|
||||
trailing: _buildUnitFuncs(unit),
|
||||
).cardx.paddingSymmetric(horizontal: 13);
|
||||
},
|
||||
childCount: units.length,
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
return units.listenVal((units) {
|
||||
if (units.isEmpty) {
|
||||
return SliverToBoxAdapter(child: CenterGreyTitle(libL10n.empty).paddingSymmetric(horizontal: 13));
|
||||
}
|
||||
return SliverList(
|
||||
delegate: SliverChildBuilderDelegate((context, index) {
|
||||
final unit = units[index];
|
||||
return ListTile(
|
||||
leading: _buildScopeTag(unit.scope),
|
||||
title: unit.description != null ? TipText(unit.name, unit.description!) : Text(unit.name),
|
||||
subtitle: Wrap(
|
||||
children: [_buildStateTag(unit.state), _buildTypeTag(unit.type)],
|
||||
).paddingOnly(top: 7),
|
||||
trailing: _buildUnitFuncs(unit),
|
||||
).cardx.paddingSymmetric(horizontal: 13);
|
||||
}, childCount: units.length),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
Widget _buildUnitFuncs(SystemdUnit unit) {
|
||||
@@ -128,11 +107,7 @@ final class _SystemdPageState extends State<SystemdPage> {
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||||
children: [
|
||||
Icon(func.icon, size: 19),
|
||||
const SizedBox(width: 10),
|
||||
Text(func.name.capitalize),
|
||||
],
|
||||
children: [Icon(func.icon, size: 19), const SizedBox(width: 10), Text(func.name.capitalize)],
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -155,8 +130,7 @@ final class _SystemdPageState extends State<SystemdPage> {
|
||||
color: color?.withValues(alpha: 0.7) ?? UIs.halfAlpha,
|
||||
borderRadius: BorderRadius.circular(5),
|
||||
),
|
||||
child: Text(tag, style: UIs.text11)
|
||||
.paddingSymmetric(horizontal: 5, vertical: 1),
|
||||
child: Text(tag, style: UIs.text11).paddingSymmetric(horizontal: 5, vertical: 1),
|
||||
).paddingOnly(right: noPad ? 0 : 5);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user