Skip to content

Commit 015f7d3

Browse files
committed
fix(checkin): adapt themes without global formhash
Check checkin status before accessing formhash.
1 parent cf07b69 commit 015f7d3

File tree

1 file changed

+36
-18
lines changed

1 file changed

+36
-18
lines changed

lib/features/checkin/utils/do_checkin.dart

Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,15 @@ Task<CheckinResult> doCheckin(NetClientProvider netClient, CheckinFeeling feelin
3939
}
4040

4141
final document = parseHtmlDocument(resp.data as String);
42+
43+
final maybeCheckinMessage = document.querySelector('h1.mt')?.innerText;
44+
if (maybeCheckinMessage != null) {
45+
final r2 = checkCheckinResultText(maybeCheckinMessage);
46+
if (r2 != null) {
47+
return r2;
48+
}
49+
}
50+
4251
final formHashMatch = _re.firstMatch(document.body?.innerHtml ?? '');
4352
final formHash = formHashMatch?.namedGroup('FormHash');
4453
if (formHash == null) {
@@ -72,27 +81,36 @@ Task<CheckinResult> doCheckin(NetClientProvider netClient, CheckinFeeling feelin
7281
return CheckinResultOtherError(resp.data as String);
7382
}
7483

75-
if (checkInResult.contains('签到成功')) {
76-
talker.info('check in success: $checkInResult');
77-
return CheckinResultSuccess(checkInResult);
78-
}
79-
80-
if (checkInResult.contains('已经签到')) {
81-
talker.error('check in failed: already checked in today');
82-
return const CheckinResultAlreadyChecked();
83-
}
84-
85-
if (checkInResult.contains('已经过了签到时间')) {
86-
talker.error('check in failed: late in time');
87-
return const CheckinResultLateInTime();
88-
}
89-
90-
if (checkInResult.contains('签到时间还没有到')) {
91-
talker.error('check in failed: early in time');
92-
return const CheckinResultEarlyInTime();
84+
final r2 = checkCheckinResultText(checkInResult);
85+
if (r2 != null) {
86+
return r2;
9387
}
9488

9589
talker.error('check in with other error: $checkInResult');
9690
return CheckinResultOtherError(resp.data as String);
9791
});
9892
}
93+
94+
CheckinResult? checkCheckinResultText(String result) {
95+
if (result.contains('签到成功')) {
96+
talker.info('check in success: $result');
97+
return CheckinResultSuccess(result);
98+
}
99+
100+
if (result.contains('已经签到')) {
101+
talker.error('check in failed: already checked in today');
102+
return const CheckinResultAlreadyChecked();
103+
}
104+
105+
if (result.contains('已经过了签到时间')) {
106+
talker.error('check in failed: late in time');
107+
return const CheckinResultLateInTime();
108+
}
109+
110+
if (result.contains('签到时间还没有到')) {
111+
talker.error('check in failed: early in time');
112+
return const CheckinResultEarlyInTime();
113+
}
114+
115+
return null;
116+
}

0 commit comments

Comments
 (0)