bt_app 完整示例
纯本地 HTML 桌面应用
文件结构:
html-demo/
index.html
style.css
index.html:
<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>HTML Demo</title>
<link rel="stylesheet" href="style.css">
<bt-app app_name="HtmlDemo" window_width="860" window_height="620" resources="style.css"></bt-app>
</head>
<body>
<h1>HTML Demo</h1>
</body>
</html>
运行:
bt_app.exe run
本地 HTML 加 BT 函数
文件结构:
static-demo/
app.json
index.html
main.bt
app.json:
{
"app": {
"name": "StaticDemo",
"title": "Static Demo",
"mode": "static",
"entry": "index.html",
"main": "main.bt",
"devtools": true,
"console": true
},
"window": {
"width": 900,
"height": 700,
"resizable": true
},
"resources": [
"index.html",
"main.bt"
]
}
main.bt:
fn add(a, b) {
return {
error:false,
message:'ok',
data:a + b
}
}
index.html:
<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>Static Demo</title>
</head>
<body>
<button id="btn">计算</button>
<pre id="out"></pre>
<script>
document.getElementById('btn').onclick = async () => {
const result = await window.bt.call('add', { a: 20, b: 22 });
document.getElementById('out').textContent = JSON.stringify(result, null, 2);
};
</script>
</body>
</html>
本地 BT 服务加 Web 页面
文件结构:
server-demo/
app.json
server.bt
main.bt
www/
main.bt
static/
index.html
app.json:
{
"app": {
"name": "ServerDemo",
"title": "BT Server Demo",
"mode": "server",
"entry": "http://127.0.0.1:18280",
"main": "main.bt",
"console": true
},
"window": {
"width": 900,
"height": 700
},
"resources": [
"server.bt",
"main.bt",
"www/**"
]
}
server.bt:
net.listen({
type:'web',
bind:'127.0.0.1:18280',
sites:[
{
domains:['127.0.0.1'],
root:'www/',
entry:'main.bt',
static:{
route:'/static/{**}',
path:'www/static/',
default:'index.html'
}
}
]
})
www/main.bt:
return 'BT Server OK'
www/static/index.html:
<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>Server Demo</title>
</head>
<body>
<h1>Server Demo</h1>
</body>
</html>
远程 Web 应用包装
app.json:
{
"app": {
"name": "RemoteDemo",
"title": "BT Remote Demo",
"mode": "remote",
"entry": "https://example.com",
"main": false,
"devtools": false,
"console": false
},
"window": {
"width": 1100,
"height": 760,
"resizable": true
},
"resources": []
}
带图标和窗口配置
app.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,
"console": false
},
"window": {
"width": 960,
"height": 640,
"resizable": true,
"fullscreen": false,
"hide_titlebar": false,
"always_on_top": false
},
"resources": [
"index.html",
"logo.ico",
"assets/**"
]
}
当前 logo.ico 必须是项目内 .ico 文件。