diff --git a/lib/api/config.dart b/lib/api/config.dart index 4c7ec54..4f2c8eb 100644 --- a/lib/api/config.dart +++ b/lib/api/config.dart @@ -39,6 +39,7 @@ class Config { required this.fetchTimeout, required this.downloadTimeout, required this.ffprobePath, + required this.redirectToFlutter, }); bool cookies; @JsonKey(name: 'db_path') @@ -87,6 +88,8 @@ class Config { int downloadTimeout; @JsonKey(name: 'ffprobe_path') String ffprobePath; + @JsonKey(name: 'redirect_to_flutter') + bool redirectToFlutter; factory Config.fromJson(Map json) => _$ConfigFromJson(json); Map toJson() => _$ConfigToJson(this); } @@ -133,6 +136,7 @@ class ConfigOptional { this.fetchTimeout, this.downloadTimeout, this.ffprobePath, + this.redirectToFlutter, }); String? cookies; @JsonKey(name: 'db_path') @@ -181,6 +185,8 @@ class ConfigOptional { int? downloadTimeout; @JsonKey(name: 'ffprobe_path') String? ffprobePath; + @JsonKey(name: 'redirect_to_flutter') + bool? redirectToFlutter; factory ConfigOptional.fromJson(Map json) => _$ConfigOptionalFromJson(json); Map toJson() => _$ConfigOptionalToJson(this); diff --git a/lib/api/config.g.dart b/lib/api/config.g.dart index 1499565..83dd738 100644 --- a/lib/api/config.g.dart +++ b/lib/api/config.g.dart @@ -39,6 +39,7 @@ Config _$ConfigFromJson(Map json) => Config( fetchTimeout: json['fetch_timeout'] as int, downloadTimeout: json['download_timeout'] as int, ffprobePath: json['ffprobe_path'] as String, + redirectToFlutter: json['redirect_to_flutter'] as bool, ); Map _$ConfigToJson(Config instance) => { @@ -69,6 +70,7 @@ Map _$ConfigToJson(Config instance) => { 'fetch_timeout': instance.fetchTimeout, 'download_timeout': instance.downloadTimeout, 'ffprobe_path': instance.ffprobePath, + 'redirect_to_flutter': instance.redirectToFlutter, }; const _$ThumbnailMethodEnumMap = { @@ -120,6 +122,7 @@ ConfigOptional _$ConfigOptionalFromJson(Map json) => fetchTimeout: json['fetch_timeout'] as int?, downloadTimeout: json['download_timeout'] as int?, ffprobePath: json['ffprobe_path'] as String?, + redirectToFlutter: json['redirect_to_flutter'] as bool?, ); Map _$ConfigOptionalToJson(ConfigOptional instance) => @@ -151,4 +154,5 @@ Map _$ConfigOptionalToJson(ConfigOptional instance) => 'fetch_timeout': instance.fetchTimeout, 'download_timeout': instance.downloadTimeout, 'ffprobe_path': instance.ffprobePath, + 'redirect_to_flutter': instance.redirectToFlutter, }; diff --git a/lib/home.dart b/lib/home.dart index 1498442..353ff4a 100644 --- a/lib/home.dart +++ b/lib/home.dart @@ -8,6 +8,53 @@ import 'main.dart'; final _log = Logger("HomePage"); +class HomeDrawer extends StatelessWidget { + const HomeDrawer({Key? key}) : super(key: key); + + @override + Widget build(BuildContext context) { + return Drawer( + child: ListView( + children: [ + Row( + children: [ + Expanded(child: Container()), + IconButton( + onPressed: () => Scaffold.of(context).closeDrawer(), + icon: const Icon(Icons.close)) + ], + ), + ListTile( + leading: const Icon(Icons.collections), + title: Text(AppLocalizations.of(context)!.galleries), + onTap: () { + Scaffold.of(context).closeDrawer(); + context.push("/galleries"); + }, + ), + auth.isAdmin == true + ? ListTile( + leading: const Icon(Icons.admin_panel_settings), + title: Text(AppLocalizations.of(context)!.serverSettings), + onTap: () { + Scaffold.of(context).closeDrawer(); + context.push("/server_settings"); + }, + ) + : Container(), + ListTile( + leading: const Icon(Icons.settings), + title: Text(AppLocalizations.of(context)!.settings), + onTap: () { + Scaffold.of(context).closeDrawer(); + context.push("/settings"); + }, + ) + ], + )); + } +} + class HomePage extends HookWidget { const HomePage({Key? key}) : super(key: key); @@ -37,42 +84,7 @@ class HomePage extends HookWidget { buildMoreVertSettingsButon(context), ], ), - drawer: Drawer( - child: ListView.builder( - itemCount: 3, - itemBuilder: (context, i) { - if (i == 0) { - return Row( - children: [ - Expanded(child: Container()), - IconButton( - onPressed: () => Scaffold.of(context).closeDrawer(), - icon: const Icon(Icons.close)) - ], - ); - } - if (i == 1) { - return ListTile( - leading: const Icon(Icons.collections), - title: Text(AppLocalizations.of(context)!.galleries), - onTap: () { - Scaffold.of(context).closeDrawer(); - context.push("/galleries"); - }, - ); - } - if (i == 2) { - return ListTile( - leading: const Icon(Icons.settings), - title: Text(AppLocalizations.of(context)!.settings), - onTap: () { - Scaffold.of(context).closeDrawer(); - context.push("/settings"); - }, - ); - } - return Container(); - })), + drawer: const HomeDrawer(), body: Center( child: TextButton( child: Text('Hello World!'), diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arb index 2aa9e21..a4dda08 100644 --- a/lib/l10n/app_en.arb +++ b/lib/l10n/app_en.arb @@ -139,5 +139,6 @@ "meiliHosts": "Meilisearch server hostname for specific domains", "meiliHostsHelp": "Requests from these domains will receive the corresponding Meilisearch server hostname.", "keyIsEmpty": "Key is empty.", - "keyIsExists": "Key is exists." + "keyIsExists": "Key is exists.", + "redirectToFlutter": "Redirect to Flutter frontend when accessing the root URL." } diff --git a/lib/l10n/app_zh.arb b/lib/l10n/app_zh.arb index 27cc130..23f2739 100644 --- a/lib/l10n/app_zh.arb +++ b/lib/l10n/app_zh.arb @@ -139,5 +139,6 @@ "meiliHosts": "特定域名的 Meilisearch 服务器主机名", "meiliHostsHelp": "来自这些域的请求将收到相应的 Meilisearch 服务器主机名。", "keyIsEmpty": "键不能为空。", - "keyIsExists": "键已存在。" + "keyIsExists": "键已存在。", + "redirectToFlutter": "访问根 URL 时重定向到 flutter 前端。" } diff --git a/lib/server_settings.dart b/lib/server_settings.dart index 47c57ea..ed89f75 100644 --- a/lib/server_settings.dart +++ b/lib/server_settings.dart @@ -284,6 +284,17 @@ class _ServerSettingsPage extends State } }, label: Text(i18n.removePreviousGallery))), + _buildWithVecticalPadding(LabeledCheckbox( + value: _now.redirectToFlutter ?? _config!.redirectToFlutter, + onChanged: (b) { + if (b != null) { + setState(() { + _now.redirectToFlutter = b; + _changed = true; + }); + } + }, + label: Text(i18n.redirectToFlutter))), ])); }