Skip to content

Commit

Permalink
优化组件调用
Browse files Browse the repository at this point in the history
  • Loading branch information
nano71 committed Oct 10, 2024
1 parent 7bf9c01 commit 02b51f0
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
6 changes: 5 additions & 1 deletion lib/common/get.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,20 @@ Future getRecentExam() async {
}
}

Future<void> getWeek() async {
Future<void> getWeek({isPreloading = false}) async {
print("getWeek");
Response response;
try {
response = await request("get", AppConfig.getWeekUrl);
} on TimeoutException catch (e) {
print("超时");
print(e);
if (isPreloading) return;
return readConfig();
} on SocketException catch (e) {
print("连接失败");
print(e);
if (isPreloading) return;
return readConfig();
}
Map<String, String> persistentData = Map.from(AppData.persistentData);
Expand All @@ -72,6 +74,8 @@ Future<void> getWeek() async {
if (span != null) {
weekHtml = span.text.trim();
} else {
print("getWeek End else");
if (isPreloading) return;
return readConfig();
}

Expand Down
1 change: 1 addition & 0 deletions lib/common/homeWidget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ void backgroundCallback(Uri? data) async {
}

Future<void> backstageRefresh() async {
print('backstageRefresh');
await readConfig();
await readSchedule();
await initTodaySchedule();
Expand Down
10 changes: 7 additions & 3 deletions lib/common/service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@ import 'package:workmanager/workmanager.dart';

import 'homeWidget.dart';


@pragma('vm:entry-point') // Mandatory if the App is obfuscated or using Flutter 3.1+
void callbackDispatcher() {
Workmanager().executeTask((task, inputData) {
Workmanager().executeTask((task, inputData) async {
print("执行任务: $task");
// 在这里处理你的后台任务逻辑
backstageRefresh();
try {
await backstageRefresh();
} catch (err) {
print('callbackDispatcher: ' + err.toString());
throw Exception(err);
}
// 返回 true 代表任务成功,false 代表任务失败
return Future.value(true);
});
Expand Down
2 changes: 1 addition & 1 deletion lib/pages/layout.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class _DataPreloadPageState extends State<DataPreloadPage> {
await readSchedule();
await initTodaySchedule();
await initTomorrowSchedule();
getWeek();
getWeek(isPreloading: true);
getUpdateForEveryday();
AppData.isInitialized = true;

Expand Down

0 comments on commit 02b51f0

Please sign in to comment.