feat: 全面迁移到 Flutter + 新增 GitHub 源与 CI 流水线
前端
- 移除全部 Avalonia 依赖,模型渲染与界面统一改用 Flutter
- 新增用户页:登录/注册(SHA-512 + 盐)、签到积分(30 天一循环)、
主题色积分购买、二选一随机、今日人品
- 新增百宝箱页、模型内嵌渲染页、自绘标题栏(最小化/最大化/关闭)
- 下载页显示模型下载进度条,下载源读取加速
- 关于页新增「重新下载启动器」并在下载后做 sha256 完整性校验
- 修复浅色主题下标题栏不跟随主题色、无法连接后端等问题
后端
- 新增 UserService:.GC/user/<用户名>.yaml 存用户名/积分/SHA-512 口令,
登录返回 session token,本地 .GC/user/user.yaml 保存登录态
- 新增 /api/user/{register,login,me,signin,theme} 接口
- 去掉 Avalonia 窗口宿主,后端只提供 HTTP API
下载源
- 新增 GitHub 镜像源(Morris-morris-cloud/GC),与 Xhmcl 并发测速
- 单源探测超时收紧到 2 秒,取最快且可用的源;GitHub 复用 GiteaRemote
(contents 带 ref、releases 带 per_page=100)
构建与 CI
- macOS 上默认只出 macOS 包,Windows 交给原生 Windows 构建
- 修复 Windows 交叉编译中 flutter-cpp-client-wrapper 双层目录嵌套
- 新增 GitHub Actions:
· nightly-prerelease:每天 21:00 编译三平台,发布 nightly 预发布
· build-bot:Issue/PR 评论 @build-bot build <mac|win-amd|win-arm|all>,
发布 ip-prerelease 预发布
· pr-review:检查能否编译、静态分析、合并冲突、是否落后 main
- 忽略 79MB 课件产物等高线.html 与工具链临时备份
This commit is contained in:
1 parent
b9cb56cb8b
commit
ea1fa6b6d1
134 files changed
+4309
-16614
No files matched your search
@@ -138,6 +138,26 @@ class JobInfo {
|
||||
final bool isDone;
|
||||
}
|
||||
|
||||
/// 「重新下载启动器」的结果。
|
||||
///
|
||||
/// State: Ready(已下载并通过 sha256 校验)/ UpToDate(已是最新,无需重下)/ Failed。
|
||||
class LauncherRedownloadInfo {
|
||||
LauncherRedownloadInfo.fromJson(Map<String, dynamic> json)
|
||||
: state = json['state'] as String? ?? '',
|
||||
version = json['version'] as String? ?? '',
|
||||
message = json['message'] as String? ?? '',
|
||||
steps = ((json['steps'] as List<dynamic>?) ?? const <dynamic>[])
|
||||
.map((e) => e.toString())
|
||||
.toList();
|
||||
|
||||
final String state;
|
||||
final String version;
|
||||
final String message;
|
||||
final List<String> steps;
|
||||
|
||||
bool get ok => state == 'Ready' || state == 'UpToDate';
|
||||
}
|
||||
|
||||
/// 界面语言选项。
|
||||
class LanguageInfo {
|
||||
LanguageInfo.fromJson(Map<String, dynamic> json)
|
||||
@@ -336,6 +356,14 @@ class ActionResult {
|
||||
List<String> _stringList(dynamic value) =>
|
||||
(value as List<dynamic>? ?? const []).map((e) => e.toString()).toList();
|
||||
|
||||
/// 握手文件内容。
|
||||
class _Endpoint {
|
||||
const _Endpoint(this.url, this.token);
|
||||
|
||||
final String url;
|
||||
final String? token;
|
||||
}
|
||||
|
||||
/// GC-UI 后端客户端。
|
||||
///
|
||||
/// 后端是本地伴随进程,端口由启动器(GC-BOOT)选定后通过 `GC_UI_PORT`
|
||||
@@ -345,6 +373,9 @@ class GcApi {
|
||||
GcApi({String? baseUrl})
|
||||
: baseUrl = baseUrl ?? defaultBaseUrl;
|
||||
|
||||
/// 后端地址。可被 [rediscover] 更新(后端换端口 / 首次靠握手文件发现)。
|
||||
String baseUrl;
|
||||
|
||||
/// 复用同一个 HTTP 连接:轮询(下载任务每秒一次)时每次都新建连接
|
||||
/// 会不断握手,桌面端也能明显看到延迟抖动。
|
||||
static final http.Client _client = http.Client();
|
||||
@@ -363,63 +394,180 @@ class GcApi {
|
||||
final port = int.tryParse(Platform.environment['GC_UI_PORT'] ?? '');
|
||||
if (port != null) return 'http://127.0.0.1:$port';
|
||||
|
||||
// 手动起后端 / 前端调试时没有环境变量:读后端写的 .GC/ui-backend.json。
|
||||
final discovered = _endpointFileUrl();
|
||||
if (discovered != null) return discovered;
|
||||
// 没有环境变量(例如直接从 Finder 打开 GC-UI.app):读后端写的握手文件。
|
||||
final discovered = _readEndpointFile();
|
||||
if (discovered != null) return discovered.url;
|
||||
|
||||
return 'http://127.0.0.1:$fallbackPort';
|
||||
}
|
||||
|
||||
/// 从运行目录下的 `.GC/ui-backend.json` 发现后端地址。
|
||||
///
|
||||
/// 后端每次启动都会写这个文件(port / pid / url)。只认 24 小时内的记录:
|
||||
/// 更早的多半是上次遗留的,连过去只会得到一个「无法连接」。
|
||||
static String? _endpointFileUrl() {
|
||||
try {
|
||||
final file = File('${Directory.current.path}/.GC/ui-backend.json');
|
||||
if (!file.existsSync()) return null;
|
||||
/// 后端启动时写的握手文件:地址 + 会话令牌。
|
||||
static _Endpoint? _endpoint;
|
||||
|
||||
final age = DateTime.now().difference(file.lastModifiedSync());
|
||||
if (age.inHours >= 24) return null;
|
||||
|
||||
final decoded = jsonDecode(file.readAsStringSync());
|
||||
if (decoded is! Map<String, dynamic>) return null;
|
||||
|
||||
final url = decoded['url'];
|
||||
if (url is String && url.startsWith('http://127.0.0.1:')) return url;
|
||||
|
||||
final port = (decoded['port'] as num?)?.toInt();
|
||||
if (port != null && port > 0 && port < 65536) {
|
||||
return 'http://127.0.0.1:$port';
|
||||
}
|
||||
} catch (_) {
|
||||
// 文件损坏 / 无权限:退回默认端口即可
|
||||
/// 依次尝试的运行目录。打包后 GC-UI.app 在 GC.app/Contents/MacOS/ 下,
|
||||
/// 直接 Finder 打开时 Directory.current 可能是 `/`,所以要把可执行文件周围都试一遍。
|
||||
static List<String> _candidateRoots() {
|
||||
final roots = <String>[];
|
||||
void add(String path) {
|
||||
if (path.isEmpty) return;
|
||||
final root = path.endsWith('/') ? path.substring(0, path.length - 1) : path;
|
||||
if (!roots.contains(root)) roots.add(root);
|
||||
}
|
||||
return null;
|
||||
|
||||
add(Platform.environment['GC_UI_HOME'] ?? '');
|
||||
try {
|
||||
add(Directory.current.path);
|
||||
} catch (_) {}
|
||||
|
||||
try {
|
||||
var dir = File(Platform.resolvedExecutable).parent;
|
||||
// GC-UI.app/Contents/MacOS -> 逐级向上都可能是 .GC 所在目录
|
||||
for (var i = 0; i < 4; i++) {
|
||||
add(dir.path);
|
||||
if (dir.parent.path == dir.path) break;
|
||||
dir = dir.parent;
|
||||
}
|
||||
} catch (_) {}
|
||||
|
||||
return roots;
|
||||
}
|
||||
|
||||
final String baseUrl;
|
||||
static _Endpoint? _readEndpointFile({bool refresh = false}) {
|
||||
if (!refresh && _endpoint != null) return _endpoint;
|
||||
|
||||
/// 启动器注入的一次性会话令牌。后端在发布包模式下会校验它,
|
||||
/// 防止前端误连到同机其他进程伪造的「后端」。
|
||||
static final String? _sessionToken = _readSessionToken();
|
||||
for (final root in _candidateRoots()) {
|
||||
try {
|
||||
final file = File('$root/.GC/ui-backend.json');
|
||||
try {
|
||||
final logFile = File('${Directory.systemTemp.path}/gc-api-debug.log');
|
||||
logFile.writeAsStringSync('[api] 检查: $root/.GC/ui-backend.json (exists=${file.existsSync()})\n', mode: FileMode.append);
|
||||
} catch (_) {}
|
||||
if (!file.existsSync()) continue;
|
||||
|
||||
// 只认 24 小时内的记录:更早的多半是上次遗留,连过去只会得到「无法连接」
|
||||
final age = DateTime.now().difference(file.lastModifiedSync());
|
||||
if (age.inHours >= 24) continue;
|
||||
|
||||
final decoded = jsonDecode(file.readAsStringSync());
|
||||
if (decoded is! Map<String, dynamic>) continue;
|
||||
|
||||
String? url;
|
||||
final rawUrl = decoded['url'];
|
||||
if (rawUrl is String && rawUrl.startsWith('http://127.0.0.1:')) {
|
||||
url = rawUrl;
|
||||
} else {
|
||||
final port = (decoded['port'] as num?)?.toInt();
|
||||
if (port != null && port > 0 && port < 65536) {
|
||||
url = 'http://127.0.0.1:$port';
|
||||
}
|
||||
}
|
||||
if (url == null) continue;
|
||||
|
||||
final token = decoded['token'];
|
||||
return _endpoint = _Endpoint(url, token is String && token.isNotEmpty ? token : null);
|
||||
} catch (_) {
|
||||
// 文件损坏 / 无权限:试下一个候选目录
|
||||
}
|
||||
}
|
||||
return _endpoint = null;
|
||||
}
|
||||
|
||||
/// 重新解析后端地址与令牌(后端重启换端口、或环境变量缺失时用)。
|
||||
/// 返回 true 表示地址或令牌发生了变化,值得重试一次。
|
||||
bool rediscover() {
|
||||
final before = (_endpoint?.url, _sessionToken);
|
||||
_endpoint = null;
|
||||
final endpoint = _readEndpointFile(refresh: true);
|
||||
|
||||
if (endpoint?.token != null && endpoint!.token != _sessionToken) {
|
||||
_sessionToken = endpoint.token;
|
||||
}
|
||||
|
||||
final envUrl = Platform.environment['GC_UI_BASE_URL'];
|
||||
final envPort = int.tryParse(Platform.environment['GC_UI_PORT'] ?? '');
|
||||
final resolved = (envUrl != null && envUrl.isNotEmpty)
|
||||
? envUrl
|
||||
: (envPort != null
|
||||
? 'http://127.0.0.1:$envPort'
|
||||
: (endpoint?.url ?? 'http://127.0.0.1:$fallbackPort'));
|
||||
|
||||
if (resolved != baseUrl) {
|
||||
baseUrl = resolved;
|
||||
return true;
|
||||
}
|
||||
return (before.$1 != _endpoint?.url) || (before.$2 != _sessionToken);
|
||||
}
|
||||
|
||||
/// 启动器注入的一次性会话令牌:环境变量优先,其次握手文件。
|
||||
/// 后端在发布包模式下校验它,防止前端连到同机伪造的「后端」。
|
||||
static String? _sessionToken = _readSessionToken();
|
||||
|
||||
static String? _readSessionToken() {
|
||||
const fromDefine = String.fromEnvironment('GC_UI_TOKEN');
|
||||
if (fromDefine.isNotEmpty) return fromDefine;
|
||||
final fromEnv = Platform.environment['GC_UI_TOKEN'];
|
||||
return (fromEnv != null && fromEnv.isNotEmpty) ? fromEnv : null;
|
||||
if (fromEnv != null && fromEnv.isNotEmpty) return fromEnv;
|
||||
// 环境变量没传进来(Finder 直接打开 GC-UI.app):用握手文件里的令牌
|
||||
return _readEndpointFile()?.token;
|
||||
}
|
||||
|
||||
/// 是否拿到了会话令牌(诊断用)。
|
||||
bool get hasSessionToken => _sessionToken != null;
|
||||
|
||||
/// 用户 session token(登录时后端返回,持久化到 ~/.GC/user/user.yaml)
|
||||
static String? _userToken;
|
||||
static String? _username;
|
||||
|
||||
static String? get userToken => _userToken;
|
||||
static String? get username => _username;
|
||||
|
||||
static Future<void> _loadUserToken() async {
|
||||
try {
|
||||
final dir = Directory('${Platform.environment['HOME'] ?? '.'}/.GC/user');
|
||||
if (!dir.existsSync()) return;
|
||||
final file = File('${dir.path}/user.yaml');
|
||||
if (!file.existsSync()) return;
|
||||
final lines = file.readAsLinesSync();
|
||||
for (var line in lines) {
|
||||
if (line.startsWith('username:')) _username = line.split(':').skip(1).join(':').trim();
|
||||
if (line.startsWith('session_token:')) _userToken = line.split(':').skip(1).join(':').trim();
|
||||
}
|
||||
} catch (_) {}
|
||||
}
|
||||
|
||||
static Future<void> _saveUserToken(String username, String token) async {
|
||||
try {
|
||||
final dir = Directory('${Platform.environment['HOME'] ?? '.'}/.GC/user');
|
||||
dir.createSync(recursive: true);
|
||||
final file = File('${dir.path}/user.yaml');
|
||||
file.writeAsStringSync('username: $username\nsession_token: $token\n');
|
||||
_username = username;
|
||||
_userToken = token;
|
||||
} catch (_) {}
|
||||
}
|
||||
|
||||
static Future<void> clearUserToken() async {
|
||||
_username = null;
|
||||
_userToken = null;
|
||||
try {
|
||||
final file = File('${Platform.environment['HOME'] ?? '.'}/.GC/user/user.yaml');
|
||||
if (file.existsSync()) file.deleteSync();
|
||||
} catch (_) {}
|
||||
}
|
||||
|
||||
/// 带会话令牌的请求头;没有令牌时返回 const 空 map(调试/独立后端模式)。
|
||||
Map<String, String> get _authHeaders =>
|
||||
_sessionToken == null ? const {} : {'X-GC-UI-Token': _sessionToken!};
|
||||
Map<String, String> get _authHeaders => {
|
||||
if (_sessionToken != null) 'X-GC-UI-Token': _sessionToken!,
|
||||
if (_userToken != null) 'X-User-Token': _userToken!,
|
||||
};
|
||||
|
||||
Uri _uri(String path, [Map<String, String>? query]) =>
|
||||
Uri.parse('$baseUrl$path').replace(queryParameters: query);
|
||||
|
||||
Future<dynamic> _send(String method, String path,
|
||||
{Map<String, String>? query, Object? body}) async {
|
||||
{Map<String, String>? query,
|
||||
Object? body,
|
||||
Duration? timeout}) async {
|
||||
final uri = _uri(path, query);
|
||||
final auth = _authHeaders;
|
||||
late http.Response response;
|
||||
@@ -427,18 +575,18 @@ class GcApi {
|
||||
switch (method) {
|
||||
case 'GET':
|
||||
response = await _client.get(uri, headers: auth)
|
||||
.timeout(const Duration(seconds: 30));
|
||||
.timeout(timeout ?? const Duration(seconds: 30));
|
||||
break;
|
||||
case 'POST':
|
||||
response = await _client
|
||||
.post(uri,
|
||||
headers: <String, String>{...auth, 'Content-Type': 'application/json'},
|
||||
body: body == null ? null : jsonEncode(body))
|
||||
.timeout(const Duration(seconds: 120));
|
||||
.timeout(timeout ?? const Duration(seconds: 120));
|
||||
break;
|
||||
case 'DELETE':
|
||||
response = await _client.delete(uri, headers: auth)
|
||||
.timeout(const Duration(seconds: 30));
|
||||
.timeout(timeout ?? const Duration(seconds: 30));
|
||||
break;
|
||||
default:
|
||||
throw ApiException('不支持的方法 $method');
|
||||
@@ -502,6 +650,14 @@ class GcApi {
|
||||
'force': force.toString(),
|
||||
}) as Map<String, dynamic>);
|
||||
|
||||
/// 重新下载本机启动器包,返回时后端已完成 sha256 完整性校验。
|
||||
Future<LauncherRedownloadInfo> redownloadLauncher() async =>
|
||||
LauncherRedownloadInfo.fromJson(await _send(
|
||||
'POST',
|
||||
'/api/launcher/redownload',
|
||||
timeout: const Duration(minutes: 10),
|
||||
) as Map<String, dynamic>);
|
||||
|
||||
Future<List<JobInfo>> jobs() async =>
|
||||
_asList(await _send('GET', '/api/download/jobs')).map(JobInfo.fromJson).toList();
|
||||
|
||||
@@ -546,4 +702,56 @@ class GcApi {
|
||||
'X-GC-UI-Token': _sessionToken!,
|
||||
}).toString();
|
||||
}
|
||||
|
||||
// ==================== 用户系统 ====================
|
||||
|
||||
/// 初始化:加载本地保存的用户token
|
||||
Future<void> initUserSession() async {
|
||||
await _loadUserToken();
|
||||
}
|
||||
|
||||
Future<Map<String, dynamic>?> me() async {
|
||||
try {
|
||||
final r = await _send('GET', '/api/user/me');
|
||||
return r as Map<String, dynamic>?;
|
||||
} on ApiException catch (e) {
|
||||
if (e.statusCode == 401 || e.statusCode == 403) {
|
||||
await clearUserToken();
|
||||
return null;
|
||||
}
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
Future<Map<String, dynamic>> register(String username, String password) async {
|
||||
final r = await _send('POST', '/api/user/register',
|
||||
body: {'username': username, 'password': password});
|
||||
return r as Map<String, dynamic>;
|
||||
}
|
||||
|
||||
Future<Map<String, dynamic>> login(String username, String password) async {
|
||||
final r = await _send('POST', '/api/user/login',
|
||||
body: {'username': username, 'password': password});
|
||||
final result = r as Map<String, dynamic>;
|
||||
// 保存 session token
|
||||
if (result.containsKey('session_token')) {
|
||||
await _saveUserToken(username, result['session_token'] as String);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Future<void> logout() async {
|
||||
await clearUserToken();
|
||||
}
|
||||
|
||||
Future<Map<String, dynamic>> signin() async {
|
||||
final r = await _send('POST', '/api/user/signin');
|
||||
return r as Map<String, dynamic>;
|
||||
}
|
||||
|
||||
Future<Map<String, dynamic>> changeTheme(String color, int cost) async {
|
||||
final r = await _send('POST', '/api/user/theme',
|
||||
body: {'color': color, 'cost': cost});
|
||||
return r as Map<String, dynamic>;
|
||||
}
|
||||
}
|
||||
@@ -87,7 +87,11 @@ class ShellController extends ChangeNotifier {
|
||||
_retryAttempt++;
|
||||
_retryTimer?.cancel();
|
||||
_retryTimer = Timer(Duration(seconds: seconds), () {
|
||||
if (settings == null) bootstrap();
|
||||
if (settings == null) {
|
||||
// 后端可能刚换端口(端口占用)或刚写好握手文件:重试前重新解析一次
|
||||
api.rediscover();
|
||||
bootstrap();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -100,6 +104,25 @@ class ShellController extends ChangeNotifier {
|
||||
void goTo(int value) {
|
||||
if (index == value) return;
|
||||
index = value;
|
||||
activeModelId = null; // 切页时收起模型视图
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
/// 当前在壳内打开的模型(null 表示在看普通页面)。
|
||||
///
|
||||
/// 模型全部由 Flutter 自绘,不再由后端开 Avalonia 窗口:
|
||||
/// 点「启动模型」只是把内容区换成模型视图,标题栏与侧栏保持可用。
|
||||
String? activeModelId;
|
||||
|
||||
void openModel(String id) {
|
||||
if (activeModelId == id) return;
|
||||
activeModelId = id;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void closeModel() {
|
||||
if (activeModelId == null) return;
|
||||
activeModelId = null;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
|
||||
@@ -17,6 +17,8 @@ class I18n {
|
||||
'nav.download': '下载',
|
||||
'nav.settings': '设置',
|
||||
'nav.about': '关于',
|
||||
'nav.treasure': '百宝箱',
|
||||
'nav.user': '用户',
|
||||
'home.title': '模型库',
|
||||
'home.subtitle': '选择模型,用可交互的三维演示讲清自转、公转与四季成因。',
|
||||
'home.launch': '启动模型',
|
||||
@@ -35,7 +37,11 @@ class I18n {
|
||||
'home.stats.sources': '模型源',
|
||||
'home.stats.memory': '内存预算',
|
||||
'home.recent': '选择模型后点击「启动模型」',
|
||||
'home.launchHint': '模型在自己的窗口里运行,可播放/暂停、切换视角并使用教学要点。',
|
||||
'home.noBuiltin': '「{0}」暂时没有内置渲染实现',
|
||||
'model.back': '返回',
|
||||
'model.missing': '这个模型还没有 Flutter 实现',
|
||||
'model.missingHint': '模型窗口已全部改为应用内渲染,该模型暂未迁移。',
|
||||
'home.launchHint': '模型直接在应用内运行,可播放/暂停、切换视角并使用教学要点。',
|
||||
'dl.title': '下载模型',
|
||||
'dl.subtitle': '从内置模型源读取可下载模型;模型源在「设置」里查看。',
|
||||
'dl.sources': '模型源',
|
||||
@@ -133,6 +139,10 @@ class I18n {
|
||||
'about.contributorsHint': '来自仓库提交记录',
|
||||
'about.repository': '仓库',
|
||||
'about.openRepository': '打开仓库',
|
||||
'about.redownload': '重新下载启动器',
|
||||
'about.redownloading': '正在下载并校验…',
|
||||
'about.redownloadOk': '已下载 v{0},完整性校验通过(sha256 一致),重启后生效',
|
||||
'about.redownloadFail': '重新下载失败',
|
||||
'about.contributions': '{0} 次提交',
|
||||
'about.noContributors': '暂无贡献者信息',
|
||||
'about.architecture': '架构',
|
||||
@@ -144,6 +154,27 @@ class I18n {
|
||||
'about.thanksHint': '特别感谢以下朋友的支持',
|
||||
'about.thanksGit': 'Git 服务与部署支持',
|
||||
'about.thanksGeo': '地理学科内容指导',
|
||||
'user.points': '积分',
|
||||
'user.days': '连续签到',
|
||||
'user.signin': '签到',
|
||||
'user.login': '登录',
|
||||
'user.register': '注册',
|
||||
'user.pick': '二选一',
|
||||
'user.theme': '主题颜色',
|
||||
'user.username': '用户名',
|
||||
'user.password': '密码',
|
||||
'user.option1': '选项一',
|
||||
'user.option2': '选项二',
|
||||
'user.pickRandom': '随机选择',
|
||||
'user.switchToRegister': '没有账号?去注册',
|
||||
'user.switchToLogin': '已有账号?去登录',
|
||||
'user.loginSuccess': '登录成功',
|
||||
'user.registerSuccess': '注册成功',
|
||||
'user.signinSuccess': '签到成功',
|
||||
'user.alreadySigned': '今天已经签到过了',
|
||||
'user.fillAll': '请填写用户名和密码',
|
||||
'user.fillOptions': '请填写两个选项',
|
||||
'user.loginFirst': '请先登录',
|
||||
},
|
||||
'en': <String, String>{
|
||||
'app.name': 'Morris GC',
|
||||
@@ -153,6 +184,8 @@ class I18n {
|
||||
'nav.download': 'Download',
|
||||
'nav.settings': 'Settings',
|
||||
'nav.about': 'About',
|
||||
'nav.treasure': 'Treasure',
|
||||
'nav.user': 'User',
|
||||
'home.title': 'Model library',
|
||||
'home.subtitle': 'Pick a model and explain rotation, revolution and the seasons with an interactive 3D scene.',
|
||||
'home.launch': 'Launch model',
|
||||
@@ -171,7 +204,11 @@ class I18n {
|
||||
'home.stats.sources': 'Sources',
|
||||
'home.stats.memory': 'Memory budget',
|
||||
'home.recent': 'Select a model, then press Launch',
|
||||
'home.launchHint': 'Models open in their own window with play/pause, view controls and teaching notes.',
|
||||
'home.noBuiltin': '"{0}" has no built-in renderer yet',
|
||||
'model.back': 'Back',
|
||||
'model.missing': 'No Flutter renderer for this model',
|
||||
'model.missingHint': 'Model windows are rendered in-app now; this model has not been migrated yet.',
|
||||
'home.launchHint': 'Models render inside the app with play/pause, view controls and teaching notes.',
|
||||
'dl.title': 'Download',
|
||||
'dl.subtitle': 'Read downloadable models from the built-in sources; manage sources in Settings.',
|
||||
'dl.sources': 'Sources',
|
||||
@@ -269,6 +306,10 @@ class I18n {
|
||||
'about.contributorsHint': 'From repository commits',
|
||||
'about.repository': 'Repository',
|
||||
'about.openRepository': 'Open repository',
|
||||
'about.redownload': 'Re-download launcher',
|
||||
'about.redownloading': 'Downloading and verifying…',
|
||||
'about.redownloadOk': 'Downloaded v{0}, integrity verified (sha256 matched); applies after restart',
|
||||
'about.redownloadFail': 'Re-download failed',
|
||||
'about.contributions': '{0} commits',
|
||||
'about.noContributors': 'No contributor information',
|
||||
'about.architecture': 'Architecture',
|
||||
@@ -280,6 +321,27 @@ class I18n {
|
||||
'about.thanksHint': 'Special thanks to',
|
||||
'about.thanksGit': 'Git hosting and deployment',
|
||||
'about.thanksGeo': 'Geography content guidance',
|
||||
'user.points': 'Points',
|
||||
'user.days': 'Streak',
|
||||
'user.signin': 'Sign In',
|
||||
'user.login': 'Login',
|
||||
'user.register': 'Register',
|
||||
'user.pick': 'Pick One',
|
||||
'user.theme': 'Theme Color',
|
||||
'user.username': 'Username',
|
||||
'user.password': 'Password',
|
||||
'user.option1': 'Option A',
|
||||
'user.option2': 'Option B',
|
||||
'user.pickRandom': 'Random',
|
||||
'user.switchToRegister': 'No account? Register',
|
||||
'user.switchToLogin': 'Have account? Login',
|
||||
'user.loginSuccess': 'Login successful',
|
||||
'user.registerSuccess': 'Registration successful',
|
||||
'user.signinSuccess': 'Signed in',
|
||||
'user.alreadySigned': 'Already signed in today',
|
||||
'user.fillAll': 'Please fill in username and password',
|
||||
'user.fillOptions': 'Please fill in both options',
|
||||
'user.loginFirst': 'Please login first',
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
import 'base.dart';
|
||||
import 'contour_flutter.dart';
|
||||
import 'geography_flutter.dart';
|
||||
import 'revolution_flutter.dart';
|
||||
import 'rotation_flutter.dart';
|
||||
import 'scale_flutter.dart';
|
||||
|
||||
/// 后端模型 id → Flutter 实现。
|
||||
///
|
||||
/// 后端(`/api/models`)用的是模型包目录名(contour-map、earth-rotation…),
|
||||
/// Flutter 实现自己的 id 带 `-flutter` 后缀,这里做一次映射。
|
||||
/// Avalonia 版模型窗口已移除,所有模型统一在客户端内用 Flutter 渲染。
|
||||
final Map<String, GcModel Function()> _factories = <String, GcModel Function()>{
|
||||
'contour-map': () => ContourModelFlutter(),
|
||||
'earth-geography': () => GeographyModelFlutter(),
|
||||
'earth-rotation': () => RotationModelFlutter(),
|
||||
'earth-revolution': () => RevolutionModelFlutter(),
|
||||
'scale-calculator': () => ScaleCalculatorModelFlutter(),
|
||||
};
|
||||
|
||||
/// 按模型 id 取 Flutter 实现;没有对应实现时返回 null。
|
||||
GcModel? flutterModelFor(String id) {
|
||||
final factory = _factories[id] ?? _factories[id.replaceAll('-flutter', '')];
|
||||
return factory?.call();
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
/// 用户记录
|
||||
class UserRecord {
|
||||
const UserRecord({
|
||||
required this.username,
|
||||
required this.points,
|
||||
required this.consecutiveDays,
|
||||
this.lastSignIn,
|
||||
this.themeColor,
|
||||
});
|
||||
|
||||
final String username;
|
||||
final int points;
|
||||
final int consecutiveDays;
|
||||
final String? lastSignIn;
|
||||
final String? themeColor;
|
||||
|
||||
factory UserRecord.fromJson(Map<String, dynamic> json) {
|
||||
return UserRecord(
|
||||
username: json['username'] as String? ?? '',
|
||||
points: json['points'] as int? ?? 0,
|
||||
consecutiveDays: json['consecutive_days'] as int? ?? 0,
|
||||
lastSignIn: json['last_sign_in'] as String?,
|
||||
themeColor: json['theme_color'] as String?,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// 签到奖励配置(30天周期)
|
||||
class SignInRewards {
|
||||
static const List<int> rewards = [
|
||||
10, 10, 10, 10, 10, 10, 10, // 第1-7天:每天+10
|
||||
20, 20, 20, 20, 20, 20, 20, // 第8-15天:每天+20
|
||||
30, 30, 30, 30, 30, 30, 30, // 第16-23天:每天+30
|
||||
30, 30, 30, 30, 30, 30, 30, // 第24-30天:每天+30
|
||||
];
|
||||
|
||||
static int getReward(int day) {
|
||||
if (day < 1) day = 1;
|
||||
if (day > 30) day = ((day - 1) % 30) + 1;
|
||||
return rewards[day - 1];
|
||||
}
|
||||
}
|
||||
|
||||
/// 主题颜色
|
||||
class ThemeColor {
|
||||
const ThemeColor({required this.name, required this.hex, required this.cost});
|
||||
|
||||
final String name;
|
||||
final String hex;
|
||||
final int cost;
|
||||
|
||||
static const List<ThemeColor> predefined = [
|
||||
ThemeColor(name: '蓝色', hex: '4A90D9', cost: 0),
|
||||
ThemeColor(name: '红色', hex: 'E74C3C', cost: 50),
|
||||
ThemeColor(name: '绿色', hex: '27AE60', cost: 50),
|
||||
ThemeColor(name: '紫色', hex: '9B59B6', cost: 50),
|
||||
ThemeColor(name: '橙色', hex: 'F39C12', cost: 50),
|
||||
ThemeColor(name: '青色', hex: '1ABC9C', cost: 50),
|
||||
ThemeColor(name: '粉色', hex: 'E91E63', cost: 50),
|
||||
ThemeColor(name: '深蓝', hex: '2C3E50', cost: 50),
|
||||
];
|
||||
}
|
||||
@@ -6,3 +6,5 @@ export 'pages/courseware.dart';
|
||||
export 'pages/download.dart';
|
||||
export 'pages/settings.dart';
|
||||
export 'pages/about.dart';
|
||||
export 'pages/treasure.dart';
|
||||
export 'pages/user_page.dart';
|
||||
@@ -32,6 +32,11 @@ class _AboutPageViewState extends State<AboutPageView> {
|
||||
bool _loading = true;
|
||||
String? _error;
|
||||
|
||||
/// 重新下载启动器的进行状态与结果
|
||||
bool _redownloading = false;
|
||||
String? _redownloadMsg;
|
||||
bool? _redownloadOk;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
@@ -65,6 +70,34 @@ class _AboutPageViewState extends State<AboutPageView> {
|
||||
}
|
||||
}
|
||||
|
||||
/// 重新下载启动器包:后端下完会用清单里的 sha256 逐块校验,
|
||||
/// 校验不过会直接返回失败,不会留下半个坏包。
|
||||
Future<void> _redownloadLauncher() async {
|
||||
setState(() {
|
||||
_redownloading = true;
|
||||
_redownloadMsg = null;
|
||||
_redownloadOk = null;
|
||||
});
|
||||
try {
|
||||
final result = await widget.controller.api.redownloadLauncher();
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
_redownloading = false;
|
||||
_redownloadOk = result.ok;
|
||||
_redownloadMsg = result.ok
|
||||
? T('about.redownloadOk', <Object?>[result.version])
|
||||
: (result.message.isEmpty ? T('about.redownloadFail') : result.message);
|
||||
});
|
||||
} catch (error) {
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
_redownloading = false;
|
||||
_redownloadOk = false;
|
||||
_redownloadMsg = error.toString();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ListView(
|
||||
@@ -175,18 +208,67 @@ class _AboutPageViewState extends State<AboutPageView> {
|
||||
],
|
||||
),
|
||||
const SizedBox(height: GcSpace.lg),
|
||||
OutlinedButton(
|
||||
onPressed: () async {
|
||||
final url = about?.repository;
|
||||
if (url == null || url.isEmpty) return;
|
||||
try {
|
||||
await widget.controller.api.openUrl(url);
|
||||
} catch (_) {
|
||||
// 忽略
|
||||
}
|
||||
},
|
||||
child: Text(T('about.openRepository')),
|
||||
Wrap(
|
||||
spacing: GcSpace.sm,
|
||||
runSpacing: GcSpace.sm,
|
||||
children: <Widget>[
|
||||
OutlinedButton(
|
||||
onPressed: () async {
|
||||
final url = about?.repository;
|
||||
if (url == null || url.isEmpty) return;
|
||||
try {
|
||||
await widget.controller.api.openUrl(url);
|
||||
} catch (_) {
|
||||
// 忽略
|
||||
}
|
||||
},
|
||||
child: Text(T('about.openRepository')),
|
||||
),
|
||||
OutlinedButton.icon(
|
||||
onPressed: _redownloading ? null : _redownloadLauncher,
|
||||
icon: _redownloading
|
||||
? const SizedBox(
|
||||
width: 14,
|
||||
height: 14,
|
||||
child: CircularProgressIndicator(strokeWidth: 2),
|
||||
)
|
||||
: const Icon(Icons.refresh_rounded, size: 16),
|
||||
label: Text(
|
||||
_redownloading
|
||||
? T('about.redownloading')
|
||||
: T('about.redownload'),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
if (_redownloadMsg != null) ...<Widget>[
|
||||
const SizedBox(height: GcSpace.md),
|
||||
Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
Icon(
|
||||
_redownloadOk == true
|
||||
? Icons.verified_rounded
|
||||
: Icons.error_outline_rounded,
|
||||
size: 16,
|
||||
color: _redownloadOk == true ? GcColors.ok : GcColors.danger,
|
||||
),
|
||||
const SizedBox(width: GcSpace.xs + 2),
|
||||
Expanded(
|
||||
child: Text(
|
||||
_redownloadMsg!,
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
height: 1.45,
|
||||
color: _redownloadOk == true
|
||||
? GcColors.muted
|
||||
: GcColors.danger,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
],
|
||||
);
|
||||
|
||||
|
||||
@@ -114,25 +114,41 @@ class _DownloadPageViewState extends State<DownloadPageView> {
|
||||
_error = null;
|
||||
});
|
||||
try {
|
||||
final sources = await widget.controller.api.sources();
|
||||
// 三个请求互不依赖,一起发出去:
|
||||
// 源列表(本地,几乎即时)、任务列表、模型索引(要打远端,最慢)
|
||||
// 以前是 sources → models → jobs 串行等三轮,进页面白等多一秒。
|
||||
final sourcesFuture = widget.controller.api.sources();
|
||||
final jobsFuture = widget.controller.api.jobs();
|
||||
final indexFuture = widget.controller.api.remoteModels(
|
||||
sourceId: _selectedSourceId,
|
||||
);
|
||||
|
||||
final sources = await sourcesFuture;
|
||||
final preferred = sources.where((s) => s.enabled).toList();
|
||||
final selected = _selectedSourceId ??
|
||||
(preferred.isNotEmpty
|
||||
? preferred.first.id
|
||||
: (sources.isNotEmpty ? sources.first.id : ''));
|
||||
|
||||
final index = selected.isEmpty
|
||||
? null
|
||||
: await widget.controller.api.remoteModels(sourceId: selected);
|
||||
// 源列表是本地的,先画出来:右侧模型列表还在等远端索引,左侧不必陪着转圈
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_sources = sources;
|
||||
_selectedSourceId = selected;
|
||||
});
|
||||
}
|
||||
|
||||
final index = await indexFuture;
|
||||
final jobs = await jobsFuture;
|
||||
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
_sources = sources;
|
||||
_selectedSourceId = selected;
|
||||
_index = index;
|
||||
_jobs = jobs;
|
||||
_loading = false;
|
||||
});
|
||||
await _refreshJobs();
|
||||
} catch (error) {
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
@@ -440,16 +456,97 @@ class _DownloadPageViewState extends State<DownloadPageView> {
|
||||
),
|
||||
),
|
||||
const SizedBox(width: GcSpace.lg),
|
||||
if (model.installed)
|
||||
OutlinedButton(
|
||||
onPressed: () => _download(model),
|
||||
child: Text(T('dl.reinstall')),
|
||||
)
|
||||
else
|
||||
FilledButton(
|
||||
onPressed: () => _download(model),
|
||||
child: Text(T('dl.download')),
|
||||
_downloadAction(model),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 该模型是否有进行中的下载任务。
|
||||
JobInfo? _activeJobFor(String modelId) {
|
||||
for (final job in _jobs) {
|
||||
if (job.isActive && job.modelId == modelId) return job;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// 按钮位:空闲时是「下载 / 重新下载」,下载中就变成这一行的进度条。
|
||||
Widget _downloadAction(RemoteModelInfo model) {
|
||||
final job = _activeJobFor(model.id);
|
||||
if (job == null) {
|
||||
if (model.installed) {
|
||||
return OutlinedButton(
|
||||
onPressed: () => _download(model),
|
||||
child: Text(T('dl.reinstall')),
|
||||
);
|
||||
}
|
||||
return FilledButton(
|
||||
onPressed: () => _download(model),
|
||||
child: Text(T('dl.download')),
|
||||
);
|
||||
}
|
||||
|
||||
final value = job.progress.clamp(0.0, 1.0).toDouble();
|
||||
final percent = (value * 100).round();
|
||||
final detail = job.detailText.isNotEmpty ? job.detailText : job.statusText;
|
||||
|
||||
return SizedBox(
|
||||
width: 148,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: <Widget>[
|
||||
Row(
|
||||
children: <Widget>[
|
||||
Text(
|
||||
'$percent%',
|
||||
style: TextStyle(
|
||||
fontSize: 12.5,
|
||||
height: 1.2,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: GcColors.accent,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: GcSpace.xs + 2),
|
||||
if (detail.isNotEmpty)
|
||||
Expanded(
|
||||
child: Text(
|
||||
detail,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
textAlign: TextAlign.right,
|
||||
style: TextStyle(
|
||||
fontSize: 11,
|
||||
height: 1.2,
|
||||
color: GcColors.faint,
|
||||
),
|
||||
),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () =>
|
||||
_jobAction(widget.controller.api.cancelJob, job.id),
|
||||
style: TextButton.styleFrom(
|
||||
minimumSize: const Size(0, 22),
|
||||
padding: const EdgeInsets.symmetric(horizontal: GcSpace.sm),
|
||||
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
||||
),
|
||||
child: Text(
|
||||
T('dl.cancel'),
|
||||
style: const TextStyle(fontSize: 11.5),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 3),
|
||||
ClipRRect(
|
||||
borderRadius: BorderRadius.circular(3),
|
||||
child: LinearProgressIndicator(
|
||||
// 还没拿到进度时走不确定态,避免显示 0% 让人以为卡住
|
||||
value: value > 0 ? value : null,
|
||||
minHeight: 6,
|
||||
backgroundColor: GcColors.surfaceAlt,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
@@ -0,0 +1,119 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../i18n.dart';
|
||||
import '../models/base.dart';
|
||||
import '../models/lookup.dart';
|
||||
import '../theme.dart';
|
||||
|
||||
/// 模型视图:在壳内直接渲染 Flutter 模型。
|
||||
///
|
||||
/// 以前「启动模型」是让后端另开一个 Avalonia 窗口;现在模型全部是 Flutter 实现,
|
||||
/// 直接换掉内容区即可 —— 不会多出一个窗口,也不用跨进程传状态。
|
||||
class ModelViewPage extends StatelessWidget {
|
||||
const ModelViewPage({
|
||||
super.key,
|
||||
required this.modelId,
|
||||
required this.onClose,
|
||||
});
|
||||
|
||||
final String modelId;
|
||||
final VoidCallback onClose;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final model = flutterModelFor(modelId);
|
||||
|
||||
if (model == null) {
|
||||
return Center(
|
||||
child: GcCard(
|
||||
padding: const EdgeInsets.all(GcSpace.xxl),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
Text(
|
||||
T('model.missing'),
|
||||
style: TextStyle(
|
||||
fontSize: 15,
|
||||
height: 1.35,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: GcColors.ink,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: GcSpace.sm),
|
||||
GcHint(T('model.missingHint')),
|
||||
const SizedBox(height: GcSpace.lg),
|
||||
OutlinedButton(
|
||||
onPressed: onClose,
|
||||
child: Text(T('model.back')),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: <Widget>[
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(
|
||||
GcSpace.xxl,
|
||||
GcSpace.lg,
|
||||
GcSpace.xxl,
|
||||
GcSpace.sm,
|
||||
),
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
OutlinedButton.icon(
|
||||
onPressed: onClose,
|
||||
icon: const Icon(Icons.arrow_back_rounded, size: 16),
|
||||
label: Text(T('model.back')),
|
||||
),
|
||||
const SizedBox(width: GcSpace.lg),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: <Widget>[
|
||||
Text(
|
||||
model.name(),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
height: 1.3,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: GcColors.ink,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 2),
|
||||
Text(
|
||||
model.description(),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
height: 1.4,
|
||||
color: GcColors.faint,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Expanded(child: ClipRect(child: _body(model))),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _body(GcModel model) {
|
||||
// 模型视图自己管状态(动画、视角),换 id 时必须重建,不能复用 State
|
||||
return KeyedSubtree(
|
||||
key: ValueKey<String>(model.id),
|
||||
child: Builder(builder: (context) => model.buildView(context)),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,163 @@
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../controller.dart';
|
||||
import '../theme.dart';
|
||||
import '../i18n.dart';
|
||||
|
||||
/// 百宝箱页:今日人品、随机运势等小玩意。
|
||||
class TreasurePage extends StatefulWidget {
|
||||
const TreasurePage({super.key, required this.controller});
|
||||
|
||||
final ShellController controller;
|
||||
|
||||
@override
|
||||
State<TreasurePage> createState() => _TreasurePageState();
|
||||
}
|
||||
|
||||
class _TreasurePageState extends State<TreasurePage> {
|
||||
String _fortune = '';
|
||||
String _luckyColor = '';
|
||||
String _luckyNumber = '';
|
||||
bool _loading = false;
|
||||
final Random _rand = Random();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_refresh();
|
||||
}
|
||||
|
||||
void _refresh() {
|
||||
setState(() => _loading = true);
|
||||
// 模拟计算延迟
|
||||
Future.delayed(const Duration(milliseconds: 400), () {
|
||||
if (!mounted) return;
|
||||
final fortunes = <String>[
|
||||
'今日宜:尝试新事物,突破舒适区。',
|
||||
'运气不错,适合做重要的决定。',
|
||||
'财运旺盛,可能会有意外收获。',
|
||||
'人际和谐,适合合作与沟通。',
|
||||
'专注当下,好运自然来。',
|
||||
'保持乐观,今天会有好消息。',
|
||||
'灵感涌现,适合创作和思考。',
|
||||
'脚踏实地,一步一个脚印。',
|
||||
'贵人运旺,多与他人交流。',
|
||||
'健康第一,注意休息和锻炼。',
|
||||
];
|
||||
final colors = <String>[
|
||||
'红色', '蓝色', '绿色', '金色', '紫色', '橙色', '粉色', '青色',
|
||||
];
|
||||
setState(() {
|
||||
_fortune = fortunes[_rand.nextInt(fortunes.length)];
|
||||
_luckyColor = colors[_rand.nextInt(colors.length)];
|
||||
_luckyNumber = '${(_rand.nextInt(99)) + 1}';
|
||||
_loading = false;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: GcColors.appBg,
|
||||
body: _loading
|
||||
? const Center(child: CircularProgressIndicator())
|
||||
: Center(
|
||||
child: ConstrainedBox(
|
||||
constraints: const BoxConstraints(maxWidth: 480),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: <Widget>[
|
||||
// 今日人品卡片
|
||||
GcCard(
|
||||
padding: const EdgeInsets.all(GcSpace.xxl),
|
||||
child: Column(
|
||||
children: <Widget>[
|
||||
Icon(
|
||||
Icons.star_rounded,
|
||||
size: 48,
|
||||
color: GcColors.accent,
|
||||
),
|
||||
const SizedBox(height: GcSpace.lg),
|
||||
Text(
|
||||
T('treasure.fortuneTitle'),
|
||||
style: const TextStyle(
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: GcSpace.md),
|
||||
Text(
|
||||
_fortune,
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
fontSize: 15,
|
||||
height: 1.5,
|
||||
color: GcColors.muted,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: GcSpace.lg),
|
||||
// 幸运信息
|
||||
Wrap(
|
||||
spacing: GcSpace.md,
|
||||
runSpacing: GcSpace.md,
|
||||
children: <Widget>[
|
||||
_buildStatCard(
|
||||
icon: Icons.check_circle_outline_rounded,
|
||||
label: T('treasure.luckyColor'),
|
||||
value: _luckyColor,
|
||||
),
|
||||
_buildStatCard(
|
||||
icon: Icons.numbers_rounded,
|
||||
label: T('treasure.luckyNumber'),
|
||||
value: _luckyNumber,
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: GcSpace.xl),
|
||||
// 刷新按钮
|
||||
FilledButton.icon(
|
||||
onPressed: _refresh,
|
||||
icon: const Icon(Icons.refresh_rounded, size: 18),
|
||||
label: Text(T('treasure.refresh')),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildStatCard({
|
||||
required IconData icon,
|
||||
required String label,
|
||||
required String value,
|
||||
}) {
|
||||
return GcCard(
|
||||
padding: const EdgeInsets.all(GcSpace.lg),
|
||||
child: Column(
|
||||
children: <Widget>[
|
||||
Icon(icon, size: 28, color: GcColors.accent),
|
||||
const SizedBox(height: GcSpace.sm),
|
||||
Text(
|
||||
label,
|
||||
style: TextStyle(fontSize: 12, color: GcColors.muted),
|
||||
),
|
||||
const SizedBox(height: GcSpace.xs),
|
||||
Text(
|
||||
value,
|
||||
style: const TextStyle(
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,404 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'dart:math';
|
||||
import '../controller.dart';
|
||||
import '../theme.dart';
|
||||
import '../i18n.dart';
|
||||
import '../models/user.dart';
|
||||
|
||||
/// 用户页面:登录/注册、签到、主题颜色、二选一
|
||||
class UserPage extends StatefulWidget {
|
||||
const UserPage({super.key, required this.controller});
|
||||
|
||||
final ShellController controller;
|
||||
|
||||
@override
|
||||
State<UserPage> createState() => _UserPageState();
|
||||
}
|
||||
|
||||
class _UserPageState extends State<UserPage> {
|
||||
UserRecord? _user;
|
||||
bool _loading = true;
|
||||
String? _error;
|
||||
|
||||
// 登录/注册表单
|
||||
final _usernameCtrl = TextEditingController();
|
||||
final _passwordCtrl = TextEditingController();
|
||||
bool _isLogin = true;
|
||||
|
||||
// 二选一
|
||||
final _option1Ctrl = TextEditingController();
|
||||
final _option2Ctrl = TextEditingController();
|
||||
String? _randomResult;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_loadUser();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_usernameCtrl.dispose();
|
||||
_passwordCtrl.dispose();
|
||||
_option1Ctrl.dispose();
|
||||
_option2Ctrl.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
Future<void> _loadUser() async {
|
||||
setState(() {
|
||||
_loading = true;
|
||||
_error = null;
|
||||
});
|
||||
try {
|
||||
await widget.controller.api.initUserSession();
|
||||
final resp = await widget.controller.api.me();
|
||||
if (!mounted) return;
|
||||
if (resp != null) {
|
||||
setState(() {
|
||||
_user = UserRecord.fromJson(resp);
|
||||
_loading = false;
|
||||
});
|
||||
} else {
|
||||
setState(() {
|
||||
_loading = false;
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
_loading = false;
|
||||
_error = e.toString();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _loginOrRegister() async {
|
||||
final username = _usernameCtrl.text.trim();
|
||||
final password = _passwordCtrl.text;
|
||||
if (username.isEmpty || password.isEmpty) {
|
||||
_showError(T('user.fillAll'));
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
Map<String, dynamic> resp;
|
||||
if (_isLogin) {
|
||||
resp = await widget.controller.api.login(username, password);
|
||||
} else {
|
||||
resp = await widget.controller.api.register(username, password);
|
||||
if (!mounted) return;
|
||||
// 注册成功后自动登录
|
||||
resp = await widget.controller.api.login(username, password);
|
||||
}
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
_user = UserRecord.fromJson(resp);
|
||||
_usernameCtrl.clear();
|
||||
_passwordCtrl.clear();
|
||||
});
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text(_isLogin ? T('user.loginSuccess') : T('user.registerSuccess'))),
|
||||
);
|
||||
} catch (e) {
|
||||
if (!mounted) return;
|
||||
_showError(e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _signin() async {
|
||||
try {
|
||||
final resp = await widget.controller.api.signin();
|
||||
if (!mounted) return;
|
||||
if (resp.containsKey('message') && resp['message'] == '今日已签到') {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text(T('user.alreadySigned'))),
|
||||
);
|
||||
return;
|
||||
}
|
||||
setState(() {
|
||||
_user = UserRecord.fromJson({
|
||||
...resp,
|
||||
'username': _user?.username ?? '',
|
||||
});
|
||||
});
|
||||
final reward = resp['reward'] as int? ?? 0;
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text('${T('user.signinSuccess')} +$reward ${T('user.points')}')),
|
||||
);
|
||||
} catch (e) {
|
||||
if (!mounted) return;
|
||||
_showError(e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
void _pickRandom() {
|
||||
final opt1 = _option1Ctrl.text.trim();
|
||||
final opt2 = _option2Ctrl.text.trim();
|
||||
if (opt1.isEmpty || opt2.isEmpty) {
|
||||
_showError(T('user.fillOptions'));
|
||||
return;
|
||||
}
|
||||
final result = Random().nextBool() ? opt1 : opt2;
|
||||
setState(() => _randomResult = result);
|
||||
}
|
||||
|
||||
Future<void> _changeTheme(String hex, int cost) async {
|
||||
if (_user == null) {
|
||||
_showError(T('user.loginFirst'));
|
||||
return;
|
||||
}
|
||||
try {
|
||||
final resp = await widget.controller.api.changeTheme(hex, cost);
|
||||
if (!mounted) return;
|
||||
if (resp.containsKey('message')) {
|
||||
setState(() {
|
||||
_user = UserRecord(
|
||||
username: _user!.username,
|
||||
points: resp['points'] as int? ?? _user!.points,
|
||||
consecutiveDays: _user!.consecutiveDays,
|
||||
lastSignIn: _user!.lastSignIn,
|
||||
themeColor: '0x${resp['theme_color'] ?? hex}',
|
||||
);
|
||||
});
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('主题已更新')),
|
||||
);
|
||||
}
|
||||
} catch (e) {
|
||||
if (!mounted) return;
|
||||
_showError(e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
void _showError(String msg) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text(msg)),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: GcColors.appBg,
|
||||
body: _loading
|
||||
? const Center(child: CircularProgressIndicator())
|
||||
: SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(GcSpace.xxl),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: <Widget>[
|
||||
// 用户信息卡片
|
||||
if (_user != null) ...[
|
||||
GcCard(
|
||||
padding: const EdgeInsets.all(GcSpace.lg),
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
Icon(Icons.person_rounded, size: 40, color: GcColors.accent),
|
||||
const SizedBox(width: GcSpace.md),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
Text(
|
||||
_user!.username,
|
||||
style: const TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
'${T('user.points')}: ${_user!.points}',
|
||||
style: TextStyle(color: GcColors.muted),
|
||||
),
|
||||
Text(
|
||||
'${T('user.days')}: ${_user!.consecutiveDays}',
|
||||
style: TextStyle(color: GcColors.muted),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
FilledButton(
|
||||
onPressed: _signin,
|
||||
child: Text(T('user.signin')),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: GcSpace.lg),
|
||||
],
|
||||
|
||||
// 登录/注册表单
|
||||
GcCard(
|
||||
padding: const EdgeInsets.all(GcSpace.lg),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
Text(
|
||||
_isLogin ? T('user.login') : T('user.register'),
|
||||
style: const TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: GcSpace.md),
|
||||
TextField(
|
||||
controller: _usernameCtrl,
|
||||
decoration: InputDecoration(
|
||||
labelText: T('user.username'),
|
||||
border: const OutlineInputBorder(),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: GcSpace.md),
|
||||
TextField(
|
||||
controller: _passwordCtrl,
|
||||
decoration: InputDecoration(
|
||||
labelText: T('user.password'),
|
||||
border: const OutlineInputBorder(),
|
||||
),
|
||||
obscureText: true,
|
||||
),
|
||||
const SizedBox(height: GcSpace.md),
|
||||
FilledButton(
|
||||
onPressed: _loginOrRegister,
|
||||
child: Text(_isLogin ? T('user.login') : T('user.register')),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () => setState(() => _isLogin = !_isLogin),
|
||||
child: Text(_isLogin ? T('user.switchToRegister') : T('user.switchToLogin')),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: GcSpace.lg),
|
||||
|
||||
// 二选一
|
||||
GcCard(
|
||||
padding: const EdgeInsets.all(GcSpace.lg),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
Text(
|
||||
T('user.pick'),
|
||||
style: const TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: GcSpace.md),
|
||||
TextField(
|
||||
controller: _option1Ctrl,
|
||||
decoration: InputDecoration(
|
||||
labelText: T('user.option1'),
|
||||
border: const OutlineInputBorder(),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: GcSpace.md),
|
||||
TextField(
|
||||
controller: _option2Ctrl,
|
||||
decoration: InputDecoration(
|
||||
labelText: T('user.option2'),
|
||||
border: const OutlineInputBorder(),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: GcSpace.md),
|
||||
FilledButton(
|
||||
onPressed: _pickRandom,
|
||||
child: Text(T('user.pickRandom')),
|
||||
),
|
||||
if (_randomResult != null) ...[
|
||||
const SizedBox(height: GcSpace.md),
|
||||
GcCard(
|
||||
child: Text(
|
||||
_randomResult!,
|
||||
textAlign: TextAlign.center,
|
||||
style: const TextStyle(fontSize: 18, fontWeight: FontWeight.w600),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: GcSpace.lg),
|
||||
|
||||
// 主题颜色
|
||||
GcCard(
|
||||
padding: const EdgeInsets.all(GcSpace.lg),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
Text(
|
||||
T('user.theme'),
|
||||
style: const TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: GcSpace.md),
|
||||
Wrap(
|
||||
spacing: GcSpace.md,
|
||||
runSpacing: GcSpace.md,
|
||||
children: ThemeColor.predefined.map((c) {
|
||||
final canAfford = _user == null || _user!.points >= c.cost;
|
||||
final isCurrent = _user?.themeColor == '0x$c.hex';
|
||||
return InkWell(
|
||||
onTap: canAfford ? () => _changeTheme(c.hex, c.cost) : null,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
child: Container(
|
||||
width: 60,
|
||||
height: 60,
|
||||
decoration: BoxDecoration(
|
||||
color: Color(int.parse('0xFF${c.hex}')),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
border: Border.all(
|
||||
color: isCurrent ? GcColors.accent : GcColors.line,
|
||||
width: isCurrent ? 2 : 1,
|
||||
),
|
||||
),
|
||||
child: Stack(
|
||||
children: <Widget>[
|
||||
if (c.cost > 0 && !_canAfford(c.cost))
|
||||
Container(
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.black.withOpacity(0.5),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Center(
|
||||
child: Text(
|
||||
'${c.cost}',
|
||||
style: const TextStyle(color: Colors.white, fontSize: 12),
|
||||
),
|
||||
),
|
||||
),
|
||||
if (isCurrent)
|
||||
const Positioned(
|
||||
bottom: 2,
|
||||
right: 2,
|
||||
child: Icon(Icons.check_rounded, size: 16, color: Colors.white),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
if (_error != null) ...[
|
||||
const SizedBox(height: GcSpace.md),
|
||||
Text(_error!, style: const TextStyle(color: Colors.red)),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
bool _canAfford(int cost) {
|
||||
if (cost <= 0) return true;
|
||||
if (_user == null) return false;
|
||||
return _user!.points >= cost;
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import 'controller.dart';
|
||||
import 'i18n.dart';
|
||||
import 'pages.dart';
|
||||
import 'theme.dart';
|
||||
import 'window_chrome.dart';
|
||||
|
||||
/// 侧边栏导航项。
|
||||
class _NavItem {
|
||||
@@ -19,6 +20,8 @@ const List<_NavItem> _navItems = <_NavItem>[
|
||||
_NavItem(Icons.download_rounded, 'nav.download'),
|
||||
_NavItem(Icons.tune_rounded, 'nav.settings'),
|
||||
_NavItem(Icons.info_outline_rounded, 'nav.about'),
|
||||
_NavItem(Icons.auto_awesome_rounded, 'nav.treasure'),
|
||||
_NavItem(Icons.person_rounded, 'nav.user'),
|
||||
];
|
||||
|
||||
/// 桌面端滚动行为:去掉移动端的拉伸回弹和边缘光晕,滚轮更跟手。
|
||||
@@ -69,16 +72,24 @@ class _ShellPageState extends State<ShellPage> {
|
||||
final controller = widget.controller;
|
||||
return Scaffold(
|
||||
backgroundColor: GcColors.appBg,
|
||||
body: Row(
|
||||
body: Column(
|
||||
children: <Widget>[
|
||||
_Sidebar(controller: controller),
|
||||
Container(width: 1, color: GcColors.line),
|
||||
// 自绘标题栏(macOS):系统标题栏已隐藏,最小化/最大化/关闭在这里画
|
||||
const GcTitleBar(),
|
||||
Expanded(
|
||||
child: Column(
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
Expanded(child: _content(controller)),
|
||||
if (controller.updateBarVisible)
|
||||
_UpdateBar(controller: controller),
|
||||
_Sidebar(controller: controller),
|
||||
Container(width: 1, color: GcColors.line),
|
||||
Expanded(
|
||||
child: Column(
|
||||
children: <Widget>[
|
||||
Expanded(child: _content(controller)),
|
||||
if (controller.updateBarVisible)
|
||||
_UpdateBar(controller: controller),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -136,6 +147,10 @@ class _ShellPageState extends State<ShellPage> {
|
||||
return SettingsPageView(controller: controller);
|
||||
case 4:
|
||||
return AboutPageView(controller: controller);
|
||||
case 5:
|
||||
return TreasurePage(controller: controller);
|
||||
case 6:
|
||||
return UserPage(controller: controller);
|
||||
default:
|
||||
return HomePageView(controller: controller);
|
||||
}
|
||||
@@ -445,7 +460,8 @@ class _BackendDown extends StatelessWidget {
|
||||
const SizedBox(height: GcSpace.md),
|
||||
GcHint(controller.loadError ?? ''),
|
||||
const SizedBox(height: GcSpace.xs),
|
||||
GcHint('${T('set.backend')}: ${controller.api.baseUrl}'),
|
||||
GcHint('${T('set.backend')}: ${controller.api.baseUrl}'
|
||||
' · ${controller.api.hasSessionToken ? '令牌已就绪' : '缺少会话令牌'}'),
|
||||
const SizedBox(height: GcSpace.lg),
|
||||
FilledButton(
|
||||
onPressed: controller.bootstrap,
|
||||
|
||||
@@ -0,0 +1,164 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
import 'theme.dart';
|
||||
|
||||
/// 自绘窗口按钮的通道(macOS 侧在 macos/Runner/MainFlutterWindow.swift 实现)。
|
||||
///
|
||||
/// 系统标题栏已去掉(titleVisibility = .hidden + fullSizeContentView),
|
||||
/// 最小化 / 最大化 / 关闭 全部由 Flutter 画,外观跟界面统一。
|
||||
class GcWindow {
|
||||
GcWindow._();
|
||||
|
||||
static const MethodChannel _channel = MethodChannel('gc/window');
|
||||
|
||||
/// 只有 macOS 走了自绘标题栏;其它平台保留系统标题栏,不显示自绘按钮。
|
||||
static bool get supported => !kIsWeb && Platform.isMacOS;
|
||||
|
||||
static Future<void> minimize() => _invoke('minimize');
|
||||
static Future<void> close() => _invoke('close');
|
||||
static Future<void> toggleMaximize() => _invoke('toggleMaximize');
|
||||
|
||||
/// 开始拖拽窗口。用原生 performDrag,比在 Flutter 里模拟位置更跟手。
|
||||
static Future<void> beginDrag() => _invoke('beginDrag');
|
||||
|
||||
static Future<bool> isMaximized() async {
|
||||
if (!supported) return false;
|
||||
try {
|
||||
return await _channel.invokeMethod<bool>('isMaximized') ?? false;
|
||||
} catch (_) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
static Future<void> _invoke(String method) async {
|
||||
if (!supported) return;
|
||||
try {
|
||||
await _channel.invokeMethod<void>(method);
|
||||
} catch (_) {
|
||||
// 通道不可用(例如截图测试环境)时静默忽略
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// 顶部标题栏:左侧应用名 + 右侧自绘的最小化 / 最大化 / 关闭。
|
||||
///
|
||||
/// 只在 macOS 显示;其它平台系统标题栏还在,这里返回零高度占位。
|
||||
class GcTitleBar extends StatelessWidget {
|
||||
const GcTitleBar({super.key, this.title = 'Morris GC'});
|
||||
|
||||
final String title;
|
||||
|
||||
static const double height = 38;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (!GcWindow.supported) return const SizedBox.shrink();
|
||||
|
||||
return GestureDetector(
|
||||
behavior: HitTestBehavior.opaque,
|
||||
onPanStart: (_) => GcWindow.beginDrag(),
|
||||
child: Container(
|
||||
height: height,
|
||||
// 与主题底色保持一致:浅色主题是纯白,深色主题是深色面板色。
|
||||
// 不叠强调色 —— 标题栏属于窗口底色,染色会显得和内容区不是一套。
|
||||
decoration: BoxDecoration(
|
||||
color: GcColors.sideBg,
|
||||
border: Border(bottom: BorderSide(color: GcColors.line)),
|
||||
),
|
||||
padding: const EdgeInsets.only(left: GcSpace.xl, right: GcSpace.sm),
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
Text(
|
||||
title,
|
||||
style: TextStyle(
|
||||
fontSize: 12.5,
|
||||
height: 1.2,
|
||||
fontWeight: FontWeight.w600,
|
||||
letterSpacing: 0.2,
|
||||
color: GcColors.faint,
|
||||
),
|
||||
),
|
||||
const Spacer(),
|
||||
_WindowButton(
|
||||
icon: Icons.remove_rounded,
|
||||
tooltip: '最小化',
|
||||
onTap: GcWindow.minimize,
|
||||
),
|
||||
_WindowButton(
|
||||
icon: Icons.crop_square_rounded,
|
||||
tooltip: '最大化',
|
||||
onTap: GcWindow.toggleMaximize,
|
||||
),
|
||||
_WindowButton(
|
||||
icon: Icons.close_rounded,
|
||||
tooltip: '关闭',
|
||||
danger: true,
|
||||
onTap: GcWindow.close,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _WindowButton extends StatefulWidget {
|
||||
const _WindowButton({
|
||||
required this.icon,
|
||||
required this.tooltip,
|
||||
required this.onTap,
|
||||
this.danger = false,
|
||||
});
|
||||
|
||||
final IconData icon;
|
||||
final String tooltip;
|
||||
final Future<void> Function() onTap;
|
||||
final bool danger;
|
||||
|
||||
@override
|
||||
State<_WindowButton> createState() => _WindowButtonState();
|
||||
}
|
||||
|
||||
class _WindowButtonState extends State<_WindowButton> {
|
||||
bool _hover = false;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final Color bg = _hover
|
||||
? (widget.danger
|
||||
? GcColors.danger.withOpacity(0.16)
|
||||
: GcColors.surfaceHover)
|
||||
: Colors.transparent;
|
||||
|
||||
return Tooltip(
|
||||
message: widget.tooltip,
|
||||
waitDuration: const Duration(milliseconds: 500),
|
||||
child: MouseRegion(
|
||||
cursor: SystemMouseCursors.basic,
|
||||
onEnter: (_) => setState(() => _hover = true),
|
||||
onExit: (_) => setState(() => _hover = false),
|
||||
child: GestureDetector(
|
||||
onTap: () => widget.onTap(),
|
||||
child: AnimatedContainer(
|
||||
duration: const Duration(milliseconds: 110),
|
||||
width: 40,
|
||||
height: GcTitleBar.height,
|
||||
alignment: Alignment.center,
|
||||
color: bg,
|
||||
child: Icon(
|
||||
widget.icon,
|
||||
size: 15,
|
||||
color: _hover
|
||||
? (widget.danger ? GcColors.danger : GcColors.ink)
|
||||
: GcColors.faint,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,52 @@ class MainFlutterWindow: NSWindow {
|
||||
self.contentViewController = flutterViewController
|
||||
self.setFrame(windowFrame, display: true)
|
||||
|
||||
// 去掉系统标题栏(应用名 + 红绿灯按钮),改由 Flutter 自绘:
|
||||
// fullSizeContentView 让内容铺满整窗,titlebarAppearsTransparent + titleVisibility
|
||||
// 隐藏标题栏文字与背景,三个系统按钮一并隐藏。
|
||||
// 注意:不要动 styleMask 里的 .resizable,否则窗口无法缩放。
|
||||
self.titleVisibility = .hidden
|
||||
self.titlebarAppearsTransparent = true
|
||||
self.styleMask.insert(.fullSizeContentView)
|
||||
self.standardWindowButton(.closeButton)?.isHidden = true
|
||||
self.standardWindowButton(.miniaturizeButton)?.isHidden = true
|
||||
self.standardWindowButton(.zoomButton)?.isHidden = true
|
||||
self.isMovableByWindowBackground = true
|
||||
|
||||
// 自绘按钮 -> 原生窗口操作
|
||||
let channel = FlutterMethodChannel(
|
||||
name: "gc/window",
|
||||
binaryMessenger: flutterViewController.engine.binaryMessenger
|
||||
)
|
||||
channel.setMethodCallHandler { [weak self] call, result in
|
||||
guard let self = self else {
|
||||
result(FlutterMethodNotImplemented)
|
||||
return
|
||||
}
|
||||
switch call.method {
|
||||
case "minimize":
|
||||
self.miniaturize(nil)
|
||||
result(nil)
|
||||
case "toggleMaximize":
|
||||
// NSWindow.zoom(_:) 自带切换语义:放大状态下再调即还原
|
||||
self.zoom(nil)
|
||||
result(nil)
|
||||
case "close":
|
||||
self.close()
|
||||
result(nil)
|
||||
case "isMaximized":
|
||||
result(self.isZoomed)
|
||||
case "beginDrag":
|
||||
// 拖拽整窗:用系统拖拽,比在 Dart 里逐帧挪窗口平滑
|
||||
if let event = NSApp.currentEvent {
|
||||
self.performDrag(with: event)
|
||||
}
|
||||
result(nil)
|
||||
default:
|
||||
result(FlutterMethodNotImplemented)
|
||||
}
|
||||
}
|
||||
|
||||
RegisterGeneratedPlugins(registry: flutterViewController)
|
||||
|
||||
super.awakeFromNib()
|
||||
|
||||
+37
-37
@@ -6,7 +6,7 @@ packages:
|
||||
description:
|
||||
name: async
|
||||
sha256: "947bfcf187f74dbc5e146c9eb9c0f10c9f8b30743e341481c1e2ed3ecc18c20c"
|
||||
url: "https://pub.dev"
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "2.11.0"
|
||||
boolean_selector:
|
||||
@@ -14,7 +14,7 @@ packages:
|
||||
description:
|
||||
name: boolean_selector
|
||||
sha256: "6cfb5af12253eaf2b368f07bacc5a80d1301a071c73360d746b7f2e32d762c66"
|
||||
url: "https://pub.dev"
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "2.1.1"
|
||||
characters:
|
||||
@@ -22,7 +22,7 @@ packages:
|
||||
description:
|
||||
name: characters
|
||||
sha256: "04a925763edad70e8443c99234dc3328f442e811f1d8fd1a72f1c8ad0f69a605"
|
||||
url: "https://pub.dev"
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "1.3.0"
|
||||
clock:
|
||||
@@ -30,7 +30,7 @@ packages:
|
||||
description:
|
||||
name: clock
|
||||
sha256: cb6d7f03e1de671e34607e909a7213e31d7752be4fb66a86d29fe1eb14bfb5cf
|
||||
url: "https://pub.dev"
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "1.1.1"
|
||||
collection:
|
||||
@@ -38,7 +38,7 @@ packages:
|
||||
description:
|
||||
name: collection
|
||||
sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a
|
||||
url: "https://pub.dev"
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "1.18.0"
|
||||
cupertino_icons:
|
||||
@@ -46,7 +46,7 @@ packages:
|
||||
description:
|
||||
name: cupertino_icons
|
||||
sha256: ba631d1c7f7bef6b729a622b7b752645a2d076dba9976925b8f25725a30e1ee6
|
||||
url: "https://pub.dev"
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "1.0.8"
|
||||
fake_async:
|
||||
@@ -54,7 +54,7 @@ packages:
|
||||
description:
|
||||
name: fake_async
|
||||
sha256: "511392330127add0b769b75a987850d136345d9227c6b94c96a04cf4a391bf78"
|
||||
url: "https://pub.dev"
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "1.3.1"
|
||||
flutter:
|
||||
@@ -67,7 +67,7 @@ packages:
|
||||
description:
|
||||
name: flutter_inappwebview
|
||||
sha256: "80092d13d3e29b6227e25b67973c67c7210bd5e35c4b747ca908e31eb71a46d5"
|
||||
url: "https://pub.dev"
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "6.1.5"
|
||||
flutter_inappwebview_android:
|
||||
@@ -75,7 +75,7 @@ packages:
|
||||
description:
|
||||
name: flutter_inappwebview_android
|
||||
sha256: "62557c15a5c2db5d195cb3892aab74fcaec266d7b86d59a6f0027abd672cddba"
|
||||
url: "https://pub.dev"
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "1.1.3"
|
||||
flutter_inappwebview_internal_annotations:
|
||||
@@ -83,7 +83,7 @@ packages:
|
||||
description:
|
||||
name: flutter_inappwebview_internal_annotations
|
||||
sha256: "787171d43f8af67864740b6f04166c13190aa74a1468a1f1f1e9ee5b90c359cd"
|
||||
url: "https://pub.dev"
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "1.2.0"
|
||||
flutter_inappwebview_ios:
|
||||
@@ -91,7 +91,7 @@ packages:
|
||||
description:
|
||||
name: flutter_inappwebview_ios
|
||||
sha256: "5818cf9b26cf0cbb0f62ff50772217d41ea8d3d9cc00279c45f8aabaa1b4025d"
|
||||
url: "https://pub.dev"
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "1.1.2"
|
||||
flutter_inappwebview_macos:
|
||||
@@ -99,7 +99,7 @@ packages:
|
||||
description:
|
||||
name: flutter_inappwebview_macos
|
||||
sha256: c1fbb86af1a3738e3541364d7d1866315ffb0468a1a77e34198c9be571287da1
|
||||
url: "https://pub.dev"
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "1.1.2"
|
||||
flutter_inappwebview_platform_interface:
|
||||
@@ -107,7 +107,7 @@ packages:
|
||||
description:
|
||||
name: flutter_inappwebview_platform_interface
|
||||
sha256: cf5323e194096b6ede7a1ca808c3e0a078e4b33cc3f6338977d75b4024ba2500
|
||||
url: "https://pub.dev"
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "1.3.0+1"
|
||||
flutter_inappwebview_web:
|
||||
@@ -115,7 +115,7 @@ packages:
|
||||
description:
|
||||
name: flutter_inappwebview_web
|
||||
sha256: "55f89c83b0a0d3b7893306b3bb545ba4770a4df018204917148ebb42dc14a598"
|
||||
url: "https://pub.dev"
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "1.1.2"
|
||||
flutter_inappwebview_windows:
|
||||
@@ -123,7 +123,7 @@ packages:
|
||||
description:
|
||||
name: flutter_inappwebview_windows
|
||||
sha256: "8b4d3a46078a2cdc636c4a3d10d10f2a16882f6be607962dbfff8874d1642055"
|
||||
url: "https://pub.dev"
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "0.6.0"
|
||||
flutter_lints:
|
||||
@@ -131,7 +131,7 @@ packages:
|
||||
description:
|
||||
name: flutter_lints
|
||||
sha256: "3f41d009ba7172d5ff9be5f6e6e6abb4300e263aab8866d2a0842ed2a70f8f0c"
|
||||
url: "https://pub.dev"
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "4.0.0"
|
||||
flutter_test:
|
||||
@@ -149,7 +149,7 @@ packages:
|
||||
description:
|
||||
name: http
|
||||
sha256: "87721a4a50b19c7f1d49001e51409bddc46303966ce89a65af4f4e6004896412"
|
||||
url: "https://pub.dev"
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "1.6.0"
|
||||
http_parser:
|
||||
@@ -157,7 +157,7 @@ packages:
|
||||
description:
|
||||
name: http_parser
|
||||
sha256: "2aa08ce0341cc9b354a498388e30986515406668dbcc4f7c950c3e715496693b"
|
||||
url: "https://pub.dev"
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "4.0.2"
|
||||
leak_tracker:
|
||||
@@ -165,7 +165,7 @@ packages:
|
||||
description:
|
||||
name: leak_tracker
|
||||
sha256: "3f87a60e8c63aecc975dda1ceedbc8f24de75f09e4856ea27daf8958f2f0ce05"
|
||||
url: "https://pub.dev"
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "10.0.5"
|
||||
leak_tracker_flutter_testing:
|
||||
@@ -173,7 +173,7 @@ packages:
|
||||
description:
|
||||
name: leak_tracker_flutter_testing
|
||||
sha256: "932549fb305594d82d7183ecd9fa93463e9914e1b67cacc34bc40906594a1806"
|
||||
url: "https://pub.dev"
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "3.0.5"
|
||||
leak_tracker_testing:
|
||||
@@ -181,7 +181,7 @@ packages:
|
||||
description:
|
||||
name: leak_tracker_testing
|
||||
sha256: "6ba465d5d76e67ddf503e1161d1f4a6bc42306f9d66ca1e8f079a47290fb06d3"
|
||||
url: "https://pub.dev"
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "3.0.1"
|
||||
lints:
|
||||
@@ -189,7 +189,7 @@ packages:
|
||||
description:
|
||||
name: lints
|
||||
sha256: "976c774dd944a42e83e2467f4cc670daef7eed6295b10b36ae8c85bcbf828235"
|
||||
url: "https://pub.dev"
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "4.0.0"
|
||||
matcher:
|
||||
@@ -197,7 +197,7 @@ packages:
|
||||
description:
|
||||
name: matcher
|
||||
sha256: d2323aa2060500f906aa31a895b4030b6da3ebdcc5619d14ce1aada65cd161cb
|
||||
url: "https://pub.dev"
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "0.12.16+1"
|
||||
material_color_utilities:
|
||||
@@ -205,7 +205,7 @@ packages:
|
||||
description:
|
||||
name: material_color_utilities
|
||||
sha256: f7142bb1154231d7ea5f96bc7bde4bda2a0945d2806bb11670e30b850d56bdec
|
||||
url: "https://pub.dev"
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "0.11.1"
|
||||
meta:
|
||||
@@ -213,7 +213,7 @@ packages:
|
||||
description:
|
||||
name: meta
|
||||
sha256: bdb68674043280c3428e9ec998512fb681678676b3c54e773629ffe74419f8c7
|
||||
url: "https://pub.dev"
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "1.15.0"
|
||||
path:
|
||||
@@ -221,7 +221,7 @@ packages:
|
||||
description:
|
||||
name: path
|
||||
sha256: "087ce49c3f0dc39180befefc60fdb4acd8f8620e5682fe2476afd0b3688bb4af"
|
||||
url: "https://pub.dev"
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "1.9.0"
|
||||
plugin_platform_interface:
|
||||
@@ -229,7 +229,7 @@ packages:
|
||||
description:
|
||||
name: plugin_platform_interface
|
||||
sha256: "4820fbfdb9478b1ebae27888254d445073732dae3d6ea81f0b7e06d5dedc3f02"
|
||||
url: "https://pub.dev"
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "2.1.8"
|
||||
sky_engine:
|
||||
@@ -242,7 +242,7 @@ packages:
|
||||
description:
|
||||
name: source_span
|
||||
sha256: "53e943d4206a5e30df338fd4c6e7a077e02254531b138a15aec3bd143c1a8b3c"
|
||||
url: "https://pub.dev"
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "1.10.0"
|
||||
stack_trace:
|
||||
@@ -250,7 +250,7 @@ packages:
|
||||
description:
|
||||
name: stack_trace
|
||||
sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b"
|
||||
url: "https://pub.dev"
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "1.11.1"
|
||||
stream_channel:
|
||||
@@ -258,7 +258,7 @@ packages:
|
||||
description:
|
||||
name: stream_channel
|
||||
sha256: ba2aa5d8cc609d96bbb2899c28934f9e1af5cddbd60a827822ea467161eb54e7
|
||||
url: "https://pub.dev"
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "2.1.2"
|
||||
string_scanner:
|
||||
@@ -266,7 +266,7 @@ packages:
|
||||
description:
|
||||
name: string_scanner
|
||||
sha256: "556692adab6cfa87322a115640c11f13cb77b3f076ddcc5d6ae3c20242bedcde"
|
||||
url: "https://pub.dev"
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "1.2.0"
|
||||
term_glyph:
|
||||
@@ -274,7 +274,7 @@ packages:
|
||||
description:
|
||||
name: term_glyph
|
||||
sha256: a29248a84fbb7c79282b40b8c72a1209db169a2e0542bce341da992fe1bc7e84
|
||||
url: "https://pub.dev"
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "1.2.1"
|
||||
test_api:
|
||||
@@ -282,7 +282,7 @@ packages:
|
||||
description:
|
||||
name: test_api
|
||||
sha256: "5b8a98dafc4d5c4c9c72d8b31ab2b23fc13422348d2997120294d3bac86b4ddb"
|
||||
url: "https://pub.dev"
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "0.7.2"
|
||||
typed_data:
|
||||
@@ -290,7 +290,7 @@ packages:
|
||||
description:
|
||||
name: typed_data
|
||||
sha256: f9049c039ebfeb4cf7a7104a675823cd72dba8297f264b6637062516699fa006
|
||||
url: "https://pub.dev"
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "1.4.0"
|
||||
vector_math:
|
||||
@@ -298,7 +298,7 @@ packages:
|
||||
description:
|
||||
name: vector_math
|
||||
sha256: "80b3257d1492ce4d091729e3a67a60407d227c27241d6927be0130c98e741803"
|
||||
url: "https://pub.dev"
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "2.1.4"
|
||||
vm_service:
|
||||
@@ -306,7 +306,7 @@ packages:
|
||||
description:
|
||||
name: vm_service
|
||||
sha256: "5c5f338a667b4c644744b661f309fb8080bb94b18a7e91ef1dbd343bed00ed6d"
|
||||
url: "https://pub.dev"
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "14.2.5"
|
||||
web:
|
||||
@@ -314,7 +314,7 @@ packages:
|
||||
description:
|
||||
name: web
|
||||
sha256: "868d88a33d8a87b18ffc05f9f030ba328ffefba92d6c127917a2ba740f9cfe4a"
|
||||
url: "https://pub.dev"
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "1.1.1"
|
||||
sdks:
|
||||
|
||||
Reference in new issue
Block a user