Files

66 lines
1.7 KiB
Go
Raw Permalink Normal View History

2021-07-25 15:37:30 +10:00
package runtime
2021-07-25 15:04:01 +10:00
import (
"context"
2021-08-15 21:07:34 +10:00
"github.com/wailsapp/wails/v2/internal/frontend"
2021-08-25 20:30:31 +10:00
"github.com/wailsapp/wails/v2/internal/logger"
2021-08-15 21:07:34 +10:00
"log"
goruntime "runtime"
2021-07-25 15:04:01 +10:00
)
2021-08-15 21:07:34 +10:00
func getFrontend(ctx context.Context) frontend.Frontend {
2021-09-09 20:11:48 +10:00
if ctx == nil {
pc, _, _, _ := goruntime.Caller(1)
funcName := goruntime.FuncForPC(pc).Name()
log.Fatalf("cannot call '%s': context is nil", funcName)
}
2021-08-15 21:07:34 +10:00
result := ctx.Value("frontend")
if result != nil {
return result.(frontend.Frontend)
}
pc, _, _, _ := goruntime.Caller(1)
funcName := goruntime.FuncForPC(pc).Name()
log.Fatalf("cannot call '%s': Application not initialised", funcName)
return nil
}
2021-08-25 20:30:31 +10:00
func getLogger(ctx context.Context) *logger.Logger {
2021-09-09 20:11:48 +10:00
if ctx == nil {
pc, _, _, _ := goruntime.Caller(1)
funcName := goruntime.FuncForPC(pc).Name()
log.Fatalf("cannot call '%s': context is nil", funcName)
}
2021-08-25 20:30:31 +10:00
result := ctx.Value("logger")
if result != nil {
return result.(*logger.Logger)
}
pc, _, _, _ := goruntime.Caller(1)
funcName := goruntime.FuncForPC(pc).Name()
log.Fatalf("cannot call '%s': Application not initialised", funcName)
return nil
}
2021-08-15 21:07:34 +10:00
func getEvents(ctx context.Context) frontend.Events {
2021-09-09 20:11:48 +10:00
if ctx == nil {
pc, _, _, _ := goruntime.Caller(1)
funcName := goruntime.FuncForPC(pc).Name()
log.Fatalf("cannot call '%s': context is nil", funcName)
}
2021-08-15 21:07:34 +10:00
result := ctx.Value("events")
if result != nil {
return result.(frontend.Events)
}
pc, _, _, _ := goruntime.Caller(1)
funcName := goruntime.FuncForPC(pc).Name()
log.Fatalf("cannot call '%s': Application not initialised", funcName)
return nil
}
2021-07-25 15:04:01 +10:00
// Quit the application
2021-07-25 15:22:13 +10:00
func Quit(ctx context.Context) {
2021-09-09 20:11:48 +10:00
if ctx == nil {
log.Fatalf("cannot call Quit: context is nil")
}
2021-08-15 21:07:34 +10:00
appFrontend := getFrontend(ctx)
appFrontend.Quit()
2021-07-25 15:04:01 +10:00
}