Fix school browser initialization and redirect detection; improve diagnostics
This commit is contained in:
@@ -11,8 +11,13 @@ import 'navigation_policy.dart';
|
||||
import 'page_probe.dart';
|
||||
import 'timetable_adapter.dart';
|
||||
import 'exam_adapter.dart';
|
||||
import '../school_browser.dart';
|
||||
|
||||
class UndergraduateSession extends ChangeNotifier {
|
||||
UndergraduateSession({this.configureBrowser = configureSchoolBrowser});
|
||||
final SchoolBrowserConfigurator configureBrowser;
|
||||
Future<SchoolBrowserInfo>? _browserReady;
|
||||
String? browserVersion;
|
||||
static final loginUri = Uri.parse('https://eams.uestc.edu.cn/eams/');
|
||||
static const manualMessage = '请在学校网页打开课表并选择学期,然后点击导入当前课表。';
|
||||
WebViewController? _web;
|
||||
@@ -99,6 +104,12 @@ class UndergraduateSession extends ChangeNotifier {
|
||||
uri,
|
||||
isMainFrame: request.isMainFrame,
|
||||
)) {
|
||||
DiagnosticLog.instance.resourceFailure(
|
||||
'undergraduate',
|
||||
request.url,
|
||||
code: 'blocked_navigation',
|
||||
mainFrame: request.isMainFrame,
|
||||
);
|
||||
if (request.isMainFrame) {
|
||||
_failure('学校跳转未完成,请重新认证。', code: 'blocked_navigation');
|
||||
}
|
||||
@@ -129,6 +140,13 @@ class UndergraduateSession extends ChangeNotifier {
|
||||
},
|
||||
onPageFinished: _loaded,
|
||||
onWebResourceError: (error) async {
|
||||
DiagnosticLog.instance.resourceFailure(
|
||||
'undergraduate',
|
||||
error.url,
|
||||
code: 'web_resource_error',
|
||||
status: error.errorCode,
|
||||
mainFrame: error.isForMainFrame,
|
||||
);
|
||||
if (error.isForMainFrame != true || error.url == null) return;
|
||||
final g = _generation,
|
||||
d = _document,
|
||||
@@ -142,6 +160,12 @@ class UndergraduateSession extends ChangeNotifier {
|
||||
}
|
||||
},
|
||||
onHttpError: (error) async {
|
||||
DiagnosticLog.instance.resourceFailure(
|
||||
'undergraduate',
|
||||
error.request?.uri.toString(),
|
||||
code: 'http_error',
|
||||
status: error.response?.statusCode,
|
||||
);
|
||||
final g = _generation,
|
||||
d = _document,
|
||||
current = await web.currentUrl();
|
||||
@@ -202,8 +226,16 @@ class UndergraduateSession extends ChangeNotifier {
|
||||
_loading = true;
|
||||
_emit();
|
||||
try {
|
||||
await web.loadRequest(uri);
|
||||
final controller = web;
|
||||
final info = await (_browserReady ??= configureBrowser(
|
||||
controller,
|
||||
'undergraduate',
|
||||
));
|
||||
if (!_valid(g)) return;
|
||||
browserVersion = info.chromiumVersion;
|
||||
await controller.loadRequest(uri);
|
||||
} catch (_) {
|
||||
_browserReady = null;
|
||||
if (_valid(g)) _failure('学校页面打开未完成,请重试。');
|
||||
}
|
||||
}
|
||||
@@ -283,6 +315,11 @@ class UndergraduateSession extends ChangeNotifier {
|
||||
!UndergraduateNavigationPolicy.canNavigate(uri, isMainFrame: true)) {
|
||||
return;
|
||||
}
|
||||
if (!UndergraduateNavigationPolicy.isDataPage(uri)) {
|
||||
_loading = false;
|
||||
_waitForLogin();
|
||||
return;
|
||||
}
|
||||
final status = await _evidence(uri, false);
|
||||
DiagnosticLog.instance.add(
|
||||
'school_evidence',
|
||||
@@ -346,8 +383,17 @@ class UndergraduateSession extends ChangeNotifier {
|
||||
await _requestExam(g);
|
||||
}
|
||||
} catch (error) {
|
||||
final current = await web.currentUrl();
|
||||
if (_valid(g) && d == _document) {
|
||||
_failure('$error', code: error.runtimeType.toString());
|
||||
if (current != url) {
|
||||
DiagnosticLog.instance.add(
|
||||
'school_probe_stale',
|
||||
fields: {'school': 'undergraduate', 'code': 'redirect_in_progress'},
|
||||
);
|
||||
if (current != null) _schedulePoll(g, d, current);
|
||||
} else {
|
||||
_failure('$error', code: error.runtimeType.toString());
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
if (_probeKey == key) _probeKey = null;
|
||||
|
||||
Reference in New Issue
Block a user