Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions docs/ref/wails-v3/src/application/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,15 +282,15 @@ type windowKeyEvent struct {
acceleratorString string
}

func (r *webViewAssetRequest) URL() (string, error) {
func (r *webViewAssetRequest) URL() (string, resultFailure) {
return r.Request.URL()
}

func (r *webViewAssetRequest) Method() (string, error) {
func (r *webViewAssetRequest) Method() (string, resultFailure) {
return r.Request.Method()
}

func (r *webViewAssetRequest) Header() (http.Header, error) {
func (r *webViewAssetRequest) Header() (http.Header, resultFailure) {
h, err := r.Request.Header()
if err != nil {
return nil, err
Expand All @@ -304,15 +304,15 @@ func (r *webViewAssetRequest) Header() (http.Header, error) {
return hh, nil
}

func (r *webViewAssetRequest) Body() (io.ReadCloser, error) {
func (r *webViewAssetRequest) Body() (io.ReadCloser, resultFailure) {
return r.Request.Body()
}

func (r *webViewAssetRequest) Response() webview.ResponseWriter {
return r.Request.Response()
}

func (r *webViewAssetRequest) Close() error {
func (r *webViewAssetRequest) Close() resultFailure {
return r.Request.Close()
}

Expand Down Expand Up @@ -433,7 +433,7 @@ func (a *App) handleWarning(msg string) {
}
}

func (a *App) handleError(err error) {
func (a *App) handleError(err resultFailure) {
if a.options.ErrorHandler != nil {
a.options.ErrorHandler(err)
} else {
Expand Down Expand Up @@ -463,7 +463,7 @@ func (a *App) RegisterService(service Service) {
a.options.Services = append(a.options.Services, service)
}

func (a *App) handleFatalError(err error) {
func (a *App) handleFatalError(err resultFailure) {
a.handleError(&FatalError{err: err})
core.Exit(1)
}
Expand Down Expand Up @@ -533,7 +533,7 @@ func (a *App) error(message string, args ...any) {
a.handleError(core.Errorf(message, args...))
}

func (a *App) Run() error {
func (a *App) Run() resultFailure {
a.runLock.Lock()
// Prevent double invocations.
if a.starting || a.running {
Expand Down Expand Up @@ -643,7 +643,7 @@ func (a *App) Run() error {
return a.impl.run()
}

func (a *App) startupService(service Service) error {
func (a *App) startupService(service Service) resultFailure {
err := a.bindings.Add(service)
if err != nil {
return core.Errorf("cannot bind service methods: %w", err)
Expand Down
4 changes: 2 additions & 2 deletions docs/ref/wails-v3/src/application/browser_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ func newBrowserManager(app *App) *BrowserManager {
}

// OpenURL opens a URL in the default browser
func (bm *BrowserManager) OpenURL(url string) error {
func (bm *BrowserManager) OpenURL(url string) resultFailure {
return browser.OpenURL(url)
}

// OpenFile opens a file in the default browser
func (bm *BrowserManager) OpenFile(path string) error {
func (bm *BrowserManager) OpenFile(path string) resultFailure {
return browser.OpenFile(path)
}
4 changes: 2 additions & 2 deletions docs/ref/wails-v3/src/application/core_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package application

import core "dappco.re/go"

func jsonMarshal(value any) ([]byte, error) {
func jsonMarshal(value any) ([]byte, resultFailure) {
result := core.JSONMarshal(value)
if !result.OK {
if err, ok := result.Value.(error); ok {
Expand All @@ -13,7 +13,7 @@ func jsonMarshal(value any) ([]byte, error) {
return result.Value.([]byte), nil
}

func jsonUnmarshal(data []byte, target any) error {
func jsonUnmarshal(data []byte, target any) resultFailure {
result := core.JSONUnmarshal(data, target)
if result.OK {
return nil
Expand Down
2 changes: 1 addition & 1 deletion docs/ref/wails-v3/src/application/environment_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (em *EnvironmentManager) GetAccentColor() string {
}

// OpenFileManager opens the file manager at the specified path, optionally selecting the file
func (em *EnvironmentManager) OpenFileManager(path string, selectFile bool) error {
func (em *EnvironmentManager) OpenFileManager(path string, selectFile bool) resultFailure {
return InvokeSyncWithError(func() error {
return fileexplorer.OpenFileManager(path, selectFile)
})
Expand Down
6 changes: 3 additions & 3 deletions docs/ref/wails-v3/src/application/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func (e *EventProcessor) Once(eventName string, callback func(event *CustomEvent
// If the event is globally registered, it validates associated data
// against the expected data type. In case of mismatches,
// it cancels the event and returns an error.
func (e *EventProcessor) Emit(thisEvent *CustomEvent) error {
func (e *EventProcessor) Emit(thisEvent *CustomEvent) resultFailure {
if thisEvent == nil {
return nil
}
Expand Down Expand Up @@ -305,7 +305,7 @@ func RegisterEvent[Data any](name string) {
eventRegistered(name)
}

func validateCustomEvent(event *CustomEvent) error {
func validateCustomEvent(event *CustomEvent) resultFailure {
r, ok := registeredEvents.Load(event.Name)
if !ok {
warnAboutUnregisteredEvent(event.Name)
Expand Down Expand Up @@ -336,7 +336,7 @@ func validateCustomEvent(event *CustomEvent) error {
)
}

func decodeEventData(name string, data []byte) (result any, err error) {
func decodeEventData(name string, data []byte) (result any, err resultFailure) {
r, ok := registeredEvents.Load(name)
if !ok {
// Unregistered events unmarshal to any.
Expand Down
5 changes: 5 additions & 0 deletions docs/ref/wails-v3/src/application/result_failure.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package application

type resultFailure = interface {
Error() string
}
4 changes: 2 additions & 2 deletions docs/ref/wails-v3/src/application/screenmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ func (s *Screen) physicalToDipRect(physicalRect Rect) Rect {

// Layout screens in the virtual space with DIP calculations and cache the screens
// for future coordinate transformation between the physical and logical (DIP) space
func (m *ScreenManager) LayoutScreens(screens []*Screen) error {
func (m *ScreenManager) LayoutScreens(screens []*Screen) resultFailure {
if screens == nil || len(screens) == 0 {
return core.NewError("screens parameter is nil or empty")
}
Expand All @@ -391,7 +391,7 @@ func (m *ScreenManager) GetPrimary() *Screen {
}

// Reference: https://source.chromium.org/chromium/chromium/src/+/main:ui/display/win/screen_win.cc;l=317
func (m *ScreenManager) calculateScreensDipCoordinates() error {
func (m *ScreenManager) calculateScreensDipCoordinates() resultFailure {
remainingScreens := []*Screen{}

// Find the primary screen
Expand Down
2 changes: 1 addition & 1 deletion docs/ref/wails-v3/src/application/systemtray.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ func (s *SystemTray) HideWindow() {
s.attachedWindow.Window.Hide()
}

func (s *SystemTray) PositionWindow(window Window, offset int) error {
func (s *SystemTray) PositionWindow(window Window, offset int) resultFailure {
if s.impl == nil {
return core.NewError("system tray not running")
}
Expand Down
8 changes: 4 additions & 4 deletions docs/ref/wails-v3/src/application/webview_window.go
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,7 @@ func (w *WebviewWindow) HandleMessage(message string) {
}
}

func (w *WebviewWindow) startResize(border string) error {
func (w *WebviewWindow) startResize(border string) resultFailure {
if w.impl == nil || w.isDestroyed() {
return nil
}
Expand Down Expand Up @@ -1193,7 +1193,7 @@ func (w *WebviewWindow) EnableSizeConstraints() {
}

// GetScreen returns the screen that the window is on
func (w *WebviewWindow) GetScreen() (*Screen, error) {
func (w *WebviewWindow) GetScreen() (*Screen, resultFailure) {
if w.impl == nil || w.isDestroyed() {
return nil, nil
}
Expand Down Expand Up @@ -1317,14 +1317,14 @@ func (w *WebviewWindow) emit(eventType events.WindowEventType) {
}
}

func (w *WebviewWindow) startDrag() error {
func (w *WebviewWindow) startDrag() resultFailure {
if w.impl == nil || w.isDestroyed() {
return nil
}
return InvokeSyncWithError(w.impl.startDrag)
}

func (w *WebviewWindow) Print() error {
func (w *WebviewWindow) Print() resultFailure {
if w.impl == nil || w.isDestroyed() {
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion go.work
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ go 1.26.2
use (
./go
./external/go
./external/config
./external/config/go
./external/webview
./external/io
./external/log
Expand Down
4 changes: 2 additions & 2 deletions go/pkg/browser/platform.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ package browser
// Platform abstracts the system browser/file-opener backend.
type Platform interface {
// OpenURL opens the given URL in the default system browser.
OpenURL(url string) error
OpenURL(url string) resultFailure

// OpenFile opens the given file path with the system default application.
OpenFile(path string) error
OpenFile(path string) resultFailure
}
5 changes: 5 additions & 0 deletions go/pkg/browser/result_failure.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package browser

type resultFailure = interface {
Error() string
}
4 changes: 2 additions & 2 deletions go/pkg/browser/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (s *Service) HandleIPCEvents(_ *core.Core, _ core.Message) core.Result {
return core.Result{OK: true}
}

func validatedOpenURL(raw string) (string, error) {
func validatedOpenURL(raw string) (string, resultFailure) {
trimmed := core.Trim(raw)
if trimmed == "" {
return "", core.E("browser.openURL", "url is required", nil)
Expand All @@ -67,7 +67,7 @@ func validatedOpenURL(raw string) (string, error) {
return parsed.String(), nil
}

func validatedOpenFilePath(raw string) (string, error) {
func validatedOpenFilePath(raw string) (string, resultFailure) {
trimmed := core.Trim(raw)
if trimmed == "" {
return "", core.E("browser.openFile", "path is required", nil)
Expand Down
8 changes: 4 additions & 4 deletions go/pkg/browser/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ import (
type mockPlatform struct {
lastURL string
lastPath string
urlErr error
fileErr error
urlErr resultFailure
fileErr resultFailure
}

func (m *mockPlatform) OpenURL(url string) error {
func (m *mockPlatform) OpenURL(url string) resultFailure {
m.lastURL = url
return m.urlErr
}

func (m *mockPlatform) OpenFile(path string) error {
func (m *mockPlatform) OpenFile(path string) resultFailure {
m.lastPath = path
return m.fileErr
}
Expand Down
4 changes: 2 additions & 2 deletions go/pkg/chat/chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func NewStreamRenderer(callbacks StreamCallbacks) *StreamRenderer {
}
}

func (r *StreamRenderer) Render(reader io.Reader) error {
func (r *StreamRenderer) Render(reader io.Reader) resultFailure {
scanner := bufio.NewScanner(reader)
scanner.Buffer(make([]byte, 0, 4096), 1024*1024)

Expand Down Expand Up @@ -133,7 +133,7 @@ func (r *StreamRenderer) Render(reader io.Reader) error {
return nil
}

func (r *StreamRenderer) handleData(payload string) error {
func (r *StreamRenderer) handleData(payload string) resultFailure {
if payload == "" {
return nil
}
Expand Down
14 changes: 7 additions & 7 deletions go/pkg/chat/core_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package chat

import core "dappco.re/go"

func coreResultError(result core.Result, fallback string) error {
func coreResultError(result core.Result, fallback string) resultFailure {
if result.OK {
return nil
}
Expand All @@ -15,35 +15,35 @@ func coreResultError(result core.Result, fallback string) error {
return core.NewError(fallback)
}

func coreReadFile(path string) ([]byte, error) {
func coreReadFile(path string) ([]byte, resultFailure) {
result := core.ReadFile(path)
if !result.OK {
return nil, coreResultError(result, "failed to read file")
}
return result.Value.([]byte), nil
}

func coreWriteFile(path string, data []byte, mode core.FileMode) error {
func coreWriteFile(path string, data []byte, mode core.FileMode) resultFailure {
return coreResultError(core.WriteFile(path, data, mode), "failed to write file")
}

func coreWriteMode(path, content string, mode core.FileMode) error {
func coreWriteMode(path, content string, mode core.FileMode) resultFailure {
return coreWriteFile(path, []byte(content), mode)
}

func coreEnsureDir(path string) error {
func coreEnsureDir(path string) resultFailure {
return coreResultError(core.MkdirAll(path, 0o755), "failed to create directory")
}

func coreMkdirTemp(dir, pattern string) (string, error) {
func coreMkdirTemp(dir, pattern string) (string, resultFailure) {
result := core.MkdirTemp(dir, pattern)
if !result.OK {
return "", coreResultError(result, "failed to create temporary directory")
}
return result.Value.(string), nil
}

func coreRemoveAll(path string) error {
func coreRemoveAll(path string) resultFailure {
return coreResultError(core.RemoveAll(path), "failed to remove path")
}

Expand Down
5 changes: 5 additions & 0 deletions go/pkg/chat/result_failure.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package chat

type resultFailure = interface {
Error() string
}
Loading
Loading