Skip to content
Open
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
1 change: 1 addition & 0 deletions v2/cmd/wails/flags/dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type Dev struct {
AppArgs string `flag:"appargs" description:"arguments to pass to the underlying app (quoted and space separated)"`
Save bool `flag:"save" description:"Save the given flags as defaults"`
FrontendDevServerURL string `flag:"frontenddevserverurl" description:"The url of the external frontend dev server to use"`
DlvFlag string `flag:"dlvflag" description:"Debug flags pass to dlv"`
ViteServerTimeout int `flag:"viteservertimeout" description:"The timeout in seconds for Vite server detection (default: 10)"`

// Internal state
Expand Down
3 changes: 2 additions & 1 deletion v2/cmd/wails/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/wailsapp/wails/v2/cmd/wails/flags"
"github.com/wailsapp/wails/v2/cmd/wails/internal/template"
"github.com/wailsapp/wails/v2/internal/colour"
"github.com/wailsapp/wails/v2/internal/conv"
"github.com/wailsapp/wails/v2/internal/fs"
"github.com/wailsapp/wails/v2/internal/project"
"github.com/wailsapp/wails/v2/pkg/clilogger"
Expand Down Expand Up @@ -230,7 +231,7 @@ func processPackageLockJSON(frontendDir string) error {
if err != nil {
return err
}
json := string(data)
json := conv.BytesToString(data)

// We will ignore these errors - it's not critical
printBulletPoint("Updating package-lock.json data...")
Expand Down
27 changes: 25 additions & 2 deletions v2/cmd/wails/internal/dev/dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/wailsapp/wails/v2/cmd/wails/flags"
"github.com/wailsapp/wails/v2/cmd/wails/internal/gomod"
"github.com/wailsapp/wails/v2/cmd/wails/internal/logutils"
"github.com/wailsapp/wails/v2/internal/conv"
"golang.org/x/mod/semver"

"github.com/wailsapp/wails/v2/pkg/commands/buildtags"
Expand Down Expand Up @@ -314,7 +315,29 @@ func restartApp(buildOptions *build.Options, debugBinaryProcess *process.Process
os.Setenv("frontenddevserverurl", f.FrontendDevServerURL)

// Start up new binary with correct args
newProcess := process.NewProcess(appBinary, args...)

var command string
if len(f.DlvFlag) == 0 {
command = appBinary
} else {
command = "dlv"

// Use shlex to properly handle quoted arguments
dlvArgs, err := shlex.Split(f.DlvFlag)
if err != nil {
buildOptions.Logger.Fatal("Unable to parse dlvflag: %s", err.Error())
}
newArgs := append(dlvArgs, "exec", appBinary)
if len(args) > 0 {
newArgs = append(newArgs, "--")

newArgs = append(newArgs, args...)
}
args = newArgs
}

logutils.LogGreen("Executing: " + command + " " + strings.Join(args, " "))
newProcess := process.NewProcess(command, args...)
err = newProcess.Start(exitCodeChannel)
if err != nil {
// Remove binary
Expand Down Expand Up @@ -485,7 +508,7 @@ func doWatcherLoop(cwd string, reloadDirs string, buildOptions *build.Options, d
if err != nil {
logutils.LogRed("Error reading assetdir from devserver: %s", err.Error())
} else {
assetDir = string(content)
assetDir = conv.BytesToString(content)
}
resp.Body.Close()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/wailsapp/wails/v2/internal/binding/binding_test/binding_test_import/int_package"
"github.com/wailsapp/wails/v2/internal/binding/binding_test/binding_test_import/map_package"
"github.com/wailsapp/wails/v2/internal/binding/binding_test/binding_test_import/uint_package"
"github.com/wailsapp/wails/v2/internal/conv"
"github.com/wailsapp/wails/v2/internal/logger"
)

Expand Down Expand Up @@ -57,7 +58,7 @@ func TestConflictingPackageName(t *testing.T) {
}

// then
generatedBindings := string(rawGeneratedBindings)
generatedBindings := conv.BytesToString(rawGeneratedBindings)
if generatedBindings != expectedBindings {
t.Fatalf("the generated bindings does not match the expected ones.\nWanted:\n%s\n\nGot:\n%s", expectedBindings, generatedBindings)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"testing"

"github.com/wailsapp/wails/v2/internal/binding"
"github.com/wailsapp/wails/v2/internal/conv"
"github.com/wailsapp/wails/v2/internal/logger"
)

Expand Down Expand Up @@ -74,7 +75,7 @@ func TestPromises(t *testing.T) {
}

// then
generatedBindings := string(rawGeneratedBindings)
generatedBindings := conv.BytesToString(rawGeneratedBindings)
if generatedBindings != expectedPromiseBindings {
t.Fatalf("the generated bindings does not match the expected ones.\nWanted:\n%s\n\nGot:\n%s", expectedPromiseBindings, generatedBindings)
}
Expand Down
6 changes: 4 additions & 2 deletions v2/internal/binding/binding_test/binding_type_alias_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package binding_test

import (
"github.com/wailsapp/wails/v2/internal/binding/binding_test/binding_test_import/int_package"
"io/fs"
"os"
"testing"

"github.com/wailsapp/wails/v2/internal/binding/binding_test/binding_test_import/int_package"
"github.com/wailsapp/wails/v2/internal/conv"

"github.com/wailsapp/wails/v2/internal/binding"
"github.com/wailsapp/wails/v2/internal/logger"
)
Expand Down Expand Up @@ -56,7 +58,7 @@ func TestAliases(t *testing.T) {
}

// then
generatedBindings := string(rawGeneratedBindings)
generatedBindings := conv.BytesToString(rawGeneratedBindings)
if generatedBindings != expectedTypeAliasBindings {
t.Fatalf("the generated bindings does not match the expected ones.\nWanted:\n%s\n\nGot:\n%s", expectedTypeAliasBindings,
generatedBindings)
Expand Down
11 changes: 11 additions & 0 deletions v2/internal/conv/conv.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package conv

import (
"unsafe"
)

// BytesToString converts []byte to string without memory allocation.
// WARNING: The returned string must be used as read-only!
func BytesToString(b []byte) string {
return *(*string)(unsafe.Pointer(&b))
}
4 changes: 3 additions & 1 deletion v2/internal/frontend/desktop/darwin/clipboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ package darwin

import (
"os/exec"

"github.com/wailsapp/wails/v2/internal/conv"
)

func (f *Frontend) ClipboardGetText() (string, error) {
Expand All @@ -12,7 +14,7 @@ func (f *Frontend) ClipboardGetText() (string, error) {
if err != nil {
return "", err
}
return string(out), nil
return conv.BytesToString(out), nil
}

func (f *Frontend) ClipboardSetText(text string) error {
Expand Down
3 changes: 2 additions & 1 deletion v2/internal/frontend/desktop/darwin/frontend.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"os"
"unsafe"

"github.com/wailsapp/wails/v2/internal/conv"
"github.com/wailsapp/wails/v2/pkg/assetserver"
"github.com/wailsapp/wails/v2/pkg/assetserver/webview"

Expand Down Expand Up @@ -462,7 +463,7 @@ func (f *Frontend) Callback(message string) {
if err != nil {
panic(err)
}
f.ExecJS(`window.wails.Callback(` + string(escaped) + `);`)
f.ExecJS(`window.wails.Callback(` + conv.BytesToString(escaped) + `);`)
}

func (f *Frontend) ExecJS(js string) {
Expand Down
2 changes: 1 addition & 1 deletion v2/internal/frontend/desktop/linux/frontend.go
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ func (f *Frontend) Callback(message string) {
if err != nil {
panic(err)
}
f.ExecJS(`window.wails.Callback(` + string(escaped) + `);`)
f.ExecJS(`window.wails.Callback(` + conv.BytesToString(escaped) + `);`)
}

func (f *Frontend) startDrag() {
Expand Down
7 changes: 4 additions & 3 deletions v2/internal/frontend/desktop/linux/single_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ package linux

import (
"encoding/json"
"github.com/godbus/dbus/v5"
"github.com/wailsapp/wails/v2/pkg/options"
"log"
"os"
"strings"

"github.com/godbus/dbus/v5"
"github.com/wailsapp/wails/v2/pkg/options"
)

type dbusHandler func(string)
Expand Down Expand Up @@ -68,7 +69,7 @@ func SetupSingleInstance(uniqueID string) {
return
}

err = conn.Object(dbusName, dbus.ObjectPath(dbusPath)).Call(dbusName+".SendMessage", 0, string(serialized)).Store()
err = conn.Object(dbusName, dbus.ObjectPath(dbusPath)).Call(dbusName+".SendMessage", 0, conv.BytesToString(serialized)).Store()
if err != nil {
return
}
Expand Down
2 changes: 1 addition & 1 deletion v2/internal/frontend/desktop/windows/frontend.go
Original file line number Diff line number Diff line change
Expand Up @@ -872,7 +872,7 @@ func (f *Frontend) Callback(message string) {
panic(err)
}
f.mainWindow.Invoke(func() {
f.chromium.Eval(`window.wails.Callback(` + string(escaped) + `);`)
f.chromium.Eval(`window.wails.Callback(` + conv.BytesToString(escaped) + `);`)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

LGTM: Optimized callback conversion, but verify import.

The replacement of string(escaped) with conv.BytesToString(escaped) provides efficient conversion for the JavaScript callback. However, ensure the conv package import is properly added to this file.


🏁 Script executed:

#!/bin/bash
# Description: Verify conv package import in windows frontend file
# Expected: Should find the conv import declaration

rg -A 5 -B 5 "github.com/wailsapp/wails/v2/internal/conv" v2/internal/frontend/desktop/windows/frontend.go

Length of output: 106


To confirm whether the conv package is actually imported and how it’s referenced, let’s inspect the import block and any occurrences of conv in the file:


🏁 Script executed:

#!/bin/bash
# Show the import section (with context)
rg -A20 -B0 "^import" v2/internal/frontend/desktop/windows/frontend.go

# List all lines where conv is referenced
rg -n "conv\." v2/internal/frontend/desktop/windows/frontend.go

Length of output: 677


Missing conv import in Windows frontend

The call to conv.BytesToString on line 812 will fail without importing the conv package. Please add the following import to v2/internal/frontend/desktop/windows/frontend.go:

 import (
   // existing imports…
+  "github.com/wailsapp/wails/v2/internal/conv"
 )

This ensures conv.BytesToString(escaped) resolves correctly.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
f.chromium.Eval(`window.wails.Callback(` + conv.BytesToString(escaped) + `);`)
import (
// existing imports…
+ "github.com/wailsapp/wails/v2/internal/conv"
)
🤖 Prompt for AI Agents
In v2/internal/frontend/desktop/windows/frontend.go at line 812, the code uses
conv.BytesToString but the conv package is not imported. To fix this, add an
import statement for the conv package at the top of the file so that
conv.BytesToString(escaped) resolves correctly and the code compiles without
errors.

})
}

Expand Down
9 changes: 5 additions & 4 deletions v2/internal/frontend/desktop/windows/single_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ package windows

import (
"encoding/json"
"github.com/wailsapp/wails/v2/internal/frontend/desktop/windows/winc/w32"
"github.com/wailsapp/wails/v2/pkg/options"
"golang.org/x/sys/windows"
"log"
"os"
"syscall"
"unsafe"

"github.com/wailsapp/wails/v2/internal/frontend/desktop/windows/winc/w32"
"github.com/wailsapp/wails/v2/pkg/options"
"golang.org/x/sys/windows"
)

type COPYDATASTRUCT struct {
Expand Down Expand Up @@ -63,7 +64,7 @@ func SetupSingleInstance(uniqueId string) {
return
}

SendMessage(hwnd, string(serialized))
SendMessage(hwnd, conv.BytesToString(serialized))
// exit second instance of app after sending message
os.Exit(0)
}
Expand Down
9 changes: 5 additions & 4 deletions v2/internal/frontend/dispatcher/calls.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"strings"

"github.com/wailsapp/wails/v2/internal/conv"
"github.com/wailsapp/wails/v2/internal/frontend"
)

Expand Down Expand Up @@ -59,13 +60,13 @@ func (d *Dispatcher) processCallMessage(message string, sender frontend.Frontend
callbackMessage.Result = result
}
messageData, err := json.Marshal(callbackMessage)
d.log.Trace("json call result data: %+v\n", string(messageData))
d.log.Trace("json call result data: %+v\n", conv.BytesToString(messageData))
if err != nil {
// what now?
d.log.Fatal(err.Error())
}

return "c" + string(messageData), nil
return "c" + conv.BytesToString(messageData), nil
}

// CallbackMessage defines a message that contains the result of a call
Expand All @@ -81,6 +82,6 @@ func (d *Dispatcher) NewErrorCallback(message string, callbackID string) (string
Err: message,
}
messageData, err := json.Marshal(result)
d.log.Trace("json call result data: %+v\n", string(messageData))
return string(messageData), err
d.log.Trace("json call result data: %+v\n", conv.BytesToString(messageData))
return conv.BytesToString(messageData), err
}
5 changes: 3 additions & 2 deletions v2/internal/frontend/dispatcher/securecalls.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"fmt"

"github.com/wailsapp/wails/v2/internal/conv"
"github.com/wailsapp/wails/v2/internal/frontend"
)

Expand Down Expand Up @@ -47,11 +48,11 @@ func (d *Dispatcher) processSecureCallMessage(message string, sender frontend.Fr
callbackMessage.Result = result
}
messageData, err := json.Marshal(callbackMessage)
d.log.Trace("json call result data: %+v\n", string(messageData))
d.log.Trace("json call result data: %+v\n", conv.BytesToString(messageData))
if err != nil {
// what now?
d.log.Fatal(err.Error())
}

return "c" + string(messageData), nil
return "c" + conv.BytesToString(messageData), nil
}
3 changes: 2 additions & 1 deletion v2/internal/menumanager/contextmenu.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"fmt"

"github.com/wailsapp/wails/v2/internal/conv"
"github.com/wailsapp/wails/v2/pkg/menu"
)

Expand All @@ -19,7 +20,7 @@ func (t *ContextMenu) AsJSON() (string, error) {
if err != nil {
return "", err
}
return string(data), nil
return conv.BytesToString(data), nil
}

func NewContextMenu(contextMenu *menu.ContextMenu) *ContextMenu {
Expand Down
3 changes: 2 additions & 1 deletion v2/internal/menumanager/processedMenu.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package menumanager
import (
"encoding/json"

"github.com/wailsapp/wails/v2/internal/conv"
"github.com/wailsapp/wails/v2/pkg/menu"
"github.com/wailsapp/wails/v2/pkg/menu/keys"
)
Expand Down Expand Up @@ -134,7 +135,7 @@ func (w *WailsMenu) AsJSON() (string, error) {
if err != nil {
return "", err
}
return string(menuAsJSON), nil
return conv.BytesToString(menuAsJSON), nil
}

func (w *WailsMenu) processRadioGroups() {
Expand Down
5 changes: 3 additions & 2 deletions v2/internal/menumanager/traymenu.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"sync"

"github.com/leaanthony/go-ansi-parser"
"github.com/wailsapp/wails/v2/internal/conv"

"github.com/pkg/errors"
"github.com/wailsapp/wails/v2/pkg/menu"
Expand Down Expand Up @@ -49,7 +50,7 @@ func (t *TrayMenu) AsJSON() (string, error) {
if err != nil {
return "", err
}
return string(data), nil
return conv.BytesToString(data), nil
}

func NewTrayMenu(trayMenu *menu.TrayMenu) *TrayMenu {
Expand Down Expand Up @@ -205,7 +206,7 @@ func (m *Manager) UpdateTrayMenuLabel(trayMenu *menu.TrayMenu) (string, error) {
return "", errors.Wrap(err, "[UpdateTrayMenuLabel] ")
}

return string(data), nil
return conv.BytesToString(data), nil
}

func (m *Manager) GetContextMenus() ([]string, error) {
Expand Down
3 changes: 2 additions & 1 deletion v2/internal/s/s.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"strings"

"github.com/bitfield/script"
"github.com/wailsapp/wails/v2/internal/conv"
)

var (
Expand Down Expand Up @@ -263,7 +264,7 @@ func LOADSTRING(filename string) string {
mute()
data := LOADBYTES(filename)
unmute()
return string(data)
return conv.BytesToString(data)
}

// SAVEBYTES will create a file with the given string
Expand Down
3 changes: 2 additions & 1 deletion v2/pkg/commands/bindings/bindings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"testing"

"github.com/matryer/is"
"github.com/wailsapp/wails/v2/internal/conv"
"github.com/wailsapp/wails/v2/pkg/templates"
)

Expand Down Expand Up @@ -61,7 +62,7 @@ func TestGenerateBindings(t *testing.T) {
i.NoErr(err)
pathToRepository := filepath.Join(workingDirectory, "..", "..", "..")
absPathToRepo, _ := filepath.Abs(pathToRepository)
goModString := string(goMod)
goModString := conv.BytesToString(goMod)
goModSplit := strings.Split(goModString, "=>")
goModSplit[1] = absPathToRepo
goModString = strings.Join(goModSplit, "=> ")
Expand Down
Loading