Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,30 @@ your-project/

随后运行 `mxu.exe`(Windows)或 `./mxu`(Linux/macOS)即可!~

### 命令行参数

MXU 支持以下启动参数:

| 参数 | 功能 | 说明 |
| --- | --- | --- |
| `-h` / `--help` | 显示帮助信息 | 输出 MXU 当前支持的命令行参数说明并退出,不启动图形界面。 |
| `--autostart` | 标记为“开机自启动”启动 | 进入开机自启动模式,并触发自动执行逻辑。该参数主要由 MXU 创建的系统自启动任务自动传入,通常无需手动设置。 |
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

既然不用手动传,那 autostart 还要写吗

Copy link
Copy Markdown
Contributor Author

@overflow65537 overflow65537 Apr 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mxu创建的开机自启动会自动加
但是用户自己配置的计划任务或者MAS之类不会自动加,还是要保留的吧(

| `-i <实例名>` / `--instance <实例名>` | 指定要自动启动的实例 | 仅在 `--autostart` 模式下生效。若指定的实例名存在,则优先使用该实例,而不是设置中配置的默认自动执行实例。也支持 `-i=<实例名>`、`--instance=<实例名>` 写法。 |
| `-q` / `--quit-after-run` | 自动执行完成后退出程序 | 当本次启动实际触发了自动执行后,等待任务结束并自动关闭 MXU,适合配合自启动场景做“一次性后台执行”。 |

示例:

```bash
# 查看命令行帮助
mxu.exe --help

# 使用系统自启动模式,并指定自动执行的实例名
mxu.exe --autostart --instance "日常任务"

# 自动执行完成后自动退出
mxu.exe --autostart -i "日常任务" --quit-after-run
```

### 用户文件

用户配置保存在 `config` 文件夹中,调试日志保存在 `debug` 文件夹中。亦可在 设置 - 调试 中直接打开文件夹。
Expand Down
43 changes: 43 additions & 0 deletions src-tauri/src/commands/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,49 @@ pub fn is_autostart() -> bool {
std::env::args().any(|arg| arg == "--autostart")
}

/// 检查命令行是否包含 -h/--help 参数
pub fn has_help_flag() -> bool {
std::env::args().skip(1).any(|arg| arg == "-h" || arg == "--help")
}

/// 生成命令行帮助文本
pub fn get_cli_help_text() -> String {
let exe_name = std::env::current_exe()
.ok()
.and_then(|path| path.file_name().map(|name| name.to_string_lossy().into_owned()))
.filter(|name| !name.is_empty())
.unwrap_or_else(|| "mxu".to_string());

format!(
"\
MXU 命令行参数

用法:
{exe_name} [参数]

参数:
-h, --help
显示本帮助并退出

--autostart
以开机自启动模式运行,并触发自动执行逻辑
通常由 MXU 创建的系统自启动任务自动传入

-i, --instance <实例名>
指定自动执行时使用的实例名
仅在 --autostart 模式下生效
也支持 -i=<实例名> 与 --instance=<实例名> 写法

-q, --quit-after-run
当本次启动实际触发自动执行后,在任务完成时自动退出

示例:
{exe_name} --autostart --instance \"日常任务\"
{exe_name} --autostart -i \"日常任务\" --quit-after-run
"
)
}

/// 从命令行参数中获取指定选项的值
/// 支持 `-x value`、`--name value`、`-x=value`、`--name=value` 格式
/// 返回第一个匹配的值;若值缺失或以 `-` 开头则视为无效并跳过
Expand Down
5 changes: 5 additions & 0 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
mod webview2;

fn main() {
if mxu_lib::commands::system::has_help_flag() {
print!("{}", mxu_lib::commands::system::get_cli_help_text());
return;
}

#[cfg(target_os = "windows")]
{
// 设置 WebView2 数据目录为程序所在目录下的 webview_data 文件夹
Expand Down
Loading