Skip to content

Commit

Permalink
Add new settings
Browse files Browse the repository at this point in the history
  • Loading branch information
lifegpc committed Feb 3, 2024
1 parent 08633de commit 36b0bc3
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 38 deletions.
6 changes: 6 additions & 0 deletions lib/api/config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class Config {
required this.fetchTimeout,
required this.downloadTimeout,
required this.ffprobePath,
required this.redirectToFlutter,
});
bool cookies;
@JsonKey(name: 'db_path')
Expand Down Expand Up @@ -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<String, dynamic> json) => _$ConfigFromJson(json);
Map<String, dynamic> toJson() => _$ConfigToJson(this);
}
Expand Down Expand Up @@ -133,6 +136,7 @@ class ConfigOptional {
this.fetchTimeout,
this.downloadTimeout,
this.ffprobePath,
this.redirectToFlutter,
});
String? cookies;
@JsonKey(name: 'db_path')
Expand Down Expand Up @@ -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<String, dynamic> json) =>
_$ConfigOptionalFromJson(json);
Map<String, dynamic> toJson() => _$ConfigOptionalToJson(this);
Expand Down
4 changes: 4 additions & 0 deletions lib/api/config.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

84 changes: 48 additions & 36 deletions lib/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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: <Widget>[
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);

Expand Down Expand Up @@ -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!'),
Expand Down
3 changes: 2 additions & 1 deletion lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -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."
}
3 changes: 2 additions & 1 deletion lib/l10n/app_zh.arb
Original file line number Diff line number Diff line change
Expand Up @@ -139,5 +139,6 @@
"meiliHosts": "特定域名的 Meilisearch 服务器主机名",
"meiliHostsHelp": "来自这些域的请求将收到相应的 Meilisearch 服务器主机名。",
"keyIsEmpty": "键不能为空。",
"keyIsExists": "键已存在。"
"keyIsExists": "键已存在。",
"redirectToFlutter": "访问根 URL 时重定向到 flutter 前端。"
}
11 changes: 11 additions & 0 deletions lib/server_settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,17 @@ class _ServerSettingsPage extends State<ServerSettingsPage>
}
},
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))),
]));
}

Expand Down

0 comments on commit 36b0bc3

Please sign in to comment.