Skip to content
Draft
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 v3/cmd/wails3/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func main() {
})

app.NewSubCommandFunction("dev", "Run in Dev mode", commands.Dev)
app.NewSubCommandFunction("debug", "Run in debug mode with delve", commands.Delve)

pkg := app.NewSubCommand("package", "Package application")
var pkgFlags flags.Package
Expand Down
28 changes: 28 additions & 0 deletions v3/internal/commands/build_assets/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,34 @@ info:
# # Additional comments to embed in Info.plist metadata
# comments: "Some Product Comments"

# Debug (Delve) configuration
debug_mode:
root_path: .
log_level: warn
debounce: 1000
ignore:
dir:
- .git
- node_modules
- frontend
- bin
file:
- .DS_Store
- .gitignore
- .gitkeep
watched_extension:
- "*.go"
- "*.js" # Watch for changes to JS/TS files included using the //wails:include directive.
- "*.ts" # The frontend directory will be excluded entirely by the setting above.
git_ignore: true
executes:
- cmd: wails3 build DEV=true
type: blocking
- cmd: wails3 task common:dev:frontend
type: background
- cmd: wails3 task run DEBUG_MODE=true
type: primary

# Dev mode configuration
dev_mode:
root_path: .
Expand Down
10 changes: 9 additions & 1 deletion v3/internal/commands/build_assets/darwin/Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ vars:

# Docker image for cross-compilation (used when building on non-macOS)
CROSS_IMAGE: wails-cross
DEBUG_MODE: '{{default "false" .DEBUG_MODE}}'

tasks:
build:
Expand Down Expand Up @@ -174,7 +175,14 @@ tasks:
- cp "{{.BIN_DIR}}/{{.APP_NAME}}" "{{.BIN_DIR}}/{{.APP_NAME}}.dev.app/Contents/MacOS"
- cp "build/darwin/Info.dev.plist" "{{.BIN_DIR}}/{{.APP_NAME}}.dev.app/Contents/Info.plist"
- codesign --force --deep --sign - "{{.BIN_DIR}}/{{.APP_NAME}}.dev.app"
- '{{.BIN_DIR}}/{{.APP_NAME}}.dev.app/Contents/MacOS/{{.APP_NAME}}'
- |
if [ "{{.DEBUG_MODE}}" = "true" ]; then
echo "Running in debug mode"
dlv exec {{.BIN_DIR}}/{{.APP_NAME}}.dev.app/Contents/MacOS/{{.APP_NAME}} --headless --listen=:2345 --api-version=2 --accept-multiclient
else
echo "Running in normal mode"
"{{.BIN_DIR}}/{{.APP_NAME}}.dev.app/Contents/MacOS/{{.APP_NAME}}"
fi

sign:
summary: Signs the application bundle with Developer ID
Expand Down
10 changes: 9 additions & 1 deletion v3/internal/commands/build_assets/linux/Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ vars:

# Docker image for cross-compilation (used when building on non-Linux or no CC available)
CROSS_IMAGE: wails-cross
DEBUG_MODE: '{{default "false" .DEBUG_MODE}}'

tasks:
build:
Expand Down Expand Up @@ -182,7 +183,14 @@ tasks:

run:
cmds:
- '{{.BIN_DIR}}/{{.APP_NAME}}'
- |
if [ "{{.DEBUG_MODE}}" = "true" ]; then
echo "Running in debug mode"
dlv exec {{.BIN_DIR}}/{{.APP_NAME}} --headless --listen=:2345 --api-version=2 --accept-multiclient
else
echo "Running in normal mode"
'{{.BIN_DIR}}/{{.APP_NAME}}'
fi

sign:deb:
summary: Signs the DEB package
Expand Down
10 changes: 9 additions & 1 deletion v3/internal/commands/build_assets/windows/Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ vars:

# Docker image for cross-compilation with CGO (used when CGO_ENABLED=1 on non-Windows)
CROSS_IMAGE: wails-cross
DEBUG_MODE: '{{default "false" .DEBUG_MODE}}'

tasks:
build:
Expand Down Expand Up @@ -153,7 +154,14 @@ tasks:

run:
cmds:
- '{{.BIN_DIR}}/{{.APP_NAME}}.exe'
- |
if [ "{{.DEBUG_MODE}}" = "true" ]; then
echo "Running in debug mode"
dlv exec {{.BIN_DIR}}/{{.APP_NAME}}.exe --headless --listen=:2345 --api-version=2 --accept-multiclient
else
echo "Running in normal mode"
'{{.BIN_DIR}}/{{.APP_NAME}}.exe'
fi

sign:
summary: Signs the Windows executable
Expand Down
6 changes: 6 additions & 0 deletions v3/internal/commands/delve.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package commands

