mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-03 01:30:32 +08:00

* Fix WindowSetRGBA API * Change WindowUnFullscreen -> WindowUnfullscreen for consistency RGBA bugfix
91 lines
2.4 KiB
Go
91 lines
2.4 KiB
Go
package messagedispatcher
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/wailsapp/wails/v2/pkg/runtime"
|
|
|
|
"github.com/wailsapp/wails/v2/internal/logger"
|
|
"github.com/wailsapp/wails/v2/internal/messagedispatcher/message"
|
|
"github.com/wailsapp/wails/v2/internal/servicebus"
|
|
)
|
|
|
|
// Client defines what a frontend client can do
|
|
type Client interface {
|
|
Quit()
|
|
NotifyEvent(message string)
|
|
CallResult(message string)
|
|
OpenFileDialog(dialogOptions runtime.OpenDialogOptions, callbackID string)
|
|
OpenMultipleFilesDialog(dialogOptions runtime.OpenDialogOptions, callbackID string)
|
|
OpenDirectoryDialog(dialogOptions runtime.OpenDialogOptions, callbackID string)
|
|
SaveDialog(dialogOptions runtime.SaveDialogOptions, callbackID string)
|
|
MessageDialog(dialogOptions runtime.MessageDialogOptions, callbackID string)
|
|
WindowSetTitle(title string)
|
|
WindowShow()
|
|
WindowHide()
|
|
WindowCenter()
|
|
WindowMaximise()
|
|
WindowUnmaximise()
|
|
WindowMinimise()
|
|
WindowUnminimise()
|
|
WindowPosition(x int, y int)
|
|
WindowSize(width int, height int)
|
|
WindowSetMinSize(width int, height int)
|
|
WindowSetMaxSize(width int, height int)
|
|
WindowFullscreen()
|
|
WindowUnfullscreen()
|
|
WindowSetColour(colour int)
|
|
DarkModeEnabled(callbackID string)
|
|
SetApplicationMenu(menuJSON string)
|
|
SetTrayMenu(trayMenuJSON string)
|
|
UpdateTrayMenuLabel(JSON string)
|
|
UpdateContextMenu(contextMenuJSON string)
|
|
DeleteTrayMenuByID(id string)
|
|
}
|
|
|
|
// DispatchClient is what the frontends use to interface with the
|
|
// dispatcher
|
|
type DispatchClient struct {
|
|
id string
|
|
logger logger.CustomLogger
|
|
|
|
bus *servicebus.ServiceBus
|
|
|
|
// Client
|
|
frontend Client
|
|
}
|
|
|
|
func newDispatchClient(id string, frontend Client, logger logger.CustomLogger, bus *servicebus.ServiceBus) *DispatchClient {
|
|
|
|
return &DispatchClient{
|
|
id: id,
|
|
frontend: frontend,
|
|
logger: logger,
|
|
bus: bus,
|
|
}
|
|
|
|
}
|
|
|
|
// DispatchMessage is called by the front ends. It is passed
|
|
// an IPC message, translates it to a more concrete message
|
|
// type then publishes it on the service bus.
|
|
func (d *DispatchClient) DispatchMessage(incomingMessage string) {
|
|
|
|
// Parse the message
|
|
d.logger.Trace(fmt.Sprintf("Received message: %+v", incomingMessage))
|
|
parsedMessage, err := message.Parse(incomingMessage)
|
|
if err != nil {
|
|
d.logger.Error(err.Error())
|
|
return
|
|
}
|
|
|
|
// Save this client id
|
|
parsedMessage.ClientID = d.id
|
|
|
|
d.logger.Trace("I got a parsedMessage: %+v", parsedMessage)
|
|
|
|
// Publish the parsed message
|
|
d.bus.PublishForTarget(parsedMessage.Topic, parsedMessage.Data, d.id)
|
|
|
|
}
|