Files
venera/lib/pages/settings/about.dart
pkuislm a1474ca9c3 更改安卓端的文件访问方式,优化导入逻辑 (#64)
* Refactor import function & Allow import local comics without copying them to local path.

* android: use file_picker instead, support directory access for android 10

* Improve import logic

* Fix sql query.

* Add ability to remove invalid favorite items.

* Perform sort before choosing cover

* Revert changes of "use file_picker instead".

* Try catch on "check update"

* Added module 'flutter_saf'

* gitignore

* remove unsupported arch in build.gradle

* Use flutter_saf to handle android's directory and files, improve import logic.

* revert changes of 'requestLegacyExternalStorage'

* fix cbz import

* openDirectoryPlatform

* Remove double check on source folder

* use openFilePlatform

* remove unused import

* improve local comic's path handling

* bump version

* fix pubspec format

* return null when comic folder is empty
2024-11-23 11:05:00 +08:00

130 lines
3.7 KiB
Dart

part of 'settings_page.dart';
class AboutSettings extends StatefulWidget {
const AboutSettings({super.key});
@override
State<AboutSettings> createState() => _AboutSettingsState();
}
class _AboutSettingsState extends State<AboutSettings> {
bool isCheckingUpdate = false;
@override
Widget build(BuildContext context) {
return SmoothCustomScrollView(
slivers: [
SliverAppbar(title: Text("About".tl)),
SizedBox(
height: 112,
width: double.infinity,
child: Center(
child: Container(
width: 112,
height: 112,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(136),
),
clipBehavior: Clip.antiAlias,
child: const Image(
image: AssetImage("assets/app_icon.png"),
filterQuality: FilterQuality.medium,
),
),
),
).paddingTop(16).toSliver(),
Column(
children: [
const SizedBox(height: 8),
Text(
"V${App.version}",
style: const TextStyle(fontSize: 16),
),
Text("Venera is a free and open-source app for comic reading.".tl),
const SizedBox(height: 8),
],
).toSliver(),
ListTile(
title: Text("Check for updates".tl),
trailing: Button.filled(
isLoading: isCheckingUpdate,
child: Text("Check".tl),
onPressed: () {
setState(() {
isCheckingUpdate = true;
});
checkUpdateUi().then((value) {
setState(() {
isCheckingUpdate = false;
});
});
},
).fixHeight(32),
).toSliver(),
ListTile(
title: const Text("Github"),
trailing: const Icon(Icons.open_in_new),
onTap: () {
launchUrlString("https://github.com/venera-app/venera");
},
).toSliver(),
],
);
}
}
Future<bool> checkUpdate() async {
var res = await AppDio().get(
"https://raw.githubusercontent.com/venera-app/venera/refs/heads/master/pubspec.yaml");
if (res.statusCode == 200) {
var data = loadYaml(res.data);
if (data["version"] != null) {
return _compareVersion(data["version"].split("+")[0], App.version);
}
}
return false;
}
Future<void> checkUpdateUi([bool showMessageIfNoUpdate = true]) async {
try {
var value = await checkUpdate();
if (value) {
showDialog(
context: App.rootContext,
builder: (context) {
return ContentDialog(
title: "New version available".tl,
content: Text(
"A new version is available. Do you want to update now?".tl),
actions: [
Button.text(
onPressed: () {
Navigator.pop(context);
launchUrlString(
"https://github.com/venera-app/venera/releases");
},
child: Text("Update".tl),
),
],
);
});
} else if (showMessageIfNoUpdate) {
App.rootContext.showMessage(message: "No new version available".tl);
}
} catch (e, s) {
Log.error("Check Update", e.toString(), s);
}
}
/// return true if version1 > version2
bool _compareVersion(String version1, String version2) {
var v1 = version1.split(".");
var v2 = version2.split(".");
for (var i = 0; i < v1.length; i++) {
if (int.parse(v1[i]) > int.parse(v2[i])) {
return true;
}
}
return false;
}