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

[windows-x] revert refactor

This commit is contained in:
Lea Anthony 2021-07-25 15:22:13 +10:00
parent 9786053324
commit 179d26b1c4
7 changed files with 32 additions and 53 deletions

View File

@ -1,3 +1,5 @@
// +build !experimental
package events package events
import ( import (

View File

@ -77,10 +77,8 @@ func processTitleAndFilter(params ...string) (string, string) {
return title, filter return title, filter
} }
type Dialog struct{}
// OpenDirectory prompts the user to select a directory // OpenDirectory prompts the user to select a directory
func (d *Dialog) OpenDirectory(ctx context.Context, dialogOptions OpenDialogOptions) (string, error) { func OpenDirectory(ctx context.Context, dialogOptions OpenDialogOptions) (string, error) {
bus := servicebus.ExtractBus(ctx) bus := servicebus.ExtractBus(ctx)
@ -107,7 +105,7 @@ func (d *Dialog) OpenDirectory(ctx context.Context, dialogOptions OpenDialogOpti
} }
// OpenFile prompts the user to select a file // OpenFile prompts the user to select a file
func (d *Dialog) OpenFile(ctx context.Context, dialogOptions OpenDialogOptions) (string, error) { func OpenFile(ctx context.Context, dialogOptions OpenDialogOptions) (string, error) {
bus := servicebus.ExtractBus(ctx) bus := servicebus.ExtractBus(ctx)
@ -134,7 +132,7 @@ func (d *Dialog) OpenFile(ctx context.Context, dialogOptions OpenDialogOptions)
} }
// OpenMultipleFiles prompts the user to select a file // OpenMultipleFiles prompts the user to select a file
func (d *Dialog) OpenMultipleFiles(ctx context.Context, dialogOptions OpenDialogOptions) ([]string, error) { func OpenMultipleFiles(ctx context.Context, dialogOptions OpenDialogOptions) ([]string, error) {
bus := servicebus.ExtractBus(ctx) bus := servicebus.ExtractBus(ctx)
uniqueCallback := crypto.RandomID() uniqueCallback := crypto.RandomID()
@ -159,7 +157,7 @@ func (d *Dialog) OpenMultipleFiles(ctx context.Context, dialogOptions OpenDialog
} }
// SaveFile prompts the user to select a file // SaveFile prompts the user to select a file
func (d *Dialog) SaveFile(ctx context.Context, dialogOptions SaveDialogOptions) (string, error) { func SaveFile(ctx context.Context, dialogOptions SaveDialogOptions) (string, error) {
bus := servicebus.ExtractBus(ctx) bus := servicebus.ExtractBus(ctx)
uniqueCallback := crypto.RandomID() uniqueCallback := crypto.RandomID()
@ -184,7 +182,7 @@ func (d *Dialog) SaveFile(ctx context.Context, dialogOptions SaveDialogOptions)
} }
// Message show a message to the user // Message show a message to the user
func (d *Dialog) Message(ctx context.Context, dialogOptions MessageDialogOptions) (string, error) { func Message(ctx context.Context, dialogOptions MessageDialogOptions) (string, error) {
bus := servicebus.ExtractBus(ctx) bus := servicebus.ExtractBus(ctx)

View File

@ -8,52 +8,50 @@ import (
"github.com/wailsapp/wails/v2/pkg/logger" "github.com/wailsapp/wails/v2/pkg/logger"
) )
type Log struct{}
// Print prints a Print level message // Print prints a Print level message
func (l *Log) Print(ctx context.Context, message string) { func Print(ctx context.Context, message string) {
bus := servicebus.ExtractBus(ctx) bus := servicebus.ExtractBus(ctx)
bus.Publish("log:print", message) bus.Publish("log:print", message)
} }
// Trace prints a Trace level message // Trace prints a Trace level message
func (l *Log) Trace(ctx context.Context, message string) { func Trace(ctx context.Context, message string) {
bus := servicebus.ExtractBus(ctx) bus := servicebus.ExtractBus(ctx)
bus.Publish("log:trace", message) bus.Publish("log:trace", message)
} }
// Debug prints a Debug level message // Debug prints a Debug level message
func (l *Log) Debug(ctx context.Context, message string) { func Debug(ctx context.Context, message string) {
bus := servicebus.ExtractBus(ctx) bus := servicebus.ExtractBus(ctx)
bus.Publish("log:debug", message) bus.Publish("log:debug", message)
} }
// Info prints a Info level message // Info prints a Info level message
func (l *Log) Info(ctx context.Context, message string) { func Info(ctx context.Context, message string) {
bus := servicebus.ExtractBus(ctx) bus := servicebus.ExtractBus(ctx)
bus.Publish("log:info", message) bus.Publish("log:info", message)
} }
// Warning prints a Warning level message // Warning prints a Warning level message
func (l *Log) Warning(ctx context.Context, message string) { func Warning(ctx context.Context, message string) {
bus := servicebus.ExtractBus(ctx) bus := servicebus.ExtractBus(ctx)
bus.Publish("log:warning", message) bus.Publish("log:warning", message)
} }
// Error prints a Error level message // Error prints a Error level message
func (l *Log) Error(ctx context.Context, message string) { func Error(ctx context.Context, message string) {
bus := servicebus.ExtractBus(ctx) bus := servicebus.ExtractBus(ctx)
bus.Publish("log:error", message) bus.Publish("log:error", message)
} }
// Fatal prints a Fatal level message // Fatal prints a Fatal level message
func (l *Log) Fatal(ctx context.Context, message string) { func Fatal(ctx context.Context, message string) {
bus := servicebus.ExtractBus(ctx) bus := servicebus.ExtractBus(ctx)
bus.Publish("log:fatal", message) bus.Publish("log:fatal", message)
} }
// SetLogLevel sets the log level // SetLogLevel sets the log level
func (l *Log) SetLogLevel(ctx context.Context, level logger.LogLevel) { func SetLogLevel(ctx context.Context, level logger.LogLevel) {
bus := servicebus.ExtractBus(ctx) bus := servicebus.ExtractBus(ctx)
bus.Publish("log:setlevel", level) bus.Publish("log:setlevel", level)
} }

View File

@ -1,3 +1,5 @@
// +build !experimental\
package menu package menu
import ( import (

View File

@ -1,17 +0,0 @@
package runtime
import (
"github.com/wailsapp/wails/v2/pkg/runtime/dialog"
"github.com/wailsapp/wails/v2/pkg/runtime/events"
"github.com/wailsapp/wails/v2/pkg/runtime/log"
"github.com/wailsapp/wails/v2/pkg/runtime/menu"
"github.com/wailsapp/wails/v2/pkg/runtime/window"
)
var (
Window = window.Window{}
Menu = menu.Menu{}
Log = log.Log{}
Events = events.Events{}
Dialog = dialog.Dialog{}
)

View File

@ -7,10 +7,8 @@ import (
"github.com/wailsapp/wails/v2/internal/servicebus" "github.com/wailsapp/wails/v2/internal/servicebus"
) )
type System struct{}
// Quit the application // Quit the application
func (s *System) Quit(ctx context.Context) { func Quit(ctx context.Context) {
bus := servicebus.ExtractBus(ctx) bus := servicebus.ExtractBus(ctx)
// Start shutdown of Wails // Start shutdown of Wails
bus.Publish("quit", "runtime.Quit()") bus.Publish("quit", "runtime.Quit()")

View File

@ -9,92 +9,90 @@ import (
"github.com/wailsapp/wails/v2/internal/servicebus" "github.com/wailsapp/wails/v2/internal/servicebus"
) )
type Window struct{}
// SetTitle sets the title of the window // SetTitle sets the title of the window
func (w *Window) SetTitle(ctx context.Context, title string) { func SetTitle(ctx context.Context, title string) {
bus := servicebus.ExtractBus(ctx) bus := servicebus.ExtractBus(ctx)
bus.Publish("window:settitle", title) bus.Publish("window:settitle", title)
} }
// Fullscreen makes the window fullscreen // Fullscreen makes the window fullscreen
func (w *Window) Fullscreen(ctx context.Context) { func Fullscreen(ctx context.Context) {
bus := servicebus.ExtractBus(ctx) bus := servicebus.ExtractBus(ctx)
bus.Publish("window:fullscreen", "") bus.Publish("window:fullscreen", "")
} }
// UnFullscreen makes the window UnFullscreen // UnFullscreen makes the window UnFullscreen
func (w *Window) UnFullscreen(ctx context.Context) { func UnFullscreen(ctx context.Context) {
bus := servicebus.ExtractBus(ctx) bus := servicebus.ExtractBus(ctx)
bus.Publish("window:unfullscreen", "") bus.Publish("window:unfullscreen", "")
} }
// Center the window on the current screen // Center the window on the current screen
func (w *Window) Center(ctx context.Context) { func Center(ctx context.Context) {
bus := servicebus.ExtractBus(ctx) bus := servicebus.ExtractBus(ctx)
bus.Publish("window:center", "") bus.Publish("window:center", "")
} }
// Show shows the window if hidden // Show shows the window if hidden
func (w *Window) Show(ctx context.Context) { func Show(ctx context.Context) {
bus := servicebus.ExtractBus(ctx) bus := servicebus.ExtractBus(ctx)
bus.Publish("window:show", "") bus.Publish("window:show", "")
} }
// Hide the window // Hide the window
func (w *Window) Hide(ctx context.Context) { func Hide(ctx context.Context) {
bus := servicebus.ExtractBus(ctx) bus := servicebus.ExtractBus(ctx)
bus.Publish("window:hide", "") bus.Publish("window:hide", "")
} }
// SetSize sets the size of the window // SetSize sets the size of the window
func (w *Window) SetSize(ctx context.Context, width int, height int) { func SetSize(ctx context.Context, width int, height int) {
bus := servicebus.ExtractBus(ctx) bus := servicebus.ExtractBus(ctx)
message := fmt.Sprintf("window:size:%d:%d", width, height) message := fmt.Sprintf("window:size:%d:%d", width, height)
bus.Publish(message, "") bus.Publish(message, "")
} }
// SetSize sets the size of the window // SetSize sets the size of the window
func (w *Window) SetMinSize(ctx context.Context, width int, height int) { func SetMinSize(ctx context.Context, width int, height int) {
bus := servicebus.ExtractBus(ctx) bus := servicebus.ExtractBus(ctx)
message := fmt.Sprintf("window:minsize:%d:%d", width, height) message := fmt.Sprintf("window:minsize:%d:%d", width, height)
bus.Publish(message, "") bus.Publish(message, "")
} }
// SetSize sets the size of the window // SetSize sets the size of the window
func (w *Window) SetMaxSize(ctx context.Context, width int, height int) { func SetMaxSize(ctx context.Context, width int, height int) {
bus := servicebus.ExtractBus(ctx) bus := servicebus.ExtractBus(ctx)
message := fmt.Sprintf("window:maxsize:%d:%d", width, height) message := fmt.Sprintf("window:maxsize:%d:%d", width, height)
bus.Publish(message, "") bus.Publish(message, "")
} }
// SetPosition sets the position of the window // SetPosition sets the position of the window
func (w *Window) SetPosition(ctx context.Context, x int, y int) { func SetPosition(ctx context.Context, x int, y int) {
bus := servicebus.ExtractBus(ctx) bus := servicebus.ExtractBus(ctx)
message := fmt.Sprintf("window:position:%d:%d", x, y) message := fmt.Sprintf("window:position:%d:%d", x, y)
bus.Publish(message, "") bus.Publish(message, "")
} }
// Maximise the window // Maximise the window
func (w *Window) Maximise(ctx context.Context) { func Maximise(ctx context.Context) {
bus := servicebus.ExtractBus(ctx) bus := servicebus.ExtractBus(ctx)
bus.Publish("window:maximise", "") bus.Publish("window:maximise", "")
} }
// Unmaximise the window // Unmaximise the window
func (w *Window) Unmaximise(ctx context.Context) { func Unmaximise(ctx context.Context) {
bus := servicebus.ExtractBus(ctx) bus := servicebus.ExtractBus(ctx)
bus.Publish("window:unmaximise", "") bus.Publish("window:unmaximise", "")
} }
// Minimise the window // Minimise the window
func (w *Window) Minimise(ctx context.Context) { func Minimise(ctx context.Context) {
bus := servicebus.ExtractBus(ctx) bus := servicebus.ExtractBus(ctx)
bus.Publish("window:minimise", "") bus.Publish("window:minimise", "")
} }
// Unminimise the window // Unminimise the window
func (w *Window) Unminimise(ctx context.Context) { func Unminimise(ctx context.Context) {
bus := servicebus.ExtractBus(ctx) bus := servicebus.ExtractBus(ctx)
bus.Publish("window:unminimise", "") bus.Publish("window:unminimise", "")
} }