Fix HMR. Better logging.

This commit is contained in:
Lea Anthony 2023-08-15 20:18:43 +10:00
commit 763c7708f4
No known key found for this signature in database
GPG key ID: 33DAF7BB90A58405
4 changed files with 32 additions and 17 deletions

View file

@ -21,6 +21,9 @@ const (
flagsPath = "/wails/flags"
)
const webViewRequestHeaderWindowId = "x-wails-window-id"
const webViewRequestHeaderWindowName = "x-wails-window-name"
type RuntimeAssets interface {
DesktopIPC() []byte
WebsocketIPC() []byte
@ -135,7 +138,9 @@ func (d *AssetServer) AddPluginScript(pluginName string, script string) {
}
func (d *AssetServer) logRequest(req *http.Request, code int) {
d.logger.Info("AssetServer:", "code", code, "method", req.Method, "url", req.URL.Path)
windowName := req.Header.Get(webViewRequestHeaderWindowName)
windowID := req.Header.Get(webViewRequestHeaderWindowId)
d.logger.Info("AssetServer:", "code", code, "windowName", windowName, "windowID", windowID, "method", req.Method, "url", req.URL.Path)
}
func (d *AssetServer) ServeHTTP(rw http.ResponseWriter, req *http.Request) {

View file

@ -44,7 +44,7 @@ func New(appOptions Options) *App {
mergeApplicationDefaults(&appOptions)
result := newApplication(&appOptions)
result := newApplication(appOptions)
globalApplication = result
if result.isDebugMode && result.Logger == nil {

View file

@ -28,10 +28,10 @@ func init() {
}
// We use this to patch the application to production mode.
func newApplication(options *Options) *App {
func newApplication(options Options) *App {
result := &App{
isDebugMode: true,
options: options.getOptions(true),
options: options,
}
result.init()
return result

View file

@ -1327,7 +1327,7 @@ func (w *windowsWebviewWindow) processRequest(req *edge.ICoreWebView2WebResource
if reqUri.Scheme != "http" {
// Let the WebView2 handle the request with its default handler
return
} else if reqUri.Host != "wails.localhost" {
} else if !strings.HasPrefix(reqUri.Host, "wails.localhost") {
// Let the WebView2 handle the request with its default handler
return
}
@ -1462,21 +1462,31 @@ func (w *windowsWebviewWindow) setupChromium() {
} else {
var startURL = "http://wails.localhost"
if globalApplication.options.Assets.ExternalURL != "" {
startURL = globalApplication.options.Assets.ExternalURL
} else if w.parent.options.URL != "" {
// parse the url
parsedURL, err := url.Parse(w.parent.options.URL)
// Parse the port
parsedURL, err := url.Parse(globalApplication.options.Assets.ExternalURL)
if err != nil {
globalApplication.fatal("Error parsing URL: " + err.Error())
globalApplication.fatal("Error parsing ExternalURL: " + err.Error())
}
if parsedURL.Scheme == "" {
startURL = path.Join(startURL, w.parent.options.URL)
// if the original URL had a trailing slash, add it back
if strings.HasSuffix(w.parent.options.URL, "/") {
startURL = startURL + "/"
port := parsedURL.Port()
if port != "" {
startURL += ":" + port
}
} else {
if w.parent.options.URL != "" {
// parse the url
parsedURL, err := url.Parse(w.parent.options.URL)
if err != nil {
globalApplication.fatal("Error parsing URL: " + err.Error())
}
if parsedURL.Scheme == "" {
startURL = path.Join(startURL, w.parent.options.URL)
// if the original URL had a trailing slash, add it back
if strings.HasSuffix(w.parent.options.URL, "/") {
startURL = startURL + "/"
}
} else {
startURL = w.parent.options.URL
}
} else {
startURL = w.parent.options.URL
}
}
chromium.Navigate(startURL)