mirror of
https://github.com/taigrr/wails.git
synced 2026-04-02 05:08:54 -07:00
[windows-x] Refactor runtime again
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
// +build !experimental
|
||||
|
||||
package dialog
|
||||
package runtime
|
||||
|
||||
import (
|
||||
"context"
|
||||
@@ -77,8 +77,8 @@ func processTitleAndFilter(params ...string) (string, string) {
|
||||
return title, filter
|
||||
}
|
||||
|
||||
// OpenDirectory prompts the user to select a directory
|
||||
func OpenDirectory(ctx context.Context, dialogOptions OpenDialogOptions) (string, error) {
|
||||
// OpenDirectoryDialog prompts the user to select a directory
|
||||
func OpenDirectoryDialog(ctx context.Context, dialogOptions OpenDialogOptions) (string, error) {
|
||||
|
||||
bus := servicebus.ExtractBus(ctx)
|
||||
|
||||
@@ -104,8 +104,8 @@ func OpenDirectory(ctx context.Context, dialogOptions OpenDialogOptions) (string
|
||||
return result.Data().(string), nil
|
||||
}
|
||||
|
||||
// OpenFile prompts the user to select a file
|
||||
func OpenFile(ctx context.Context, dialogOptions OpenDialogOptions) (string, error) {
|
||||
// OpenFileDialog prompts the user to select a file
|
||||
func OpenFileDialog(ctx context.Context, dialogOptions OpenDialogOptions) (string, error) {
|
||||
|
||||
bus := servicebus.ExtractBus(ctx)
|
||||
|
||||
@@ -131,8 +131,8 @@ func OpenFile(ctx context.Context, dialogOptions OpenDialogOptions) (string, err
|
||||
return result.Data().(string), nil
|
||||
}
|
||||
|
||||
// OpenMultipleFiles prompts the user to select a file
|
||||
func OpenMultipleFiles(ctx context.Context, dialogOptions OpenDialogOptions) ([]string, error) {
|
||||
// OpenMultipleFilesDialog prompts the user to select a file
|
||||
func OpenMultipleFilesDialog(ctx context.Context, dialogOptions OpenDialogOptions) ([]string, error) {
|
||||
|
||||
bus := servicebus.ExtractBus(ctx)
|
||||
uniqueCallback := crypto.RandomID()
|
||||
@@ -156,8 +156,8 @@ func OpenMultipleFiles(ctx context.Context, dialogOptions OpenDialogOptions) ([]
|
||||
return result.Data().([]string), nil
|
||||
}
|
||||
|
||||
// SaveFile prompts the user to select a file
|
||||
func SaveFile(ctx context.Context, dialogOptions SaveDialogOptions) (string, error) {
|
||||
// SaveFileDialog prompts the user to select a file
|
||||
func SaveFileDialog(ctx context.Context, dialogOptions SaveDialogOptions) (string, error) {
|
||||
|
||||
bus := servicebus.ExtractBus(ctx)
|
||||
uniqueCallback := crypto.RandomID()
|
||||
@@ -181,8 +181,8 @@ func SaveFile(ctx context.Context, dialogOptions SaveDialogOptions) (string, err
|
||||
return result.Data().(string), nil
|
||||
}
|
||||
|
||||
// Message show a message to the user
|
||||
func Message(ctx context.Context, dialogOptions MessageDialogOptions) (string, error) {
|
||||
// MessageDialog show a message dialog to the user
|
||||
func MessageDialog(ctx context.Context, dialogOptions MessageDialogOptions) (string, error) {
|
||||
|
||||
bus := servicebus.ExtractBus(ctx)
|
||||
|
||||
45
v2/pkg/runtime/events.go
Normal file
45
v2/pkg/runtime/events.go
Normal file
@@ -0,0 +1,45 @@
|
||||
// +build !experimental
|
||||
|
||||
package runtime
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/wailsapp/wails/v2/internal/messagedispatcher/message"
|
||||
"github.com/wailsapp/wails/v2/internal/servicebus"
|
||||
)
|
||||
|
||||
// On registers a listener for a particular event
|
||||
func On(ctx context.Context, eventName string, callback func(optionalData ...interface{})) {
|
||||
|
||||
bus := servicebus.ExtractBus(ctx)
|
||||
|
||||
eventMessage := &message.OnEventMessage{
|
||||
Name: eventName,
|
||||
Callback: callback,
|
||||
Counter: -1,
|
||||
}
|
||||
bus.Publish("event:on", eventMessage)
|
||||
}
|
||||
|
||||
// Once registers a listener for a particular event. After the first callback, the
|
||||
// listener is deleted.
|
||||
func Once(ctx context.Context, eventName string, callback func(optionalData ...interface{})) {
|
||||
bus := servicebus.ExtractBus(ctx)
|
||||
eventMessage := &message.OnEventMessage{
|
||||
Name: eventName,
|
||||
Callback: callback,
|
||||
Counter: 1,
|
||||
}
|
||||
bus.Publish("event:on", eventMessage)
|
||||
}
|
||||
|
||||
// Emit pass through
|
||||
func Emit(ctx context.Context, eventName string, optionalData ...interface{}) {
|
||||
bus := servicebus.ExtractBus(ctx)
|
||||
eventMessage := &message.EventMessage{
|
||||
Name: eventName,
|
||||
Data: optionalData,
|
||||
}
|
||||
|
||||
bus.Publish("event:emit:from:g", eventMessage)
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
// +build !experimental
|
||||
|
||||
package log
|
||||
package runtime
|
||||
|
||||
import (
|
||||
"context"
|
||||
@@ -1,6 +1,6 @@
|
||||
// +build !experimental\
|
||||
// +build !experimental
|
||||
|
||||
package menu
|
||||
package runtime
|
||||
|
||||
import (
|
||||
"context"
|
||||
@@ -1,6 +1,6 @@
|
||||
// +build !experimental
|
||||
|
||||
package system
|
||||
package runtime
|
||||
|
||||
import (
|
||||
"context"
|
||||
@@ -1,6 +1,6 @@
|
||||
// +build !experimental
|
||||
|
||||
package window
|
||||
package runtime
|
||||
|
||||
import (
|
||||
"context"
|
||||
@@ -9,90 +9,90 @@ import (
|
||||
"github.com/wailsapp/wails/v2/internal/servicebus"
|
||||
)
|
||||
|
||||
// SetTitle sets the title of the window
|
||||
func SetTitle(ctx context.Context, title string) {
|
||||
// WindowSetTitle sets the title of the window
|
||||
func WindowSetTitle(ctx context.Context, title string) {
|
||||
bus := servicebus.ExtractBus(ctx)
|
||||
bus.Publish("window:settitle", title)
|
||||
}
|
||||
|
||||
// Fullscreen makes the window fullscreen
|
||||
func Fullscreen(ctx context.Context) {
|
||||
// WindowFullscreen makes the window fullscreen
|
||||
func WindowFullscreen(ctx context.Context) {
|
||||
bus := servicebus.ExtractBus(ctx)
|
||||
bus.Publish("window:fullscreen", "")
|
||||
}
|
||||
|
||||
// UnFullscreen makes the window UnFullscreen
|
||||
func UnFullscreen(ctx context.Context) {
|
||||
// WindowUnFullscreen makes the window UnFullscreen
|
||||
func WindowUnFullscreen(ctx context.Context) {
|
||||
bus := servicebus.ExtractBus(ctx)
|
||||
bus.Publish("window:unfullscreen", "")
|
||||
}
|
||||
|
||||
// Center the window on the current screen
|
||||
func Center(ctx context.Context) {
|
||||
// WindowCenter the window on the current screen
|
||||
func WindowCenter(ctx context.Context) {
|
||||
bus := servicebus.ExtractBus(ctx)
|
||||
bus.Publish("window:center", "")
|
||||
}
|
||||
|
||||
// Show shows the window if hidden
|
||||
func Show(ctx context.Context) {
|
||||
// WindowShow shows the window if hidden
|
||||
func WindowShow(ctx context.Context) {
|
||||
bus := servicebus.ExtractBus(ctx)
|
||||
bus.Publish("window:show", "")
|
||||
}
|
||||
|
||||
// Hide the window
|
||||
func Hide(ctx context.Context) {
|
||||
// WindowHide the window
|
||||
func WindowHide(ctx context.Context) {
|
||||
bus := servicebus.ExtractBus(ctx)
|
||||
bus.Publish("window:hide", "")
|
||||
}
|
||||
|
||||
// SetSize sets the size of the window
|
||||
func SetSize(ctx context.Context, width int, height int) {
|
||||
// WindowSetSize sets the size of the window
|
||||
func WindowSetSize(ctx context.Context, width int, height int) {
|
||||
bus := servicebus.ExtractBus(ctx)
|
||||
message := fmt.Sprintf("window:size:%d:%d", width, height)
|
||||
bus.Publish(message, "")
|
||||
}
|
||||
|
||||
// SetSize sets the size of the window
|
||||
func SetMinSize(ctx context.Context, width int, height int) {
|
||||
// WindowSetSize sets the size of the window
|
||||
func WindowSetMinSize(ctx context.Context, width int, height int) {
|
||||
bus := servicebus.ExtractBus(ctx)
|
||||
message := fmt.Sprintf("window:minsize:%d:%d", width, height)
|
||||
bus.Publish(message, "")
|
||||
}
|
||||
|
||||
// SetSize sets the size of the window
|
||||
func SetMaxSize(ctx context.Context, width int, height int) {
|
||||
// WindowSetSize sets the size of the window
|
||||
func WindowSetMaxSize(ctx context.Context, width int, height int) {
|
||||
bus := servicebus.ExtractBus(ctx)
|
||||
message := fmt.Sprintf("window:maxsize:%d:%d", width, height)
|
||||
bus.Publish(message, "")
|
||||
}
|
||||
|
||||
// SetPosition sets the position of the window
|
||||
func SetPosition(ctx context.Context, x int, y int) {
|
||||
// WindowSetPosition sets the position of the window
|
||||
func WindowSetPosition(ctx context.Context, x int, y int) {
|
||||
bus := servicebus.ExtractBus(ctx)
|
||||
message := fmt.Sprintf("window:position:%d:%d", x, y)
|
||||
bus.Publish(message, "")
|
||||
}
|
||||
|
||||
// Maximise the window
|
||||
func Maximise(ctx context.Context) {
|
||||
// WindowMaximise the window
|
||||
func WindowMaximise(ctx context.Context) {
|
||||
bus := servicebus.ExtractBus(ctx)
|
||||
bus.Publish("window:maximise", "")
|
||||
}
|
||||
|
||||
// Unmaximise the window
|
||||
func Unmaximise(ctx context.Context) {
|
||||
// WindowUnmaximise the window
|
||||
func WindowUnmaximise(ctx context.Context) {
|
||||
bus := servicebus.ExtractBus(ctx)
|
||||
bus.Publish("window:unmaximise", "")
|
||||
}
|
||||
|
||||
// Minimise the window
|
||||
func Minimise(ctx context.Context) {
|
||||
// WindowMinimise the window
|
||||
func WindowMinimise(ctx context.Context) {
|
||||
bus := servicebus.ExtractBus(ctx)
|
||||
bus.Publish("window:minimise", "")
|
||||
}
|
||||
|
||||
// Unminimise the window
|
||||
func Unminimise(ctx context.Context) {
|
||||
// WindowUnminimise the window
|
||||
func WindowUnminimise(ctx context.Context) {
|
||||
bus := servicebus.ExtractBus(ctx)
|
||||
bus.Publish("window:unminimise", "")
|
||||
}
|
||||
Reference in New Issue
Block a user