From f0c75d8e56390a75e43c5be0fec3032bf0d7d5cb Mon Sep 17 00:00:00 2001
From: GitButler
Date: Tue, 15 Apr 2025 22:10:46 +0800
Subject: [PATCH 01/19] GitButler Workspace Commit
This is placeholder commit and will be replaced by a merge of yourvirtual branches.
Due to GitButler managing multiple virtual branches, you cannot switch back and
forth between git branches and virtual branches easily.
If you switch to another branch, GitButler will need to be reinitialized.
If you commit on this branch, GitButler will throw it away.
For more information about what we're doing here, check out our docs:
https://docs.gitbutler.com/features/virtual-branches/integration-branch
From a4db898cdbd5ce4268f46c2380809d83e09a2616 Mon Sep 17 00:00:00 2001
From: realth000
Date: Tue, 15 Apr 2025 22:23:35 +0800
Subject: [PATCH 02/19] docs(readme): update readme
---
README.md | 10 +---------
1 file changed, 1 insertion(+), 9 deletions(-)
diff --git a/README.md b/README.md
index de03191b..95792f85 100644
--- a/README.md
+++ b/README.md
@@ -15,10 +15,8 @@
-
+
-
-
> [!TIP]
@@ -110,8 +108,6 @@
## 功能
-*斜体字功能目前尚未release*
-
* [x] 看贴
* [x] 回复
* [x] 基本信息(用户名、头像)
@@ -215,10 +211,6 @@
* [ ] 收藏帖子或分区
* [ ] RSS订阅
* [x] 多用户
-* [ ] 多语言
- * [x] 软件界面
- * [ ] 浏览内容翻译为繁体中文
-* [ ] ...
### 不实现的功能
From 392316e45865b82e5b9415a35d3d224db7ee1343 Mon Sep 17 00:00:00 2001
From: realth000
Date: Wed, 16 Apr 2025 02:06:21 +0800
Subject: [PATCH 03/19] feat(utils): bottom sheet layout avoid view insets
---
lib/utils/show_bottom_sheet.dart | 30 +++++++++++++++++++-----------
1 file changed, 19 insertions(+), 11 deletions(-)
diff --git a/lib/utils/show_bottom_sheet.dart b/lib/utils/show_bottom_sheet.dart
index 56bbbaac..3d0fb42a 100644
--- a/lib/utils/show_bottom_sheet.dart
+++ b/lib/utils/show_bottom_sheet.dart
@@ -1,3 +1,5 @@
+import 'dart:math' as math;
+
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:go_router/go_router.dart';
@@ -31,17 +33,23 @@ Future showCustomBottomSheet({
context: context,
constraints: constraints,
showDragHandle: true,
- builder: (_) {
- return Padding(
- padding: edgeInsetsL12T4R12B12,
- child: Column(
- mainAxisSize: MainAxisSize.min,
- children: [
- Text(title, style: Theme.of(context).textTheme.titleLarge),
- if (pinnedWidget != null) ...[sizedBoxW8H8, pinnedWidget],
- sizedBoxW12H12,
- if (useExpand) Expanded(child: content) else content,
- ],
+ isScrollControlled: true,
+ builder: (context) {
+ final size = MediaQuery.sizeOf(context);
+ final viewInsets = MediaQuery.viewInsetsOf(context);
+ return SizedBox(
+ height: math.min(size.height / 2 + viewInsets.bottom, size.height - viewInsets.top),
+ child: Padding(
+ padding: edgeInsetsL12T4R12B12.add(MediaQuery.viewInsetsOf(context)),
+ child: Column(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ Text(title, style: Theme.of(context).textTheme.titleLarge),
+ if (pinnedWidget != null) ...[sizedBoxW8H8, pinnedWidget],
+ sizedBoxW12H12,
+ if (useExpand) Expanded(child: content) else content,
+ ],
+ ),
),
);
},
From dcb4d27e747aa40494f010bf45e94a924a30551e Mon Sep 17 00:00:00 2001
From: realth000
Date: Wed, 16 Apr 2025 03:00:50 +0800
Subject: [PATCH 04/19] feat: auto parse for bilibili share links
---
lib/features/editor/widgets/url_dialog.dart | 49 +++++++++++++++++++
lib/i18n/en.i18n.json | 6 ++-
lib/i18n/zh-CN.i18n.json | 6 ++-
lib/i18n/zh-TW.i18n.json | 6 ++-
lib/utils/clipboard.dart | 6 +++
lib/widgets/annimate/animated_visibility.dart | 8 +--
6 files changed, 75 insertions(+), 6 deletions(-)
diff --git a/lib/features/editor/widgets/url_dialog.dart b/lib/features/editor/widgets/url_dialog.dart
index deaf82c4..70530ea3 100644
--- a/lib/features/editor/widgets/url_dialog.dart
+++ b/lib/features/editor/widgets/url_dialog.dart
@@ -5,6 +5,8 @@ import 'package:tsdm_client/constants/layout.dart';
import 'package:tsdm_client/extensions/list.dart';
import 'package:tsdm_client/extensions/string.dart';
import 'package:tsdm_client/i18n/strings.g.dart';
+import 'package:tsdm_client/utils/clipboard.dart';
+import 'package:tsdm_client/widgets/annimate/animated_visibility.dart';
/// Link prefix, originally in quill_flutter.
const _linkPrefixes = [
@@ -60,6 +62,11 @@ class _UrlDialogState extends State {
late final TextEditingController descController;
late final TextEditingController urlController;
+ /// Regex to capture url and description in bilibili share text content.
+ final _bilibiliShareRe = RegExp(r'^【(?.+)】 (?https://www\.bilibili\.com/video/\w+)');
+
+ var _bilibiliTipExpanded = false;
+
@override
void initState() {
super.initState();
@@ -95,6 +102,7 @@ class _UrlDialogState extends State {
key: formKey,
child: Column(
mainAxisSize: MainAxisSize.min,
+ crossAxisAlignment: CrossAxisAlignment.start,
children: [
TextFormField(
controller: descController,
@@ -109,6 +117,47 @@ class _UrlDialogState extends State {
decoration: InputDecoration(prefixIcon: const Icon(Icons.link_outlined), labelText: tr.link),
validator: (v) => v!.trim().isNotEmpty ? null : tr.errorEmpty,
),
+ Column(
+ mainAxisSize: MainAxisSize.min,
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Row(
+ children: [
+ TextButton(
+ child: Text(tr.autoPaste.tip),
+ onPressed: () async {
+ final bilibiliText = await getPlainTextFromClipboard();
+ if (bilibiliText == null) {
+ return;
+ }
+
+ final reMatch = _bilibiliShareRe.firstMatch(bilibiliText);
+ if (reMatch == null) {
+ return;
+ }
+
+ final desc = reMatch.namedGroup('desc')!;
+ final url = reMatch.namedGroup('url')!;
+ setState(() {
+ descController.text = desc;
+ urlController.text = url;
+ });
+ },
+ ),
+ const Spacer(),
+ IconButton(
+ icon: const Icon(Icons.info_outline),
+ onPressed: () => setState(() => _bilibiliTipExpanded = !_bilibiliTipExpanded),
+ ),
+ ],
+ ),
+ AnimatedVisibility(
+ visible: _bilibiliTipExpanded,
+ duration: duration200,
+ child: Text(tr.autoPaste.detail, style: Theme.of(context).textTheme.labelSmall),
+ ),
+ ],
+ ),
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
diff --git a/lib/i18n/en.i18n.json b/lib/i18n/en.i18n.json
index 37c22541..9174f242 100644
--- a/lib/i18n/en.i18n.json
+++ b/lib/i18n/en.i18n.json
@@ -749,7 +749,11 @@
"title": "Insert Url",
"description": "Url description",
"link": "Url link",
- "errorEmpty": "Should not be empty"
+ "errorEmpty": "Should not be empty",
+ "autoPaste": {
+ "tip": "Paste bilibili share link",
+ "detail": "Paste bilibili video share link from clipboard. \nFormat is 【VIDEO_NAME】 https://www.bilibili.com/VIDEO_ID"
+ }
},
"foregroundColor": {
"title": "Font Color"
diff --git a/lib/i18n/zh-CN.i18n.json b/lib/i18n/zh-CN.i18n.json
index 27c5d5ec..3509c098 100644
--- a/lib/i18n/zh-CN.i18n.json
+++ b/lib/i18n/zh-CN.i18n.json
@@ -749,7 +749,11 @@
"title": "插入链接",
"description": "描述",
"link": "链接",
- "errorEmpty": "不能为空"
+ "errorEmpty": "不能为空",
+ "autoPaste": {
+ "tip": "粘贴b站分享链接",
+ "detail": "从剪切板粘贴b站分享链接。\n格式为【视频名】 https://www.bilibili.com/BV号或AV号"
+ }
},
"foregroundColor": {
"title": "字体颜色"
diff --git a/lib/i18n/zh-TW.i18n.json b/lib/i18n/zh-TW.i18n.json
index a004ea6e..fa6338a4 100644
--- a/lib/i18n/zh-TW.i18n.json
+++ b/lib/i18n/zh-TW.i18n.json
@@ -749,7 +749,11 @@
"title": "插入連結",
"description": "描述",
"link": "連結",
- "errorEmpty": "不能為空"
+ "errorEmpty": "不能為空",
+ "autoPaste": {
+ "tip": "貼上b站分享連結",
+ "detail": "從剪貼簿貼上b站分享連結。\n格式為【影片名稱】 https://www.bilibili.com/BV號或AV號"
+ }
},
"foregroundColor": {
"title": "字體顏色"
diff --git a/lib/utils/clipboard.dart b/lib/utils/clipboard.dart
index 31396493..fafe6e69 100644
--- a/lib/utils/clipboard.dart
+++ b/lib/utils/clipboard.dart
@@ -14,3 +14,9 @@ Future copyToClipboard(BuildContext context, String data, {bool showSnackB
toast.showSnackBar(context: context, message: context.t.general.copiedToClipboard);
}
}
+
+/// Get the plain text content in system clipboard.
+Future getPlainTextFromClipboard() async {
+ final data = await Clipboard.getData('text/plain');
+ return data?.text;
+}
diff --git a/lib/widgets/annimate/animated_visibility.dart b/lib/widgets/annimate/animated_visibility.dart
index 29fcb6ce..ff7feabc 100644
--- a/lib/widgets/annimate/animated_visibility.dart
+++ b/lib/widgets/annimate/animated_visibility.dart
@@ -17,10 +17,12 @@ class AnimatedVisibility extends StatelessWidget {
@override
Widget build(BuildContext context) {
- return AnimatedSize(
- alignment: Alignment.centerLeft,
+ return AnimatedSwitcher(
+ transitionBuilder:
+ (Widget child, Animation animation) =>
+ SizeTransition(sizeFactor: animation, axisAlignment: 1, child: child),
duration: duration ?? duration100,
- child: Container(child: visible ? child : null),
+ child: visible ? child : null,
);
}
}
From 81794eebedeab18465dc40c7be91f9b7d1b93f4a Mon Sep 17 00:00:00 2001
From: realth000
Date: Wed, 16 Apr 2025 03:07:49 +0800
Subject: [PATCH 05/19] docs(readme): fix broken link
[ci skip]
---
README.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/README.md b/README.md
index 95792f85..2f9d2cd9 100644
--- a/README.md
+++ b/README.md
@@ -15,7 +15,7 @@
-
+
From 79e989fb670b89d8b0484f93fb7bb83dda99dc67 Mon Sep 17 00:00:00 2001
From: Qing-Novel <136884931+Qing-Novel@users.noreply.github.com>
Date: Wed, 19 Nov 2025 17:50:36 +0800
Subject: [PATCH 06/19] Update pubspec.yaml
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
修改 pubspec.yaml 文件,添加 workmanager
From c5e0bda8e657657ca9c91b5ab70d4bc35db06c4e Mon Sep 17 00:00:00 2001
From: Qing-Novel <136884931+Qing-Novel@users.noreply.github.com>
Date: Wed, 19 Nov 2025 17:56:18 +0800
Subject: [PATCH 07/19] Create BackgroundService for task management
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
创建新文件 lib/services/background_service.dart,创建后台任务逻辑
---
lib/lib/services/background_service.dart | 38 ++++++++++++++++++++++++
1 file changed, 38 insertions(+)
create mode 100644 lib/lib/services/background_service.dart
diff --git a/lib/lib/services/background_service.dart b/lib/lib/services/background_service.dart
new file mode 100644
index 00000000..c5e42e0b
--- /dev/null
+++ b/lib/lib/services/background_service.dart
@@ -0,0 +1,38 @@
+// 创建新文件: lib/services/background_service.dart
+import 'package:workmanager/workmanager.dart';
+
+@pragma('vm:entry-point')
+void callbackDispatcher() {
+ Workmanager().executeTask((task, inputData) {
+ print("BackgroundTask: TSDM Client is running in background!");
+ // 这里可以添加实际的后台任务逻辑
+ // 例如:检查更新、同步数据等
+
+ return Future.value(true);
+ });
+}
+
+class BackgroundService {
+ static Future initialize() async {
+ await Workmanager().initialize(
+ callbackDispatcher,
+ isInDebugMode: false,
+ );
+ }
+
+ static Future startBackgroundTask() async {
+ await Workmanager().registerPeriodicTask(
+ "tsdmBackgroundTask",
+ "tsdmBackgroundTask",
+ frequency: Duration(minutes: 15),
+ initialDelay: Duration(seconds: 10),
+ constraints: Constraints(
+ networkType: NetworkType.connected,
+ ),
+ );
+ }
+
+ static Future stopBackgroundTask() async {
+ await Workmanager().cancelByUniqueName("tsdmBackgroundTask");
+ }
+}
From 166eba5f337c467c06c4a0077909aee3f23c9a56 Mon Sep 17 00:00:00 2001
From: Qing-Novel <136884931+Qing-Novel@users.noreply.github.com>
Date: Wed, 19 Nov 2025 17:59:06 +0800
Subject: [PATCH 08/19] Delete lib/lib directory
---
lib/lib/services/background_service.dart | 38 ------------------------
1 file changed, 38 deletions(-)
delete mode 100644 lib/lib/services/background_service.dart
diff --git a/lib/lib/services/background_service.dart b/lib/lib/services/background_service.dart
deleted file mode 100644
index c5e42e0b..00000000
--- a/lib/lib/services/background_service.dart
+++ /dev/null
@@ -1,38 +0,0 @@
-// 创建新文件: lib/services/background_service.dart
-import 'package:workmanager/workmanager.dart';
-
-@pragma('vm:entry-point')
-void callbackDispatcher() {
- Workmanager().executeTask((task, inputData) {
- print("BackgroundTask: TSDM Client is running in background!");
- // 这里可以添加实际的后台任务逻辑
- // 例如:检查更新、同步数据等
-
- return Future.value(true);
- });
-}
-
-class BackgroundService {
- static Future initialize() async {
- await Workmanager().initialize(
- callbackDispatcher,
- isInDebugMode: false,
- );
- }
-
- static Future startBackgroundTask() async {
- await Workmanager().registerPeriodicTask(
- "tsdmBackgroundTask",
- "tsdmBackgroundTask",
- frequency: Duration(minutes: 15),
- initialDelay: Duration(seconds: 10),
- constraints: Constraints(
- networkType: NetworkType.connected,
- ),
- );
- }
-
- static Future stopBackgroundTask() async {
- await Workmanager().cancelByUniqueName("tsdmBackgroundTask");
- }
-}
From 64ea762b52e17a36047a7e9f5689fbe557bac885 Mon Sep 17 00:00:00 2001
From: Qing-Novel <136884931+Qing-Novel@users.noreply.github.com>
Date: Wed, 19 Nov 2025 18:00:06 +0800
Subject: [PATCH 09/19] Create BackgroundService for task management
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
创建后台任务逻辑
---
lib/services/background_service.dart | 45 ++++++++++++++++++++++++++++
1 file changed, 45 insertions(+)
create mode 100644 lib/services/background_service.dart
diff --git a/lib/services/background_service.dart b/lib/services/background_service.dart
new file mode 100644
index 00000000..9f20a048
--- /dev/null
+++ b/lib/services/background_service.dart
@@ -0,0 +1,45 @@
+// services/background_service.dart
+import 'package:workmanager/workmanager.dart';
+
+@pragma('vm:entry-point') // 这是一个关键的注解,防止代码被优化掉
+void callbackDispatcher() {
+ Workmanager().executeTask((task, inputData) {
+ // 这里是后台任务实际执行的地方
+ print("BackgroundTask: TSDM Client is running in background!");
+ // 例如:你可以在这里检查新消息、更新数据等
+ // 注意:这里的代码运行在独立的Isolate中,不能直接操作UI
+
+ // 返回 Future.value(true) 表示任务成功
+ // 返回 Future.value(false) 表示任务失败
+ return Future.value(true);
+ });
+}
+
+class BackgroundService {
+ static Future initialize() async {
+ await Workmanager().initialize(
+ callbackDispatcher, // 上面的回调函数
+ isInDebugMode: false, // 开发时设为true可看更多日志
+ );
+ }
+
+ static Future startBackgroundTask() async {
+ // 注册一个周期性任务
+ // 注意事项:
+ // - 在Android上,最小间隔是15分钟
+ // - iOS上的行为可能不同,更受系统限制
+ await Workmanager().registerPeriodicTask(
+ "tsdmBackgroundTask",
+ "tsdmBackgroundTask",
+ frequency: Duration(minutes: 15),
+ initialDelay: Duration(seconds: 10),
+ constraints: Constraints(
+ networkType: NetworkType.connected, // 指定网络条件
+ ),
+ );
+ }
+
+ static Future stopBackgroundTask() async {
+ await Workmanager().cancelByUniqueName("tsdmBackgroundTask");
+ }
+}
From 9f9ecfaacd5dfc11bdc7241f145164761eaf6f06 Mon Sep 17 00:00:00 2001
From: Qing-Novel <136884931+Qing-Novel@users.noreply.github.com>
Date: Wed, 19 Nov 2025 18:55:49 +0800
Subject: [PATCH 10/19] Update settings_page.dart
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
修改 lib/features/settings/view/settings_page.dart
在这个文件中添加后台常驻开关:
---
lib/features/settings/view/settings_page.dart | 47 +++++++++++++++++++
1 file changed, 47 insertions(+)
diff --git a/lib/features/settings/view/settings_page.dart b/lib/features/settings/view/settings_page.dart
index 1b986283..96a277ba 100644
--- a/lib/features/settings/view/settings_page.dart
+++ b/lib/features/settings/view/settings_page.dart
@@ -46,6 +46,8 @@ import 'package:tsdm_client/widgets/section_switch_list_tile.dart';
import 'package:tsdm_client/widgets/section_title_text.dart';
import 'package:tsdm_client/widgets/shutdown.dart';
import 'package:tsdm_client/widgets/tips.dart';
+import 'package:provider/provider.dart';
+import '../provider/settings_provider.dart';
/// Settings page of the app.
class SettingsPage extends StatefulWidget {
@@ -865,3 +867,48 @@ class _SettingsPageState extends State {
);
}
}
+
+Widget build(BuildContext context) {
+ return CupertinoPageScaffold(
+ navigationBar: CupertinoNavigationBar(
+ middle: Text('设置'),
+ ),
+ child: SafeArea(
+ child: ListView(
+ children: [
+ // ... 其他现有设置项 ...
+
+ // === 添加后台常驻开关 ===
+ CupertinoFormSection.insetGrouped(
+ header: Text('行为'),
+ children: [
+ CupertinoFormRow(
+ prefix: Container(
+ width: 24, // 留空图标位置
+ ),
+ helper: Text('开启后,应用在后台时会尝试保持活动状态以执行任务'),
+ child: Row(
+ children: [
+ Expanded(
+ child: Text('后台常驻'),
+ ),
+ Consumer(
+ builder: (context, settings, child) {
+ return CupertinoSwitch(
+ value: settings.backgroundKeepAlive,
+ onChanged: (bool value) {
+ settings.setBackgroundKeepAlive(value);
+ },
+ );
+ },
+ ),
+ ],
+ ),
+ ),
+ ],
+ ),
+ ],
+ ),
+ ),
+ );
+}
From 16a41f5fc21c7f9e5065fe13e7e8956a3833f606 Mon Sep 17 00:00:00 2001
From: Qing-Novel <136884931+Qing-Novel@users.noreply.github.com>
Date: Wed, 19 Nov 2025 19:28:54 +0800
Subject: [PATCH 11/19] Implement SettingsProvider for background task
management
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
创建或修改设置提供者
---
.../settings/provider/settings_provider.dart | 30 +++++++++++++++++++
1 file changed, 30 insertions(+)
create mode 100644 lib/features/settings/provider/settings_provider.dart
diff --git a/lib/features/settings/provider/settings_provider.dart b/lib/features/settings/provider/settings_provider.dart
new file mode 100644
index 00000000..48fa729b
--- /dev/null
+++ b/lib/features/settings/provider/settings_provider.dart
@@ -0,0 +1,30 @@
+// lib/features/settings/provider/settings_provider.dart
+import 'package:flutter/foundation.dart';
+import 'package:shared_preferences/shared_preferences.dart';
+import '../../../services/background_service.dart';
+
+class SettingsProvider with ChangeNotifier {
+ bool _backgroundKeepAlive = false;
+
+ bool get backgroundKeepAlive => _backgroundKeepAlive;
+
+ Future setBackgroundKeepAlive(bool value) async {
+ _backgroundKeepAlive = value;
+ final prefs = await SharedPreferences.getInstance();
+ await prefs.setBool('background_keep_alive', value);
+ notifyListeners();
+
+ // 根据开关状态启动或停止后台任务
+ if (value) {
+ await BackgroundService.startBackgroundTask();
+ } else {
+ await BackgroundService.stopBackgroundTask();
+ }
+ }
+
+ Future loadBackgroundKeepAlive() async {
+ final prefs = await SharedPreferences.getInstance();
+ _backgroundKeepAlive = prefs.getBool('background_keep_alive') ?? false;
+ notifyListeners();
+ }
+}
From 36b8f05ae43840f18e54eba35fb2f89fe5119305 Mon Sep 17 00:00:00 2001
From: Qing-Novel <136884931+Qing-Novel@users.noreply.github.com>
Date: Wed, 19 Nov 2025 19:33:49 +0800
Subject: [PATCH 12/19] Update main.dart
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
在 main.dart 中添加后台服务初始化
---
lib/main.dart | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/lib/main.dart b/lib/main.dart
index aebda4a0..d1b4f5b8 100644
--- a/lib/main.dart
+++ b/lib/main.dart
@@ -31,6 +31,18 @@ Future _boot(List args) async {
talker.debug('------------------- start app -------------------');
await initProviders();
+ // 初始化后台服务
+ await BackgroundService.initialize();
+
+ // 获取设置仓库并检查后台常驻设置
+ final settingsRepo = getIt.get();
+ final backgroundKeepAliveEnabled = settingsRepo.currentSettings.backgroundKeepAlive ?? false;
+
+ // 如果设置中启用了后台常驻,则启动后台任务
+ if (backgroundKeepAliveEnabled) {
+ await BackgroundService.startBackgroundTask();
+ }
+
final settings = getIt.get().currentSettings;
final settingsLocale = settings.locale;
From 51d8befb530fd4873ff1f8f1574170472f5ecb84 Mon Sep 17 00:00:00 2001
From: Qing-Novel <136884931+Qing-Novel@users.noreply.github.com>
Date: Wed, 19 Nov 2025 19:37:57 +0800
Subject: [PATCH 13/19] Add background_service import to main.dart
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
添加必要的导入
---
lib/main.dart | 1 +
1 file changed, 1 insertion(+)
diff --git a/lib/main.dart b/lib/main.dart
index d1b4f5b8..148896f1 100644
--- a/lib/main.dart
+++ b/lib/main.dart
@@ -13,6 +13,7 @@ import 'package:tsdm_client/features/local_notice/callback.dart';
import 'package:tsdm_client/features/settings/repositories/settings_repository.dart';
import 'package:tsdm_client/i18n/strings.g.dart';
import 'package:tsdm_client/instance.dart';
+import 'package:tsdm_client/services/background_service.dart';
import 'package:tsdm_client/shared/providers/providers.dart';
import 'package:tsdm_client/shared/providers/proxy_provider/proxy_provider.dart';
import 'package:tsdm_client/utils/platform.dart';
From dcea4498d9f22a6f9104c41736d11b75adba78ae Mon Sep 17 00:00:00 2001
From: Qing-Novel <136884931+Qing-Novel@users.noreply.github.com>
Date: Wed, 19 Nov 2025 19:50:23 +0800
Subject: [PATCH 14/19] Enhance BackgroundService with error handling and
logging
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
在 initialize() 方法中:
添加了 try-catch 块
添加了成功和失败的日志输出
添加了异常重新抛出
在 startBackgroundTask() 方法中:
添加了 try-catch 块
添加了 existingWorkPolicy: ExistingWorkPolicy.replace 参数
添加了成功和失败的日志输出
添加了异常重新抛出
在 stopBackgroundTask() 方法中:
添加了 try-catch 块
添加了成功和失败的日志输出
添加了异常重新抛出
---
lib/services/background_service.dart | 28 +++++++++++++++++++++++-----
1 file changed, 23 insertions(+), 5 deletions(-)
diff --git a/lib/services/background_service.dart b/lib/services/background_service.dart
index 9f20a048..ba25a4e7 100644
--- a/lib/services/background_service.dart
+++ b/lib/services/background_service.dart
@@ -17,10 +17,16 @@ void callbackDispatcher() {
class BackgroundService {
static Future initialize() async {
- await Workmanager().initialize(
- callbackDispatcher, // 上面的回调函数
- isInDebugMode: false, // 开发时设为true可看更多日志
- );
+ try {
+ await Workmanager().initialize(
+ callbackDispatcher, // 上面的回调函数
+ isInDebugMode: false, // 开发时设为true可看更多日志
+ );
+ print("BackgroundService: Initialized successfully"); // 添加这行
+ } catch (e) {
+ print("BackgroundService: Initialization failed - $e"); // 添加这行
+ rethrow; // 添加这行
+ }
}
static Future startBackgroundTask() async {
@@ -36,10 +42,22 @@ class BackgroundService {
constraints: Constraints(
networkType: NetworkType.connected, // 指定网络条件
),
+ existingWorkPolicy: ExistingWorkPolicy.replace, // 添加这行
);
+ print("BackgroundService: Background task started successfully"); // 添加这行
+ } catch (e) {
+ print("BackgroundService: Failed to start background task - $e"); // 添加这行
+ rethrow; // 添加这行
+ }
}
static Future stopBackgroundTask() async {
- await Workmanager().cancelByUniqueName("tsdmBackgroundTask");
+ try {
+ await Workmanager().cancelByUniqueName("tsdmBackgroundTask");
+ print("BackgroundService: Background task stopped successfully"); // 添加这行
+ } catch (e) {
+ print("BackgroundService: Failed to stop background task - $e"); // 添加这行
+ rethrow; // 添加这行
+ }
}
}
From c07010f6830c6c557b63ffc9253514a73d130532 Mon Sep 17 00:00:00 2001
From: Qing-Novel <136884931+Qing-Novel@users.noreply.github.com>
Date: Wed, 19 Nov 2025 19:53:26 +0800
Subject: [PATCH 15/19] Update AndroidManifest.xml
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
添加后台服务权限
---
android/app/src/main/AndroidManifest.xml | 2 ++
1 file changed, 2 insertions(+)
diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml
index 620d5a3d..92964ddc 100644
--- a/android/app/src/main/AndroidManifest.xml
+++ b/android/app/src/main/AndroidManifest.xml
@@ -1,6 +1,8 @@
+
+
Date: Wed, 19 Nov 2025 19:56:17 +0800
Subject: [PATCH 16/19] Update Info.plist
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
添加后台模式配置
---
ios/Runner/Info.plist | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/ios/Runner/Info.plist b/ios/Runner/Info.plist
index 33d6d24a..3d221592 100644
--- a/ios/Runner/Info.plist
+++ b/ios/Runner/Info.plist
@@ -45,5 +45,10 @@
UIApplicationSupportsIndirectInputEvents
+ UIBackgroundModes
+
+ fetch
+ processing
+
From 3b235dfcacd95aaccf453766bd98e184edee68c0 Mon Sep 17 00:00:00 2001
From: Qing-Novel <136884931+Qing-Novel@users.noreply.github.com>
Date: Wed, 19 Nov 2025 20:03:08 +0800
Subject: [PATCH 17/19] Update background_service.dart
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
询问deepseek解决报错问题
---
lib/services/background_service.dart | 60 ++++++++++++----------------
1 file changed, 25 insertions(+), 35 deletions(-)
diff --git a/lib/services/background_service.dart b/lib/services/background_service.dart
index ba25a4e7..84edcd06 100644
--- a/lib/services/background_service.dart
+++ b/lib/services/background_service.dart
@@ -1,63 +1,53 @@
-// services/background_service.dart
import 'package:workmanager/workmanager.dart';
-@pragma('vm:entry-point') // 这是一个关键的注解,防止代码被优化掉
+@pragma('vm:entry-point')
void callbackDispatcher() {
Workmanager().executeTask((task, inputData) {
- // 这里是后台任务实际执行的地方
print("BackgroundTask: TSDM Client is running in background!");
- // 例如:你可以在这里检查新消息、更新数据等
- // 注意:这里的代码运行在独立的Isolate中,不能直接操作UI
-
- // 返回 Future.value(true) 表示任务成功
- // 返回 Future.value(false) 表示任务失败
return Future.value(true);
});
}
class BackgroundService {
static Future initialize() async {
- try {
+ try {
await Workmanager().initialize(
- callbackDispatcher, // 上面的回调函数
- isInDebugMode: false, // 开发时设为true可看更多日志
+ callbackDispatcher,
+ isInDebugMode: false,
);
- print("BackgroundService: Initialized successfully"); // 添加这行
+ print("BackgroundService: Initialized successfully");
} catch (e) {
- print("BackgroundService: Initialization failed - $e"); // 添加这行
- rethrow; // 添加这行
+ print("BackgroundService: Initialization failed - $e");
+ rethrow;
}
}
static Future startBackgroundTask() async {
- // 注册一个周期性任务
- // 注意事项:
- // - 在Android上,最小间隔是15分钟
- // - iOS上的行为可能不同,更受系统限制
- await Workmanager().registerPeriodicTask(
- "tsdmBackgroundTask",
- "tsdmBackgroundTask",
- frequency: Duration(minutes: 15),
- initialDelay: Duration(seconds: 10),
- constraints: Constraints(
- networkType: NetworkType.connected, // 指定网络条件
- ),
- existingWorkPolicy: ExistingWorkPolicy.replace, // 添加这行
- );
- print("BackgroundService: Background task started successfully"); // 添加这行
+ try {
+ await Workmanager().registerPeriodicTask(
+ "tsdmBackgroundTask",
+ "tsdmBackgroundTask",
+ frequency: Duration(minutes: 15),
+ initialDelay: Duration(seconds: 10),
+ constraints: Constraints(
+ networkType: NetworkType.connected,
+ ),
+ existingWorkPolicy: ExistingWorkPolicy.replace,
+ );
+ print("BackgroundService: Background task started successfully");
} catch (e) {
- print("BackgroundService: Failed to start background task - $e"); // 添加这行
- rethrow; // 添加这行
+ print("BackgroundService: Failed to start background task - $e");
+ rethrow;
}
}
static Future stopBackgroundTask() async {
- try {
+ try {
await Workmanager().cancelByUniqueName("tsdmBackgroundTask");
- print("BackgroundService: Background task stopped successfully"); // 添加这行
+ print("BackgroundService: Background task stopped successfully");
} catch (e) {
- print("BackgroundService: Failed to stop background task - $e"); // 添加这行
- rethrow; // 添加这行
+ print("BackgroundService: Failed to stop background task - $e");
+ rethrow;
}
}
}
From db442a756dddf0f84674831194802cd2c05752c2 Mon Sep 17 00:00:00 2001
From: Qing-Novel <136884931+Qing-Novel@users.noreply.github.com>
Date: Wed, 19 Nov 2025 20:05:42 +0800
Subject: [PATCH 18/19] Update AndroidManifest.xml
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
询问deepseek修复github报错
---
android/app/src/main/AndroidManifest.xml | 38 ++++++++++++------------
1 file changed, 19 insertions(+), 19 deletions(-)
diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml
index 92964ddc..20a2d876 100644
--- a/android/app/src/main/AndroidManifest.xml
+++ b/android/app/src/main/AndroidManifest.xml
@@ -1,40 +1,40 @@
-
-
+
+
+ android:label="天使动漫"
+ android:name="${applicationName}"
+ android:usesCleartextTraffic="true"
+ android:icon="@mipmap/ic_launcher">
+ android:name=".MainActivity"
+ android:exported="true"
+ android:launchMode="singleTop"
+ android:theme="@style/Theme.TsdmClient.Launcher"
+ android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
+ android:hardwareAccelerated="true"
+ android:windowSoftInputMode="adjustResize">
-
-
+
+
+ android:name="flutterEmbedding"
+ android:value="2" />
From bc3d011a71b2ae9ecd98a2e54d55cf7121f7245a Mon Sep 17 00:00:00 2001
From: Qing-Novel <136884931+Qing-Novel@users.noreply.github.com>
Date: Wed, 19 Nov 2025 20:09:16 +0800
Subject: [PATCH 19/19] Update Info.plist
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
修复github报错
---
ios/Runner/Info.plist | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/ios/Runner/Info.plist b/ios/Runner/Info.plist
index 3d221592..09f1d8ed 100644
--- a/ios/Runner/Info.plist
+++ b/ios/Runner/Info.plist
@@ -45,7 +45,7 @@
UIApplicationSupportsIndirectInputEvents
- UIBackgroundModes
+ UIBackgroundModes
fetch
processing