mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-02 19:50:15 +08:00
Move watcher init to doWatcherLoop and implement -reloaddirs (#2871)
* remove random print statement * move watcher into loop and implement reloaddirs * Fixed -reloaddirs for issue #2829 --------- Co-authored-by: Lea Anthony <lea.anthony@gmail.com>
This commit is contained in:
parent
acf8dea170
commit
069fe18b9d
@ -5,6 +5,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
@ -138,20 +139,6 @@ func Application(f *flags.Dev, logger *clilogger.CLILogger) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// create the project files watcher
|
|
||||||
watcher, err := initialiseWatcher(cwd)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
defer func(watcher *fsnotify.Watcher) {
|
|
||||||
err := watcher.Close()
|
|
||||||
if err != nil {
|
|
||||||
logger.Fatal(err.Error())
|
|
||||||
}
|
|
||||||
}(watcher)
|
|
||||||
|
|
||||||
logutils.LogGreen("Watching (sub)/directory: %s", cwd)
|
|
||||||
logutils.LogGreen("Using DevServer URL: %s", f.DevServerURL())
|
logutils.LogGreen("Using DevServer URL: %s", f.DevServerURL())
|
||||||
if f.FrontendDevServerURL != "" {
|
if f.FrontendDevServerURL != "" {
|
||||||
logutils.LogGreen("Using Frontend DevServer URL: %s", f.FrontendDevServerURL)
|
logutils.LogGreen("Using Frontend DevServer URL: %s", f.FrontendDevServerURL)
|
||||||
@ -165,7 +152,10 @@ func Application(f *flags.Dev, logger *clilogger.CLILogger) error {
|
|||||||
}()
|
}()
|
||||||
|
|
||||||
// Watch for changes and trigger restartApp()
|
// Watch for changes and trigger restartApp()
|
||||||
debugBinaryProcess = doWatcherLoop(buildOptions, debugBinaryProcess, f, watcher, exitCodeChannel, quitChannel, f.DevServerURL(), legacyUseDevServerInsteadofCustomScheme)
|
debugBinaryProcess, err = doWatcherLoop(cwd, buildOptions, debugBinaryProcess, f, exitCodeChannel, quitChannel, f.DevServerURL(), legacyUseDevServerInsteadofCustomScheme)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// Kill the current program if running and remove dev binary
|
// Kill the current program if running and remove dev binary
|
||||||
if err := killProcessAndCleanupBinary(debugBinaryProcess, appBinary); err != nil {
|
if err := killProcessAndCleanupBinary(debugBinaryProcess, appBinary); err != nil {
|
||||||
@ -337,7 +327,23 @@ func restartApp(buildOptions *build.Options, debugBinaryProcess *process.Process
|
|||||||
}
|
}
|
||||||
|
|
||||||
// doWatcherLoop is the main watch loop that runs while dev is active
|
// doWatcherLoop is the main watch loop that runs while dev is active
|
||||||
func doWatcherLoop(buildOptions *build.Options, debugBinaryProcess *process.Process, f *flags.Dev, watcher *fsnotify.Watcher, exitCodeChannel chan int, quitChannel chan os.Signal, devServerURL *url.URL, legacyUseDevServerInsteadofCustomScheme bool) *process.Process {
|
func doWatcherLoop(cwd string, buildOptions *build.Options, debugBinaryProcess *process.Process, f *flags.Dev, exitCodeChannel chan int, quitChannel chan os.Signal, devServerURL *url.URL, legacyUseDevServerInsteadofCustomScheme bool) (*process.Process, error) {
|
||||||
|
// create the project files watcher
|
||||||
|
watcher, err := initialiseWatcher(cwd)
|
||||||
|
if err != nil {
|
||||||
|
logutils.LogRed("Unable to create filesystem watcher. Reloads will not occur.")
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
defer func(watcher *fsnotify.Watcher) {
|
||||||
|
err := watcher.Close()
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err.Error())
|
||||||
|
}
|
||||||
|
}(watcher)
|
||||||
|
|
||||||
|
logutils.LogGreen("Watching (sub)/directory: %s", cwd)
|
||||||
|
|
||||||
// Main Loop
|
// Main Loop
|
||||||
var extensionsThatTriggerARebuild = sliceToMap(strings.Split(f.Extensions, ","))
|
var extensionsThatTriggerARebuild = sliceToMap(strings.Split(f.Extensions, ","))
|
||||||
var dirsThatTriggerAReload []string
|
var dirsThatTriggerAReload []string
|
||||||
@ -351,6 +357,12 @@ func doWatcherLoop(buildOptions *build.Options, debugBinaryProcess *process.Proc
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
dirsThatTriggerAReload = append(dirsThatTriggerAReload, thePath)
|
dirsThatTriggerAReload = append(dirsThatTriggerAReload, thePath)
|
||||||
|
err = watcher.Add(thePath)
|
||||||
|
if err != nil {
|
||||||
|
logutils.LogRed("Unable to watch path: %s due to error %v", thePath, err)
|
||||||
|
} else {
|
||||||
|
logutils.LogGreen("Watching (sub)/directory: %s", thePath)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
quit := false
|
quit := false
|
||||||
@ -499,7 +511,7 @@ func doWatcherLoop(buildOptions *build.Options, debugBinaryProcess *process.Proc
|
|||||||
quit = true
|
quit = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return debugBinaryProcess
|
return debugBinaryProcess, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func joinPath(url *url.URL, subPath string) string {
|
func joinPath(url *url.URL, subPath string) string {
|
||||||
|
@ -38,7 +38,6 @@ func initialiseWatcher(cwd string) (*fsnotify.Watcher, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
println("watching: " + dir)
|
|
||||||
}
|
}
|
||||||
return watcher, nil
|
return watcher, nil
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
- Fixed `SetBackgroundColour` so it sets the window's background color to reduce resize flickering on Linux. Added by @lyimmi in [PR](https://github.com/wailsapp/wails/pull/2853)
|
- Fixed `SetBackgroundColour` so it sets the window's background color to reduce resize flickering on Linux. Added by @lyimmi in [PR](https://github.com/wailsapp/wails/pull/2853)
|
||||||
- Fixed disable window resize option and wrong initial window size when its enabled. Added by @lyimmi in [PR](https://github.com/wailsapp/wails/pull/2863)
|
- Fixed disable window resize option and wrong initial window size when its enabled. Added by @lyimmi in [PR](https://github.com/wailsapp/wails/pull/2863)
|
||||||
- Fixed build hook command parsing. Added by @smac89 in [PR](https://github.com/wailsapp/wails/pull/2836)
|
- Fixed build hook command parsing. Added by @smac89 in [PR](https://github.com/wailsapp/wails/pull/2836)
|
||||||
|
- Fixed `-reloaddir` flag to watch additional directories (non-recursively). [@haukened](https://github.com/haukened) in [PR #2871](https://github.com/wailsapp/wails/pull/2871)
|
||||||
- Fixed support for Go 1.21 `go.mod` files. Fixed by @stffabi in [PR](https://github.com/wailsapp/wails/pull/2876)
|
- Fixed support for Go 1.21 `go.mod` files. Fixed by @stffabi in [PR](https://github.com/wailsapp/wails/pull/2876)
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
Loading…
Reference in New Issue
Block a user