Skip to content

Commit

Permalink
refactor: git tool
Browse files Browse the repository at this point in the history
  • Loading branch information
narumi147 committed Jan 21, 2021
1 parent e802ff7 commit 8167ee8
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 45 deletions.
20 changes: 12 additions & 8 deletions lib/components/git_tool.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ import 'package:flutter/scheduler.dart';
import 'package:github/github.dart' as github;
import 'package:path/path.dart' as pathlib;

enum GitReleaseType { app, dataset }
const String _owner = 'narumishi';
const String _appRepo = 'chaldea';
const String _datasetRepo = 'chaldea-dataset';

enum GitSource { gitee, github }

class GitRelease {
int id;
Expand Down Expand Up @@ -62,16 +66,16 @@ class GitAsset {
GitAsset({required this.name, required this.browserDownloadUrl});
}

enum GitSource { github, gitee }

const String _owner = 'narumishi';
const String _appRepo = 'chaldea';
const String _datasetRepo = 'chaldea-dataset';

class GitTool {
GitSource source;

GitTool([this.source = GitSource.github]);
GitTool([this.source = GitSource.gitee]);

GitTool.fromIndex(int? index)
: source =
(index == null || index < 0 || index >= GitSource.values.length)
? GitSource.values.first
: GitSource.values[index];

static String getReleasePageUrl(int? sourceIndex, bool appOrDataset) {
if (sourceIndex == null ||
Expand Down
54 changes: 29 additions & 25 deletions lib/modules/home/subpage/about_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,13 @@ class _AboutPageState extends State<AboutPage> {
onTap: () => jumpToLink(context, 'NGA-FGO',
'https://bbs.nga.cn/read.php?tid=24926789'),
),
if(Platform.isIOS||Platform.isMacOS)
ListTile(
title: Text('App Store评分'),
onTap: (){
launch('itms-apps://itunes.apple.com/app/id1548713491');
},
)
if (Platform.isIOS || Platform.isMacOS)
ListTile(
title: Text('App Store评分'),
onTap: () {
launch('itms-apps://itunes.apple.com/app/id1548713491');
},
)
],
),
if (kDebugMode_)
Expand Down Expand Up @@ -202,24 +202,28 @@ class _AboutPageState extends State<AboutPage> {
Future<void> checkAppUpdate() async {
// android, windows: download github releases
if (Platform.isAndroid || Platform.isWindows) {
GitTool gitTool = GitTool(GitSource.gitee);
final release = await gitTool.latestAppRelease();
String curVersion =
AppInfo.fullVersion.isEmpty ? 'Unknown' : AppInfo.fullVersion;
SimpleCancelOkDialog(
title: Text('应用更新'),
content: Text('当前版本: $curVersion\n'
'最新版本: ${release.name ?? "查询失败"}\n'
'跳转到浏览器下载'),
onTapOk: () {
if (release.targetAsset?.browserDownloadUrl?.isNotEmpty == true) {
launch(release.targetAsset.browserDownloadUrl);
} else {
launch(GitTool.getReleasePageUrl(
db.userData.appDatasetUpdateSource, true));
}
},
).show(context);
try {
GitTool gitTool = GitTool.fromIndex(db.userData.appDatasetUpdateSource);
final release = await gitTool.latestAppRelease();
String curVersion =
AppInfo.fullVersion.isEmpty ? 'Unknown' : AppInfo.fullVersion;
SimpleCancelOkDialog(
title: Text('应用更新'),
content: Text('当前版本: $curVersion\n'
'最新版本: ${release.name ?? "查询失败"}\n'
'跳转到浏览器下载'),
onTapOk: () {
if (release.targetAsset?.browserDownloadUrl?.isNotEmpty == true) {
launch(release.targetAsset.browserDownloadUrl);
} else {
launch(GitTool.getReleasePageUrl(
db.userData.appDatasetUpdateSource, true));
}
},
).show(context);
} catch (e) {
EasyLoading.showToast('Check update failed: $e');
}
} else if (Platform.isIOS || Platform.isMacOS) {
// to App Store
SimpleCancelOkDialog(
Expand Down
4 changes: 1 addition & 3 deletions lib/modules/home/subpage/dataset_manage_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -416,9 +416,7 @@ class _DatasetManagePageState extends State<DatasetManagePage> {

void downloadGamedata() {
void _downloadAsset([bool fullSize = true]) async {
int source = db.userData.appDatasetUpdateSource ?? 0;
source = (source < 0 || source >= GitSource.values.length) ? 0 : source;
final gitTool = GitTool(GitSource.values[source]);
final gitTool = GitTool.fromIndex(db.userData.appDatasetUpdateSource);
final release = await gitTool.latestDatasetRelease(fullSize);
Navigator.of(context).pop();
String fp = pathlib.join(
Expand Down
14 changes: 5 additions & 9 deletions lib/modules/statistics/game_statistics_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,11 @@ class _GameStatisticsPageState extends State<GameStatisticsPage>
return ListView(
padding: EdgeInsets.symmetric(vertical: 12),
children: [
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Checkbox(
value: includeCurItems,
onChanged: (v) => setState(() => includeCurItems = v),
),
Text('计算现有素材')
],
CheckboxListTile(
value: includeCurItems,
onChanged: (v) => setState(() => includeCurItems = v),
controlAffinity: ListTileControlAffinity.leading,
title: Text('包含现有素材'),
),
ListTile(
leading: Image(image: db.getIconImage(Item.qp)),
Expand Down

0 comments on commit 8167ee8

Please sign in to comment.