# bt-app 完整示例 ## 纯本地 HTML 桌面应用 文件结构: ```text html-demo/ index.html ``` `index.html`: ```html

HTML Demo

``` 运行: ```bash ./bt-app.exe run ``` 首次运行会生成默认 `app.json`。默认配置会收集 `assets/**`,可直接覆盖 Vue/Vite 这类常见前端构建产物。若项目还有 `style.css`、`main.js`、`images/**` 或其他自定义资源,并且需要打包分发,请创建自己的 `app.json`,把这些文件写入 `resources`。 ## 本地 HTML 加 BT 函数 文件结构: ```text static-demo/ app.json index.html main.bt ``` `app.json`: ```json { "app": { "name": "StaticDemo", "title": "Static Demo", "mode": "static", "entry": "index.html", "main": "main.bt" }, "window": { "width": 900, "height": 700, "resizable": true }, "dev": { "watch": true, "delay": 500, "devtools": true, "console": true }, "resources": [ "index.html", "main.bt" ], "exclude": [] } ``` `main.bt`: ```bt fn add(args) { return { error:false, message:'ok', data:args.a + args.b } } ``` `index.html`: ```html Static Demo

  


```

## 本地 BT 服务加 Web 页面
文件结构:

```text
server-demo/
  app.json
  server.bt
  main.bt
  www/
    main.bt
    index.bt
```

`app.json`:

```json
{
  "app": {
    "name": "ServerDemo",
    "title": "BT Server Demo",
    "mode": "server",
    "entry": "http://127.0.0.1:18280",
    "main": "main.bt"
  },
  "window": {
    "width": 900,
    "height": 700
  },
  "dev": {
    "watch": true,
    "delay": 500,
    "devtools": false,
    "console": true
  },
  "resources": [
    "server.bt",
    "main.bt",
    "www/**"
  ],
  "exclude": []
}
```

`server.bt`:

```bt
net.listen({
    type:'web'
    bind:'127.0.0.1:18280'
    sites:[
        {
            domains:['127.0.0.1']
            root:'www/'
            entry:'main.bt'
        }
    ]
})
```

`www/main.bt`:

```bt
include('www/index.bt')
```

`www/static/index.bt`:

```html
# TPL 首页



  
  Server Demo


  

Server Demo

``` ## 远程 Web 应用包装 `app.json`: ```json { "app": { "name": "RemoteDemo", "title": "BT Remote Demo", "mode": "remote", "entry": "https://example.com", "main": false }, "window": { "width": 1100, "height": 760, "resizable": true }, "dev": { "watch": true, "delay": 500, "devtools": false, "console": false }, "resources": [], "exclude": [] } ``` ## 带图标和窗口配置 `app.json`: ```json { "app": { "name": "IconDemo", "title": "带图标的应用", "version": "1.0.0", "description": "BT 桌面图标示例", "copyright": "Copyright 2026 BT", "mode": "static", "entry": "index.html", "icon": "logo.ico", "main": false }, "window": { "width": 960, "height": 640, "resizable": true, "fullscreen": false, "hide_titlebar": false, "transparent": false, "always_on_top": false }, "dev": { "watch": true, "delay": 500, "devtools": false, "console": false }, "resources": [ "index.html", "logo.ico", "assets/**" ], "exclude": [] } ``` 当前 `logo.ico` 必须是项目内 `.ico` 文件。 ## 屏幕吸管与框选截图 仓库中的 `examples/desktop-screen-tools` 是完整可运行示例,提供: - 默认第一、第二槽位内置屏幕吸管和框选截图;`Alt+1` 至 `Alt+9` 始终按当前槽位位置执行。 - 设置菜单可添加 `.btr` 软件、`.exe` 和 Windows `.lnk` 快捷方式,支持上移、下移、移除和恢复默认工具。 - BTR 使用 `window.bt.app.info()` 读取 app.json 标题与图标,点击或位置快捷键通过 `window.bt.app.run()` 启动独立软件进程。 - 透明无标题栏悬浮工具条,圆角和半透明表面由 HTML/CSS 绘制;支持横向或纵向排列,拖动后自动吸附到最近屏幕边缘并在 1 秒后滑入边缘隐藏。 - 鼠标触达对应屏幕边缘时自动滑出,三点菜单可切换方向、隐藏到托盘或彻底退出;关闭到托盘后全局快捷键继续响应。 运行: ```powershell cd examples/desktop-screen-tools ..\..\target\release\bt-app.exe ``` 构建单文件应用: ```powershell ..\..\target\release\bt-app.exe build ``` 也可只生成工具条 BTR: ```powershell ..\..\target\release\bt-app.exe pack ..\..\target\release\bt-app.exe run .\dist\UniversalToolsDemo.btr ``` 成功取色后可在文本输入框按 `Ctrl+V` 或 `Cmd+V` 粘贴色值;成功截图后可在支持图片粘贴的聊天窗口按相同快捷键粘贴图片。详细验收步骤见示例目录的 `README.md`。