mirror of
https://github.com/wavetermdev/wails.git
synced 2026-08-05 13:53:43 -07:00
Made go runtime package public.
Using loglevel store to keep loglevel in sync
This commit is contained in:
@@ -11,6 +11,7 @@ import (
|
||||
"github.com/wailsapp/wails/v2/internal/signal"
|
||||
"github.com/wailsapp/wails/v2/internal/subsystem"
|
||||
"github.com/wailsapp/wails/v2/pkg/options"
|
||||
"github.com/wailsapp/wails/v2/pkg/runtime"
|
||||
)
|
||||
|
||||
// App defines a Wails application structure
|
||||
@@ -19,6 +20,7 @@ type App struct {
|
||||
servicebus *servicebus.ServiceBus
|
||||
logger *logger.Logger
|
||||
signal *signal.Manager
|
||||
options *options.App
|
||||
|
||||
// Subsystems
|
||||
log *subsystem.Log
|
||||
@@ -33,6 +35,9 @@ type App struct {
|
||||
|
||||
// This is our binding DB
|
||||
bindings *binding.Bindings
|
||||
|
||||
// LogLevel Store
|
||||
loglevelStore *runtime.Store
|
||||
}
|
||||
|
||||
// Create App
|
||||
@@ -54,6 +59,8 @@ func CreateApp(options *options.App) *App {
|
||||
bindings: binding.NewBindings(myLogger),
|
||||
}
|
||||
|
||||
result.options = options
|
||||
|
||||
// Initialise the app
|
||||
result.Init()
|
||||
|
||||
@@ -84,6 +91,9 @@ func (a *App) Run() error {
|
||||
a.runtime = runtime
|
||||
a.runtime.Start()
|
||||
|
||||
// Application Stores
|
||||
a.loglevelStore = a.runtime.GoRuntime().Store.New("loglevel", a.options.LogLevel)
|
||||
|
||||
// Start the binding subsystem
|
||||
binding, err := subsystem.NewBinding(a.servicebus, a.logger, a.bindings, a.runtime.GoRuntime())
|
||||
if err != nil {
|
||||
@@ -93,7 +103,7 @@ func (a *App) Run() error {
|
||||
a.binding.Start()
|
||||
|
||||
// Start the logging subsystem
|
||||
log, err := subsystem.NewLog(a.servicebus, a.logger)
|
||||
log, err := subsystem.NewLog(a.servicebus, a.logger, a.loglevelStore)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ func (b *BoundMethod) VerifyWailsInit() error {
|
||||
}
|
||||
|
||||
// Check input type
|
||||
if !b.Inputs[0].IsType("*goruntime.Runtime") {
|
||||
if !b.Inputs[0].IsType("*runtime.Runtime") {
|
||||
return fmt.Errorf("invalid method signature for %s: expected `WailsInit(*wails.Runtime) error`", b.Name)
|
||||
}
|
||||
|
||||
|
||||
@@ -116,7 +116,8 @@ func (a *Application) Run(incomingDispatcher Dispatcher, bindings string) error
|
||||
devtools := a.bool2Cint(a.config.DevTools)
|
||||
fullscreen := a.bool2Cint(a.config.Fullscreen)
|
||||
startHidden := a.bool2Cint(a.config.StartHidden)
|
||||
app := C.NewApplication(title, width, height, resizable, devtools, fullscreen, startHidden)
|
||||
logLevel := C.int(a.config.LogLevel)
|
||||
app := C.NewApplication(title, width, height, resizable, devtools, fullscreen, startHidden, logLevel)
|
||||
|
||||
// Save app reference
|
||||
a.app = unsafe.Pointer(app)
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
extern void *NewApplication(const char *title, int width, int height, int resizable, int devtools, int fullscreen, int startHidden);
|
||||
extern void *NewApplication(const char *title, int width, int height, int resizable, int devtools, int fullscreen, int startHidden, int logLevel);
|
||||
extern void SetMinWindowSize(void *app, int minWidth, int minHeight);
|
||||
extern void SetMaxWindowSize(void *app, int maxWidth, int maxHeight);
|
||||
extern void Run(void *app, int argc, char **argv);
|
||||
|
||||
@@ -139,6 +139,7 @@ struct Application {
|
||||
const char *appearance;
|
||||
int decorations;
|
||||
bool dragging;
|
||||
int logLevel;
|
||||
|
||||
// Features
|
||||
int frame;
|
||||
@@ -325,7 +326,7 @@ void themeChanged(id self, SEL cmd, id sender) {
|
||||
// Debug(app, "willFinishLaunching called!");
|
||||
// }
|
||||
|
||||
void* NewApplication(const char *title, int width, int height, int resizable, int devtools, int fullscreen, int startHidden) {
|
||||
void* NewApplication(const char *title, int width, int height, int resizable, int devtools, int fullscreen, int startHidden, int logLevel) {
|
||||
// Setup main application struct
|
||||
struct Application *result = malloc(sizeof(struct Application));
|
||||
result->title = title;
|
||||
@@ -343,6 +344,7 @@ void* NewApplication(const char *title, int width, int height, int resizable, in
|
||||
result->minimised = 0;
|
||||
result->startHidden = startHidden;
|
||||
result->decorations = 0;
|
||||
result->logLevel = logLevel;
|
||||
|
||||
result->mainWindow = NULL;
|
||||
result->mouseEvent = NULL;
|
||||
@@ -869,11 +871,17 @@ void createMainWindow(struct Application *app) {
|
||||
}
|
||||
|
||||
const char* getInitialState(struct Application *app) {
|
||||
const char *result = "";
|
||||
if( isDarkMode(app) ) {
|
||||
return "window.wails.System.IsDarkMode.set(true);";
|
||||
result = "window.wails.System.IsDarkMode.set(true);";
|
||||
} else {
|
||||
return "window.wails.System.IsDarkMode.set(false);";
|
||||
result = "window.wails.System.IsDarkMode.set(false);";
|
||||
}
|
||||
char buffer[999];
|
||||
snprintf(&buffer[0], sizeof(buffer), "window.wails.System.LogLevel.set(%d);", app->logLevel);
|
||||
result = concat(result, &buffer[0]);
|
||||
Debug(app, "initialstate = %s", result);
|
||||
return result;
|
||||
}
|
||||
|
||||
void Run(struct Application *app, int argc, char **argv) {
|
||||
|
||||
@@ -49,6 +49,7 @@ export function Init() {
|
||||
|
||||
// Setup system
|
||||
window.wails.System.IsDarkMode = Store.New('isdarkmode');
|
||||
window.wails.System.LogLevel = Store.New('loglevel');
|
||||
|
||||
// Do platform specific Init
|
||||
Platform.Init();
|
||||
|
||||
@@ -3,8 +3,8 @@ package subsystem
|
||||
import (
|
||||
"github.com/wailsapp/wails/v2/internal/binding"
|
||||
"github.com/wailsapp/wails/v2/internal/logger"
|
||||
"github.com/wailsapp/wails/v2/internal/runtime/goruntime"
|
||||
"github.com/wailsapp/wails/v2/internal/servicebus"
|
||||
"github.com/wailsapp/wails/v2/pkg/runtime"
|
||||
)
|
||||
|
||||
// Binding is the Binding subsystem. It manages all service bus messages
|
||||
@@ -21,11 +21,11 @@ type Binding struct {
|
||||
logger logger.CustomLogger
|
||||
|
||||
// runtime
|
||||
runtime *goruntime.Runtime
|
||||
runtime *runtime.Runtime
|
||||
}
|
||||
|
||||
// NewBinding creates a new binding subsystem. Uses the given bindings db for reference.
|
||||
func NewBinding(bus *servicebus.ServiceBus, logger *logger.Logger, bindings *binding.Bindings, runtime *goruntime.Runtime) (*Binding, error) {
|
||||
func NewBinding(bus *servicebus.ServiceBus, logger *logger.Logger, bindings *binding.Bindings, runtime *runtime.Runtime) (*Binding, error) {
|
||||
|
||||
// Register quit channel
|
||||
quitChannel, err := bus.Subscribe("quit")
|
||||
|
||||
@@ -9,8 +9,7 @@ import (
|
||||
"github.com/wailsapp/wails/v2/internal/logger"
|
||||
"github.com/wailsapp/wails/v2/internal/messagedispatcher/message"
|
||||
"github.com/wailsapp/wails/v2/internal/servicebus"
|
||||
"github.com/wailsapp/wails/v2/internal/runtime/goruntime"
|
||||
|
||||
"github.com/wailsapp/wails/v2/pkg/runtime"
|
||||
)
|
||||
|
||||
// Call is the Call subsystem. It manages all service bus messages
|
||||
@@ -30,11 +29,11 @@ type Call struct {
|
||||
logger logger.CustomLogger
|
||||
|
||||
// runtime
|
||||
runtime *goruntime.Runtime
|
||||
runtime *runtime.Runtime
|
||||
}
|
||||
|
||||
// NewCall creates a new call subsystem
|
||||
func NewCall(bus *servicebus.ServiceBus, logger *logger.Logger, DB *binding.DB, runtime *goruntime.Runtime) (*Call, error) {
|
||||
func NewCall(bus *servicebus.ServiceBus, logger *logger.Logger, DB *binding.DB, runtime *runtime.Runtime) (*Call, error) {
|
||||
|
||||
// Register quit channel
|
||||
quitChannel, err := bus.Subscribe("quit")
|
||||
@@ -54,7 +53,7 @@ func NewCall(bus *servicebus.ServiceBus, logger *logger.Logger, DB *binding.DB,
|
||||
logger: logger.CustomLogger("Call Subsystem"),
|
||||
DB: DB,
|
||||
bus: bus,
|
||||
runtime: runtime,
|
||||
runtime: runtime,
|
||||
}
|
||||
|
||||
return result, nil
|
||||
@@ -122,7 +121,7 @@ func (c *Call) processSystemCall(payload *message.CallMessage, clientID string)
|
||||
c.logger.Trace("Got internal System call: %+v", payload)
|
||||
callName := strings.TrimPrefix(payload.Name, ".wails.")
|
||||
switch callName {
|
||||
case "IsDarkMode":
|
||||
case "IsDarkMode":
|
||||
darkModeEnabled := c.runtime.System.IsDarkMode()
|
||||
c.sendResult(darkModeEnabled, payload, clientID)
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
|
||||
"github.com/wailsapp/wails/v2/internal/logger"
|
||||
"github.com/wailsapp/wails/v2/internal/servicebus"
|
||||
"github.com/wailsapp/wails/v2/pkg/runtime"
|
||||
)
|
||||
|
||||
// Log is the Logging subsystem. It handles messages with topics starting
|
||||
@@ -17,10 +18,13 @@ type Log struct {
|
||||
|
||||
// Logger!
|
||||
logger *logger.Logger
|
||||
|
||||
// Loglevel store
|
||||
logLevelStore *runtime.Store
|
||||
}
|
||||
|
||||
// NewLog creates a new log subsystem
|
||||
func NewLog(bus *servicebus.ServiceBus, logger *logger.Logger) (*Log, error) {
|
||||
func NewLog(bus *servicebus.ServiceBus, logger *logger.Logger, logLevelStore *runtime.Store) (*Log, error) {
|
||||
|
||||
// Subscribe to log messages
|
||||
logChannel, err := bus.Subscribe("log")
|
||||
@@ -35,9 +39,10 @@ func NewLog(bus *servicebus.ServiceBus, logger *logger.Logger) (*Log, error) {
|
||||
}
|
||||
|
||||
result := &Log{
|
||||
logChannel: logChannel,
|
||||
quitChannel: quitChannel,
|
||||
logger: logger,
|
||||
logChannel: logChannel,
|
||||
quitChannel: quitChannel,
|
||||
logger: logger,
|
||||
logLevelStore: logLevelStore,
|
||||
}
|
||||
|
||||
return result, nil
|
||||
@@ -76,13 +81,16 @@ func (l *Log) Start() error {
|
||||
switch inLevel := logMessage.Data().(type) {
|
||||
case logger.LogLevel:
|
||||
l.logger.SetLogLevel(inLevel)
|
||||
l.logLevelStore.Set(inLevel)
|
||||
case string:
|
||||
uint64level, err := strconv.ParseUint(inLevel, 10, 8)
|
||||
if err != nil {
|
||||
l.logger.Error("Error parsing log level: %+v", inLevel)
|
||||
continue
|
||||
}
|
||||
l.logger.SetLogLevel(logger.LogLevel(uint64level))
|
||||
level := logger.LogLevel(uint64level)
|
||||
l.logLevelStore.Set(level)
|
||||
l.logger.SetLogLevel(level)
|
||||
}
|
||||
|
||||
default:
|
||||
|
||||
@@ -5,8 +5,8 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/wailsapp/wails/v2/internal/logger"
|
||||
"github.com/wailsapp/wails/v2/internal/runtime/goruntime"
|
||||
"github.com/wailsapp/wails/v2/internal/servicebus"
|
||||
"github.com/wailsapp/wails/v2/pkg/runtime"
|
||||
)
|
||||
|
||||
// Runtime is the Runtime subsystem. It handles messages with topics starting
|
||||
@@ -19,7 +19,7 @@ type Runtime struct {
|
||||
logger logger.CustomLogger
|
||||
|
||||
// Runtime library
|
||||
runtime *goruntime.Runtime
|
||||
runtime *runtime.Runtime
|
||||
}
|
||||
|
||||
// NewRuntime creates a new runtime subsystem
|
||||
@@ -41,7 +41,7 @@ func NewRuntime(bus *servicebus.ServiceBus, logger *logger.Logger) (*Runtime, er
|
||||
quitChannel: quitChannel,
|
||||
runtimeChannel: runtimeChannel,
|
||||
logger: logger.CustomLogger("Runtime Subsystem"),
|
||||
runtime: goruntime.New(bus),
|
||||
runtime: runtime.New(bus),
|
||||
}
|
||||
|
||||
return result, nil
|
||||
@@ -93,7 +93,7 @@ func (r *Runtime) Start() error {
|
||||
}
|
||||
|
||||
// GoRuntime returns the Go Runtime object
|
||||
func (r *Runtime) GoRuntime() *goruntime.Runtime {
|
||||
func (r *Runtime) GoRuntime() *runtime.Runtime {
|
||||
return r.runtime
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
package options
|
||||
|
||||
import (
|
||||
"github.com/wailsapp/wails/v2/pkg/options/mac"
|
||||
import (
|
||||
"github.com/wailsapp/wails/v2/pkg/logger"
|
||||
"github.com/wailsapp/wails/v2/pkg/options/mac"
|
||||
)
|
||||
|
||||
// Default options for creating the App
|
||||
var Default = &App{
|
||||
Title: "My Wails App",
|
||||
@@ -17,5 +18,6 @@ var Default = &App{
|
||||
WebviewIsTransparent: false,
|
||||
WindowBackgroundIsTranslucent: false,
|
||||
},
|
||||
Logger: logger.NewDefaultLogger(),
|
||||
Logger: logger.NewDefaultLogger(),
|
||||
LogLevel: logger.INFO,
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package goruntime
|
||||
package runtime
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@@ -1,4 +1,4 @@
|
||||
package goruntime
|
||||
package runtime
|
||||
|
||||
import (
|
||||
"os"
|
||||
@@ -1,4 +1,4 @@
|
||||
package goruntime
|
||||
package runtime
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@@ -1,4 +1,4 @@
|
||||
package goruntime
|
||||
package runtime
|
||||
|
||||
import (
|
||||
"github.com/wailsapp/wails/v2/internal/messagedispatcher/message"
|
||||
@@ -1,4 +1,4 @@
|
||||
package goruntime
|
||||
package runtime
|
||||
|
||||
import (
|
||||
"github.com/wailsapp/wails/v2/internal/servicebus"
|
||||
@@ -1,4 +1,4 @@
|
||||
package goruntime
|
||||
package runtime
|
||||
|
||||
import "github.com/wailsapp/wails/v2/internal/servicebus"
|
||||
|
||||
@@ -9,13 +9,14 @@ type Runtime struct {
|
||||
Window Window
|
||||
Dialog Dialog
|
||||
System System
|
||||
Store *StoreProvider
|
||||
Log Log
|
||||
bus *servicebus.ServiceBus
|
||||
}
|
||||
|
||||
// New creates a new runtime
|
||||
func New(serviceBus *servicebus.ServiceBus) *Runtime {
|
||||
return &Runtime{
|
||||
result := &Runtime{
|
||||
Browser: newBrowser(),
|
||||
Events: newEvents(serviceBus),
|
||||
Window: newWindow(serviceBus),
|
||||
@@ -24,6 +25,8 @@ func New(serviceBus *servicebus.ServiceBus) *Runtime {
|
||||
Log: newLog(serviceBus),
|
||||
bus: serviceBus,
|
||||
}
|
||||
result.Store = newStore(result)
|
||||
return result
|
||||
}
|
||||
|
||||
// Quit the application
|
||||
@@ -1,6 +1,6 @@
|
||||
// Package goruntime contains all the methods and data structures related to the
|
||||
// package runtime contains all the methods and data structures related to the
|
||||
// runtime library of Wails. This includes both Go and JS runtimes.
|
||||
package goruntime
|
||||
package runtime
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
@@ -32,8 +32,8 @@ type StoreProvider struct {
|
||||
runtime *Runtime
|
||||
}
|
||||
|
||||
// NewStoreProvider creates new stores using the provided Runtime reference.
|
||||
func NewStoreProvider(runtime *Runtime) *StoreProvider {
|
||||
// newStore creates new stores using the provided Runtime reference.
|
||||
func newStore(runtime *Runtime) *StoreProvider {
|
||||
return &StoreProvider{
|
||||
runtime: runtime,
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package goruntime
|
||||
package runtime
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@@ -1,4 +1,4 @@
|
||||
package goruntime
|
||||
package runtime
|
||||
|
||||
import (
|
||||
"github.com/wailsapp/wails/v2/internal/servicebus"
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user