mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-02 17:52:29 +08:00
added appargs for application arguments in dev mode
This commit is contained in:
parent
3948c8ca61
commit
b5f68e24d6
@ -16,10 +16,10 @@ import (
|
|||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/google/shlex"
|
||||||
"github.com/wailsapp/wails/v2/cmd/wails/internal"
|
"github.com/wailsapp/wails/v2/cmd/wails/internal"
|
||||||
"github.com/wailsapp/wails/v2/internal/gomod"
|
"github.com/wailsapp/wails/v2/internal/gomod"
|
||||||
|
|
||||||
"github.com/leaanthony/slicer"
|
|
||||||
"github.com/wailsapp/wails/v2/internal/project"
|
"github.com/wailsapp/wails/v2/internal/project"
|
||||||
|
|
||||||
"github.com/pkg/browser"
|
"github.com/pkg/browser"
|
||||||
@ -72,6 +72,7 @@ type devFlags struct {
|
|||||||
forceBuild bool
|
forceBuild bool
|
||||||
debounceMS int
|
debounceMS int
|
||||||
devServerURL string
|
devServerURL string
|
||||||
|
appargs string
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddSubcommand adds the `dev` command for the Wails application
|
// AddSubcommand adds the `dev` command for the Wails application
|
||||||
@ -93,6 +94,7 @@ func AddSubcommand(app *clir.Cli, w io.Writer) error {
|
|||||||
command.BoolFlag("f", "Force build application", &flags.forceBuild)
|
command.BoolFlag("f", "Force build application", &flags.forceBuild)
|
||||||
command.IntFlag("debounce", "The amount of time to wait to trigger a reload on change", &flags.debounceMS)
|
command.IntFlag("debounce", "The amount of time to wait to trigger a reload on change", &flags.debounceMS)
|
||||||
command.StringFlag("devserverurl", "The url of the dev server to use", &flags.devServerURL)
|
command.StringFlag("devserverurl", "The url of the dev server to use", &flags.devServerURL)
|
||||||
|
command.StringFlag("appargs", "arguments to pass to the underlying app (quoted and space searated)", &flags.appargs)
|
||||||
|
|
||||||
command.Action(func() error {
|
command.Action(func() error {
|
||||||
// Create logger
|
// Create logger
|
||||||
@ -353,6 +355,10 @@ func loadAndMergeProjectConfig(cwd string, flags *devFlags) (*project.Project, e
|
|||||||
shouldSaveConfig = true
|
shouldSaveConfig = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if flags.appargs == "" && projectConfig.AppArgs != "" {
|
||||||
|
flags.appargs = projectConfig.AppArgs
|
||||||
|
}
|
||||||
|
|
||||||
if shouldSaveConfig {
|
if shouldSaveConfig {
|
||||||
err = projectConfig.Save()
|
err = projectConfig.Save()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -462,7 +468,13 @@ func restartApp(buildOptions *build.Options, debugBinaryProcess *process.Process
|
|||||||
|
|
||||||
debugBinaryProcess = nil
|
debugBinaryProcess = nil
|
||||||
}
|
}
|
||||||
args := slicer.StringSlicer{}
|
|
||||||
|
// parse appargs if any
|
||||||
|
args, err := shlex.Split(flags.appargs)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
buildOptions.Logger.Fatal("Unable to parse appargs: %s", err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
// Set environment variables accordingly
|
// Set environment variables accordingly
|
||||||
os.Setenv("loglevel", flags.loglevel)
|
os.Setenv("loglevel", flags.loglevel)
|
||||||
@ -470,7 +482,7 @@ func restartApp(buildOptions *build.Options, debugBinaryProcess *process.Process
|
|||||||
os.Setenv("devserverurl", flags.devServerURL)
|
os.Setenv("devserverurl", flags.devServerURL)
|
||||||
|
|
||||||
// Start up new binary with correct args
|
// Start up new binary with correct args
|
||||||
newProcess := process.NewProcess(appBinary, args.AsSlice()...)
|
newProcess := process.NewProcess(appBinary, args...)
|
||||||
err = newProcess.Start(exitCodeChannel)
|
err = newProcess.Start(exitCodeChannel)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Remove binary
|
// Remove binary
|
||||||
|
@ -56,6 +56,7 @@ require (
|
|||||||
github.com/go-git/gcfg v1.5.0 // indirect
|
github.com/go-git/gcfg v1.5.0 // indirect
|
||||||
github.com/go-ole/go-ole v1.2.5 // indirect
|
github.com/go-ole/go-ole v1.2.5 // indirect
|
||||||
github.com/google/go-cmp v0.5.5 // indirect
|
github.com/google/go-cmp v0.5.5 // indirect
|
||||||
|
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
|
||||||
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
|
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
|
||||||
github.com/jchv/go-winloader v0.0.0-20210711035445-715c2860da7e // indirect
|
github.com/jchv/go-winloader v0.0.0-20210711035445-715c2860da7e // indirect
|
||||||
github.com/kevinburke/ssh_config v0.0.0-20201106050909-4977a11b4351 // indirect
|
github.com/kevinburke/ssh_config v0.0.0-20201106050909-4977a11b4351 // indirect
|
||||||
|
@ -75,6 +75,8 @@ github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
|
|||||||
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
|
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
|
||||||
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||||
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||||
|
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 h1:El6M4kTTCOh6aBiKaUGG7oYTSPP8MxqL4YI3kZKwcP4=
|
||||||
|
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510/go.mod h1:pupxD2MaaD3pAXIBCelhxNneeOaAeabZDe5s4K6zSpQ=
|
||||||
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||||
github.com/google/uuid v1.1.2 h1:EVhdT+1Kseyi1/pUmXKaFxYsDNy9RQYkMWRH68J/W7Y=
|
github.com/google/uuid v1.1.2 h1:EVhdT+1Kseyi1/pUmXKaFxYsDNy9RQYkMWRH68J/W7Y=
|
||||||
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||||
|
@ -53,6 +53,9 @@ type Project struct {
|
|||||||
|
|
||||||
// The url to use to server assets. Default "https://localhost:34115"
|
// The url to use to server assets. Default "https://localhost:34115"
|
||||||
DevServerURL string `json:"devserverurl"`
|
DevServerURL string `json:"devserverurl"`
|
||||||
|
|
||||||
|
// Arguments that are forwared to the application in dev mode
|
||||||
|
AppArgs string `json:"appargs"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Project) Save() error {
|
func (p *Project) Save() error {
|
||||||
|
@ -134,6 +134,7 @@ Your system is ready for Wails development!
|
|||||||
| -wailsjsdir | The directory to generate the generated Wails JS modules | Value in `wails.json` |
|
| -wailsjsdir | The directory to generate the generated Wails JS modules | Value in `wails.json` |
|
||||||
| -debounce | The time to wait for reload after an asset change is detected | 100 (milliseconds) |
|
| -debounce | The time to wait for reload after an asset change is detected | 100 (milliseconds) |
|
||||||
| -devserverurl "url" | Use 3rd party dev server url, EG Vite | "http://localhost:34115" |
|
| -devserverurl "url" | Use 3rd party dev server url, EG Vite | "http://localhost:34115" |
|
||||||
|
| -appargs "args" | Arguments passed to the application in shell style | |
|
||||||
|
|
||||||
If the `assetdir`, `wailsjsdir`, `debounce` or `devserverurl` flags are provided on the command line, they are saved in
|
If the `assetdir`, `wailsjsdir`, `debounce` or `devserverurl` flags are provided on the command line, they are saved in
|
||||||
`wails.json`, and become the defaults for subsequent invocations.
|
`wails.json`, and become the defaults for subsequent invocations.
|
||||||
|
@ -17,7 +17,9 @@ The project config resides in the `wails.json` file in the project directory. Th
|
|||||||
"version": "[Project config version]",
|
"version": "[Project config version]",
|
||||||
"outputfilename": "[The name of the binary]",
|
"outputfilename": "[The name of the binary]",
|
||||||
"debounceMS": 100, // The default time the dev server waits to reload when it detects a vhange in assets
|
"debounceMS": 100, // The default time the dev server waits to reload when it detects a vhange in assets
|
||||||
"devserverurl": "[URL to the dev server serving local assets. Default: http://localhost:34115]"
|
"devserverurl": "[URL to the dev server serving local assets. Default: http://localhost:34115]",
|
||||||
|
"appargs": "[Arguments passed to the application in shell style when in dev mode]"
|
||||||
|
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user