You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Can anyone tell me what I'm doing wrong? I don't quite understand how V3 works yet compared to V2.
I have the following as my main.go:
package main
import (
"embed""log""time""github.com/wailsapp/wails/v3/pkg/application"
g "xabbo.b7c.io/goearth"
)
//go:embed frontend/distvarassets embed.FS// Initialize the G-Earth extensionvarext=g.NewExt(g.ExtInfo{
Title: "[JTD] Template Starter Kit Extension",
Description: "Quickly build your G-Earth GUI Extensions from this starter-kit.",
Version: "1.0.0",
Author: "JTD",
})
funcmain() {
// Create the G-Earth servicegEarthService:=NewGearthService(ext)
// Create a new Wails applicationapp:=application.New(application.Options{
Name: "starterkit",
Description: "[JTD] Template Starter Kit Extension",
Assets: application.AssetOptions{
Handler: application.AssetFileServerFS(assets),
},
Services: []application.Service{
application.NewService(gEarthService), // Register G-Earth serviceapplication.NewService(&GreetService{}),
},
Mac: application.MacOptions{
ApplicationShouldTerminateAfterLastWindowClosed: true,
},
})
// Create a new windowapp.NewWebviewWindowWithOptions(application.WebviewWindowOptions{
Title: "[JTD] Template Starter Kit Extension",
Mac: application.MacWindow{
InvisibleTitleBarHeight: 50,
Backdrop: application.MacBackdropTranslucent,
TitleBar: application.MacTitleBarHiddenInset,
},
BackgroundColour: application.NewRGB(27, 38, 54),
URL: "/",
})
// Emit an event every second to the frontendgofunc() {
for {
now:=time.Now().Format(time.RFC1123)
app.EmitEvent("time", now)
time.Sleep(time.Second)
}
}()
// Run the applicationerr:=app.Run()
// Handle any errorsiferr!=nil {
log.Fatal(err)
}
}
And then I have this in my App.go
package main
import (
"context""fmt""log""os""strings""sync""time""github.com/wailsapp/wails/v3/pkg/application"
g "xabbo.b7c.io/goearth""xabbo.b7c.io/goearth/shockwave/out"
)
typeGearthServicestruct {
ext*g.Extlog []stringlogMu sync.Mutexctx context.Contextapp*application.App
}
funcNewGearthService(ext*g.Ext) *GearthService {
return&GearthService{
ext: ext,
}
}
// Optional: Name of the service for logging purposesfunc (gs*GearthService) Name() string {
return"G-Earth Service"
}
// OnStartup is called when the application startsfunc (gs*GearthService) OnStartup(ctx context.Context, options application.ServiceOptions) error {
gs.ctx=ctxgs.setupExt()
gofunc() {
gs.runExt()
}()
returnnil
}
func (gs*GearthService) runExt() {
deferos.Exit(0)
gs.ext.Run()
}
func (gs*GearthService) setupExt() {
gs.ext.Initialized(func(e g.InitArgs) {
logMsg:=fmt.Sprintf("initialized (connected=%t)", e.Connected)
log.Printf(logMsg)
//gs.app.EmitEvent("log_event", logMsg) // Emit event to frontend// log.Printf("initialized (connected=%t)", e.Connected)
})
gs.ext.Activated(func() {
log.Printf("activated")
// You can trigger the window to show if necessary// app.ShowWindow() would work in the main.go context
})
gs.ext.Connected(func(e g.ConnectArgs) { // Correct event typelog.Printf("connected (%s:%d)", e.Host, e.Port)
log.Printf("client %s (%s)", e.Client.Identifier, e.Client.Version)
gofunc() {
gs.ext.Send(out.FRIENDLIST_UPDATE)
time.Sleep(time.Second*10)
}()
})
gs.ext.Disconnected(func() {
log.Printf("connection lost")
})
// Add G-Earth intercepts heregs.ext.Intercept(out.CHAT, out.WHISPER, out.SHOUT).With(gs.onChatMessage)
}
func (gs*GearthService) onChatMessage(e*g.Intercept) {
msg:=e.Packet.ReadString()
// Process commands based on the message prefix and suffixifstrings.HasPrefix(msg, ":") {
command:=strings.TrimPrefix(msg, ":")
parts:=strings.Fields(command)
switchparts[0] {
case"test":
e.Block()
log.Print("[Test] Command Detected")
gs.ext.Send(out.WAVE)
}
}
}
// OnShutdown is called when the application shuts downfunc (gs*GearthService) OnShutdown() error {
log.Println("Shutting down G-Earth service")
returnnil
}
Everything works fine (the default HelloWorld app shows) and I see the log messages in the console when I'm supposed to however when I uncomment this line:
gs.app.EmitEvent("log_event", logMsg) // Emit event to frontend
the application hangs stopping the functionality of everything (the default app does not appear and no log messages appear in console after this is executed:
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Can anyone tell me what I'm doing wrong? I don't quite understand how V3 works yet compared to V2.
I have the following as my main.go:
And then I have this in my App.go
Everything works fine (the default HelloWorld app shows) and I see the log messages in the console when I'm supposed to however when I uncomment this line:
the application hangs stopping the functionality of everything (the default app does not appear and no log messages appear in console after this is executed:
Beta Was this translation helpful? Give feedback.
All reactions