From 14a37963af6418c1e992e037b9c755b498e3f6e9 Mon Sep 17 00:00:00 2001 From: Rarya <3148438955@qq.com> Date: Fri, 21 Aug 2026 08:32:40 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E6=96=B0=E5=A2=9E=20=E8=87=AA=E5=AE=9A?= =?UTF-8?q?=E4=B9=89=E9=A2=9D=E5=A4=96=E5=90=AF=E5=8A=A8=E5=91=BD=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 22 +++++-- lib/ui/controllers/terminal_controller.dart | 12 +++- lib/ui/controllers/terminal_tab_manager.dart | 20 +++++- lib/ui/pages/settings/settings_page.dart | 67 ++++++++++++++++++++ pubspec.yaml | 2 +- 5 files changed, 113 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 89d707d..9e92ef4 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,22 @@ ## 当前维护内容 -以下内容为更改包名前 相较于 AstrBot-Android-App 1.5.3 的最终更新内容。 +- 自定义启动项 (准备更新) + +- 终端页新功能 +- 细节优化 + +- 具体信息请查看发行版更新内容 + +## 后续计划 + +- 适配深色模式 +- 自定义接入平台 +- 暂无更多 + + +### fix版最终更新内容 +以下内容为更改包名前 fix版 相较于 AstrBot-Android-App 1.5.3 原版的最终更新内容。 ### 新增功能 @@ -34,11 +49,6 @@ - 安装完成后后续进入无需等待 AstrBot 启动。 - 在启动时请求存储权限,避免因无存储权限无法从备份中恢复。 -### 后续计划 - -- 适配深色模式 -- 自定义接入平台 -- 暂无更多 你是否想过,用自己的 QQ 号,变成一个可以自动回复消息、调用大模型进行智能对话的“AI 账号”? diff --git a/lib/ui/controllers/terminal_controller.dart b/lib/ui/controllers/terminal_controller.dart index 9174bd9..cc00231 100644 --- a/lib/ui/controllers/terminal_controller.dart +++ b/lib/ui/controllers/terminal_controller.dart @@ -29,6 +29,7 @@ class HomeController extends GetxController { SettingNode privacySetting = 'privacy'.setting; SettingNode napCatWebUiEnabled = 'napcat_webui_enabled'.setting; SettingNode showTerminalWhiteText = 'show_terminal_white_text'.setting; + SettingNode customStartupCommand = 'custom_startup_command'.setting; Pty? pseudoTerminal; Pty? napcatTerminal; @@ -73,6 +74,10 @@ class HomeController extends GetxController { terminalFontSize.value = size.clamp(minTerminalFontSize, maxTerminalFontSize).toDouble(); } + String getCustomStartupCommand() { + return customStartupCommand.get() as String? ?? ''; + } + // 进度 +1 // Progress +1 void bumpProgress() { @@ -439,6 +444,11 @@ class HomeController extends GetxController { // 当进度到达 "Napcat 已安装" 时,启动 NapCat 终端 if (content.contains('Napcat ${S.current.installed}')) { napcatTerminal?.writeString('source ${RuntimeEnvir.homePath}/common.sh\nlogin_ubuntu "cd /root/Napcat; exec bash launcher.sh"\n'); + // 新建终端页并运行自定义启动命令 + final command = getCustomStartupCommand(); + if (command.trim().isNotEmpty) { + terminalTabManager.addSystemTerminalTab(command); + } bumpProgress(); Log.i('检测到 Napcat 已安装,启动 NapCat 终端', tag: 'AstrBot'); } @@ -449,7 +459,7 @@ class HomeController extends GetxController { // 清除终端先前显示的所有文本 terminal.buffer.clear(); terminal.buffer.setCursor(0, 0); - Log.i('检测到 AstrBot 配置中,清除终端内容并开始过滤非彩色终端输出', tag: 'AstrBot'); + Log.i('检测到 AstrBot 配置中,清除终端内容', tag: 'AstrBot'); } update(); diff --git a/lib/ui/controllers/terminal_tab_manager.dart b/lib/ui/controllers/terminal_tab_manager.dart index 2152c10..2da86e7 100644 --- a/lib/ui/controllers/terminal_tab_manager.dart +++ b/lib/ui/controllers/terminal_tab_manager.dart @@ -77,7 +77,7 @@ class TerminalTabManager extends GetxController { } /// 添加新的系统终端标签页 - Future addSystemTerminalTab() async { + Future addSystemTerminalTab([String? customCommand]) async { try { final newIndex = tabs.where((t) => t.type == TerminalTabType.system).length + 1; @@ -97,6 +97,9 @@ class TerminalTabManager extends GetxController { // 标志:是否已经创建了标签页 var tabCreated = false; + // 标志:是否已发送自定义启动命令 + var commandSent = false; + // 连接终端的 onResize 和 onOutput 事件(需要在监听输出前就连接好) newTerminal.onResize = (width, height, pixelWidth, pixelHeight) { newPty.resize(height, width); @@ -142,6 +145,19 @@ class TerminalTabManager extends GetxController { // 标签页创建后,正常输出所有内容 if (tabCreated) { + + // 如果未发送自定义启动命令并且有设置自定义启动命令 + // 就向终端发送格式化后的自定义启动命令 + if (!commandSent && customCommand != null) { + final normalizedCommand = customCommand + ?.split(RegExp(r'\r?\n')) + ?.where((line) => line.trim().isNotEmpty) + ?.map((line) => '$line\n') + ?.join() ?? ''; + newPty.writeString('$normalizedCommand\n'); + commandSent = true; + } + // 自动清理旧行,避免行数满后不更新 while (newTerminal.buffer.lines.length >= newTerminal.maxLines) { newTerminal.buffer.lines.remove(0, 1); @@ -153,7 +169,7 @@ class TerminalTabManager extends GetxController { // 登录到ubuntu容器 final command = - 'source ${RuntimeEnvir.homePath}/common.sh\nlogin_ubuntu "exec bash -il" \n'; + 'source ${RuntimeEnvir.homePath}/common.sh\nlogin_ubuntu "exec bash -il"\n'; newPty.writeString(command); } catch (e) { Log.e('添加系统终端标签页失败: $e', tag: 'TerminalTabManager'); diff --git a/lib/ui/pages/settings/settings_page.dart b/lib/ui/pages/settings/settings_page.dart index 16c10cd..f93989b 100644 --- a/lib/ui/pages/settings/settings_page.dart +++ b/lib/ui/pages/settings/settings_page.dart @@ -973,6 +973,7 @@ class _SettingsPageState extends State { hintText: '留空使用默认逻辑', border: OutlineInputBorder(), ), + minLines: 1, maxLines: 3, keyboardType: TextInputType.multiline, ), @@ -1029,6 +1030,66 @@ class _SettingsPageState extends State { commandController.dispose(); } + Future _showCustomStartupCommandDialog() async { + final currentCommand = + homeController.customStartupCommand.get() as String? ?? ''; + final commandController = TextEditingController(text: currentCommand); + final result = await Get.dialog( + AlertDialog( + title: const Text('自定义启动命令'), + content: SingleChildScrollView( + child: Column( + mainAxisSize: MainAxisSize.min, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + const Text( + '自动打开新终端并执行任意启动命令', + style: TextStyle(fontSize: 12, color: Colors.grey), + ), + const SizedBox(height: 8), + const Text( + '示例:\ncd /root/AstrBot\npython main.py &', + style: TextStyle(fontSize: 11, color: Colors.grey), + ), + const SizedBox(height: 16), + TextField( + controller: commandController, + decoration: const InputDecoration( + labelText: '自定义启动命令', + hintText: '留空则不执行', + border: OutlineInputBorder(), + ), + minLines: 1, + maxLines: 6, + keyboardType: TextInputType.multiline, + ), + ], + ), + ), + actions: [ + TextButton( + onPressed: () => Get.back(result: false), + child: const Text('取消'), + ), + TextButton( + onPressed: () => Get.back(result: true), + child: const Text('保存'), + ), + ], + ), + ); + + if (result == true) { + final command = commandController.text.trim(); + homeController.customStartupCommand.set(command); + Get.snackbar( + '保存成功', + command.isEmpty ? '已清除自定义启动命令' : '自定义启动命令已保存', + ); + } + commandController.dispose(); + } + // 打开文件管理器并导航到 AstrBot Ubuntu 文件系统位置 Future _openFileManager() async { try { @@ -1689,6 +1750,12 @@ class _SettingsPageState extends State { subtitle: const Text('自定义 AstrBot 的获取方式'), onTap: () => _showCustomGitCloneDialog(), ), + ListTile( + leading: const Icon(Icons.terminal), + title: const Text('自定义启动命令'), + subtitle: const Text('自动打开新终端并执行任意启动命令'), + onTap: () => _showCustomStartupCommandDialog(), + ), ListTile( leading: const Icon(Icons.text_fields), title: const Text('显示终端白色文本日志'), diff --git a/pubspec.yaml b/pubspec.yaml index 5b1719b..87c4a94 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,7 +1,7 @@ name: astrbot_android description: AstrBot Android App publish_to: "none" # Remove this line if you wish to publish to pub.dev -version: 1.0.4+5 +version: 1.0.5+6 environment: sdk: ">=3.3.0 <4.0.0" From 79d1b3925f04130ecd73c3661594fdbc9c3d9a36 Mon Sep 17 00:00:00 2001 From: Rarya <3148438955@qq.com> Date: Fri, 21 Aug 2026 09:10:52 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E4=BF=AE=E6=94=B9=20=E8=87=AA=E5=AE=9A?= =?UTF-8?q?=E4=B9=89=E5=90=AF=E5=8A=A8=E5=91=BD=E4=BB=A4=E6=89=A7=E8=A1=8C?= =?UTF-8?q?=E6=97=B6=E6=9C=BA=EF=BC=8C=E9=81=BF=E5=85=8D=E9=87=8D=E5=A4=8D?= =?UTF-8?q?=E8=A7=A6=E5=8F=91=20=E4=BC=98=E5=8C=96=20=E8=87=AA=E5=AE=9A?= =?UTF-8?q?=E4=B9=89=E5=90=AF=E5=8A=A8=E5=91=BD=E4=BB=A4=E4=BF=9D=E5=AD=98?= =?UTF-8?q?=E6=8F=90=E7=A4=BA=E5=BC=B9=E5=87=BA=E4=BD=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/ui/controllers/terminal_controller.dart | 12 +++++++----- lib/ui/pages/settings/settings_page.dart | 2 ++ 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/ui/controllers/terminal_controller.dart b/lib/ui/controllers/terminal_controller.dart index cc00231..766e7fc 100644 --- a/lib/ui/controllers/terminal_controller.dart +++ b/lib/ui/controllers/terminal_controller.dart @@ -277,6 +277,13 @@ class HomeController extends GetxController { ); _isNapCatLogin = true; // 视为已登录,防止重复触发 } + + // 新建终端页并运行自定义启动命令 + final command = getCustomStartupCommand(); + if (command.trim().isNotEmpty) { + terminalTabManager.addSystemTerminalTab(command); + } + }); } } @@ -444,11 +451,6 @@ class HomeController extends GetxController { // 当进度到达 "Napcat 已安装" 时,启动 NapCat 终端 if (content.contains('Napcat ${S.current.installed}')) { napcatTerminal?.writeString('source ${RuntimeEnvir.homePath}/common.sh\nlogin_ubuntu "cd /root/Napcat; exec bash launcher.sh"\n'); - // 新建终端页并运行自定义启动命令 - final command = getCustomStartupCommand(); - if (command.trim().isNotEmpty) { - terminalTabManager.addSystemTerminalTab(command); - } bumpProgress(); Log.i('检测到 Napcat 已安装,启动 NapCat 终端', tag: 'AstrBot'); } diff --git a/lib/ui/pages/settings/settings_page.dart b/lib/ui/pages/settings/settings_page.dart index f93989b..21616b7 100644 --- a/lib/ui/pages/settings/settings_page.dart +++ b/lib/ui/pages/settings/settings_page.dart @@ -1085,6 +1085,8 @@ class _SettingsPageState extends State { Get.snackbar( '保存成功', command.isEmpty ? '已清除自定义启动命令' : '自定义启动命令已保存', + snackPosition: SnackPosition.BOTTOM, + duration: const Duration(seconds: 2), ); } commandController.dispose(); From cfe847a09a2c447f62478348d1560ba581e5da6f Mon Sep 17 00:00:00 2001 From: Rarya <3148438955@qq.com> Date: Fri, 21 Aug 2026 09:13:45 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E4=BC=98=E5=8C=96=20=E8=87=AA=E5=AE=9A?= =?UTF-8?q?=E4=B9=89=E5=91=BD=E4=BB=A4=E4=B8=8D=E4=BF=9D=E5=AD=98=E8=BF=9B?= =?UTF-8?q?bash=5Fhistory?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/ui/controllers/terminal_tab_manager.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ui/controllers/terminal_tab_manager.dart b/lib/ui/controllers/terminal_tab_manager.dart index 2da86e7..f096657 100644 --- a/lib/ui/controllers/terminal_tab_manager.dart +++ b/lib/ui/controllers/terminal_tab_manager.dart @@ -152,7 +152,7 @@ class TerminalTabManager extends GetxController { final normalizedCommand = customCommand ?.split(RegExp(r'\r?\n')) ?.where((line) => line.trim().isNotEmpty) - ?.map((line) => '$line\n') + ?.map((line) => ' $line\n') ?.join() ?? ''; newPty.writeString('$normalizedCommand\n'); commandSent = true; From 8ce0a7883f7c6f1423b98931d790e711de963534 Mon Sep 17 00:00:00 2001 From: Rarya <3148438955@qq.com> Date: Fri, 21 Aug 2026 10:33:53 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20napcat=E7=99=BB?= =?UTF-8?q?=E5=BD=95=E6=8F=90=E9=86=92=E5=92=8C=E8=87=AA=E5=AE=9A=E4=B9=89?= =?UTF-8?q?=E5=90=AF=E5=8A=A8=E5=91=BD=E4=BB=A4=E5=A4=B1=E6=95=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/ui/controllers/terminal_controller.dart | 58 +++++++++++---------- 1 file changed, 30 insertions(+), 28 deletions(-) diff --git a/lib/ui/controllers/terminal_controller.dart b/lib/ui/controllers/terminal_controller.dart index 766e7fc..54f4efb 100644 --- a/lib/ui/controllers/terminal_controller.dart +++ b/lib/ui/controllers/terminal_controller.dart @@ -249,6 +249,34 @@ class HomeController extends GetxController { // 检查条件是否满足,如果满足则触发跳转 void _checkAndNavigateToWebview() { + + if (!_isNapCatLogin && !_isNapCatQuickLogin) { + Get.snackbar( + 'NapCat 未登录', + '请前往 NapCat 终端页或 WebUI 自行扫码登录', + snackPosition: SnackPosition.BOTTOM, + backgroundColor: Colors.red.withValues(alpha: 0.8), + colorText: Colors.white, + duration: const Duration(seconds: 5), + ); + } else if (!_isNapCatLogin && _isNapCatQuickLogin) { + Get.snackbar( + 'NapCat 未配置快速登录', + '请前往设置页配置快速登录QQ账号设置', + snackPosition: SnackPosition.BOTTOM, + backgroundColor: Colors.yellow.withValues(alpha: 0.8), + colorText: Colors.white, + duration: const Duration(seconds: 5), + ); + _isNapCatLogin = true; // 视为已登录,防止重复触发 + } + + // 新建终端页并运行自定义启动命令 + final command = getCustomStartupCommand(); + if (command.trim().isNotEmpty) { + terminalTabManager.addSystemTerminalTab(command); + } + // 只有当条件满足且应用在前台时才跳转 if (isLocalhostDetected.value && _isAppInForeground && @@ -257,33 +285,6 @@ class HomeController extends GetxController { // 使用路由跳转 Get.toNamed(AppRoutes.webview); webviewHasOpen = true; // 只有真正打开webview时才设置为true - if (!_isNapCatLogin && !_isNapCatQuickLogin) { - Get.snackbar( - 'NapCat 未登录', - '请前往 NapCat 终端页或 WebUI 自行扫码登录', - snackPosition: SnackPosition.BOTTOM, - backgroundColor: Colors.red.withValues(alpha: 0.8), - colorText: Colors.white, - duration: const Duration(seconds: 5), - ); - } else if (!_isNapCatLogin && _isNapCatQuickLogin) { - Get.snackbar( - 'NapCat 未配置快速登录', - '请前往设置页配置快速登录QQ账号设置', - snackPosition: SnackPosition.BOTTOM, - backgroundColor: Colors.yellow.withValues(alpha: 0.8), - colorText: Colors.white, - duration: const Duration(seconds: 5), - ); - _isNapCatLogin = true; // 视为已登录,防止重复触发 - } - - // 新建终端页并运行自定义启动命令 - final command = getCustomStartupCommand(); - if (command.trim().isNotEmpty) { - terminalTabManager.addSystemTerminalTab(command); - } - }); } } @@ -313,7 +314,8 @@ class HomeController extends GetxController { isLocalhostDetected.value = true; bumpProgress(); - // 检查是否两个条件都满足 + // 检查是否条件满足 + // 现在的实际功能为检查napcat登录状态和新建终端运行自定义启动命令 _checkAndNavigateToWebview(); Future.delayed(const Duration(milliseconds: 2000), () {