Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
StephenBrown2 opened this issue Nov 8, 2023 · 4 comments
Closed
Assignees

Comments

@StephenBrown2
Copy link

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:

getTheme := func(body []interface{}) (string, bool) {
if body[0].(string) != "org.gnome.desktop.interface" {
return "", false
}
if body[1].(string) == "color-scheme" {
return body[2].(dbus.Variant).Value().(string), true
}
return "", false
}
for v := range c {
theme, ok := getTheme(v.Body)

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 added a commit that referenced this issue Nov 9, 2023
Need at least two elements to decide what theme it is and if it is
a theme message at all.

Addresses #3040
@tmclane
Copy link
Member

tmclane commented Nov 9, 2023

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
Copy link

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

@johnmaguire
Copy link

Is this issue still valid?

@leaanthony
Copy link
Member

No I don't think so

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants