mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-03 06:39:30 +08:00
[v2] New -debounce flag to configure debounce time of dev server
This commit is contained in:
parent
a51ab25e2c
commit
f6b83b0933
@ -93,6 +93,9 @@ func AddSubcommand(app *clir.Cli, w io.Writer) error {
|
|||||||
forceBuild := false
|
forceBuild := false
|
||||||
command.BoolFlag("f", "Force build application", &forceBuild)
|
command.BoolFlag("f", "Force build application", &forceBuild)
|
||||||
|
|
||||||
|
debounceMS := 100
|
||||||
|
command.IntFlag("debounce", "The amount of time to wait to trigger a reload on change", &debounceMS)
|
||||||
|
|
||||||
command.Action(func() error {
|
command.Action(func() error {
|
||||||
|
|
||||||
// Create logger
|
// Create logger
|
||||||
@ -249,10 +252,26 @@ func AddSubcommand(app *clir.Cli, w io.Writer) error {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
if debounceMS == 100 && projectConfig.DebounceMS != 100 {
|
||||||
|
if projectConfig.DebounceMS == 0 {
|
||||||
|
projectConfig.DebounceMS = 100
|
||||||
|
}
|
||||||
|
debounceMS = projectConfig.DebounceMS
|
||||||
|
}
|
||||||
|
|
||||||
|
if debounceMS != projectConfig.DebounceMS {
|
||||||
|
projectConfig.DebounceMS = debounceMS
|
||||||
|
err := projectConfig.Save()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
LogGreen("Using reload debounce setting of %d milliseconds", debounceMS)
|
||||||
|
|
||||||
// Main Loop
|
// Main Loop
|
||||||
quit := false
|
quit := false
|
||||||
// Use 100ms debounce
|
interval := time.Duration(debounceMS) * time.Millisecond
|
||||||
interval := 100 * time.Millisecond
|
|
||||||
timer := time.NewTimer(interval)
|
timer := time.NewTimer(interval)
|
||||||
rebuild := false
|
rebuild := false
|
||||||
reload := false
|
reload := false
|
||||||
|
@ -46,6 +46,9 @@ type Project struct {
|
|||||||
|
|
||||||
// Fully qualified filename
|
// Fully qualified filename
|
||||||
filename string
|
filename string
|
||||||
|
|
||||||
|
// The debounce time for hot-reload of the built-in dev server
|
||||||
|
DebounceMS int `json:"debounceMS"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Project) Save() error {
|
func (p *Project) Save() error {
|
||||||
|
@ -161,11 +161,20 @@ The second, if given, will be executed in the `frontend` directory to build the
|
|||||||
|
|
||||||
If these 2 keys aren't given, then Wails does absolutely nothing with the frontend. It is only expecting that `embed.FS`.
|
If these 2 keys aren't given, then Wails does absolutely nothing with the frontend. It is only expecting that `embed.FS`.
|
||||||
|
|
||||||
## Live Reloading
|
## Built in Dev Server
|
||||||
|
|
||||||
Running `wails dev` will start a file watcher in your project directory. By default, if any file changes, wails checks
|
Running `wails dev` will start the built in dev server which will start a file watcher in your project directory. By
|
||||||
if it was an application file (default: `.go`, configurable with `-e` flag). If it was, then it will rebuild your
|
default, if any file changes, wails checks if it was an application file (default: `.go`, configurable with `-e` flag).
|
||||||
application and relaunch it. If the changed file was in the `assetdir` directory, it will issue a reload.
|
If it was, then it will rebuild your application and relaunch it. If the changed file was in the `assetdir` directory,
|
||||||
|
it will issue a reload after a short amount of time.
|
||||||
|
|
||||||
|
The dev server uses a technique called "debouncing" which means it doesn't reload straight away,
|
||||||
|
as there may be multiple files changed in a short amount of time. When a trigger occurs, it waits for a set amount of time
|
||||||
|
before issuing a reload. If another trigger happens, it resets to the wait time again. By default this value is `100ms`.
|
||||||
|
If this value doesn't work for your project, it can be configured using the `-debounce` flag. If used, this value will
|
||||||
|
be saved to your project config and become the default.
|
||||||
|
|
||||||
|
## External Dev Server
|
||||||
|
|
||||||
Some frameworks come with their own live-reloading server, however they will not be able to take advantage of the Wails
|
Some frameworks come with their own live-reloading server, however they will not be able to take advantage of the Wails
|
||||||
Go bindings. In this scenario, it is best to run a watcher script that rebuilds the project into the build directory, which
|
Go bindings. In this scenario, it is best to run a watcher script that rebuilds the project into the build directory, which
|
||||||
|
@ -131,7 +131,8 @@ Your system is ready for Wails development!
|
|||||||
| -loglevel "loglevel"| Loglevel to use - Trace, Debug, Info, Warning, Error | Debug |
|
| -loglevel "loglevel"| Loglevel to use - Trace, Debug, Info, Warning, Error | Debug |
|
||||||
| -noreload | Disable automatic reload when assets change | |
|
| -noreload | Disable automatic reload when assets change | |
|
||||||
| -v | Verbosity level (0 - silent, 1 - standard, 2 - verbose) | 1 |
|
| -v | Verbosity level (0 - silent, 1 - standard, 2 - verbose) | 1 |
|
||||||
| -wailsjsdir | The directory to generate the generated Wails JS modules | Value store 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) |
|
||||||
|
|
||||||
If the `-assetdir` or `-wailsjsdir` flags are provided on the command line, they are saved in `wails.json`, and become
|
If the `-assetdir` or `-wailsjsdir` flags are provided on the command line, they are saved in `wails.json`, and become
|
||||||
the defaults for subsequent invocations.
|
the defaults for subsequent invocations.
|
||||||
|
@ -14,7 +14,8 @@ The project config resides in the `wails.json` file in the project directory. Th
|
|||||||
"frontend:build": "[The command to build the assets, run in the frontend directory - often `npm run build`]",
|
"frontend:build": "[The command to build the assets, run in the frontend directory - often `npm run build`]",
|
||||||
"wailsjsdir": "[Relative path to the directory that the auto-generated JS modules will be created]",
|
"wailsjsdir": "[Relative path to the directory that the auto-generated JS modules will be created]",
|
||||||
"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
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user