wailsapp / wails

Create beautiful applications using Go
https://wails.io
MIT License
24.57k stars 1.18k forks source link

[v3 linux] Panic when attempting to getTheme from empty dbus Signal #3040

Open StephenBrown2 opened 10 months ago

StephenBrown2 commented 10 months ago

Loving the progress, posting an issue here because the discord invite link here is invalid: https://discord.gg/3mgVyGua

I just pulled the v3-alpha branch and wanted to try out the systray implementation. It started fine, but it panicked here when I clicked the "Hello World" Menu option:

https://github.com/wailsapp/wails/blob/412c3a5ed1c764100fe00ba14b2a7afda6a44e4f/v3/pkg/application/application_linux.go#L155-L166

Because the Body of the DBus signal is empty. I'd recommend adding a check for the body length in the getTheme function.

        getTheme := func(body []interface{}) (string, bool) {
            if len(body) < 1 {
                return "", false
            }

With that added, the question dialog successfully pops up, albeit "unthemed", and I can also have it open the window.

Hope this doesn't clutter things too much, feel free to close and reorganize elsewhere.


Logs:

❯ go1.21.4 run .
# github.com/wailsapp/wails/v3/pkg/application
cgo-gcc-prolog: In function ‘_cgo_4865b4e94e09_Cfunc_webkit_javascript_result_get_global_context’:
cgo-gcc-prolog:2296:2: warning: ‘webkit_javascript_result_get_global_context’ is deprecated [-Wdeprecated-declarations]
In file included from /usr/include/webkitgtk-4.0/webkit2/webkit2.h:58,
                 from ../../pkg/application/linux_cgo.go:21:
/usr/include/webkitgtk-4.0/webkit/WebKitJavascriptResult.h:51:1: note: declared here
   51 | webkit_javascript_result_get_global_context (WebKitJavascriptResult *js_result);
      | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cgo-gcc-prolog: In function ‘_cgo_4865b4e94e09_Cfunc_webkit_javascript_result_get_value’:
cgo-gcc-prolog:2332:2: warning: ‘webkit_javascript_result_get_value’ is deprecated: Use 'webkit_javascript_result_get_js_value' instead [-Wdeprecated-declarations]
/usr/include/webkitgtk-4.0/webkit/WebKitJavascriptResult.h:54:1: note: declared here
   54 | webkit_javascript_result_get_value          (WebKitJavascriptResult *js_result);
      | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4:10PM INF Build Info: Wails=v3.0.0-alpha.0 Compiler=go1.21.4 CGO_CXXFLAGS="" CGO_LDFLAGS="" GOAMD64=v1 -buildmode=exe -compiler=gc CGO_CPPFLAGS="" GOOS=linux CGO_ENABLED=1 CGO_CFLAGS="" GOARCH=amd64
4:10PM INF AssetServer Info: assetsFS=true middleware=false handler=false externalURL=""
4:10PM INF Platform Info: ID=fedora Name="Fedora Linux" Version=38 Branding="38 (KDE Plasma)"
2023/11/08 16:10:16 linuxApp.setIcon not implemented
2023/11/08 16:10:16 linuxApp.on() 1032
on() 1181
on() 1187
Overriding existing handler for signal 10. Set JSC_SIGNAL_FOR_GC if you want WebKit to use a different signal
attempting to set in the center
on() 1143
4:10PM INF Asset Request: windowName="" windowID=1 code=200 method=GET path=/ duration=1.259374ms
4:10PM INF Asset Request: windowName="" windowID=1 code=200 method=GET path=/wails/ipc.js duration=36.43µs
4:10PM INF Asset Request: windowName="" windowID=1 code=200 method=GET path=/wails/runtime.js duration=125.416µs
4:10PM INF Asset Request: windowName="" windowID=1 code=200 method=GET path=/wails/flags duration=112.222µs
4:10PM INF Asset Request: windowName="" windowID=1 code=200 method=GET path=/wails/capabilities duration=69.857µs
Hello World!
panic: runtime error: index out of range [0] with length 0

goroutine 20 [running]:
github.com/wailsapp/wails/v3/pkg/application.(*linuxApp).monitorThemeChanges.func1.1(...)
        /home/sb/wails/v3/pkg/application/application_linux.go:156
github.com/wailsapp/wails/v3/pkg/application.(*linuxApp).monitorThemeChanges.func1()
        /home/sb/wails/v3/pkg/application/application_linux.go:166 +0x55b
created by github.com/wailsapp/wails/v3/pkg/application.(*linuxApp).monitorThemeChanges in goroutine 1
        /home/sb/wails/v3/pkg/application/application_linux.go:138 +0x4f
exit status 2

wails3 doctor output:

# Build Environment
Wails CLI    | v3.0.0-alpha.0                          
Go Version   | go1.21.4                                
Revision     | 412c3a5ed1c764100fe00ba14b2a7afda6a44e4f
Modified     | true                                    
-buildmode   | exe                                     
-compiler    | gc                                      
CGO_CFLAGS   |                                         
CGO_CPPFLAGS |                                         
CGO_CXXFLAGS |                                         
CGO_ENABLED  | 1                                       
CGO_LDFLAGS  |                                         
GOAMD64      | v1                                      
GOARCH       | amd64                                   
GOOS         | linux                                   
vcs          | git                                     
vcs.modified | true                                    
vcs.revision | 412c3a5ed1c764100fe00ba14b2a7afda6a44e4f
vcs.time     | 2023-11-08T11:36:47Z                    

# System
Name         | Fedora Linux                                                           
Version      | 38                                                                     
ID           | fedora                                                                 
Branding     | 38 (KDE Plasma)                                                        
Platform     | linux                                                                  
Architecture | amd64                                                                  
gcc          | 13.2.1                                                                 
libgtk-3     | 3.24.38                                                                
libwebkit    | 2.42.1                                                                 
npm          | 9.8.1                                                                  
pkg-config   | 1.8.0                                                                  
CPU          | 12th Gen Intel(R) Core(TM) i7-12800H                                   
GPU 1        | Alder Lake-P GT2 [Iris Xe Graphics] (Intel Corporation) - Driver: i915 
Memory       | 66GB                                                                   

# Diagnosis
 SUCCESS  Your system is ready for Wails development!
tmclane commented 10 months ago

Let me know if that fixes it for you. The theme in this case is merely to know if we are using light or dark but unless you added a handler to your application nothing else happens at this time.

sbrownjc commented 10 months ago

Yup, works for me now! Thanks, and godspeed!