diff --git a/lib/pages/settings/app.dart b/lib/pages/settings/app.dart index e190d14..a6f91f8 100644 --- a/lib/pages/settings/app.dart +++ b/lib/pages/settings/app.dart @@ -140,17 +140,6 @@ class _AppSettingsState extends State { }, actionTitle: 'Set'.tl, ).toSliver(), - _SettingPartTitle( - title: "Log".tl, - icon: Icons.error_outline, - ), - _CallbackSetting( - title: "Open Log".tl, - callback: () { - context.to(() => const LogsPage()); - }, - actionTitle: 'Open'.tl, - ).toSliver(), _SettingPartTitle( title: "User".tl, icon: Icons.person_outline, diff --git a/lib/pages/settings/debug.dart b/lib/pages/settings/debug.dart new file mode 100644 index 0000000..232861b --- /dev/null +++ b/lib/pages/settings/debug.dart @@ -0,0 +1,95 @@ +part of 'settings_page.dart'; + +class DebugPage extends StatefulWidget { + const DebugPage({super.key}); + + @override + State createState() => DebugPageState(); +} + +class DebugPageState extends State { + final controller = TextEditingController(); + + var result = ""; + + @override + Widget build(BuildContext context) { + return SmoothCustomScrollView( + slivers: [ + SliverAppbar(title: Text("Debug".tl)), + _CallbackSetting( + title: "Reload Configs", + actionTitle: "Reload", + callback: () { + ComicSourceManager().reload(); + }, + ).toSliver(), + _CallbackSetting( + title: "Open Log".tl, + callback: () { + context.to(() => const LogsPage()); + }, + actionTitle: 'Open'.tl, + ).toSliver(), + SliverToBoxAdapter( + child: Column( + children: [ + const SizedBox(height: 8), + const Text( + "JS Evaluator", + style: TextStyle(fontSize: 16), + ).toAlign(Alignment.centerLeft).paddingLeft(16), + Container( + width: double.infinity, + height: 200, + margin: const EdgeInsets.symmetric(vertical: 8, horizontal: 16), + child: TextField( + controller: controller, + maxLines: null, + expands: true, + textAlign: TextAlign.start, + textAlignVertical: TextAlignVertical.top, + decoration: InputDecoration( + border: const OutlineInputBorder(), + contentPadding: const EdgeInsets.all(8), + ), + ), + ), + TextButton( + onPressed: () { + try { + var res = JsEngine().runCode(controller.text); + setState(() { + result = res.toString(); + }); + } catch (e) { + setState(() { + result = e.toString(); + }); + } + }, + child: const Text("Run"), + ).toAlign(Alignment.centerRight).paddingRight(16), + const Text( + "Result", + style: TextStyle(fontSize: 16), + ).toAlign(Alignment.centerLeft).paddingLeft(16), + Container( + width: double.infinity, + height: 200, + margin: const EdgeInsets.symmetric(vertical: 8, horizontal: 16), + decoration: BoxDecoration( + border: Border.all(color: context.colorScheme.outline), + borderRadius: BorderRadius.circular(4), + ), + child: SingleChildScrollView( + child: Text(result).paddingAll(4), + ), + ), + ], + ), + ), + ], + ); + } +} diff --git a/lib/pages/settings/settings_page.dart b/lib/pages/settings/settings_page.dart index cb79750..2bfc02f 100644 --- a/lib/pages/settings/settings_page.dart +++ b/lib/pages/settings/settings_page.dart @@ -30,6 +30,7 @@ part 'local_favorites.dart'; part 'app.dart'; part 'about.dart'; part 'network.dart'; +part 'debug.dart'; class SettingsPage extends StatefulWidget { const SettingsPage({this.initialPage = -1, super.key}); @@ -55,6 +56,7 @@ class _SettingsPageState extends State implements PopEntry { "APP", "Network", "About", + "Debug" ]; final icons = [ @@ -64,7 +66,8 @@ class _SettingsPageState extends State implements PopEntry { Icons.collections_bookmark_rounded, Icons.apps, Icons.public, - Icons.info + Icons.info, + Icons.bug_report, ]; double offset = 0; @@ -350,6 +353,7 @@ class _SettingsPageState extends State implements PopEntry { 4 => const AppSettings(), 5 => const NetworkSettings(), 6 => const AboutSettings(), + 7 => const DebugPage(), _ => throw UnimplementedError() }; }