Skip to content

Commit 7e40957

Browse files
committed
✨ 更新依赖项版本,优化 WeChat 术语获取逻辑,添加错误处理
1 parent b498cff commit 7e40957

5 files changed

Lines changed: 82 additions & 110 deletions

File tree

Cargo.lock

Lines changed: 37 additions & 90 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/views/widgets/termpicker.dart

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import 'dart:async';
22

3+
import 'package:arche/arche.dart';
4+
import 'package:arche/extensions/dialogs.dart';
5+
import 'package:cczu_helper/models/fields.dart';
36
import 'package:cczu_helper/src/bindings/signals/signals.dart';
47
import 'package:flutter/material.dart';
58

@@ -21,25 +24,42 @@ class TermPicker extends StatefulWidget {
2124
class _TermPickerState extends State<TermPicker> {
2225
final termPopMenuKey = GlobalKey<PopupMenuButtonState>();
2326
List<String>? terms;
27+
late final StreamSubscription listener;
2428
String? term;
2529
@override
2630
void initState() {
2731
super.initState();
2832
if (widget.ensureAwake) {
29-
late final StreamSubscription listener;
3033
listener = WeChatTermsOutput.rustSignalStream.listen((data) {
34+
if (data.message.terms.isEmpty) {
35+
if (viewKey.currentContext != null) {
36+
ComplexDialog.instance.text(
37+
title: Text("Error"),
38+
context: viewKey.currentContext,
39+
content: Text(
40+
"Failed to get terms: ${data.message.error}, please check connection and reopen"));
41+
}
42+
return;
43+
}
44+
termPopMenuKey.currentState?.showButtonMenu();
45+
3146
widget.onChanged(data.message.terms.first);
3247
setState(() {
3348
terms = data.message.terms;
3449
term = data.message.terms.first;
3550
});
36-
listener.cancel();
3751
});
3852

3953
WeChatTermsInput().sendSignalToRust();
4054
}
4155
}
4256

57+
@override
58+
void dispose() {
59+
super.dispose();
60+
listener.cancel();
61+
}
62+
4363
@override
4464
Widget build(BuildContext context) {
4565
return PopupMenuButton(
@@ -48,15 +68,19 @@ class _TermPickerState extends State<TermPicker> {
4868
term = value;
4969
widget.onChanged(value);
5070
}),
51-
itemBuilder: (context) {
52-
if (terms == null || terms!.isEmpty) {
53-
WeChatTermsOutput.rustSignalStream.listen((data) {
54-
terms = (data.message.terms);
55-
termPopMenuKey.currentState?.showButtonMenu();
56-
});
57-
71+
onOpened: () {
72+
if (terms?.isEmpty ?? true) {
5873
WeChatTermsInput().sendSignalToRust();
59-
terms = [];
74+
}
75+
},
76+
itemBuilder: (context) {
77+
if (terms == null) {
78+
return [
79+
PopupMenuItem(
80+
enabled: false,
81+
child: CircularProgressIndicator(),
82+
)
83+
];
6084
}
6185

6286
return terms!

native/hub/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ edition = "2021"
1212
crate-type = ["lib", "cdylib", "staticlib"]
1313

1414
[dependencies]
15-
rinf = "8.6.0"
15+
rinf = "8.8.1"
1616
tokio = { version = "1", features = ["rt-multi-thread", "sync", "macros"] }
1717
cczuni = { git = "https://github.com/CCZU-OSSA/cczuni.git", default-features = false, features = [
1818
"calendar",
@@ -24,5 +24,5 @@ serde_json = "*"
2424
reqwest = { version = "*", default-features = false }
2525

2626
[target.'cfg(windows)'.dependencies]
27-
guid-create = "0.4.1"
28-
windows = { version = "0.61.3", features = ["Win32_System_Com"] }
27+
guid-create = "0.5.2"
28+
windows = { version = "0.62.2", features = ["Win32_System_Com"] }

0 commit comments

Comments
 (0)