@@ -486,3 +486,99 @@ func GetArgAt[T any](e Event, idx uint) (arg T, err error) {
486486 arg = ret
487487 return
488488}
489+
490+ // GetBestBrowser returns the recommended web browser ID to use.
491+ // If you are already using one, this function will return the same ID.
492+ func (w Window ) GetBestBrowser () Browser {
493+ return Browser (C .webui_get_best_browser (C .size_t (w )))
494+ }
495+
496+ // BrowserExists checks if a web browser is installed.
497+ func BrowserExists (browser Browser ) bool {
498+ return bool (C .webui_browser_exist (C .size_t (browser )))
499+ }
500+
501+ // StartServer starts only the web server and returns the URL.
502+ // No window will be shown.
503+ func (w Window ) StartServer (content string ) string {
504+ ccontent := C .CString (content )
505+ defer C .free (unsafe .Pointer (ccontent ))
506+ return C .GoString (C .webui_start_server (C .size_t (w ), ccontent ))
507+ }
508+
509+ // GetFreePort returns an available usable free network port.
510+ func GetFreePort () uint {
511+ return uint (C .webui_get_free_port ())
512+ }
513+
514+ // ShowWebView shows a WebView window using embedded HTML or a file.
515+ // If the window is already open, it will be refreshed.
516+ // Note: Windows requires WebView2Loader.dll
517+ func (w Window ) ShowWebView (content string ) (err error ) {
518+ ccontent := C .CString (content )
519+ defer C .free (unsafe .Pointer (ccontent ))
520+ if ! C .webui_show_wv (C .size_t (w ), ccontent ) {
521+ err = errors .New ("error: failed to show WebView window" )
522+ }
523+ return
524+ }
525+
526+ // SetMinimumSize sets the window minimum size.
527+ func (w Window ) SetMinimumSize (width , height uint ) {
528+ C .webui_set_minimum_size (C .size_t (w ), C .uint (width ), C .uint (height ))
529+ }
530+
531+ // SetHighContrast sets the window with high-contrast support.
532+ // Useful when you want to build a better high-contrast theme with CSS.
533+ func (w Window ) SetHighContrast (status bool ) {
534+ C .webui_set_high_contrast (C .size_t (w ), C ._Bool (status ))
535+ }
536+
537+ // IsHighContrast returns whether the OS is using high contrast theme.
538+ func IsHighContrast () bool {
539+ return bool (C .webui_is_high_contrast ())
540+ }
541+
542+ // SetCustomParameters adds user-defined web browser's CLI parameters.
543+ func (w Window ) SetCustomParameters (params string ) {
544+ cparams := C .CString (params )
545+ defer C .free (unsafe .Pointer (cparams ))
546+ C .webui_set_custom_parameters (C .size_t (w ), cparams )
547+ }
548+
549+ // GetMimeType returns the HTTP mime type of a file.
550+ func GetMimeType (filename string ) string {
551+ cfilename := C .CString (filename )
552+ defer C .free (unsafe .Pointer (cfilename ))
553+ return C .GoString (C .webui_get_mime_type (cfilename ))
554+ }
555+
556+ // OpenURL opens a URL in the native default web browser.
557+ func OpenURL (url string ) {
558+ curl := C .CString (url )
559+ defer C .free (unsafe .Pointer (curl ))
560+ C .webui_open_url (curl )
561+ }
562+
563+ // SetTLSCertificate sets the SSL/TLS certificate and the private key content,
564+ // both in PEM format. This works only with `webui-2-secure` library.
565+ // If set empty, WebUI will generate a self-signed certificate.
566+ func SetTLSCertificate (certificatePEM , privateKeyPEM string ) bool {
567+ ccert := C .CString (certificatePEM )
568+ ckey := C .CString (privateKeyPEM )
569+ defer C .free (unsafe .Pointer (ccert ))
570+ defer C .free (unsafe .Pointer (ckey ))
571+ return bool (C .webui_set_tls_certificate (ccert , ckey ))
572+ }
573+
574+ // Malloc safely allocates memory using the WebUI memory management system.
575+ func Malloc (size uint ) unsafe.Pointer {
576+ return C .webui_malloc (C .size_t (size ))
577+ }
578+
579+ // SendRaw safely sends raw data to the UI. All clients.
580+ func (w Window ) SendRaw (function string , raw []byte ) {
581+ cfunc := C .CString (function )
582+ defer C .free (unsafe .Pointer (cfunc ))
583+ C .webui_send_raw (C .size_t (w ), cfunc , unsafe .Pointer (& raw [0 ]), C .size_t (len (raw )))
584+ }
0 commit comments