func Delve(options *DevOptions) error {
options.UseDelve = true
return Dev(options)
}
7 changes: 7 additions & 0 deletions v3/internal/commands/dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type DevOptions struct {
Config string `description:"The config file including path" default:"./build/config.yml"`
VitePort int `name:"port" description:"Specify the vite dev server port"`
Secure bool `name:"s" description:"Enable HTTPS"`
UseDelve bool `name:"debug" description:"Use delve for development"`
}

func Dev(options *DevOptions) error {
Expand Down Expand Up @@ -52,7 +53,13 @@ func Dev(options *DevOptions) error {
os.Setenv("FRONTEND_DEVSERVER_URL", fmt.Sprintf("http://%s:%d", host, port))
}

opMode := "dev"
if options.UseDelve {
opMode = "debug"
}

return Watcher(&WatcherOptions{
Mode: opMode,
Config: options.Config,
})
}
18 changes: 14 additions & 4 deletions v3/internal/commands/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ package commands
import (
"context"
"fmt"
"github.com/wailsapp/wails/v3/internal/term"
"os"
"path/filepath"
"strings"
"time"

"github.com/wailsapp/wails/v3/internal/term"

"github.com/wailsapp/task/v3"
"github.com/wailsapp/task/v3/taskfile/ast"
)
Expand Down Expand Up @@ -123,9 +124,13 @@ func RunTask(options *RunTaskOptions, otherArgs []string) error {
return nil
}

if e.Taskfile != nil && e.Taskfile.Vars == nil {
e.Taskfile.Vars = &ast.Vars{}
}

// Parse task name and CLI variables from otherArgs or os.Args
var tasksAndVars []string

// Check if we have a task name specified in options
if options.Name != "" {
// If task name is provided via options, use it and treat otherArgs as CLI variables
Expand Down Expand Up @@ -159,13 +164,13 @@ func RunTask(options *RunTaskOptions, otherArgs []string) error {
// Parse task name and CLI variables
taskName := tasksAndVars[0]
cliVars := tasksAndVars[1:]

// Create call with CLI variables
call := &ast.Call{
Task: taskName,
Vars: &ast.Vars{},
}

// Parse CLI variables (format: KEY=VALUE)
for _, v := range cliVars {
if strings.Contains(v, "=") {
Expand All @@ -174,6 +179,11 @@ func RunTask(options *RunTaskOptions, otherArgs []string) error {
call.Vars.Set(parts[0], ast.Var{
Value: parts[1],
})
if e.Taskfile != nil {
e.Taskfile.Vars.Set(parts[0], ast.Var{
Value: parts[1],
})
}
}
}
}
Expand Down
51 changes: 34 additions & 17 deletions v3/internal/commands/watcher.go
Original file line number Diff line number Diff line change
@@ -1,65 +1,82 @@
package commands

import (
"os"

"github.com/atterpac/refresh/engine"
"github.com/wailsapp/wails/v3/internal/signal"
"gopkg.in/yaml.v3"
"os"
)

type WatcherOptions struct {
Mode string `description:"Whether standard dev mode or using delve" default:"dev"`
Config string `description:"The config file including path" default:"."`
}

func Watcher(options *WatcherOptions) error {
stopChan := make(chan struct{})

// Parse the config file
type devConfig struct {
Config engine.Config `yaml:"dev_mode"`
}

var devconfig devConfig

// Parse the config file
c, err := os.ReadFile(options.Config)
if err != nil {
return err
}
err = yaml.Unmarshal(c, &devconfig)
if err != nil {
return err

var usedConfig engine.Config

switch options.Mode {
case "dev":
type devConfig struct {
Config engine.Config `yaml:"dev_mode"`
}
var transitoryConfig devConfig
err = yaml.Unmarshal(c, &transitoryConfig)
if err != nil {
return err
}
usedConfig = transitoryConfig.Config

case "debug":
type debugConfig struct {
Config engine.Config `yaml:"debug_mode"`
}
var transitoryConfig debugConfig
err = yaml.Unmarshal(c, &transitoryConfig)
if err != nil {
return err
}
usedConfig = transitoryConfig.Config
}

watcherEngine, err := engine.NewEngineFromConfig(devconfig.Config)
watcherEngine, err := engine.NewEngineFromConfig(usedConfig)
if err != nil {
return err
}

// Setup cleanup function that stops the engine
cleanup := func() {
watcherEngine.Stop()
}
defer cleanup()

// Signal handler needs to notify when to stop
signalCleanup := func() {
cleanup()
stopChan <- struct{}{}
}

signalHandler := signal.NewSignalHandler(signalCleanup)
signalHandler.ExitMessage = func(sig os.Signal) string {
return ""
}
signalHandler.Start()

// Start the engine
err = watcherEngine.Start()
if err != nil {
return err
}

<-stopChan
return nil
}
Loading