You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
20 lines
846 B
20 lines
846 B
import { Webview, SizeHint } from "webview-bun";
|
|
import fs from "node:fs";
|
|
// 把html嵌入到单独可执行文件中,编译无需带ui.html
|
|
import html from "./ui.html" with { type: "text" };
|
|
import path from "node:path";
|
|
// 第一个参数是禁止开发者工具 SizeHint.FIXED是禁窗口最大化
|
|
const webview = new Webview(false, { height: 480, width: 640, hint: SizeHint.NONE });
|
|
|
|
let counter = 0;
|
|
// 绑定前端button(increment,decrement)的事件
|
|
webview.bind("count", (a) => counter += a);
|
|
// 绑定前端button(compute)的事件
|
|
webview.bind("compute", (a, b) => a + b);
|
|
// 软件标题
|
|
webview.title = "Bun App";
|
|
fs.writeFileSync("./aaa.txt", import.meta.path)
|
|
fs.writeFileSync("./bbb.txt", process.cwd())
|
|
const data = fs.readFileSync(path.resolve("./ui.html"), "utf-8").toString()
|
|
webview.setHTML(data);
|
|
webview.run();
|