fix: automate graduate timetable read and refine blue glass Dock
This commit is contained in:
@@ -12,3 +12,5 @@ artifacts/*.xml
|
|||||||
artifacts/emulator-*.txt
|
artifacts/emulator-*.txt
|
||||||
artifacts/screenshots/probe-state*.png
|
artifacts/screenshots/probe-state*.png
|
||||||
artifacts/reference-video/
|
artifacts/reference-video/
|
||||||
|
|
||||||
|
artifacts/rschedule-gles-probe.apk
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
# RSchedule
|
# RSchedule
|
||||||
|
|
||||||
电子科技大学研究生课表 APP,Flutter 实现,Android 0.3.0+4,Android 7.0 及以上。
|
电子科技大学研究生课表 APP,Flutter 实现,Android 0.3.1+5,Android 7.0 及以上。
|
||||||
|
|
||||||
三个图标标签页:课表、考试、个人设置。透明蓝色液态玻璃风格悬浮 Dock 支持点击图标或拖动选中滑块切换;按压放大、拖动拉伸、松手弹簧回弹。页面切换采用短距离移动与淡入淡出,并保留每页滚动位置。页面本身不支持左右滑动切换。课表和考试页面向下滚动隐藏 Dock,向上滚动恢复;个人设置页面保持显示。系统“减少动画”开启时减少切页与回弹动画。
|
三个图标标签页:课表、考试、个人设置。界面统一蓝色,三个页面标题对齐。透明蓝色液态玻璃风格悬浮 Dock 缩窄至264,选中滑块与图标为灰色,静止边距为3。支持点击图标或拖动选中滑块切换;按压和拖动时放大、松手弹簧回弹,支持的渲染模式启用实时背景折射。页面切换采用短距离移动与淡入淡出,并保留每页滚动位置。页面本身不支持左右滑动切换。课表和考试页面向下滚动时 Dock 用360ms过渡滑出屏幕底部,向上滚动恢复;个人设置页面保持显示。系统“减少动画”开启时减少切页与回弹动画。
|
||||||
|
|
||||||
课表周一至周日固定七列同屏,无横向滚动。同节数课程条等长;课程名可省略,老师和教室完整换行,点击查看全部信息。课程条默认长度125%,在「个人设置 → 课表设置 → 课程条长度」调节80%–200%。课前提醒、手机日历及学期设置继续保留。
|
课表周一至周日固定七列同屏,无横向滚动。同节数课程条等长;课程名可省略,老师和教室完整换行,点击查看全部信息。课程条默认长度125%,在「个人设置 → 课表设置 → 课程条长度」调节80%–200%。课前提醒、手机日历及学期设置继续保留。
|
||||||
|
|
||||||
@@ -41,4 +41,4 @@ flutter test
|
|||||||
flutter analyze
|
flutter analyze
|
||||||
```
|
```
|
||||||
|
|
||||||
仓库根目录运行 `./scripts/build-android.ps1` 构建。验证记录:[0.3.0登录、考试和动画](docs/rschedule-0.3-validation.md)。Windows模拟器可仅在测试启动时使用软件渲染并关闭Impeller;交付APK保留手机默认渲染配置。历史验证:[0.2.1](docs/blue-glass-and-course-length.md)、[0.2.0](docs/riverside-revision-validation.md)、[首版](docs/android-mvp-validation.md)。
|
仓库根目录运行 `./scripts/build-android.ps1` 构建。验证记录:[0.3.1自动读取与玻璃动画修正](docs/rschedule-0.3.1-validation.md)、[0.3.0登录、考试和动画](docs/rschedule-0.3-validation.md)。Windows模拟器可仅在测试启动时使用软件渲染并关闭Impeller;交付APK保留手机默认渲染配置。历史验证:[0.2.1](docs/blue-glass-and-course-length.md)、[0.2.0](docs/riverside-revision-validation.md)、[首版](docs/android-mvp-validation.md)。
|
||||||
|
|||||||
@@ -0,0 +1,38 @@
|
|||||||
|
# RSchedule 0.3.1+5 · 自动读取与玻璃动画修正
|
||||||
|
|
||||||
|
2026-10-13。
|
||||||
|
|
||||||
|
## 登录自动读取
|
||||||
|
|
||||||
|
原判断假设真实研究生系统存在href为/pyxx/home/exit的退出链接。两个实际附件均没有该链接;实际使用window.logout()函数,且有navbar与main-container页面节点。旧版因此未触发自动跳转。
|
||||||
|
|
||||||
|
新流程在学生完成统一认证后检测真实研究生页面结构和logout函数,自动进入课表查询、等待表格就绪并导入。支持/pyxx根首页、HTTP研究生回调、异步表格和同源内嵌页面;每750ms检测,45秒内有界等待。学生只需完成学校登录和验证码,不需要手动进入课表。读取当前页面仅为恢复入口。
|
||||||
|
|
||||||
|
只读取可信学校文档中的选中学期和已识别表格片段,排除密码页和跨源文档,保持原严格解析器。旧导航、旧读取、旧网络失败和关闭页面后的结果均失效;已有数据不会被残缺表格覆盖。
|
||||||
|
|
||||||
|
## 外观与交互
|
||||||
|
|
||||||
|
- 三个页面统一蓝色主色、浅蓝背景和深蓝文本。课表标题左边距8+14=22,与其他两页一致;七天网格宽度保留。
|
||||||
|
- Dock宽度280→264,高度68,静止滑块边距3。选中态浅灰,未选中部分透明玻璃。
|
||||||
|
- 按压、拖动时滑块放大约18%–20%,随速度拉伸,并用弹簧回弹;滑块能在交互时高于Dock,不被底座裁切。
|
||||||
|
- 滑块交互时提高透明感,实时背景滤镜弯曲边缘采样、轻微放大中部并模拟色散和反光。图标位于滤镜上方。
|
||||||
|
- 向下隐藏使用360ms缓入缓出滑出屏幕底部,取消过早淡出;向上滚动滑回。页面仍不支持横向滑动切页。
|
||||||
|
|
||||||
|
设计参考:[苹果iOS27](https://www.apple.com/os/ios/)、[苹果液态玻璃指南](https://developer.apple.com/documentation/technologyoverviews/adopting-liquid-glass)、[苹果Tab bar指南](https://developer.apple.com/design/human-interface-guidelines/tab-bars),以及用户视频。
|
||||||
|
|
||||||
|
## 验证
|
||||||
|
|
||||||
|
- 合并后的107项Flutter测试通过,flutter analyze无问题,安卓构建成功。
|
||||||
|
- 新回归覆盖:无退出链接但有logout函数时自动跳转;异步表格等待;嵌入表格读取;退出/关闭/重新打开的旧结果隔离;HTTP同源子页面;自动导航失败不影响新草稿。
|
||||||
|
- Node独立执行原生产网页检测脚本,验证真实选中学期序列化、根首页、嵌套同源文档、密码排除与源校验。
|
||||||
|
- 两个真实附件的解析仍正确:11条课程安排、8门未排考课程。
|
||||||
|
- 动画测试检查按压放大、松手恢复、隐藏过程仍可见且位置向下移动;折射像素测试用实际图像纹理验证边缘像素改变且中心保持稳定。
|
||||||
|
- Android兼容渲染模式实际截图保存在dist/screenshots/rschedule-week.png、rschedule-exams.png、rschedule-profile.png、rschedule-dock-held.png。
|
||||||
|
|
||||||
|
## 验证范围
|
||||||
|
|
||||||
|
学生真实账户和验证码未由代理填写,真实认证后的端到端流程仍需学生本人验证。已修复确定的错误选择器,并通过真实HTML、网页脚本及会话流程回归验证。
|
||||||
|
|
||||||
|
实时折射使用Flutter ImageFilter.shader,要求支持Impeller。其他模式保留透明玻璃高光与轻微模糊。本机Android模拟器GPU运行会导致宿主显卡进程退出;OpenGL测试模式同样无法运行,因此实际截图和原生动画复核使用兼容模式。折射算法已有真实像素测试,但真实手机GPU下的背景定位与视觉效果尚未实测。[Flutter接口限制](https://api.flutter.dev/flutter/dart-ui/ImageFilter/ImageFilter.shader.html)
|
||||||
|
|
||||||
|
测试用渲染配置已恢复,交付APK保留默认手机配置。原始HTML、视频及个人学号姓名不在源码或APK中。
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
# 学校接入状态 · RSchedule 0.3.0
|
# 学校接入状态 · RSchedule 0.3.1
|
||||||
|
|
||||||
专用入口:https://yjsjy.uestc.edu.cn/pyxx/jzsso/login。
|
专用入口:https://yjsjy.uestc.edu.cn/pyxx/jzsso/login。
|
||||||
课表查询:https://yjsjy.uestc.edu.cn/pyxx/pygl/xskbcx/index/1。
|
课表查询:https://yjsjy.uestc.edu.cn/pyxx/pygl/xskbcx/index/1。
|
||||||
@@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
旧版先打开课表或通用身份认证页面,缺少研究生系统专用 `service` 交接。2026-10-13直接核对学校入口HTTP响应,HTTPS专用入口302指向 `http://idas.uestc.edu.cn/authserver/login?service=http%3A%2F%2Fyjsjy.uestc.edu.cn%2Fpyxx%2Fjzsso%2Flogin`。安卓地址检查原先会拦截这一HTTP跳转。
|
旧版先打开课表或通用身份认证页面,缺少研究生系统专用 `service` 交接。2026-10-13直接核对学校入口HTTP响应,HTTPS专用入口302指向 `http://idas.uestc.edu.cn/authserver/login?service=http%3A%2F%2Fyjsjy.uestc.edu.cn%2Fpyxx%2Fjzsso%2Flogin`。安卓地址检查原先会拦截这一HTTP跳转。
|
||||||
|
|
||||||
现在从专用入口开始,把准确的HTTP身份认证入口升级为HTTPS,保留完整原始查询参数。移除自绘账号密码表单及JavaScript凭证注入,学生在学校WebView中完成认证和验证码。返回研究生系统且检测到其退出登录链接后自动查找目标页面;识别完整数据后保存。研究生域名的HTTP回调在Android网络配置中单独放行。其他HTTP身份认证地址不直接加载。
|
现在从专用入口开始,把准确的HTTP身份认证入口升级为HTTPS,保留完整原始查询参数。移除自绘账号密码表单及JavaScript凭证注入,学生在学校WebView中完成认证和验证码。旧版错误地查找不存在的退出链接;真实页面使用window.logout()函数。现在根据该函数及真实研究生页面结构识别登录完成,自动打开目标页面并保存完整数据,不需要学生手动进入课表。读取仅在认证页面活跃时每750ms检查一次、最多45秒,支持延迟加载和同源内嵌课表。手动读取按钮只作为故障恢复,读取当前页而非重新认证。研究生域名的HTTP回调在Android网络配置中单独放行。其他HTTP身份认证地址不直接加载。
|
||||||
|
|
||||||
导航、重新打开、退出会让旧读取失效。保存确认同时检查原页面版本和原草稿,旧结果不会删除新草稿或关闭新路由。退出操作与下一次打开串行交接,原生清理失败显示可恢复信息;迟到的网络错误必须匹配当前页面。
|
导航、重新打开、退出会让旧读取失效。保存确认同时检查原页面版本和原草稿,旧结果不会删除新草稿或关闭新路由。退出操作与下一次打开串行交接,原生清理失败显示可恢复信息;迟到的网络错误必须匹配当前页面。
|
||||||
|
|
||||||
|
|||||||
@@ -2,9 +2,9 @@ import 'package:flutter/material.dart';
|
|||||||
|
|
||||||
import '../domain/app_settings.dart';
|
import '../domain/app_settings.dart';
|
||||||
|
|
||||||
const river = Color(0xFF348F91);
|
const river = Color(0xFF007AFF);
|
||||||
const ink = Color(0xFF183F43);
|
const ink = Color(0xFF183451);
|
||||||
const canvas = Color(0xFFF3F7F6);
|
const canvas = Color(0xFFF3F7FF);
|
||||||
const coursePalette = [
|
const coursePalette = [
|
||||||
Color(0xFFDDEEEF),
|
Color(0xFFDDEEEF),
|
||||||
Color(0xFFE3E7F6),
|
Color(0xFFE3E7F6),
|
||||||
|
|||||||
@@ -231,7 +231,7 @@ class _ShellState extends State<_Shell> with WidgetsBindingObserver {
|
|||||||
gradient: LinearGradient(
|
gradient: LinearGradient(
|
||||||
begin: Alignment.topLeft,
|
begin: Alignment.topLeft,
|
||||||
end: Alignment.bottomRight,
|
end: Alignment.bottomRight,
|
||||||
colors: [Color(0xFFF0F7F5), Color(0xFFF7F8F5), Color(0xFFEFF5F3)],
|
colors: [Color(0xFFF0F6FF), Color(0xFFF7FAFF), Color(0xFFEDF4FF)],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
child: SafeArea(
|
child: SafeArea(
|
||||||
@@ -313,15 +313,11 @@ class _ShellState extends State<_Shell> with WidgetsBindingObserver {
|
|||||||
: Offset.zero,
|
: Offset.zero,
|
||||||
duration: MediaQuery.disableAnimationsOf(context)
|
duration: MediaQuery.disableAnimationsOf(context)
|
||||||
? Duration.zero
|
? Duration.zero
|
||||||
: const Duration(milliseconds: 240),
|
: const Duration(milliseconds: 360),
|
||||||
curve: Curves.easeOutCubic,
|
curve: Curves.easeInOutCubic,
|
||||||
child: AnimatedOpacity(
|
child: GlassDock(
|
||||||
opacity: _dockHidden ? 0 : 1,
|
selectedIndex: _tab,
|
||||||
duration: const Duration(milliseconds: 180),
|
onSelected: _selectTab,
|
||||||
child: GlassDock(
|
|
||||||
selectedIndex: _tab,
|
|
||||||
onSelected: _selectTab,
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -22,7 +22,11 @@ class _SchoolAuthPageState extends State<SchoolAuthPage> {
|
|||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
widget.session.addListener(_changed);
|
widget.session.addListener(_changed);
|
||||||
WidgetsBinding.instance.addPostFrameCallback((_) => _changed());
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||||
|
if (!mounted) return;
|
||||||
|
widget.session.setReadingActive(true);
|
||||||
|
_changed();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void _changed() {
|
void _changed() {
|
||||||
@@ -80,6 +84,7 @@ class _SchoolAuthPageState extends State<SchoolAuthPage> {
|
|||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
widget.session.removeListener(_changed);
|
widget.session.removeListener(_changed);
|
||||||
|
widget.session.setReadingActive(false);
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -96,10 +101,8 @@ class _SchoolAuthPageState extends State<SchoolAuthPage> {
|
|||||||
icon: const Icon(Icons.refresh_rounded),
|
icon: const Icon(Icons.refresh_rounded),
|
||||||
),
|
),
|
||||||
IconButton(
|
IconButton(
|
||||||
tooltip: '重试读取',
|
tooltip: '读取当前页面',
|
||||||
onPressed: _saving
|
onPressed: _saving ? null : s.readCurrentPage,
|
||||||
? null
|
|
||||||
: (s.requestingExams ? s.openExams : s.openTimetable),
|
|
||||||
icon: const Icon(Icons.sync_rounded),
|
icon: const Icon(Icons.sync_rounded),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -4,14 +4,17 @@ import 'school_navigation_policy.dart';
|
|||||||
class SchoolLoginFlow {
|
class SchoolLoginFlow {
|
||||||
Uri? _target;
|
Uri? _target;
|
||||||
bool _requested = false;
|
bool _requested = false;
|
||||||
|
int _attempts = 0;
|
||||||
void begin(Uri target) {
|
void begin(Uri target) {
|
||||||
_target = target;
|
_target = target;
|
||||||
_requested = false;
|
_requested = false;
|
||||||
|
_attempts = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void reset() {
|
void reset() {
|
||||||
_target = null;
|
_target = null;
|
||||||
_requested = false;
|
_requested = false;
|
||||||
|
_attempts = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
Uri? onLoaded(Uri uri, {required bool authenticated}) {
|
Uri? onLoaded(Uri uri, {required bool authenticated}) {
|
||||||
@@ -24,11 +27,13 @@ class SchoolLoginFlow {
|
|||||||
}
|
}
|
||||||
if (uri.path == _target!.path ||
|
if (uri.path == _target!.path ||
|
||||||
_requested ||
|
_requested ||
|
||||||
|
_attempts >= 2 ||
|
||||||
!authenticated ||
|
!authenticated ||
|
||||||
!uri.path.startsWith('/pyxx/')) {
|
!SchoolNavigationPolicy.isGraduatePage(uri)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
_requested = true;
|
_requested = true;
|
||||||
|
_attempts++;
|
||||||
return _target;
|
return _target;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,8 @@ class SchoolNavigationPolicy {
|
|||||||
|
|
||||||
static bool canNavigate(Uri uri, {required bool isMainFrame}) => isMainFrame
|
static bool canNavigate(Uri uri, {required bool isMainFrame}) => isMainFrame
|
||||||
? isSchoolPage(uri)
|
? isSchoolPage(uri)
|
||||||
: (uri.scheme == 'https' && uri.userInfo.isEmpty) ||
|
: isGraduatePage(uri) ||
|
||||||
|
(uri.scheme == 'https' && uri.userInfo.isEmpty) ||
|
||||||
(uri.scheme == 'about' && uri.path == 'blank');
|
(uri.scheme == 'about' && uri.path == 'blank');
|
||||||
static bool _https(Uri uri) =>
|
static bool _https(Uri uri) =>
|
||||||
uri.scheme == 'https' && uri.port == 443 && uri.userInfo.isEmpty;
|
uri.scheme == 'https' && uri.port == 443 && uri.userInfo.isEmpty;
|
||||||
@@ -43,7 +44,11 @@ class SchoolNavigationPolicy {
|
|||||||
uri.port == 80 &&
|
uri.port == 80 &&
|
||||||
uri.userInfo.isEmpty &&
|
uri.userInfo.isEmpty &&
|
||||||
uri.host == 'yjsjy.uestc.edu.cn' &&
|
uri.host == 'yjsjy.uestc.edu.cn' &&
|
||||||
uri.path.startsWith('/pyxx/'));
|
(uri.path == '/pyxx' || uri.path.startsWith('/pyxx/')));
|
||||||
|
static bool isGraduatePage(Uri uri) =>
|
||||||
|
isSchoolPage(uri) &&
|
||||||
|
uri.host == 'yjsjy.uestc.edu.cn' &&
|
||||||
|
(uri.path == '/pyxx' || uri.path.startsWith('/pyxx/'));
|
||||||
static bool isExam(Uri uri) =>
|
static bool isExam(Uri uri) =>
|
||||||
_https(uri) &&
|
_https(uri) &&
|
||||||
uri.host == 'yjsjy.uestc.edu.cn' &&
|
uri.host == 'yjsjy.uestc.edu.cn' &&
|
||||||
|
|||||||
@@ -0,0 +1,97 @@
|
|||||||
|
import 'dart:convert';
|
||||||
|
|
||||||
|
import 'school_navigation_policy.dart';
|
||||||
|
|
||||||
|
/// Only serialize recognized table fragments, never a login document.
|
||||||
|
const schoolPageProbeScript = r'''(() => {
|
||||||
|
const trusted = value => {
|
||||||
|
try {
|
||||||
|
const u = new URL(value);
|
||||||
|
return u.hostname === 'yjsjy.uestc.edu.cn' && !u.username && !u.password &&
|
||||||
|
((u.protocol === 'https:' && (!u.port || u.port === '443')) ||
|
||||||
|
(u.protocol === 'http:' && (!u.port || u.port === '80'))) &&
|
||||||
|
/^\/pyxx(?:\/|$)/.test(u.pathname);
|
||||||
|
} catch (_) { return false; }
|
||||||
|
};
|
||||||
|
const topUrl = location.href;
|
||||||
|
const result = {topUrl, authenticated: false, pages: []};
|
||||||
|
if (!trusted(topUrl) || document.querySelector('input[type="password"]')) {
|
||||||
|
return JSON.stringify(result);
|
||||||
|
}
|
||||||
|
const topOrigin = new URL(topUrl).origin;
|
||||||
|
const home = /^\/pyxx\/home\/(?:index)?\/?$/.test(location.pathname);
|
||||||
|
const chrome = document.querySelector('#navbar') && document.querySelector('#main-container');
|
||||||
|
result.authenticated = typeof window.logout === 'function' && Boolean(chrome || home);
|
||||||
|
const seen = new Set();
|
||||||
|
const visit = (doc, depth) => {
|
||||||
|
if (!doc || depth > 4 || seen.size >= 16 || seen.has(doc)) return;
|
||||||
|
seen.add(doc);
|
||||||
|
let url;
|
||||||
|
try { url = doc.location.href; } catch (_) { return; }
|
||||||
|
if (!trusted(url) || new URL(url).origin !== topOrigin ||
|
||||||
|
doc.querySelector('input[type="password"]')) return;
|
||||||
|
for (const [kind, tableId, termId] of [
|
||||||
|
['timetable', '#tbl', '#drpxq'], ['exams', '#sample-table-1', '#xqbh']
|
||||||
|
]) {
|
||||||
|
const table = doc.querySelector(tableId), term = doc.querySelector(termId);
|
||||||
|
if (!table || !term || !term.options || term.selectedIndex < 0) continue;
|
||||||
|
const selected = term.cloneNode(true);
|
||||||
|
Array.from(selected.options).forEach((option, index) => {
|
||||||
|
if (index === term.selectedIndex) option.setAttribute('selected', 'selected');
|
||||||
|
else option.removeAttribute('selected');
|
||||||
|
});
|
||||||
|
const html = selected.outerHTML + table.outerHTML;
|
||||||
|
if (html.length <= 2 * 1024 * 1024) result.pages.push({kind, url, html});
|
||||||
|
}
|
||||||
|
for (const frame of doc.querySelectorAll('iframe,frame')) {
|
||||||
|
try { visit(frame.contentDocument, depth + 1); } catch (_) {}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
visit(document, 0);
|
||||||
|
return JSON.stringify(result);
|
||||||
|
})()''';
|
||||||
|
|
||||||
|
class SchoolTableFragment {
|
||||||
|
const SchoolTableFragment(this.kind, this.url, this.html);
|
||||||
|
final String kind;
|
||||||
|
final Uri url;
|
||||||
|
final String html;
|
||||||
|
}
|
||||||
|
|
||||||
|
class SchoolPageEvidence {
|
||||||
|
const SchoolPageEvidence(this.authenticated, this.pages);
|
||||||
|
final bool authenticated;
|
||||||
|
final List<SchoolTableFragment> pages;
|
||||||
|
|
||||||
|
static SchoolPageEvidence decode(Object raw, Uri current) {
|
||||||
|
dynamic value = raw;
|
||||||
|
for (var i = 0; i < 2 && value is String; i++) {
|
||||||
|
value = jsonDecode(value);
|
||||||
|
}
|
||||||
|
if (value is! Map ||
|
||||||
|
value['topUrl'] != current.toString() ||
|
||||||
|
!SchoolNavigationPolicy.isGraduatePage(current)) {
|
||||||
|
throw const FormatException('Untrusted school page evidence');
|
||||||
|
}
|
||||||
|
final pages = <SchoolTableFragment>[];
|
||||||
|
final candidates = value['pages'];
|
||||||
|
if (candidates is List && candidates.length <= 32) {
|
||||||
|
for (final page in candidates) {
|
||||||
|
if (page is! Map || page['url'] is! String || page['html'] is! String) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
final uri = Uri.tryParse(page['url'] as String);
|
||||||
|
final content = page['html'] as String;
|
||||||
|
if (uri == null ||
|
||||||
|
!SchoolNavigationPolicy.isGraduatePage(uri) ||
|
||||||
|
uri.origin != current.origin ||
|
||||||
|
utf8.encode(content).length > 2 * 1024 * 1024 ||
|
||||||
|
!const ['timetable', 'exams'].contains(page['kind'])) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
pages.add(SchoolTableFragment(page['kind'] as String, uri, content));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return SchoolPageEvidence(value['authenticated'] == true, pages);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'dart:convert';
|
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:webview_flutter/webview_flutter.dart';
|
import 'package:webview_flutter/webview_flutter.dart';
|
||||||
@@ -10,6 +9,7 @@ import 'school_navigation_policy.dart';
|
|||||||
import 'school_page_adapter.dart';
|
import 'school_page_adapter.dart';
|
||||||
import 'school_exam_adapter.dart';
|
import 'school_exam_adapter.dart';
|
||||||
import 'school_login_flow.dart';
|
import 'school_login_flow.dart';
|
||||||
|
import 'school_page_probe.dart';
|
||||||
|
|
||||||
enum SchoolConnectionState {
|
enum SchoolConnectionState {
|
||||||
signedOut,
|
signedOut,
|
||||||
@@ -31,10 +31,13 @@ class SchoolSession extends ChangeNotifier {
|
|||||||
? null
|
? null
|
||||||
: SchoolNavigationPolicy.secureIdentityRedirect(uri);
|
: SchoolNavigationPolicy.secureIdentityRedirect(uri);
|
||||||
if (upgrade != null) {
|
if (upgrade != null) {
|
||||||
|
final generation = _pageGeneration;
|
||||||
try {
|
try {
|
||||||
await web.loadRequest(upgrade);
|
await web.loadRequest(upgrade);
|
||||||
} catch (_) {
|
} catch (_) {
|
||||||
_failure('学校身份认证暂时无法打开,请重试。');
|
if (generation == _pageGeneration) {
|
||||||
|
_failure('学校身份认证暂时无法打开,请重试。');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return NavigationDecision.prevent;
|
return NavigationDecision.prevent;
|
||||||
}
|
}
|
||||||
@@ -54,11 +57,13 @@ class SchoolSession extends ChangeNotifier {
|
|||||||
return NavigationDecision.navigate;
|
return NavigationDecision.navigate;
|
||||||
},
|
},
|
||||||
onPageStarted: (_) {
|
onPageStarted: (_) {
|
||||||
|
_poll?.cancel();
|
||||||
|
_manualRead = false;
|
||||||
_pageGeneration++;
|
_pageGeneration++;
|
||||||
_reader.invalidate();
|
_reader.invalidate();
|
||||||
pendingDraft = null;
|
pendingDraft = null;
|
||||||
pendingExams = null;
|
pendingExams = null;
|
||||||
if (!hasOpened) return;
|
if (!hasOpened || _routeClosed) return;
|
||||||
_loading = true;
|
_loading = true;
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
},
|
},
|
||||||
@@ -90,6 +95,11 @@ class SchoolSession extends ChangeNotifier {
|
|||||||
final _reader = SchoolReader(SchoolPageAdapter());
|
final _reader = SchoolReader(SchoolPageAdapter());
|
||||||
final _flow = SchoolLoginFlow();
|
final _flow = SchoolLoginFlow();
|
||||||
Timer? _timeout;
|
Timer? _timeout;
|
||||||
|
Timer? _poll;
|
||||||
|
bool _readingActive = false, _manualRead = false;
|
||||||
|
bool _routeClosed = false;
|
||||||
|
int _pollsLeft = 0;
|
||||||
|
int? _probeGeneration;
|
||||||
SchoolConnectionState connectionState = SchoolConnectionState.signedOut;
|
SchoolConnectionState connectionState = SchoolConnectionState.signedOut;
|
||||||
bool _loading = false,
|
bool _loading = false,
|
||||||
hasOpened = false,
|
hasOpened = false,
|
||||||
@@ -137,8 +147,11 @@ class SchoolSession extends ChangeNotifier {
|
|||||||
if (closing != null) await closing;
|
if (closing != null) await closing;
|
||||||
if (serial != _openSerial) return;
|
if (serial != _openSerial) return;
|
||||||
_timeout?.cancel();
|
_timeout?.cancel();
|
||||||
|
_poll?.cancel();
|
||||||
|
_manualRead = false;
|
||||||
_pageGeneration++;
|
_pageGeneration++;
|
||||||
_reader.invalidate();
|
_reader.invalidate();
|
||||||
|
final generation = _pageGeneration;
|
||||||
pendingDraft = null;
|
pendingDraft = null;
|
||||||
pendingExams = null;
|
pendingExams = null;
|
||||||
requestingExams = exams;
|
requestingExams = exams;
|
||||||
@@ -155,7 +168,9 @@ class SchoolSession extends ChangeNotifier {
|
|||||||
try {
|
try {
|
||||||
await web.loadRequest(connected ? _target : authUrl);
|
await web.loadRequest(connected ? _target : authUrl);
|
||||||
} catch (_) {
|
} catch (_) {
|
||||||
if (serial == _openSerial) _failure('学校入口无法打开,请检查校园网络后重试。');
|
if (serial == _openSerial && generation == _pageGeneration) {
|
||||||
|
_failure('学校入口无法打开,请检查校园网络后重试。');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -169,32 +184,67 @@ class SchoolSession extends ChangeNotifier {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void _failure(String text) {
|
void _failure(String text) {
|
||||||
if (!hasOpened) return;
|
if (!hasOpened || _routeClosed) return;
|
||||||
_pageGeneration++;
|
_pageGeneration++;
|
||||||
_reader.invalidate();
|
_reader.invalidate();
|
||||||
_timeout?.cancel();
|
_timeout?.cancel();
|
||||||
|
_poll?.cancel();
|
||||||
|
pendingDraft = null;
|
||||||
|
pendingExams = null;
|
||||||
finding = false;
|
finding = false;
|
||||||
_loading = false;
|
_loading = false;
|
||||||
message = text;
|
message = text;
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<String> _html() async {
|
/// Poll only while the authentication screen is open. Navigation callbacks
|
||||||
final raw = await web.runJavaScriptReturningResult(
|
/// still read immediately; polling handles scripts and frames ready later.
|
||||||
'JSON.stringify(document.documentElement.outerHTML)',
|
void setReadingActive(bool active) {
|
||||||
);
|
if (_readingActive == active && _routeClosed == !active) return;
|
||||||
final value = raw is String ? raw : raw.toString();
|
_readingActive = active;
|
||||||
try {
|
_routeClosed = !active;
|
||||||
final decoded = jsonDecode(value);
|
_poll?.cancel();
|
||||||
return decoded is String ? decoded : value;
|
if (active && hasOpened) {
|
||||||
} catch (_) {
|
web.currentUrl().then((url) {
|
||||||
return value;
|
if (_readingActive && url != null) _loaded(url);
|
||||||
|
});
|
||||||
|
} else if (!active) {
|
||||||
|
_pageGeneration++;
|
||||||
|
_reader.invalidate();
|
||||||
|
_timeout?.cancel();
|
||||||
|
pendingDraft = null;
|
||||||
|
pendingExams = null;
|
||||||
|
finding = false;
|
||||||
|
_loading = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool _truth(Object value) => value == true || value.toString() == 'true';
|
void _scheduleProbe(String url, int generation) {
|
||||||
Future<void> _loaded(String url) async {
|
if (!_readingActive ||
|
||||||
if (!hasOpened) return;
|
!hasOpened ||
|
||||||
|
generation != _pageGeneration ||
|
||||||
|
pendingDraft != null ||
|
||||||
|
pendingExams != null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_poll?.cancel();
|
||||||
|
if (_pollsLeft-- <= 0) {
|
||||||
|
if (finding) _failure('查找超时,请检查学校页面后重试。已有数据保持不变。');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_poll = Timer(const Duration(milliseconds: 750), () {
|
||||||
|
_loaded(url, resetPolling: false);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<SchoolPageEvidence> _evidence(Uri uri) async =>
|
||||||
|
SchoolPageEvidence.decode(
|
||||||
|
await web.runJavaScriptReturningResult(schoolPageProbeScript),
|
||||||
|
uri,
|
||||||
|
);
|
||||||
|
|
||||||
|
Future<void> _loaded(String url, {bool resetPolling = true}) async {
|
||||||
|
if (!hasOpened || _routeClosed) return;
|
||||||
final generation = _pageGeneration;
|
final generation = _pageGeneration;
|
||||||
final uri = Uri.tryParse(url);
|
final uri = Uri.tryParse(url);
|
||||||
final current = await web.currentUrl();
|
final current = await web.currentUrl();
|
||||||
@@ -206,6 +256,7 @@ class SchoolSession extends ChangeNotifier {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_loading = false;
|
_loading = false;
|
||||||
|
if (pendingDraft != null || pendingExams != null) return;
|
||||||
if (uri.host == 'idas.uestc.edu.cn') {
|
if (uri.host == 'idas.uestc.edu.cn') {
|
||||||
_timeout?.cancel();
|
_timeout?.cancel();
|
||||||
finding = false;
|
finding = false;
|
||||||
@@ -215,51 +266,61 @@ class SchoolSession extends ChangeNotifier {
|
|||||||
notifyListeners();
|
notifyListeners();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (!SchoolNavigationPolicy.isGraduatePage(uri) ||
|
||||||
|
_probeGeneration == generation) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (resetPolling) _pollsLeft = 60;
|
||||||
|
_probeGeneration = generation;
|
||||||
final targetPage = requestingExams
|
final targetPage = requestingExams
|
||||||
? SchoolNavigationPolicy.isExam(uri)
|
? SchoolNavigationPolicy.isExam(uri)
|
||||||
: SchoolNavigationPolicy.isTimetable(uri);
|
: SchoolNavigationPolicy.isTimetable(uri);
|
||||||
if (targetPage) {
|
if (targetPage || _manualRead) {
|
||||||
finding = true;
|
finding = true;
|
||||||
message = _findingMessage;
|
message = _findingMessage;
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
try {
|
if (_timeout?.isActive != true) _armTimeout();
|
||||||
if (requestingExams) {
|
}
|
||||||
final text = await _html();
|
try {
|
||||||
if (!hasOpened || generation != _pageGeneration) return;
|
final evidence = await _evidence(uri);
|
||||||
final draft = SchoolExamAdapter.extract(text);
|
if (!hasOpened ||
|
||||||
pendingExams = draft;
|
generation != _pageGeneration ||
|
||||||
} else {
|
await web.currentUrl() != url) {
|
||||||
final draft = await readTimetable();
|
|
||||||
if (!hasOpened || generation != _pageGeneration) return;
|
|
||||||
pendingDraft = draft;
|
|
||||||
}
|
|
||||||
_timeout?.cancel();
|
|
||||||
connectionState = SchoolConnectionState.connected;
|
|
||||||
message = '读取成功,正在保存…';
|
|
||||||
} catch (_) {
|
|
||||||
if (!hasOpened || generation != _pageGeneration) return;
|
|
||||||
_failure(
|
|
||||||
'没有读取到完整${requestingExams ? '考试信息' : '课表'},请检查学校页面后重试。已有数据保持不变。',
|
|
||||||
);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
for (final page in evidence.pages) {
|
||||||
// A logout link is evidence of a graduate-system session, unlike simply
|
if (page.kind != (requestingExams ? 'exams' : 'timetable')) continue;
|
||||||
// returning to a callback URL or the identity administration dashboard.
|
try {
|
||||||
bool authenticated = false;
|
if (requestingExams) {
|
||||||
try {
|
final draft = SchoolExamAdapter.extract(page.html);
|
||||||
authenticated = _truth(
|
if (generation != _pageGeneration) return;
|
||||||
await web.runJavaScriptReturningResult("""(() => {
|
pendingExams = draft;
|
||||||
return Array.from(document.querySelectorAll('a[href]')).some(a => {
|
} else {
|
||||||
try { const u = new URL(a.href, location.href); return u.hostname === 'yjsjy.uestc.edu.cn' && u.pathname === '/pyxx/home/exit'; } catch (_) { return false; }
|
// The probe validates the live document's origin. The strict parser
|
||||||
});
|
// gets only its recognized fragment with the canonical table path.
|
||||||
})()"""),
|
final draft = await _reader.read(
|
||||||
);
|
timetableUrl,
|
||||||
} catch (_) {
|
() async => page.html,
|
||||||
/* Keep the school page available for manual recovery. */
|
);
|
||||||
|
if (!hasOpened || generation != _pageGeneration) return;
|
||||||
|
pendingDraft = draft;
|
||||||
|
}
|
||||||
|
_timeout?.cancel();
|
||||||
|
_poll?.cancel();
|
||||||
|
connectionState = SchoolConnectionState.connected;
|
||||||
|
finding = true;
|
||||||
|
message = '读取成功,正在保存…';
|
||||||
|
notifyListeners();
|
||||||
|
return;
|
||||||
|
} catch (_) {
|
||||||
|
if (generation != _pageGeneration) return;
|
||||||
|
// A recognized table can still be incomplete during asynchronous load.
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (!hasOpened || generation != _pageGeneration) return;
|
if (!hasOpened || generation != _pageGeneration) return;
|
||||||
final next = _flow.onLoaded(uri, authenticated: authenticated);
|
final next = _manualRead
|
||||||
|
? null
|
||||||
|
: _flow.onLoaded(uri, authenticated: evidence.authenticated);
|
||||||
if (next != null) {
|
if (next != null) {
|
||||||
finding = true;
|
finding = true;
|
||||||
_loading = true;
|
_loading = true;
|
||||||
@@ -269,20 +330,54 @@ class SchoolSession extends ChangeNotifier {
|
|||||||
try {
|
try {
|
||||||
await web.loadRequest(next);
|
await web.loadRequest(next);
|
||||||
} catch (_) {
|
} catch (_) {
|
||||||
_failure('课表查询页面暂时无法打开,请重试。');
|
if (generation == _pageGeneration) {
|
||||||
|
_failure('课表查询页面暂时无法打开,请重试。');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
finding = false;
|
if (!finding) message = '请在学校网页完成认证;进入研究生系统后会自动读取。';
|
||||||
message = '请在学校网页完成认证;进入研究生系统后会自动读取。';
|
} catch (_) {
|
||||||
|
// JavaScript and frame access can fail briefly while the page is changing.
|
||||||
|
} finally {
|
||||||
|
if (_probeGeneration == generation) _probeGeneration = null;
|
||||||
|
_scheduleProbe(url, generation);
|
||||||
}
|
}
|
||||||
notifyListeners();
|
if (hasOpened && generation == _pageGeneration) notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<ImportDraft> readTimetable() async {
|
Future<ImportDraft> readTimetable() async {
|
||||||
|
final generation = _pageGeneration;
|
||||||
final uri = Uri.tryParse(await web.currentUrl() ?? '');
|
final uri = Uri.tryParse(await web.currentUrl() ?? '');
|
||||||
if (uri == null) throw UnsupportedSchoolLayout();
|
if (uri == null || !SchoolNavigationPolicy.isGraduatePage(uri)) {
|
||||||
return _reader.read(uri, _html);
|
throw UnsupportedSchoolLayout();
|
||||||
|
}
|
||||||
|
final evidence = await _evidence(uri);
|
||||||
|
if (generation != _pageGeneration ||
|
||||||
|
await web.currentUrl() != uri.toString()) {
|
||||||
|
throw UnsupportedSchoolLayout();
|
||||||
|
}
|
||||||
|
for (final page in evidence.pages) {
|
||||||
|
if (page.kind != 'timetable') continue;
|
||||||
|
try {
|
||||||
|
return await _reader.read(timetableUrl, () async => page.html);
|
||||||
|
} on UnsupportedSchoolLayout {
|
||||||
|
if (generation != _pageGeneration) rethrow;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw UnsupportedSchoolLayout();
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> readCurrentPage() async {
|
||||||
|
_poll?.cancel();
|
||||||
|
_timeout?.cancel();
|
||||||
|
_pageGeneration++;
|
||||||
|
_reader.invalidate();
|
||||||
|
pendingDraft = null;
|
||||||
|
pendingExams = null;
|
||||||
|
_manualRead = true;
|
||||||
|
final url = await web.currentUrl();
|
||||||
|
if (url != null) await _loaded(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool saved({
|
bool saved({
|
||||||
@@ -319,6 +414,7 @@ class SchoolSession extends ChangeNotifier {
|
|||||||
_reader.invalidate();
|
_reader.invalidate();
|
||||||
_flow.reset();
|
_flow.reset();
|
||||||
_timeout?.cancel();
|
_timeout?.cancel();
|
||||||
|
_poll?.cancel();
|
||||||
hasOpened = false;
|
hasOpened = false;
|
||||||
pendingDraft = null;
|
pendingDraft = null;
|
||||||
pendingExams = null;
|
pendingExams = null;
|
||||||
@@ -343,7 +439,11 @@ class SchoolSession extends ChangeNotifier {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
|
hasOpened = false;
|
||||||
|
_pageGeneration++;
|
||||||
|
_reader.invalidate();
|
||||||
_timeout?.cancel();
|
_timeout?.cancel();
|
||||||
|
_poll?.cancel();
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,12 +40,11 @@ class _TimetablePageState extends State<TimetablePage> {
|
|||||||
140 + MediaQuery.paddingOf(context).bottom,
|
140 + MediaQuery.paddingOf(context).bottom,
|
||||||
),
|
),
|
||||||
children: [
|
children: [
|
||||||
const Text(
|
const Padding(
|
||||||
'RSchedule',
|
padding: EdgeInsets.symmetric(horizontal: 14),
|
||||||
style: TextStyle(
|
child: Text(
|
||||||
fontSize: 22,
|
'RSchedule',
|
||||||
fontWeight: FontWeight.w700,
|
style: TextStyle(fontSize: 22, fontWeight: FontWeight.w700),
|
||||||
letterSpacing: -0.5,
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(height: 10),
|
const SizedBox(height: 10),
|
||||||
@@ -107,21 +106,21 @@ class _TimetablePageState extends State<TimetablePage> {
|
|||||||
vertical: 7,
|
vertical: 7,
|
||||||
),
|
),
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: const Color(0xFFF3E9D6),
|
color: const Color(0xFFE2EEFF),
|
||||||
borderRadius: BorderRadius.circular(10),
|
borderRadius: BorderRadius.circular(10),
|
||||||
),
|
),
|
||||||
child: const Text(
|
child: const Text(
|
||||||
'示例课表',
|
'示例课表',
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
fontSize: 11,
|
fontSize: 11,
|
||||||
color: Color(0xFF94733D),
|
color: Color(0xFF356AA8),
|
||||||
fontWeight: FontWeight.w600,
|
fontWeight: FontWeight.w600,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
const Text(
|
const Text(
|
||||||
'不会生成提醒或日历事件',
|
'不会生成提醒或日历事件',
|
||||||
style: TextStyle(fontSize: 10, color: Color(0xFF85928E)),
|
style: TextStyle(fontSize: 10, color: Color(0xFF8193AB)),
|
||||||
),
|
),
|
||||||
TextButton(onPressed: c.leaveDemo, child: const Text('退出示例')),
|
TextButton(onPressed: c.leaveDemo, child: const Text('退出示例')),
|
||||||
],
|
],
|
||||||
@@ -148,7 +147,7 @@ class _TimetablePageState extends State<TimetablePage> {
|
|||||||
const Icon(
|
const Icon(
|
||||||
Icons.calendar_month_outlined,
|
Icons.calendar_month_outlined,
|
||||||
size: 66,
|
size: 66,
|
||||||
color: Color(0xFFB9D6D3),
|
color: Color(0xFFB7CDF0),
|
||||||
),
|
),
|
||||||
const SizedBox(height: 22),
|
const SizedBox(height: 22),
|
||||||
const Text(
|
const Text(
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ import 'dart:ui' as ui;
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/physics.dart';
|
import 'package:flutter/physics.dart';
|
||||||
|
|
||||||
|
import 'glass_refraction.dart';
|
||||||
|
|
||||||
class GlassDock extends StatefulWidget {
|
class GlassDock extends StatefulWidget {
|
||||||
const GlassDock({
|
const GlassDock({
|
||||||
super.key,
|
super.key,
|
||||||
@@ -17,21 +19,45 @@ class GlassDock extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _GlassDockState extends State<GlassDock> with TickerProviderStateMixin {
|
class _GlassDockState extends State<GlassDock> with TickerProviderStateMixin {
|
||||||
static const _width = 280.0, _travel = 88.0;
|
static const _width = 264.0, _height = 68.0, _inset = 3.0, _travel = 86.0;
|
||||||
static const _blue = Color(0xFF007AFF);
|
static const _blue = Color(0xFF007AFF);
|
||||||
|
static const _selectedInk = Color(0xFF62666C);
|
||||||
late final AnimationController _motion = AnimationController.unbounded(
|
late final AnimationController _motion = AnimationController.unbounded(
|
||||||
vsync: this,
|
vsync: this,
|
||||||
value: widget.selectedIndex.toDouble(),
|
value: widget.selectedIndex.toDouble(),
|
||||||
);
|
);
|
||||||
late final AnimationController _press = AnimationController(
|
late final AnimationController _press = AnimationController.unbounded(
|
||||||
vsync: this,
|
vsync: this,
|
||||||
duration: const Duration(milliseconds: 140),
|
value: 0,
|
||||||
);
|
);
|
||||||
|
bool _reduceMotion = false;
|
||||||
|
double get _pressure => _press.value.clamp(0.0, 1.18);
|
||||||
|
void _pressTo(double target) {
|
||||||
|
if (_reduceMotion) {
|
||||||
|
_press.value = target;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_press.animateWith(
|
||||||
|
SpringSimulation(
|
||||||
|
const SpringDescription(mass: 1, stiffness: 440, damping: 20),
|
||||||
|
_press.value,
|
||||||
|
target,
|
||||||
|
_press.velocity,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void didChangeDependencies() {
|
||||||
|
super.didChangeDependencies();
|
||||||
|
_reduceMotion = MediaQuery.disableAnimationsOf(context);
|
||||||
|
}
|
||||||
|
|
||||||
double? _drag;
|
double? _drag;
|
||||||
double _dragSpeed = 0;
|
double _dragSpeed = 0;
|
||||||
double get _position => _drag ?? _motion.value.clamp(-0.12, 2.12);
|
double get _position => _drag ?? _motion.value.clamp(-0.12, 2.12);
|
||||||
void _spring(int index, [double velocity = 0]) {
|
void _spring(int index, [double velocity = 0]) {
|
||||||
if (MediaQuery.disableAnimationsOf(context)) {
|
if (_reduceMotion) {
|
||||||
_motion.value = index.toDouble();
|
_motion.value = index.toDouble();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -50,7 +76,7 @@ class _GlassDockState extends State<GlassDock> with TickerProviderStateMixin {
|
|||||||
setState(() => _drag = null);
|
setState(() => _drag = null);
|
||||||
_motion.value = position;
|
_motion.value = position;
|
||||||
_spring(index, velocity);
|
_spring(index, velocity);
|
||||||
_press.reverse();
|
_pressTo(0);
|
||||||
widget.onSelected(index);
|
widget.onSelected(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,53 +95,59 @@ class _GlassDockState extends State<GlassDock> with TickerProviderStateMixin {
|
|||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _glass({required Widget child, bool lens = false}) => ClipRRect(
|
Widget _glass({required Widget child, bool lens = false}) {
|
||||||
borderRadius: BorderRadius.circular(lens ? 36 : 40),
|
final pressure = _pressure.clamp(0.0, 1.0);
|
||||||
child: BackdropFilter(
|
final content = CustomPaint(
|
||||||
// Keep the underlying timetable visible. Optical rims provide the glass
|
foregroundPainter: _GlassRimPainter(lens: lens),
|
||||||
// thickness instead of a frosted, heavily tinted fill.
|
child: DecoratedBox(
|
||||||
filter: ui.ImageFilter.blur(
|
decoration: BoxDecoration(
|
||||||
sigmaX: lens ? 0.6 : 1.5,
|
gradient: LinearGradient(
|
||||||
sigmaY: lens ? 0.6 : 1.5,
|
begin: Alignment.topLeft,
|
||||||
),
|
end: Alignment.bottomRight,
|
||||||
child: CustomPaint(
|
colors: lens
|
||||||
foregroundPainter: _GlassRimPainter(lens: lens),
|
? [
|
||||||
child: DecoratedBox(
|
const Color(0xFFD8DBE0)
|
||||||
decoration: BoxDecoration(
|
.withValues(alpha: 0.72 * (1 - pressure * 0.91)),
|
||||||
gradient: LinearGradient(
|
const Color(0xFFC3C7CE)
|
||||||
begin: Alignment.topLeft,
|
.withValues(alpha: 0.60 * (1 - pressure * 0.93)),
|
||||||
end: Alignment.bottomRight,
|
const Color(0xFFE5E7EB)
|
||||||
colors: lens
|
.withValues(alpha: 0.72 * (1 - pressure * 0.90)),
|
||||||
? [
|
]
|
||||||
Colors.white.withValues(alpha: 0.045),
|
: [
|
||||||
_blue.withValues(alpha: 0.018),
|
Colors.white.withValues(alpha: 0.028),
|
||||||
Colors.white.withValues(alpha: 0.012),
|
_blue.withValues(alpha: 0.005),
|
||||||
]
|
Colors.white.withValues(alpha: 0.012),
|
||||||
: [
|
],
|
||||||
Colors.white.withValues(alpha: 0.028),
|
|
||||||
_blue.withValues(alpha: 0.005),
|
|
||||||
Colors.white.withValues(alpha: 0.012),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
child: child,
|
|
||||||
),
|
),
|
||||||
|
child: child,
|
||||||
),
|
),
|
||||||
),
|
);
|
||||||
);
|
return ClipRRect(
|
||||||
|
borderRadius: BorderRadius.circular(40),
|
||||||
|
child: lens
|
||||||
|
? GlassRefraction(strength: 0.25 + pressure * 0.95, child: content)
|
||||||
|
: BackdropFilter(
|
||||||
|
filter: ui.ImageFilter.blur(sigmaX: 1.0, sigmaY: 1.0),
|
||||||
|
child: content,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) => AnimatedBuilder(
|
Widget build(BuildContext context) => AnimatedBuilder(
|
||||||
animation: Listenable.merge([_motion, _press]),
|
animation: Listenable.merge([_motion, _press]),
|
||||||
builder: (context, _) {
|
builder: (context, _) {
|
||||||
final press = Curves.easeOut.transform(_press.value);
|
final press = _pressure;
|
||||||
final speed = (_drag != null ? _dragSpeed : _motion.velocity).abs();
|
final speed = (_drag != null ? _dragSpeed : _motion.velocity).abs();
|
||||||
final stretch = (speed / 16).clamp(0.0, 0.14) + press * 0.04;
|
final stretch = (speed / 16).clamp(0.0, 0.12) + press * 0.18;
|
||||||
final lensWidth = 88 * (1 + stretch);
|
final lensWidth = _travel * (1 + stretch);
|
||||||
final lensHeight = 56 + press * 5 - stretch * 9;
|
final lensHeight =
|
||||||
|
(_height - _inset * 2) *
|
||||||
|
(1 + press * 0.19 - (speed / 16).clamp(0.0, 0.07));
|
||||||
return SizedBox(
|
return SizedBox(
|
||||||
width: _width,
|
width: _width,
|
||||||
height: 70,
|
height: _height,
|
||||||
child: DecoratedBox(
|
child: DecoratedBox(
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
borderRadius: BorderRadius.circular(40),
|
borderRadius: BorderRadius.circular(40),
|
||||||
@@ -127,34 +159,34 @@ class _GlassDockState extends State<GlassDock> with TickerProviderStateMixin {
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
child: _glass(
|
child: Stack(
|
||||||
child: Stack(
|
clipBehavior: Clip.none,
|
||||||
clipBehavior: Clip.none,
|
children: [
|
||||||
children: [
|
Positioned.fill(child: _glass(child: const SizedBox.expand())),
|
||||||
Positioned(
|
Positioned(
|
||||||
left: 8 + _position * _travel - (lensWidth - 88) / 2,
|
left: (_inset + _position * _travel - (lensWidth - _travel) / 2)
|
||||||
top: (70 - lensHeight) / 2,
|
.clamp(1.0, _width - lensWidth - 1),
|
||||||
width: lensWidth,
|
top: (_height - lensHeight) / 2,
|
||||||
height: lensHeight,
|
width: lensWidth,
|
||||||
child: IgnorePointer(
|
height: lensHeight,
|
||||||
child: _glass(lens: true, child: const SizedBox.expand()),
|
child: IgnorePointer(
|
||||||
),
|
child: _glass(lens: true, child: const SizedBox.expand()),
|
||||||
),
|
),
|
||||||
Positioned(
|
),
|
||||||
left: 8,
|
Positioned(
|
||||||
right: 8,
|
left: _inset,
|
||||||
top: 7,
|
right: _inset,
|
||||||
bottom: 7,
|
top: _inset,
|
||||||
child: Row(
|
bottom: _inset,
|
||||||
children: [
|
child: Row(
|
||||||
_item(0, Icons.calendar_month_rounded, '课表'),
|
children: [
|
||||||
_item(1, Icons.assignment_outlined, '考试'),
|
_item(0, Icons.calendar_month_rounded, '课表'),
|
||||||
_item(2, Icons.person_rounded, '个人设置'),
|
_item(1, Icons.assignment_outlined, '考试'),
|
||||||
],
|
_item(2, Icons.person_rounded, '个人设置'),
|
||||||
),
|
],
|
||||||
),
|
),
|
||||||
],
|
),
|
||||||
),
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@@ -170,16 +202,16 @@ class _GlassDockState extends State<GlassDock> with TickerProviderStateMixin {
|
|||||||
child: GestureDetector(
|
child: GestureDetector(
|
||||||
key: index == widget.selectedIndex ? const Key('dock-cursor') : null,
|
key: index == widget.selectedIndex ? const Key('dock-cursor') : null,
|
||||||
behavior: HitTestBehavior.opaque,
|
behavior: HitTestBehavior.opaque,
|
||||||
onTapDown: (_) => _press.forward(),
|
onTapDown: (_) => _pressTo(1),
|
||||||
onTapCancel: () {
|
onTapCancel: () {
|
||||||
if (_drag == null) _press.reverse();
|
if (_drag == null) _pressTo(0);
|
||||||
},
|
},
|
||||||
onTap: () => _select(index),
|
onTap: () => _select(index),
|
||||||
onHorizontalDragStart: index == widget.selectedIndex
|
onHorizontalDragStart: index == widget.selectedIndex
|
||||||
? (_) {
|
? (_) {
|
||||||
final start = _position.clamp(0.0, 2.0);
|
final start = _position.clamp(0.0, 2.0);
|
||||||
_motion.stop();
|
_motion.stop();
|
||||||
_press.forward();
|
_pressTo(1);
|
||||||
setState(() {
|
setState(() {
|
||||||
_drag = start;
|
_drag = start;
|
||||||
_dragSpeed = 0;
|
_dragSpeed = 0;
|
||||||
@@ -203,24 +235,25 @@ class _GlassDockState extends State<GlassDock> with TickerProviderStateMixin {
|
|||||||
: null,
|
: null,
|
||||||
onHorizontalDragCancel: index == widget.selectedIndex
|
onHorizontalDragCancel: index == widget.selectedIndex
|
||||||
? () {
|
? () {
|
||||||
|
if (!mounted) return;
|
||||||
final position = _position;
|
final position = _position;
|
||||||
setState(() => _drag = null);
|
setState(() => _drag = null);
|
||||||
_motion.value = position;
|
_motion.value = position;
|
||||||
_spring(widget.selectedIndex);
|
_spring(widget.selectedIndex);
|
||||||
_press.reverse();
|
_pressTo(0);
|
||||||
}
|
}
|
||||||
: null,
|
: null,
|
||||||
child: Center(
|
child: Center(
|
||||||
child: AnimatedScale(
|
child: AnimatedScale(
|
||||||
scale: index == _position.round().clamp(0, 2)
|
scale: index == _position.round().clamp(0, 2)
|
||||||
? 1 + _press.value * 0.08
|
? 1 + _pressure * 0.08
|
||||||
: 1,
|
: 1,
|
||||||
duration: const Duration(milliseconds: 130),
|
duration: const Duration(milliseconds: 130),
|
||||||
child: Icon(
|
child: Icon(
|
||||||
icon,
|
icon,
|
||||||
size: 27,
|
size: 27,
|
||||||
color: index == _position.round().clamp(0, 2)
|
color: index == _position.round().clamp(0, 2)
|
||||||
? _blue
|
? _selectedInk
|
||||||
: _blue.withValues(alpha: 0.48),
|
: _blue.withValues(alpha: 0.48),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -238,6 +271,7 @@ class _GlassRimPainter extends CustomPainter {
|
|||||||
static const _blue = Color(0xFF007AFF);
|
static const _blue = Color(0xFF007AFF);
|
||||||
@override
|
@override
|
||||||
void paint(Canvas canvas, Size size) {
|
void paint(Canvas canvas, Size size) {
|
||||||
|
final edge = lens ? const Color(0xFF7B838F) : _blue;
|
||||||
final bounds = Offset.zero & size;
|
final bounds = Offset.zero & size;
|
||||||
final outer = RRect.fromRectAndRadius(
|
final outer = RRect.fromRectAndRadius(
|
||||||
bounds.deflate(0.7),
|
bounds.deflate(0.7),
|
||||||
@@ -256,10 +290,10 @@ class _GlassRimPainter extends CustomPainter {
|
|||||||
bounds.center,
|
bounds.center,
|
||||||
[
|
[
|
||||||
Colors.white.withValues(alpha: 0.90),
|
Colors.white.withValues(alpha: 0.90),
|
||||||
_blue.withValues(alpha: lens ? 0.30 : 0.15),
|
edge.withValues(alpha: lens ? 0.30 : 0.15),
|
||||||
Colors.white.withValues(alpha: 0.10),
|
Colors.white.withValues(alpha: 0.10),
|
||||||
Colors.white.withValues(alpha: 0.86),
|
Colors.white.withValues(alpha: 0.86),
|
||||||
_blue.withValues(alpha: 0.12),
|
edge.withValues(alpha: 0.12),
|
||||||
Colors.white.withValues(alpha: 0.90),
|
Colors.white.withValues(alpha: 0.90),
|
||||||
],
|
],
|
||||||
[0.0, 0.18, 0.38, 0.60, 0.80, 1.0],
|
[0.0, 0.18, 0.38, 0.60, 0.80, 1.0],
|
||||||
@@ -278,7 +312,7 @@ class _GlassRimPainter extends CustomPainter {
|
|||||||
bounds.bottomRight,
|
bounds.bottomRight,
|
||||||
[
|
[
|
||||||
Colors.white.withValues(alpha: 0.30),
|
Colors.white.withValues(alpha: 0.30),
|
||||||
_blue.withValues(alpha: lens ? 0.13 : 0.07),
|
edge.withValues(alpha: lens ? 0.13 : 0.07),
|
||||||
Colors.white.withValues(alpha: 0.40),
|
Colors.white.withValues(alpha: 0.40),
|
||||||
],
|
],
|
||||||
[0.0, 0.5, 1.0],
|
[0.0, 0.5, 1.0],
|
||||||
|
|||||||
@@ -0,0 +1,115 @@
|
|||||||
|
import 'dart:ui' as ui;
|
||||||
|
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter/rendering.dart';
|
||||||
|
|
||||||
|
/// Filters live pixels beneath the glass; symbols above it remain undistorted.
|
||||||
|
class GlassRefraction extends StatefulWidget {
|
||||||
|
const GlassRefraction({
|
||||||
|
super.key,
|
||||||
|
required this.strength,
|
||||||
|
required this.child,
|
||||||
|
});
|
||||||
|
final double strength;
|
||||||
|
final Widget child;
|
||||||
|
@override
|
||||||
|
State<GlassRefraction> createState() => _GlassRefractionState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _GlassRefractionState extends State<GlassRefraction> {
|
||||||
|
static Future<ui.FragmentProgram>? _program;
|
||||||
|
ui.FragmentShader? _shader;
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
if (ui.ImageFilter.isShaderFilterSupported) _load();
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _load() async {
|
||||||
|
try {
|
||||||
|
final program = await (_program ??= ui.FragmentProgram.fromAsset(
|
||||||
|
'shaders/liquid_glass.frag',
|
||||||
|
));
|
||||||
|
if (mounted) setState(() => _shader = program.fragmentShader());
|
||||||
|
} catch (error) {
|
||||||
|
_program = null;
|
||||||
|
debugPrint('Glass refraction unavailable: $error');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
_shader?.dispose();
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) => _shader == null
|
||||||
|
? BackdropFilter(
|
||||||
|
filter: ui.ImageFilter.blur(sigmaX: 0.6, sigmaY: 0.6),
|
||||||
|
child: widget.child,
|
||||||
|
)
|
||||||
|
: _LiveGlassFilter(
|
||||||
|
shader: _shader!,
|
||||||
|
strength: widget.strength,
|
||||||
|
pixelRatio: MediaQuery.devicePixelRatioOf(context),
|
||||||
|
child: widget.child,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
class _LiveGlassFilter extends SingleChildRenderObjectWidget {
|
||||||
|
const _LiveGlassFilter({
|
||||||
|
required this.shader,
|
||||||
|
required this.strength,
|
||||||
|
required this.pixelRatio,
|
||||||
|
required super.child,
|
||||||
|
});
|
||||||
|
final ui.FragmentShader shader;
|
||||||
|
final double strength, pixelRatio;
|
||||||
|
@override
|
||||||
|
_RenderLiveGlass createRenderObject(BuildContext context) =>
|
||||||
|
_RenderLiveGlass(shader, strength, pixelRatio);
|
||||||
|
@override
|
||||||
|
void updateRenderObject(
|
||||||
|
BuildContext context,
|
||||||
|
_RenderLiveGlass renderObject,
|
||||||
|
) => renderObject.update(shader, strength, pixelRatio);
|
||||||
|
}
|
||||||
|
|
||||||
|
class _RenderLiveGlass extends RenderProxyBox {
|
||||||
|
_RenderLiveGlass(this._shader, this._strength, this._pixelRatio);
|
||||||
|
ui.FragmentShader _shader;
|
||||||
|
double _strength, _pixelRatio;
|
||||||
|
final _layer = LayerHandle<BackdropFilterLayer>();
|
||||||
|
void update(ui.FragmentShader shader, double strength, double pixelRatio) {
|
||||||
|
_shader = shader;
|
||||||
|
_strength = strength;
|
||||||
|
_pixelRatio = pixelRatio;
|
||||||
|
markNeedsPaint();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool get alwaysNeedsCompositing => child != null;
|
||||||
|
@override
|
||||||
|
void paint(PaintingContext context, Offset offset) {
|
||||||
|
if (child == null) return;
|
||||||
|
// Sample coordinates are physical pixels. Resolve the actual transform
|
||||||
|
// during paint so the glass also follows the Dock's hide/show animation.
|
||||||
|
final origin = localToGlobal(Offset.zero) * _pixelRatio;
|
||||||
|
_shader
|
||||||
|
..setFloat(2, origin.dx)
|
||||||
|
..setFloat(3, origin.dy)
|
||||||
|
..setFloat(4, size.width * _pixelRatio)
|
||||||
|
..setFloat(5, size.height * _pixelRatio)
|
||||||
|
..setFloat(6, _strength);
|
||||||
|
_layer.layer ??= BackdropFilterLayer();
|
||||||
|
_layer.layer!.filter = ui.ImageFilter.shader(_shader);
|
||||||
|
context.pushLayer(_layer.layer!, super.paint, offset);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
_layer.layer = null;
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
+3
-1
@@ -1,7 +1,7 @@
|
|||||||
name: hepan_everyday
|
name: hepan_everyday
|
||||||
description: RSchedule 研究生课表
|
description: RSchedule 研究生课表
|
||||||
publish_to: none
|
publish_to: none
|
||||||
version: 0.3.0+4
|
version: 0.3.1+5
|
||||||
environment:
|
environment:
|
||||||
sdk: ^3.13.5
|
sdk: ^3.13.5
|
||||||
dependencies:
|
dependencies:
|
||||||
@@ -24,3 +24,5 @@ dev_dependencies:
|
|||||||
flutter_lints: ^6.0.0
|
flutter_lints: ^6.0.0
|
||||||
flutter:
|
flutter:
|
||||||
uses-material-design: true
|
uses-material-design: true
|
||||||
|
shaders:
|
||||||
|
- shaders/liquid_glass.frag
|
||||||
|
|||||||
@@ -0,0 +1,41 @@
|
|||||||
|
#include <flutter/runtime_effect.glsl>
|
||||||
|
|
||||||
|
// The engine supplies the backing texture and its physical size.
|
||||||
|
uniform vec2 u_texture_size;
|
||||||
|
uniform vec2 u_origin;
|
||||||
|
uniform vec2 u_extent;
|
||||||
|
uniform float u_strength;
|
||||||
|
uniform sampler2D u_background;
|
||||||
|
out vec4 frag_color;
|
||||||
|
|
||||||
|
vec2 sampleUV(vec2 point) {
|
||||||
|
vec2 uv = point / u_texture_size;
|
||||||
|
#ifdef IMPELLER_TARGET_OPENGLES
|
||||||
|
uv.y = 1.0 - uv.y;
|
||||||
|
#endif
|
||||||
|
return clamp(uv, vec2(0.001), vec2(0.999));
|
||||||
|
}
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
vec2 point = FlutterFragCoord().xy;
|
||||||
|
vec2 centre = u_origin + u_extent * 0.5;
|
||||||
|
vec2 local = point - centre;
|
||||||
|
float radius = max(u_extent.y * 0.5, 1.0);
|
||||||
|
float spine = max(u_extent.x * 0.5 - radius, 0.0);
|
||||||
|
vec2 outward = local - vec2(clamp(local.x, -spine, spine), 0.0);
|
||||||
|
float distance = length(outward);
|
||||||
|
vec2 normal = outward / max(distance, 0.001);
|
||||||
|
float depth = radius - distance;
|
||||||
|
float rim = 1.0 - smoothstep(0.0, radius * 0.46, depth);
|
||||||
|
// Curved glass bends rays most at its edge, with subtle centre magnification.
|
||||||
|
vec2 ray = centre + local / (1.0 + u_strength * 0.075)
|
||||||
|
- normal * rim * rim * radius * u_strength * 0.20;
|
||||||
|
vec4 colour = texture(u_background, sampleUV(ray));
|
||||||
|
float dispersion = u_strength * rim * 0.65;
|
||||||
|
colour.r = texture(u_background, sampleUV(ray + normal * dispersion)).r;
|
||||||
|
colour.b = texture(u_background, sampleUV(ray - normal * dispersion)).b;
|
||||||
|
float reflection = pow(rim, 4.0) * u_strength * 0.10
|
||||||
|
* max(0.0, dot(normal, normalize(vec2(-0.5, -0.8))));
|
||||||
|
colour.rgb = min(colour.rgb + reflection * colour.a, vec3(colour.a));
|
||||||
|
frag_color = colour;
|
||||||
|
}
|
||||||
@@ -2,6 +2,26 @@ import 'package:flutter_test/flutter_test.dart';
|
|||||||
import 'package:hepan_everyday/features/school/school_login_flow.dart';
|
import 'package:hepan_everyday/features/school/school_login_flow.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
|
test(
|
||||||
|
'repeated school login bounces have a bounded automatic redirect budget',
|
||||||
|
() {
|
||||||
|
final flow = SchoolLoginFlow();
|
||||||
|
final target = Uri.parse(
|
||||||
|
'https://yjsjy.uestc.edu.cn/pyxx/pygl/xskbcx/index/1',
|
||||||
|
);
|
||||||
|
final login = Uri.parse('https://idas.uestc.edu.cn/authserver/login');
|
||||||
|
final home = Uri.parse('https://yjsjy.uestc.edu.cn/pyxx/home/index');
|
||||||
|
flow.begin(target);
|
||||||
|
for (var i = 0; i < 2; i++) {
|
||||||
|
flow.onLoaded(login, authenticated: false);
|
||||||
|
expect(flow.onLoaded(home, authenticated: true), target);
|
||||||
|
}
|
||||||
|
flow.onLoaded(login, authenticated: false);
|
||||||
|
expect(flow.onLoaded(home, authenticated: true), isNull);
|
||||||
|
flow.begin(target);
|
||||||
|
expect(flow.onLoaded(home, authenticated: true), target);
|
||||||
|
},
|
||||||
|
);
|
||||||
test('wait for student authentication then request timetable once', () {
|
test('wait for student authentication then request timetable once', () {
|
||||||
final flow = SchoolLoginFlow();
|
final flow = SchoolLoginFlow();
|
||||||
final target = Uri.parse(
|
final target = Uri.parse(
|
||||||
|
|||||||
@@ -2,6 +2,31 @@ import 'package:flutter_test/flutter_test.dart';
|
|||||||
import 'package:hepan_everyday/features/school/school_navigation_policy.dart';
|
import 'package:hepan_everyday/features/school/school_navigation_policy.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
|
test(
|
||||||
|
'official HTTP graduate child frames can load for same-origin DOM reading',
|
||||||
|
() {
|
||||||
|
expect(
|
||||||
|
SchoolNavigationPolicy.canNavigate(
|
||||||
|
Uri.parse('http://yjsjy.uestc.edu.cn/pyxx/pygl/xskbcx/index/1'),
|
||||||
|
isMainFrame: false,
|
||||||
|
),
|
||||||
|
isTrue,
|
||||||
|
);
|
||||||
|
for (final value in [
|
||||||
|
'http://evil.test/pyxx/pygl/xskbcx/index/1',
|
||||||
|
'http://yjsjy.uestc.edu.cn:81/pyxx/pygl/xskbcx/index/1',
|
||||||
|
'http://user@yjsjy.uestc.edu.cn/pyxx/pygl/xskbcx/index/1',
|
||||||
|
]) {
|
||||||
|
expect(
|
||||||
|
SchoolNavigationPolicy.canNavigate(
|
||||||
|
Uri.parse(value),
|
||||||
|
isMainFrame: false,
|
||||||
|
),
|
||||||
|
isFalse,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
test('secure captcha frames are allowed without authorizing credential injection', () {
|
test('secure captcha frames are allowed without authorizing credential injection', () {
|
||||||
final captcha = Uri.parse('https://captcha.example.test/challenge');
|
final captcha = Uri.parse('https://captcha.example.test/challenge');
|
||||||
expect(
|
expect(
|
||||||
|
|||||||
@@ -0,0 +1,83 @@
|
|||||||
|
// Run with Node: exercises the exact WebView script without executing school HTML scripts.
|
||||||
|
const assert = require('node:assert/strict');
|
||||||
|
const fs = require('node:fs');
|
||||||
|
const path = require('node:path');
|
||||||
|
const vm = require('node:vm');
|
||||||
|
const source = fs.readFileSync(path.join(__dirname, '../../lib/features/school/school_page_probe.dart'), 'utf8');
|
||||||
|
const script = source.match(/schoolPageProbeScript = r'''([\s\S]*?)''';/)[1];
|
||||||
|
const home = 'https://yjsjy.uestc.edu.cn/pyxx/home/index';
|
||||||
|
const timetable = 'https://yjsjy.uestc.edu.cn/pyxx/pygl/xskbcx/index/1';
|
||||||
|
|
||||||
|
function term(id) {
|
||||||
|
const result = {
|
||||||
|
selectedIndex: 1,
|
||||||
|
options: [false, false].map(selected => ({
|
||||||
|
selected,
|
||||||
|
setAttribute() { this.selected = true; },
|
||||||
|
removeAttribute() { this.selected = false; },
|
||||||
|
})),
|
||||||
|
cloneNode() { return term(id); },
|
||||||
|
get outerHTML() {
|
||||||
|
return `<select id="${id}">${this.options.map((o, i) =>
|
||||||
|
`<option value="${i}"${o.selected ? ' selected="selected"' : ''}>Term ${i}</option>`).join('')}</select>`;
|
||||||
|
},
|
||||||
|
};
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
function doc(url, { password = false, chrome = false, table = false, exams = false, frames = [] } = {}) {
|
||||||
|
return {
|
||||||
|
location: new URL(url),
|
||||||
|
querySelector(selector) {
|
||||||
|
if (selector === 'input[type="password"]') return password ? {} : null;
|
||||||
|
if (selector === '#navbar' || selector === '#main-container') return chrome ? {} : null;
|
||||||
|
if (selector === '#tbl') return table ? {outerHTML: '<table id="tbl">synthetic timetable</table>'} : null;
|
||||||
|
if (selector === '#drpxq') return table ? term('drpxq') : null;
|
||||||
|
if (selector === '#sample-table-1') return exams ? {outerHTML: '<table id="sample-table-1">synthetic exams</table>'} : null;
|
||||||
|
if (selector === '#xqbh') return exams ? term('xqbh') : null;
|
||||||
|
return null;
|
||||||
|
},
|
||||||
|
querySelectorAll(selector) { return selector === 'iframe,frame' ? frames : []; },
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function probe(document, logout = () => {}) {
|
||||||
|
return JSON.parse(vm.runInNewContext(script, {
|
||||||
|
URL, document, location: document.location, window: {logout},
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.equal(probe(doc(home)).authenticated, true, 'real logout function on known graduate home');
|
||||||
|
assert.equal(probe(doc(timetable, {chrome: true})).authenticated, true, 'graduate shell plus logout');
|
||||||
|
assert.equal(probe(doc('http://yjsjy.uestc.edu.cn/pyxx?targetUrl=-1', {chrome: true})).authenticated, true, 'graduate root shell');
|
||||||
|
assert.equal(probe(doc(home), undefined).authenticated, true); // default function
|
||||||
|
assert.equal(probe(doc(home), null).authenticated, false, 'home URL alone is insufficient');
|
||||||
|
assert.equal(probe(doc('https://yjsjy.uestc.edu.cn/pyxx/jzsso/login')).authenticated, false, 'callback alone is insufficient');
|
||||||
|
|
||||||
|
const top = probe(doc(timetable, {table: true}));
|
||||||
|
assert.equal(top.pages.length, 1);
|
||||||
|
assert.match(top.pages[0].html, /value="1" selected="selected"/);
|
||||||
|
assert.doesNotMatch(top.pages[0].html, /value="0" selected/);
|
||||||
|
|
||||||
|
const inaccessible = {};
|
||||||
|
Object.defineProperty(inaccessible, 'contentDocument', {get() { throw new Error('cross-origin'); }});
|
||||||
|
const embedded = probe(doc(home, {frames: [
|
||||||
|
inaccessible,
|
||||||
|
{contentDocument: doc('https://captcha.example.test/pyxx/timetable', {table: true})},
|
||||||
|
{contentDocument: doc('http://yjsjy.uestc.edu.cn/pyxx/timetable', {table: true})},
|
||||||
|
{contentDocument: doc(timetable, {password: true, table: true})},
|
||||||
|
{contentDocument: doc(timetable, {frames: [{contentDocument: doc(timetable, {table: true})}]})},
|
||||||
|
]}));
|
||||||
|
assert.equal(embedded.pages.length, 1, 'only nested same-origin graduate timetable is captured');
|
||||||
|
assert.equal(embedded.pages[0].url, timetable);
|
||||||
|
assert.equal(probe(doc(home, {password: true, table: true})).pages.length, 0);
|
||||||
|
assert.equal(probe(doc('https://idas.uestc.edu.cn/authserver/login', {table: true})).pages.length, 0);
|
||||||
|
for (const url of [
|
||||||
|
'https://yjsjy.uestc.edu.cn.evil.test/pyxx/home/index',
|
||||||
|
'https://yjsjy.uestc.edu.cn:444/pyxx/home/index',
|
||||||
|
'https://user@yjsjy.uestc.edu.cn/pyxx/home/index',
|
||||||
|
'file:///pyxx/home/index',
|
||||||
|
]) assert.equal(probe(doc(url, {table: true})).pages.length, 0);
|
||||||
|
assert.equal(probe(doc('http://yjsjy.uestc.edu.cn/pyxx/home/index', {table: true})).pages.length, 1);
|
||||||
|
assert.equal(probe(doc(home, {exams: true})).pages[0].kind, 'exams');
|
||||||
|
console.log('School WebView probe: authentication, table selection, frames, password exclusion, origins passed.');
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'dart:convert';
|
|
||||||
|
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
import 'package:webview_flutter_platform_interface/webview_flutter_platform_interface.dart';
|
import 'package:webview_flutter_platform_interface/webview_flutter_platform_interface.dart';
|
||||||
@@ -8,6 +7,7 @@ import 'package:hepan_everyday/features/school/school_exam_adapter.dart';
|
|||||||
|
|
||||||
import '../support/fake_school_web.dart';
|
import '../support/fake_school_web.dart';
|
||||||
import 'exam_adapter_test.dart' show examHtml;
|
import 'exam_adapter_test.dart' show examHtml;
|
||||||
|
import 'recognized_timetable_test.dart' show fixture;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
TestWidgetsFlutterBinding.ensureInitialized();
|
TestWidgetsFlutterBinding.ensureInitialized();
|
||||||
@@ -25,6 +25,170 @@ void main() {
|
|||||||
platform.delegate.finished(url);
|
platform.delegate.finished(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test('graduate logout function automatically opens timetable without an exit anchor', () async {
|
||||||
|
await session.open();
|
||||||
|
platform.web.javascript = (script) async =>
|
||||||
|
script.contains("typeof window.logout")
|
||||||
|
? schoolPageEvidence(topUrl: platform.web.url!, authenticated: true)
|
||||||
|
: false;
|
||||||
|
navigate('http://yjsjy.uestc.edu.cn/pyxx/home/index');
|
||||||
|
await flushSchoolEvents();
|
||||||
|
expect(platform.web.loads.last, SchoolSession.timetableUrl.toString());
|
||||||
|
});
|
||||||
|
|
||||||
|
test('manual graduate page reads recognized embedded timetable instead of restarting login', () async {
|
||||||
|
await session.open();
|
||||||
|
const home = 'https://yjsjy.uestc.edu.cn/pyxx/home/index';
|
||||||
|
platform.web.url = home;
|
||||||
|
platform.web.javascript = (_) async => schoolPageEvidence(
|
||||||
|
topUrl: home,
|
||||||
|
html: fixture(),
|
||||||
|
documentUrl: SchoolSession.timetableUrl.toString(),
|
||||||
|
);
|
||||||
|
final draft = await session.readTimetable();
|
||||||
|
expect(draft.courses.length, 4);
|
||||||
|
expect(platform.web.loads.length, 1);
|
||||||
|
});
|
||||||
|
|
||||||
|
test(
|
||||||
|
'closed authentication screen ignores later page-finished callbacks',
|
||||||
|
() async {
|
||||||
|
await session.open();
|
||||||
|
session.setReadingActive(true);
|
||||||
|
session.setReadingActive(false);
|
||||||
|
platform.web.javascript = (_) async =>
|
||||||
|
schoolPageEvidence(topUrl: platform.web.url!, html: fixture());
|
||||||
|
navigate(SchoolSession.timetableUrl.toString());
|
||||||
|
await flushSchoolEvents();
|
||||||
|
expect(session.pendingDraft, isNull);
|
||||||
|
expect(session.finding, isFalse);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
test(
|
||||||
|
'asynchronous timetable DOM is imported without another navigation',
|
||||||
|
() async {
|
||||||
|
await session.open();
|
||||||
|
session.setReadingActive(true);
|
||||||
|
var ready = false;
|
||||||
|
platform.web.javascript = (_) async => schoolPageEvidence(
|
||||||
|
topUrl: platform.web.url!,
|
||||||
|
html: ready ? fixture() : null,
|
||||||
|
);
|
||||||
|
navigate(SchoolSession.timetableUrl.toString());
|
||||||
|
await flushSchoolEvents();
|
||||||
|
expect(session.pendingDraft, isNull);
|
||||||
|
expect(session.finding, isTrue);
|
||||||
|
ready = true;
|
||||||
|
await Future<void>.delayed(const Duration(milliseconds: 850));
|
||||||
|
await flushSchoolEvents();
|
||||||
|
expect(session.pendingDraft!.courses.length, 4);
|
||||||
|
expect(platform.web.loads.length, 1);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
test('stale script response cannot cancel polling on a newer page', () async {
|
||||||
|
await session.open();
|
||||||
|
session.setReadingActive(true);
|
||||||
|
final old = Completer<Object>();
|
||||||
|
platform.web.javascript = (_) => old.future;
|
||||||
|
navigate('https://yjsjy.uestc.edu.cn/pyxx/home/index');
|
||||||
|
await flushSchoolEvents();
|
||||||
|
var ready = false;
|
||||||
|
platform.web.javascript = (_) async => schoolPageEvidence(
|
||||||
|
topUrl: platform.web.url!,
|
||||||
|
html: ready ? fixture() : null,
|
||||||
|
);
|
||||||
|
navigate(SchoolSession.timetableUrl.toString());
|
||||||
|
await flushSchoolEvents();
|
||||||
|
old.complete(
|
||||||
|
schoolPageEvidence(
|
||||||
|
topUrl: 'https://yjsjy.uestc.edu.cn/pyxx/home/index',
|
||||||
|
authenticated: true,
|
||||||
|
html: fixture(),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
await flushSchoolEvents();
|
||||||
|
ready = true;
|
||||||
|
await Future<void>.delayed(const Duration(milliseconds: 850));
|
||||||
|
await flushSchoolEvents();
|
||||||
|
expect(session.pendingDraft?.courses.length, 4);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('external document evidence cannot become a school import', () async {
|
||||||
|
await session.open();
|
||||||
|
platform.web.url = SchoolSession.timetableUrl.toString();
|
||||||
|
for (final url in [
|
||||||
|
'https://evil.test/pyxx/pygl/xskbcx/index/1',
|
||||||
|
'https://yjsjy.uestc.edu.cn:444/pyxx/pygl/xskbcx/index/1',
|
||||||
|
'http://yjsjy.uestc.edu.cn/pyxx/pygl/xskbcx/index/1',
|
||||||
|
'https://user@yjsjy.uestc.edu.cn/pyxx/pygl/xskbcx/index/1',
|
||||||
|
]) {
|
||||||
|
platform.web.javascript = (_) async => schoolPageEvidence(
|
||||||
|
topUrl: platform.web.url!,
|
||||||
|
documentUrl: url,
|
||||||
|
html: fixture(),
|
||||||
|
);
|
||||||
|
await expectLater(session.readTimetable(), throwsA(isA<Exception>()));
|
||||||
|
}
|
||||||
|
expect(session.pendingDraft, isNull);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('read-current recovery imports a frame and never reloads SSO', () async {
|
||||||
|
await session.open();
|
||||||
|
const home = 'http://yjsjy.uestc.edu.cn/pyxx/home/index';
|
||||||
|
platform.web.url = home;
|
||||||
|
platform.web.javascript = (_) async => schoolPageEvidence(
|
||||||
|
topUrl: home,
|
||||||
|
documentUrl: home,
|
||||||
|
authenticated: true,
|
||||||
|
html: fixture(),
|
||||||
|
);
|
||||||
|
await session.readCurrentPage();
|
||||||
|
expect(session.pendingDraft?.courses.length, 4);
|
||||||
|
expect(platform.web.loads.length, 1);
|
||||||
|
});
|
||||||
|
|
||||||
|
test(
|
||||||
|
'authenticated graduate root dashboard automatically opens timetable',
|
||||||
|
() async {
|
||||||
|
await session.open();
|
||||||
|
const home = 'http://yjsjy.uestc.edu.cn/pyxx?targetUrl=-1';
|
||||||
|
final decision = await platform.delegate.navigation(
|
||||||
|
const NavigationRequest(url: home, isMainFrame: true),
|
||||||
|
);
|
||||||
|
expect(decision, NavigationDecision.navigate);
|
||||||
|
platform.web.javascript = (_) async =>
|
||||||
|
schoolPageEvidence(topUrl: home, authenticated: true);
|
||||||
|
navigate(home);
|
||||||
|
await flushSchoolEvents();
|
||||||
|
expect(platform.web.loads.last, SchoolSession.timetableUrl.toString());
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
test(
|
||||||
|
'obsolete automatic request failure preserves a newer pending import',
|
||||||
|
() async {
|
||||||
|
await session.open();
|
||||||
|
final oldRequest = Completer<void>();
|
||||||
|
platform.web.request = (_) => oldRequest.future;
|
||||||
|
platform.web.javascript = (_) async =>
|
||||||
|
schoolPageEvidence(topUrl: platform.web.url!, authenticated: true);
|
||||||
|
navigate('https://yjsjy.uestc.edu.cn/pyxx/home/index');
|
||||||
|
await flushSchoolEvents();
|
||||||
|
platform.web.javascript = (_) async =>
|
||||||
|
schoolPageEvidence(topUrl: platform.web.url!, html: fixture());
|
||||||
|
navigate(SchoolSession.timetableUrl.toString());
|
||||||
|
await flushSchoolEvents();
|
||||||
|
final fresh = session.pendingDraft;
|
||||||
|
expect(fresh, isNotNull);
|
||||||
|
oldRequest.completeError(StateError('obsolete request failure'));
|
||||||
|
await flushSchoolEvents();
|
||||||
|
expect(session.pendingDraft, same(fresh));
|
||||||
|
expect(session.message, '读取成功,正在保存…');
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
test('actual session follows service login then reads exam HTML', () async {
|
test('actual session follows service login then reads exam HTML', () async {
|
||||||
await session.openExams();
|
await session.openExams();
|
||||||
expect(platform.web.loads.single, SchoolSession.authUrl.toString());
|
expect(platform.web.loads.single, SchoolSession.authUrl.toString());
|
||||||
@@ -32,8 +196,14 @@ void main() {
|
|||||||
await flushSchoolEvents();
|
await flushSchoolEvents();
|
||||||
expect(session.connectionState, SchoolConnectionState.authenticating);
|
expect(session.connectionState, SchoolConnectionState.authenticating);
|
||||||
expect(session.finding, isFalse);
|
expect(session.finding, isFalse);
|
||||||
platform.web.javascript = (script) async =>
|
platform.web.javascript = (_) async => schoolPageEvidence(
|
||||||
script.contains('outerHTML') ? jsonEncode(examHtml()) : true;
|
topUrl: platform.web.url!,
|
||||||
|
authenticated: true,
|
||||||
|
html: platform.web.url == SchoolSession.examUrl.toString()
|
||||||
|
? examHtml()
|
||||||
|
: null,
|
||||||
|
kind: 'exams',
|
||||||
|
);
|
||||||
navigate('http://yjsjy.uestc.edu.cn/pyxx/home/index');
|
navigate('http://yjsjy.uestc.edu.cn/pyxx/home/index');
|
||||||
await flushSchoolEvents();
|
await flushSchoolEvents();
|
||||||
expect(platform.web.loads.last, SchoolSession.examUrl.toString());
|
expect(platform.web.loads.last, SchoolSession.examUrl.toString());
|
||||||
@@ -47,7 +217,11 @@ void main() {
|
|||||||
'obsolete main-frame error cannot interrupt a newer exam read',
|
'obsolete main-frame error cannot interrupt a newer exam read',
|
||||||
() async {
|
() async {
|
||||||
await session.openExams();
|
await session.openExams();
|
||||||
platform.web.javascript = (_) async => jsonEncode(examHtml());
|
platform.web.javascript = (_) async => schoolPageEvidence(
|
||||||
|
topUrl: platform.web.url!,
|
||||||
|
html: examHtml(),
|
||||||
|
kind: 'exams',
|
||||||
|
);
|
||||||
navigate(SchoolSession.examUrl.toString());
|
navigate(SchoolSession.examUrl.toString());
|
||||||
await flushSchoolEvents();
|
await flushSchoolEvents();
|
||||||
platform.delegate.resourceError(
|
platform.delegate.resourceError(
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
import 'dart:convert';
|
||||||
|
|
||||||
import 'package:webview_flutter_platform_interface/webview_flutter_platform_interface.dart';
|
import 'package:webview_flutter_platform_interface/webview_flutter_platform_interface.dart';
|
||||||
|
|
||||||
@@ -25,6 +26,7 @@ class FakeSchoolWeb extends PlatformWebViewController {
|
|||||||
final loads = <String>[];
|
final loads = <String>[];
|
||||||
String? url;
|
String? url;
|
||||||
Future<Object> Function(String)? javascript;
|
Future<Object> Function(String)? javascript;
|
||||||
|
Future<void> Function(Uri)? request;
|
||||||
@override
|
@override
|
||||||
Future<void> setJavaScriptMode(JavaScriptMode mode) async {}
|
Future<void> setJavaScriptMode(JavaScriptMode mode) async {}
|
||||||
@override
|
@override
|
||||||
@@ -35,6 +37,7 @@ class FakeSchoolWeb extends PlatformWebViewController {
|
|||||||
Future<void> loadRequest(LoadRequestParams params) async {
|
Future<void> loadRequest(LoadRequestParams params) async {
|
||||||
url = params.uri.toString();
|
url = params.uri.toString();
|
||||||
loads.add(url!);
|
loads.add(url!);
|
||||||
|
await request?.call(params.uri);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -100,3 +103,18 @@ Future<void> flushSchoolEvents() async {
|
|||||||
await Future<void>.delayed(Duration.zero);
|
await Future<void>.delayed(Duration.zero);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String schoolPageEvidence({
|
||||||
|
required String topUrl,
|
||||||
|
bool authenticated = false,
|
||||||
|
String? html,
|
||||||
|
String? documentUrl,
|
||||||
|
String kind = 'timetable',
|
||||||
|
}) => jsonEncode({
|
||||||
|
'topUrl': topUrl,
|
||||||
|
'authenticated': authenticated,
|
||||||
|
'pages': [
|
||||||
|
if (html != null)
|
||||||
|
{'kind': kind, 'url': documentUrl ?? topUrl, 'html': html},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|||||||
@@ -0,0 +1,78 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:timezone/data/latest.dart' as tzdata;
|
||||||
|
import 'package:hepan_everyday/widgets/glass_dock.dart';
|
||||||
|
import 'package:hepan_everyday/app/hepan_app.dart';
|
||||||
|
|
||||||
|
import 'navigation_test.dart' show uiController;
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
setUpAll(tzdata.initializeTimeZones);
|
||||||
|
testWidgets('held cursor enlarges before dragging and returns on release', (
|
||||||
|
tester,
|
||||||
|
) async {
|
||||||
|
await tester.pumpWidget(
|
||||||
|
MaterialApp(
|
||||||
|
home: Scaffold(
|
||||||
|
body: Center(child: GlassDock(selectedIndex: 0, onSelected: (_) {})),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
final lens = find
|
||||||
|
.descendant(
|
||||||
|
of: find.byType(GlassDock),
|
||||||
|
matching: find.byType(BackdropFilter),
|
||||||
|
)
|
||||||
|
.last;
|
||||||
|
final resting = tester.getSize(lens);
|
||||||
|
final gesture = await tester.startGesture(
|
||||||
|
tester.getCenter(find.byKey(const Key('dock-cursor'))),
|
||||||
|
);
|
||||||
|
await tester.pump(const Duration(milliseconds: 110));
|
||||||
|
await tester.pump(const Duration(milliseconds: 200));
|
||||||
|
final held = tester.getSize(lens);
|
||||||
|
expect(held.width, greaterThan(resting.width * 1.12));
|
||||||
|
expect(held.height, greaterThan(resting.height * 1.12));
|
||||||
|
await gesture.cancel();
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
expect(tester.getSize(lens).width, closeTo(resting.width, 0.5));
|
||||||
|
expect(tester.getSize(lens).height, closeTo(resting.height, 0.5));
|
||||||
|
});
|
||||||
|
testWidgets(
|
||||||
|
'Dock stays visible while sliding down instead of abruptly fading',
|
||||||
|
(tester) async {
|
||||||
|
tester.view.physicalSize = const Size(390, 844);
|
||||||
|
tester.view.devicePixelRatio = 1;
|
||||||
|
addTearDown(tester.view.resetPhysicalSize);
|
||||||
|
addTearDown(tester.view.resetDevicePixelRatio);
|
||||||
|
final c = uiController();
|
||||||
|
await c.initialize();
|
||||||
|
await c.showDemo();
|
||||||
|
await tester.pumpWidget(HepanApp(controller: c));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
final dock = find.byType(GlassDock);
|
||||||
|
final before = tester.getRect(dock);
|
||||||
|
final gesture = await tester.startGesture(
|
||||||
|
tester.getCenter(find.text('周三')),
|
||||||
|
);
|
||||||
|
await gesture.moveBy(const Offset(0, -80));
|
||||||
|
await tester.pump();
|
||||||
|
await tester.pump(const Duration(milliseconds: 120));
|
||||||
|
final fading = find.ancestor(
|
||||||
|
of: dock,
|
||||||
|
matching: find.byType(FadeTransition),
|
||||||
|
);
|
||||||
|
final opacity = fading.evaluate().isEmpty
|
||||||
|
? 1.0
|
||||||
|
: tester.widget<FadeTransition>(fading.first).opacity.value;
|
||||||
|
expect(opacity, greaterThan(0.95));
|
||||||
|
expect(tester.getRect(dock).top, greaterThan(before.top));
|
||||||
|
expect(tester.getRect(dock).top, lessThan(844));
|
||||||
|
await gesture.up();
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
expect(dock.hitTestable(), findsNothing);
|
||||||
|
c.dispose();
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,61 @@
|
|||||||
|
import 'dart:ui' as ui;
|
||||||
|
import 'dart:typed_data';
|
||||||
|
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
TestWidgetsFlutterBinding.ensureInitialized();
|
||||||
|
test(
|
||||||
|
'glass samples and bends background pixels while keeping the centre stable',
|
||||||
|
() async {
|
||||||
|
const width = 160, height = 100;
|
||||||
|
final sourceRecorder = ui.PictureRecorder();
|
||||||
|
final sourceCanvas = ui.Canvas(sourceRecorder);
|
||||||
|
for (var x = 0; x < width; x++) {
|
||||||
|
sourceCanvas.drawRect(
|
||||||
|
ui.Rect.fromLTWH(x.toDouble(), 0, 1, height.toDouble()),
|
||||||
|
ui.Paint()..color = ui.Color.fromARGB(255, 40 + x, 70, 90),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
final sourcePicture = sourceRecorder.endRecording();
|
||||||
|
final source = await sourcePicture.toImage(width, height);
|
||||||
|
final program = await ui.FragmentProgram.fromAsset(
|
||||||
|
'shaders/liquid_glass.frag',
|
||||||
|
);
|
||||||
|
final shader = program.fragmentShader()
|
||||||
|
..setFloat(0, width.toDouble())
|
||||||
|
..setFloat(1, height.toDouble())
|
||||||
|
..setFloat(2, 0)
|
||||||
|
..setFloat(3, 0)
|
||||||
|
..setFloat(4, width.toDouble())
|
||||||
|
..setFloat(5, height.toDouble())
|
||||||
|
..setImageSampler(0, source);
|
||||||
|
Future<ui.Image> draw(double strength) async {
|
||||||
|
shader.setFloat(6, strength);
|
||||||
|
final recorder = ui.PictureRecorder();
|
||||||
|
ui.Canvas(recorder).drawRect(
|
||||||
|
ui.Rect.fromLTWH(0, 0, width.toDouble(), height.toDouble()),
|
||||||
|
ui.Paint()..shader = shader,
|
||||||
|
);
|
||||||
|
final picture = recorder.endRecording();
|
||||||
|
final image = await picture.toImage(width, height);
|
||||||
|
picture.dispose();
|
||||||
|
return image;
|
||||||
|
}
|
||||||
|
|
||||||
|
final plain = await draw(0), refracted = await draw(1);
|
||||||
|
final a = (await plain.toByteData())!,
|
||||||
|
b = (await refracted.toByteData())!;
|
||||||
|
int red(ByteData data, int x) => data.getUint8((50 * width + x) * 4);
|
||||||
|
expect(red(a, 12), closeTo(52, 1));
|
||||||
|
expect((red(b, 12) - red(a, 12)).abs(), greaterThan(3));
|
||||||
|
expect(red(b, 80), closeTo(red(a, 80), 1));
|
||||||
|
expect(b.getUint8((50 * width + 12) * 4 + 3), 255);
|
||||||
|
shader.dispose();
|
||||||
|
plain.dispose();
|
||||||
|
refracted.dispose();
|
||||||
|
source.dispose();
|
||||||
|
sourcePicture.dispose();
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user