mirror of
https://github.com/venera-app/venera.git
synced 2025-09-27 15:57:25 +00:00
check updates on start
This commit is contained in:
@@ -168,7 +168,8 @@
|
|||||||
"Order": "顺序",
|
"Order": "顺序",
|
||||||
"minAppVersion @version is required": "需要最低App版本 @version",
|
"minAppVersion @version is required": "需要最低App版本 @version",
|
||||||
"Remove": "移除",
|
"Remove": "移除",
|
||||||
"Long press to zoom": "长按缩放"
|
"Long press to zoom": "长按缩放",
|
||||||
|
"Updates Available": "更新可用"
|
||||||
},
|
},
|
||||||
"zh_TW": {
|
"zh_TW": {
|
||||||
"Home": "首頁",
|
"Home": "首頁",
|
||||||
@@ -339,6 +340,7 @@
|
|||||||
"Order": "順序",
|
"Order": "順序",
|
||||||
"minAppVersion @version is required": "需要最低App版本 @version",
|
"minAppVersion @version is required": "需要最低App版本 @version",
|
||||||
"Remove": "移除",
|
"Remove": "移除",
|
||||||
"Long press to zoom": "長按縮放"
|
"Long press to zoom": "長按縮放",
|
||||||
|
"Updates Available": "更新可用"
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -129,13 +129,14 @@ void showDialogMessage(BuildContext context, String title, String message) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void showConfirmDialog({
|
Future<void> showConfirmDialog({
|
||||||
required BuildContext context,
|
required BuildContext context,
|
||||||
required String title,
|
required String title,
|
||||||
required String content,
|
required String content,
|
||||||
required void Function() onConfirm,
|
required void Function() onConfirm,
|
||||||
|
String confirmText = "Confirm",
|
||||||
}) {
|
}) {
|
||||||
showDialog(
|
return showDialog(
|
||||||
context: context,
|
context: context,
|
||||||
builder: (context) => ContentDialog(
|
builder: (context) => ContentDialog(
|
||||||
title: title,
|
title: title,
|
||||||
@@ -146,7 +147,7 @@ void showConfirmDialog({
|
|||||||
context.pop();
|
context.pop();
|
||||||
onConfirm();
|
onConfirm();
|
||||||
},
|
},
|
||||||
child: Text("Confirm".tl),
|
child: Text(confirmText.tl),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
@@ -112,6 +112,7 @@ class _Settings with ChangeNotifier {
|
|||||||
'cacheSize': 2048, // in MB
|
'cacheSize': 2048, // in MB
|
||||||
'downloadThreads': 5,
|
'downloadThreads': 5,
|
||||||
'enableLongPressToZoom': true,
|
'enableLongPressToZoom': true,
|
||||||
|
'checkUpdateOnStart': true,
|
||||||
};
|
};
|
||||||
|
|
||||||
operator [](String key) {
|
operator [](String key) {
|
||||||
|
@@ -4,7 +4,9 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:flutter_localizations/flutter_localizations.dart';
|
import 'package:flutter_localizations/flutter_localizations.dart';
|
||||||
import 'package:venera/foundation/log.dart';
|
import 'package:venera/foundation/log.dart';
|
||||||
|
import 'package:venera/pages/comic_source_page.dart';
|
||||||
import 'package:venera/pages/main_page.dart';
|
import 'package:venera/pages/main_page.dart';
|
||||||
|
import 'package:venera/pages/settings/settings_page.dart';
|
||||||
import 'package:venera/utils/app_links.dart';
|
import 'package:venera/utils/app_links.dart';
|
||||||
import 'package:window_manager/window_manager.dart';
|
import 'package:window_manager/window_manager.dart';
|
||||||
import 'components/components.dart';
|
import 'components/components.dart';
|
||||||
@@ -63,6 +65,7 @@ class MyApp extends StatefulWidget {
|
|||||||
class _MyAppState extends State<MyApp> {
|
class _MyAppState extends State<MyApp> {
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
|
checkUpdates();
|
||||||
App.registerForceRebuild(forceRebuild);
|
App.registerForceRebuild(forceRebuild);
|
||||||
SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge);
|
SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge);
|
||||||
super.initState();
|
super.initState();
|
||||||
@@ -163,6 +166,22 @@ class _MyAppState extends State<MyApp> {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void checkUpdates() async {
|
||||||
|
if(!appdata.settings['checkUpdateOnStart']) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var lastCheck = appdata.implicitData['lastCheckUpdate'] ?? 0;
|
||||||
|
var now = DateTime.now().millisecondsSinceEpoch;
|
||||||
|
if(now - lastCheck < 24 * 60 * 60 * 1000) {
|
||||||
|
// return;
|
||||||
|
}
|
||||||
|
appdata.implicitData['lastCheckUpdate'] = now;
|
||||||
|
appdata.writeImplicitData();
|
||||||
|
await Future.delayed(const Duration(milliseconds: 300));
|
||||||
|
await checkUpdateUi(false);
|
||||||
|
await ComicSourcePage.checkComicSourceUpdate(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class _SystemUiProvider extends StatelessWidget {
|
class _SystemUiProvider extends StatelessWidget {
|
||||||
|
@@ -14,11 +14,11 @@ import 'package:venera/utils/translations.dart';
|
|||||||
class ComicSourcePage extends StatefulWidget {
|
class ComicSourcePage extends StatefulWidget {
|
||||||
const ComicSourcePage({super.key});
|
const ComicSourcePage({super.key});
|
||||||
|
|
||||||
static void checkComicSourceUpdate([bool showLoading = false]) async {
|
static Future<void> checkComicSourceUpdate([bool implicit = false]) async {
|
||||||
if (ComicSource.all().isEmpty) {
|
if (ComicSource.all().isEmpty) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var controller = showLoading ? showLoadingDialog(App.rootContext) : null;
|
var controller = implicit ? null : showLoadingDialog(App.rootContext);
|
||||||
var dio = AppDio();
|
var dio = AppDio();
|
||||||
var res = await dio.get<String>(
|
var res = await dio.get<String>(
|
||||||
"https://raw.githubusercontent.com/venera-app/venera-configs/master/index.json");
|
"https://raw.githubusercontent.com/venera-app/venera-configs/master/index.json");
|
||||||
@@ -40,7 +40,9 @@ class ComicSourcePage extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
controller?.close();
|
controller?.close();
|
||||||
if (shouldUpdate.isEmpty) {
|
if (shouldUpdate.isEmpty) {
|
||||||
|
if(!implicit) {
|
||||||
App.rootContext.showMessage(message: "No Update Available".tl);
|
App.rootContext.showMessage(message: "No Update Available".tl);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var msg = "";
|
var msg = "";
|
||||||
@@ -48,10 +50,11 @@ class ComicSourcePage extends StatefulWidget {
|
|||||||
msg += "${ComicSource.find(key)?.name}: v${versions[key]}\n";
|
msg += "${ComicSource.find(key)?.name}: v${versions[key]}\n";
|
||||||
}
|
}
|
||||||
msg = msg.trim();
|
msg = msg.trim();
|
||||||
showConfirmDialog(
|
await showConfirmDialog(
|
||||||
context: App.rootContext,
|
context: App.rootContext,
|
||||||
title: "Updates Available".tl,
|
title: "Updates Available".tl,
|
||||||
content: msg,
|
content: msg,
|
||||||
|
confirmText: "Update",
|
||||||
onConfirm: () {
|
onConfirm: () {
|
||||||
for (var key in shouldUpdate) {
|
for (var key in shouldUpdate) {
|
||||||
var source = ComicSource.find(key);
|
var source = ComicSource.find(key);
|
||||||
@@ -104,7 +107,7 @@ class _BodyState extends State<_Body> {
|
|||||||
child: ListTile(
|
child: ListTile(
|
||||||
leading: const Icon(Icons.update_outlined),
|
leading: const Icon(Icons.update_outlined),
|
||||||
title: Text("Check updates".tl),
|
title: Text("Check updates".tl),
|
||||||
onTap: () => ComicSourcePage.checkComicSourceUpdate(true),
|
onTap: () => ComicSourcePage.checkComicSourceUpdate(false),
|
||||||
trailing: const Icon(Icons.arrow_right),
|
trailing: const Icon(Icons.arrow_right),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
@@ -53,30 +53,7 @@ class _AboutSettingsState extends State<AboutSettings> {
|
|||||||
setState(() {
|
setState(() {
|
||||||
isCheckingUpdate = true;
|
isCheckingUpdate = true;
|
||||||
});
|
});
|
||||||
checkUpdate().then((value) {
|
checkUpdateUi().then((value) {
|
||||||
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 {
|
|
||||||
context.showMessage(message: "No new version available".tl);
|
|
||||||
}
|
|
||||||
setState(() {
|
setState(() {
|
||||||
isCheckingUpdate = false;
|
isCheckingUpdate = false;
|
||||||
});
|
});
|
||||||
@@ -108,6 +85,33 @@ Future<bool> checkUpdate() async {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> checkUpdateUi([bool showMessageIfNoUpdate = true]) async {
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// return true if version1 > version2
|
/// return true if version1 > version2
|
||||||
bool _compareVersion(String version1, String version2) {
|
bool _compareVersion(String version1, String version2) {
|
||||||
var v1 = version1.split(".");
|
var v1 = version1.split(".");
|
||||||
|
Reference in New Issue
Block a user