Skip to content

Commit 86047f1

Browse files
committed
fix(examples): improve advanced window controls and icon handling
- update window icon to use raw SVG string instead of base64 - refine window hide/show logic to use minimize/maximize for better UX - replace window.destroy with window.close for proper resource management - add missing charset meta tag and webui.js script to HTML
1 parent 800d575 commit 86047f1

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

examples/advanced_window/index.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<!DOCTYPE html>
22
<html>
33
<head>
4+
<meta charset="UTF-8" />
5+
<script src="/webui.js"></script>
46
<title>Advanced Window Controls</title>
57
<style>
68
:root {

examples/advanced_window/main.zig

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ const builtin = @import("builtin");
44

55
pub fn main() !void {
66
const window = webui.newWindow();
7-
defer window.destroy();
87

98
// Set window properties before showing
109
window.setSize(1024, 768);
@@ -24,8 +23,10 @@ pub fn main() !void {
2423
// Set connection timeout (0 means wait forever)
2524
webui.setTimeout(30); // 30 seconds timeout
2625

27-
// Set window icon (base64 encoded favicon)
28-
const icon_svg = "PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxNiIgaGVpZ2h0PSIxNiI+PGNpcmNsZSBjeD0iOCIgY3k9IjgiIHI9IjgiIGZpbGw9IiM0Mjg1RjQiLz48L3N2Zz4=";
26+
// Set window icon (raw SVG string)
27+
const icon_svg =
28+
"<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"16\" height=\"16\" viewBox=\"0 0 16 16\">" ++
29+
"<circle cx=\"8\" cy=\"8\" r=\"8\" fill=\"#4285F4\"/></svg>";
2930
window.setIcon(icon_svg, "image/svg+xml");
3031

3132
// Bind window control events
@@ -57,8 +58,15 @@ fn centerWindow(e: *webui.Event) void {
5758
fn toggleHide(e: *webui.Event) void {
5859
const window = e.getWindow();
5960
const hide = e.getBool();
60-
window.setHide(hide);
61-
e.returnString(if (hide) "Window hidden" else "Window shown");
61+
if (hide) {
62+
// 使用 WebUI API 最小化窗口,避免触发 wait() 返回
63+
window.minimize();
64+
e.returnString("Window minimized");
65+
} else {
66+
// 使用 WebUI API 最大化/还原窗口
67+
window.maximize();
68+
e.returnString("Window maximized");
69+
}
6270
}
6371

6472
fn resizeWindow(e: *webui.Event) void {
@@ -144,6 +152,6 @@ fn getProcessInfo(e: *webui.Event) void {
144152

145153
fn destroyWindow(e: *webui.Event) void {
146154
const window = e.getWindow();
147-
e.returnString("Window will be destroyed");
148-
window.destroy();
155+
window.close();
156+
e.returnString("Window closed");
149157
}

0 commit comments

Comments
 (0)