mirror of
https://github.com/lollipopkit/flutter_server_box.git
synced 2026-01-31 13:25:10 +01:00
* refactor(Settings page): Simplify the click handling logic of the cancel button * fix(backup_service): Add a cancel button in the restore backup dialog * refactor(Settings Page): Refactor the ordered list component and optimize state management - Extract the logic for building list items into a separate method to improve maintainability - Add animation effects to enhance the dragging experience - Use PageStorageKey to maintain the scroll position - Optimize the state management logic of the checkbox - Add new contributors in github_id.dart * fix: Add SafeArea to the settings page to prevent content from being obscured Add SafeArea wrapping content in multiple settings pages to prevent content from being obscured by the navigation bar on certain devices, thereby enhancing user experience * refactor: Extract file list retrieval method and optimize asynchronous loading of iOS settings page Extract the `_getEntities` method from an inline function to a class member method to enhance code readability Preload watch context and push token in the iOS settings page to avoid repeatedly creating Futures * fix: Add a `key` attribute to the ChoiceChipX component to avoid rendering issues * refactor(Settings page): Refactor the platform-related settings logic and merge the Android settings into the main page Migrate the Android platform settings from a standalone page to the main settings page, and remove redundant Android settings page files Adjust the platform setting logic, retaining only the special setting entry for the iOS platform * build: Update fl_lib dependency to v1.0.363 * feat(Settings): Add persistent disable state for cards and virtual keys Add persistent storage functionality for server detail cards and SSH virtual key disable status Modify the logic of relevant pages to support the saving and restoration of disabled states * refactor(setting): Simplify save logic and optimize file sorting performance In the settings page, remove the unnecessary `enabledList` filtering and directly save the `_order` list Optimize the sorting logic on the local file page by first retrieving the file status before proceeding with sorting * fix: Optimize data filtering and backup service error handling on the settings page Fix the data filtering logic in the settings page to only process key-value pairs with specific prefixes Add error handling to the backup service, capture and display merge failure exceptions * fix(Settings page): Fixed the issue where disabled items were not included in the order settings and asynchronously saved preference settings Fix the issue where disabled items in the virtual keyboard and service details order settings are not included in the order list Change the preference setting saving method to an asynchronous operation, and add a mounted check to prevent updating the state after the component is unmounted * refactor: Optimize the reordering logic and remove redundant sorting methods Narrow the scope of state updates in the reordering logic to only encompass the parts where data is actually modified Remove the unused sorting methods in `_local.dart` to simplify the code * refactor(view): Optimize the refresh logic of the local file page Refactor the refresh method that directly calls setState into a unified _refresh method Use the `_entitiesFuture` to cache the list of files to obtain results and avoid redundant calculations * Update lib/view/page/storage/local.dart Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --------- Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
140 lines
4.1 KiB
Dart
140 lines
4.1 KiB
Dart
import 'package:fl_lib/fl_lib.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:server_box/core/extension/context/locale.dart';
|
|
import 'package:server_box/core/utils/misc.dart';
|
|
import 'package:server_box/data/res/store.dart';
|
|
import 'package:watch_connectivity/watch_connectivity.dart';
|
|
|
|
class IosSettingsPage extends StatefulWidget {
|
|
const IosSettingsPage({super.key});
|
|
|
|
@override
|
|
State<IosSettingsPage> createState() => _IosSettingsPageState();
|
|
|
|
static const route = AppRouteNoArg(page: IosSettingsPage.new, path: '/settings/ios');
|
|
}
|
|
|
|
class _IosSettingsPageState extends State<IosSettingsPage> {
|
|
final _pushToken = ValueNotifier<String?>(null);
|
|
final wc = WatchConnectivity();
|
|
late final _watchContextFuture = _loadWatchContext();
|
|
late final _pushTokenFuture = getToken();
|
|
|
|
Future<Map<String, dynamic>?> _loadWatchContext() async {
|
|
if (!await wc.isPaired) return null;
|
|
return await wc.applicationContext;
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
super.dispose();
|
|
_pushToken.dispose();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: CustomAppBar(title: const Text('iOS')),
|
|
body: ListView(
|
|
padding: const EdgeInsets.symmetric(horizontal: 17),
|
|
children: [
|
|
_buildPushToken(),
|
|
_buildAutoUpdateHomeWidget(),
|
|
_buildWatchApp(),
|
|
].map((e) => CardX(child: e)).toList(),
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildPushToken() {
|
|
return ListTile(
|
|
title: Text(l10n.pushToken),
|
|
trailing: IconButton(
|
|
icon: const Icon(Icons.copy),
|
|
alignment: Alignment.centerRight,
|
|
padding: EdgeInsets.zero,
|
|
onPressed: () {
|
|
final val = _pushToken.value;
|
|
if (val != null) {
|
|
Pfs.copy(val);
|
|
context.showSnackBar(libL10n.success);
|
|
} else {
|
|
context.showSnackBar(libL10n.fail);
|
|
}
|
|
},
|
|
),
|
|
subtitle: FutureWidget<String?>(
|
|
future: _pushTokenFuture,
|
|
loading: const Text('...'),
|
|
error: (error, trace) => Text('${libL10n.error}: $error'),
|
|
success: (text) {
|
|
_pushToken.value = text;
|
|
return Text(text ?? 'null', style: UIs.textGrey, overflow: TextOverflow.ellipsis, maxLines: 1);
|
|
},
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildAutoUpdateHomeWidget() {
|
|
return ListTile(
|
|
title: Text(l10n.autoUpdateHomeWidget),
|
|
subtitle: Text(l10n.whenOpenApp, style: UIs.textGrey),
|
|
trailing: StoreSwitch(prop: Stores.setting.autoUpdateHomeWidget),
|
|
);
|
|
}
|
|
|
|
Widget _buildWatchApp() {
|
|
return FutureWidget(
|
|
future: _watchContextFuture,
|
|
loading: UIs.centerLoading,
|
|
error: (e, trace) {
|
|
Loggers.app.warning('WatchOS error', e, trace);
|
|
return ListTile(
|
|
title: const Text('Watch app'),
|
|
subtitle: Text('${libL10n.error}: $e', style: UIs.textGrey),
|
|
);
|
|
},
|
|
success: (ctx) {
|
|
if (ctx == null) {
|
|
return ListTile(
|
|
title: const Text('Watch app'),
|
|
subtitle: Text(l10n.watchNotPaired, style: UIs.textGrey),
|
|
);
|
|
}
|
|
return ListTile(
|
|
title: const Text('Watch app'),
|
|
trailing: const Icon(Icons.keyboard_arrow_right),
|
|
onTap: () async => _onTapWatchApp(ctx),
|
|
);
|
|
},
|
|
);
|
|
}
|
|
|
|
void _onTapWatchApp(Map<String, dynamic> map) async {
|
|
final cfgs = List<String>.from(map['urls'] as List? ?? []);
|
|
final result = await JsonListEditor.route.go(context, JsonListEditorArgs(data: cfgs));
|
|
if (result == null) return;
|
|
|
|
final (_, err) = await context.showLoadingDialog(
|
|
fn: () async {
|
|
final data = {'urls': result};
|
|
// Try realtime update (app must be running foreground).
|
|
try {
|
|
if (await wc.isReachable) {
|
|
await wc.sendMessage(data);
|
|
return;
|
|
}
|
|
} catch (e) {
|
|
Loggers.app.warning('Failed to send message to watch', e);
|
|
}
|
|
|
|
// fallback
|
|
await wc.updateApplicationContext(data);
|
|
},
|
|
);
|
|
if (err == null) {
|
|
context.showSnackBar(libL10n.success);
|
|
}
|
|
}
|
|
}
|