5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-04 05:20:00 +08:00

Misc tidy up

This commit is contained in:
Lea Anthony 2021-01-14 13:55:20 +11:00
parent 742e4ba2cb
commit 29ffeaa9f3
No known key found for this signature in database
GPG Key ID: 33DAF7BB90A58405
4 changed files with 59 additions and 23 deletions

View File

@ -45,8 +45,8 @@ type App struct {
appconfigStore *runtime.Store appconfigStore *runtime.Store
// Startup/Shutdown // Startup/Shutdown
startup func(*runtime.Runtime) startupCallback func(*runtime.Runtime)
shutdown func() shutdownCallback func()
} }
// Create App // Create App
@ -85,8 +85,8 @@ func CreateApp(appoptions *options.App) (*App, error) {
logger: myLogger, logger: myLogger,
bindings: binding.NewBindings(myLogger), bindings: binding.NewBindings(myLogger),
menuManager: menuManager, menuManager: menuManager,
startup: appoptions.Startup, startupCallback: appoptions.Startup,
shutdown: appoptions.Shutdown, shutdownCallback: appoptions.Shutdown,
} }
result.options = appoptions result.options = appoptions
@ -118,7 +118,7 @@ func (a *App) Run() error {
return err return err
} }
runtimesubsystem, err := subsystem.NewRuntime(a.servicebus, a.logger) runtimesubsystem, err := subsystem.NewRuntime(a.servicebus, a.logger, a.startupCallback, a.shutdownCallback)
if err != nil { if err != nil {
return err return err
} }

View File

