diff --git a/lib/router.dart b/lib/router.dart index dbe56a0..99eabb9 100644 --- a/lib/router.dart +++ b/lib/router.dart @@ -20,6 +20,7 @@ import 'package:git_touch/screens/gt_object.dart'; import 'package:git_touch/screens/gt_orgs.dart'; import 'package:git_touch/screens/gt_repo.dart'; import 'package:git_touch/screens/gt_repos.dart'; +import 'package:git_touch/screens/gt_status.dart'; import 'package:git_touch/screens/gt_user.dart'; import 'package:git_touch/screens/gl_blob.dart'; import 'package:git_touch/screens/gl_commits.dart'; @@ -264,6 +265,7 @@ class GitlabRouter { class GiteaRouter { static const prefix = '/gitea'; static final routes = [ + GiteaRouter.status, GiteaRouter.user, GiteaRouter.repo, GiteaRouter.object, @@ -274,6 +276,8 @@ class GiteaRouter { GiteaRouter.issues, GiteaRouter.pulls, ]; + static final status = + RouterScreen('/status', (context, parameters) => GtStatusScreen()); static final user = RouterScreen('/:login', (context, p) { final login = p['login'].first; final tab = p['tab']?.first; diff --git a/lib/screens/gt_status.dart b/lib/screens/gt_status.dart new file mode 100644 index 0000000..83d77da --- /dev/null +++ b/lib/screens/gt_status.dart @@ -0,0 +1,36 @@ +import 'dart:convert'; +import 'package:flutter/material.dart'; +import 'package:flutter/widgets.dart'; +import 'package:git_touch/models/auth.dart'; +import 'package:git_touch/scaffolds/refresh_stateful.dart'; +import 'package:git_touch/widgets/blob_view.dart'; +import 'package:provider/provider.dart'; + +class GtStatusScreen extends StatelessWidget { + @override + Widget build(BuildContext context) { + return RefreshStatefulScaffold( + title: Text('Gitea status'), + fetchData: () async { + final auth = context.read(); + final res = await Future.wait([ + auth.fetchGitea('/version'), + auth.fetchGitea('/settings/attachment'), + auth.fetchGitea('/settings/api'), + auth.fetchGitea('/settings/repository'), + auth.fetchGitea('/settings/ui'), + ]); + return JsonEncoder.withIndent(' ').convert({ + ...res[0], + 'attachment': res[1], + 'api': res[2], + 'repository': res[3], + 'ui': res[4], + }); + }, + bodyBuilder: (jsonStr, _) { + return BlobView('0.json', text: jsonStr); + }, + ); + } +} diff --git a/lib/screens/gt_user.dart b/lib/screens/gt_user.dart index 5e87504..306749f 100644 --- a/lib/screens/gt_user.dart +++ b/lib/screens/gt_user.dart @@ -129,6 +129,17 @@ class GtUserScreen extends StatelessWidget { ]), ContributionWidget(weeks: p.userHeatmap), CommonStyle.border, + TableView( + hasIcon: true, + items: [ + TableViewItem( + leftIconData: Octicons.home, + text: Text('Organizations'), + url: '/gitea/$login?tab=organizations', + ), + ], + ), + CommonStyle.border, Column( children: [ for (var v in p.userRepos) @@ -145,17 +156,6 @@ class GtUserScreen extends StatelessWidget { ) ], ), - CommonStyle.border, - TableView( - hasIcon: true, - items: [ - TableViewItem( - leftIconData: Octicons.home, - text: Text('Organizations'), - url: '/gitea/$login?tab=organizations', - ), - ], - ), ], ); } else if (p.org != null) { diff --git a/lib/screens/settings.dart b/lib/screens/settings.dart index 941e10d..d06ddb5 100644 --- a/lib/screens/settings.dart +++ b/lib/screens/settings.dart @@ -19,18 +19,6 @@ class SettingsScreen extends StatefulWidget { } class _SettingsScreenState extends State { - var _version = ''; - - @override - void initState() { - super.initState(); - PackageInfo.fromPlatform().then((info) { - setState(() { - _version = info.version; - }); - }); - } - Widget _buildRightWidget(BuildContext context, bool checked) { final theme = Provider.of(context); if (!checked) return null; @@ -60,6 +48,18 @@ class _SettingsScreenState extends State { 'https://github.com/settings/connections/applications/$clientId', rightWidget: Text(auth.activeAccount.login), ), + if (auth.activeAccount.platform == PlatformType.gitea) + TableViewItem( + leftIconData: Octicons.info, + text: Text('Gitea'), + url: '/gitea/status', + rightWidget: FutureBuilder( + future: auth.fetchGitea('/version').then((v) => v['version']), + builder: (context, snapshot) { + return Text(snapshot.data ?? ''); + }, + ), + ) ]), CommonStyle.verticalGap, TableView(headerText: 'theme', items: [ @@ -143,7 +143,15 @@ class _SettingsScreenState extends State { ]), CommonStyle.verticalGap, TableView(headerText: 'about', items: [ - TableViewItem(text: Text('Version'), rightWidget: Text(_version)), + TableViewItem( + text: Text('Version'), + rightWidget: FutureBuilder( + future: + PackageInfo.fromPlatform().then((info) => info.version), + builder: (context, snapshot) { + return Text(snapshot.data ?? ''); + }, + )), TableViewItem( text: Text('Source Code'), rightWidget: Text('pd4d10/git-touch'),