mirror of
https://github.com/taigrr/wails.git
synced 2026-04-17 04:05:12 -07:00
Made go runtime package public.
Using loglevel store to keep loglevel in sync
This commit is contained in:
50
v2/pkg/runtime/system.go
Normal file
50
v2/pkg/runtime/system.go
Normal file
@@ -0,0 +1,50 @@
|
||||
package runtime
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/wailsapp/wails/v2/internal/crypto"
|
||||
"github.com/wailsapp/wails/v2/internal/servicebus"
|
||||
)
|
||||
|
||||
// System defines all System related operations
|
||||
type System interface {
|
||||
IsDarkMode() bool
|
||||
}
|
||||
|
||||
// system exposes the System interface
|
||||
type system struct {
|
||||
bus *servicebus.ServiceBus
|
||||
}
|
||||
|
||||
// newSystem creates a new System struct
|
||||
func newSystem(bus *servicebus.ServiceBus) System {
|
||||
return &system{
|
||||
bus: bus,
|
||||
}
|
||||
}
|
||||
|
||||
// On pass through
|
||||
func (r *system) IsDarkMode() bool {
|
||||
|
||||
// Create unique system callback
|
||||
uniqueCallback := crypto.RandomID()
|
||||
|
||||
// Subscribe to the respose channel
|
||||
responseTopic := "systemresponse:" + uniqueCallback
|
||||
systemResponseChannel, err := r.bus.Subscribe(responseTopic)
|
||||
if err != nil {
|
||||
fmt.Printf("ERROR: Cannot subscribe to bus topic: %+v\n", err.Error())
|
||||
}
|
||||
|
||||
message := "system:isdarkmode:" + uniqueCallback
|
||||
r.bus.Publish(message, nil)
|
||||
|
||||
// Wait for result
|
||||
var result *servicebus.Message = <-systemResponseChannel
|
||||
|
||||
// Delete subscription to response topic
|
||||
r.bus.UnSubscribe(responseTopic)
|
||||
|
||||
return result.Data().(bool)
|
||||
}
|
||||
Reference in New Issue
Block a user