mirror of
https://github.com/venera-app/venera.git
synced 2025-09-27 15:57:25 +00:00
143 lines
4.1 KiB
Dart
143 lines
4.1 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(),
|
|
_SwitchSetting(
|
|
title: "Check for updates on startup".tl,
|
|
settingKey: "checkUpdateOnStart",
|
|
).toSliver(),
|
|
ListTile(
|
|
title: const Text("Github"),
|
|
trailing: const Icon(Icons.open_in_new),
|
|
onTap: () {
|
|
launchUrlString("https://github.com/venera-app/venera");
|
|
},
|
|
).toSliver(),
|
|
ListTile(
|
|
title: const Text("Telegram"),
|
|
trailing: const Icon(Icons.open_in_new),
|
|
onTap: () {
|
|
launchUrlString("https://t.me/venera_release");
|
|
},
|
|
).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)
|
|
.paddingHorizontal(8),
|
|
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;
|
|
}
|