Skip to content

Commit 48f557d

Browse files
committed
feat!: use error return for show proc for more uniform error handling
similar to e.g. the `script` proc and returns in the Go and V bindings
1 parent 2b43f43 commit 48f557d

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

webui.odin

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -159,33 +159,32 @@ foreign webui {
159159

160160
// == Wrapper functions =======================================================
161161

162+
Error :: enum {
163+
None,
164+
Failed,
165+
}
162166

163167
// Show a window using embedded HTML, or a file. If the window is already open, it will be refreshed.
164-
show :: proc(win: Window, content: string, await: bool = false, timeout: uint = 10) -> bool {
168+
show :: proc(win: Window, content: string, await: bool = false, timeout: uint = 10) -> Error {
165169
res := webui_show(win, strings.unsafe_string_to_cstring(content))
166170
if !await {
167-
return res
171+
return .Failed
168172
}
169173
for _ in 0 ..< timeout * 100 {
170174
if is_shown(win) {
171-
return true
175+
return nil
172176
}
173177
// Slow down check interval to reduce load.
174178
time.sleep(10 * time.Millisecond)
175179
}
176-
return false
180+
return .Failed
177181
}
178182

179183
// Navigate to a specific URL
180184
navigate :: proc(win: Window, url: string) {
181185
webui_navigate(win, strings.unsafe_string_to_cstring(url))
182186
}
183187

184-
Error :: enum {
185-
None,
186-
Failed,
187-
}
188-
189188
// Run JavaScript without waiting for the response.
190189
run :: proc(win: Window, script: string) {
191190
webui_run(win, strings.unsafe_string_to_cstring(script))

0 commit comments

Comments
 (0)