@ -21,10 +21,6 @@ int debug;
// A cache for all our dialog icons // A cache for all our dialog icons
struct hashmap_s dialogIconCache; struct hashmap_s dialogIconCache;
// Context menu data is given by the frontend when clicking a context menu.
// We send this to the backend when an item is selected;
const char *contextMenuData;
// Dispatch Method // Dispatch Method
typedef void (^dispatchMethod)(void); typedef void (^dispatchMethod)(void);
@ -255,6 +251,10 @@ void messageHandler(id self, SEL cmd, id contentController, id message) {
// TODO: Check this actually does reduce flicker // TODO: Check this actually does reduce flicker
msg(app->config, s("setValue:forKey:"), msg(c("NSNumber"), s("numberWithBool:"), 0), str("suppressesIncrementalRendering")); msg(app->config, s("setValue:forKey:"), msg(c("NSNumber"), s("numberWithBool:"), 0), str("suppressesIncrementalRendering"));
// Notify backend we are ready (system startup)
app->sendMessageToBackend("SS");
} else if( strcmp(name, "windowDrag") == 0 ) { } else if( strcmp(name, "windowDrag") == 0 ) {
// Guard against null events // Guard against null events
if( app->mouseEvent != NULL ) { if( app->mouseEvent != NULL ) {
@ -633,6 +633,8 @@ extern void MessageDialog(struct Application *app, char *callbackID, char *type,
dialogIcon = icon; dialogIcon = icon;
} }
// TODO: move dialog icons + methods to own file
// Determine what dialog icon we are looking for // Determine what dialog icon we are looking for
id dialogImage = NULL; id dialogImage = NULL;
// Look for `name-theme2x` first // Look for `name-theme2x` first
@ -1501,6 +1503,9 @@ void Run(struct Application *app, int argc, char **argv) {
makeWindowBackgroundTranslucent(app); makeWindowBackgroundTranslucent(app);
} }
// We set it to be invisible by default. It will become visible when everything has initialised
msg(app->mainWindow, s("setIsVisible:"), NO);
// Setup webview // Setup webview
id config = msg(c("WKWebViewConfiguration"), s("new")); id config = msg(c("WKWebViewConfiguration"), s("new"));
msg(config, s("setValue:forKey:"), msg(c("NSNumber"), s("numberWithBool:"), 1), str("suppressesIncrementalRendering")); msg(config, s("setValue:forKey:"), msg(c("NSNumber"), s("numberWithBool:"), 1), str("suppressesIncrementalRendering"));
@ -1651,9 +1656,6 @@ void Run(struct Application *app, int argc, char **argv) {
// Process dialog icons // Process dialog icons
processUserDialogIcons(app); processUserDialogIcons(app);
// We set it to be invisible by default. It will become visible when everything has initialised
msg(app->mainWindow, s("setIsVisible:"), NO);
// Finally call run // Finally call run
Debug(app, "Run called"); Debug(app, "Run called");
msg(app->application, s("run")); msg(app->application, s("run"));

View File

@ -44,6 +44,7 @@ func (r *system) IsDarkMode() bool {
systemResponseChannel, err := r.bus.Subscribe(responseTopic) systemResponseChannel, err := r.bus.Subscribe(responseTopic)
if err != nil { if err != nil {
fmt.Printf("ERROR: Cannot subscribe to bus topic: %+v\n", err.Error()) fmt.Printf("ERROR: Cannot subscribe to bus topic: %+v\n", err.Error())
return false
} }
message := "system:isdarkmode:" + uniqueCallback message := "system:isdarkmode:" + uniqueCallback

View File

@ -14,6 +14,12 @@ import (
type Runtime struct { type Runtime struct {
quitChannel <-chan *servicebus.Message quitChannel <-chan *servicebus.Message
runtimeChannel <-chan *servicebus.Message runtimeChannel <-chan *servicebus.Message
// The hooks channel allows us to hook into frontend startup
hooksChannel <-chan *servicebus.Message
startupCallback func(*runtime.Runtime)
shutdownCallback func()
running bool running bool
logger logger.CustomLogger logger logger.CustomLogger
@ -23,7 +29,7 @@ type Runtime struct {
} }
// NewRuntime creates a new runtime subsystem // NewRuntime creates a new runtime subsystem
func NewRuntime(bus *servicebus.ServiceBus, logger *logger.Logger) (*Runtime, error) { func NewRuntime(bus *servicebus.ServiceBus, logger *logger.Logger, startupCallback func(*runtime.Runtime), shutdownCallback func()) (*Runtime, error) {
// Register quit channel // Register quit channel
quitChannel, err := bus.Subscribe("quit") quitChannel, err := bus.Subscribe("quit")
@ -37,11 +43,20 @@ func NewRuntime(bus *servicebus.ServiceBus, logger *logger.Logger) (*Runtime, er
return nil, err return nil, err
} }
// Subscribe to log messages
hooksChannel, err := bus.Subscribe("hooks:")
if err != nil {
return nil, err
}
result := &Runtime{ result := &Runtime{
quitChannel: quitChannel, quitChannel: quitChannel,
runtimeChannel: runtimeChannel, runtimeChannel: runtimeChannel,
hooksChannel: hooksChannel,
logger: logger.CustomLogger("Runtime Subsystem"), logger: logger.CustomLogger("Runtime Subsystem"),
runtime: runtime.New(bus), runtime: runtime.New(bus),
startupCallback: startupCallback,
shutdownCallback: shutdownCallback,
} }
return result, nil return result, nil
@ -59,6 +74,21 @@ func (r *Runtime) Start() error {
case <-r.quitChannel: case <-r.quitChannel:
r.running = false r.running = false
break break
case hooksMessage := <-r.hooksChannel:
r.logger.Trace(fmt.Sprintf("Received hooksmessage: %+v", hooksMessage))
messageSlice := strings.Split(hooksMessage.Topic(), ":")
hook := messageSlice[1]
switch hook {
case "startup":
if r.startupCallback != nil {
go r.startupCallback(r.runtime)
} else {
r.logger.Error("no startup callback registered!")
}
default:
r.logger.Error("unknown hook message: %+v", hooksMessage)
continue
}
case runtimeMessage := <-r.runtimeChannel: case runtimeMessage := <-r.runtimeChannel:
r.logger.Trace(fmt.Sprintf("Received message: %+v", runtimeMessage)) r.logger.Trace(fmt.Sprintf("Received message: %+v", runtimeMessage))
// Topics have the format: "runtime:category:call" // Topics have the format: "runtime:category:call"
@ -99,6 +129,9 @@ func (r *Runtime) GoRuntime() *runtime.Runtime {
} }
func (r *Runtime) shutdown() { func (r *Runtime) shutdown() {
if r.shutdownCallback != nil {
go r.shutdownCallback()
}
r.logger.Trace("Shutdown") r.logger.Trace("Shutdown")
} }