Skip to content

Commit

Permalink
Move startURL calculation to assetserver
Browse files Browse the repository at this point in the history
  • Loading branch information
leaanthony committed Jan 20, 2024
1 parent bcb390f commit c82facd
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 30 deletions.
35 changes: 35 additions & 0 deletions v3/internal/assetserver/assetserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"net/http"
"net/http/httptest"
"net/http/httputil"
"net/url"
"path"
"strings"
"time"
)
Expand Down Expand Up @@ -165,3 +167,36 @@ func (a *AssetServer) AddPluginScript(pluginName string, script string) {
pluginScriptName := fmt.Sprintf("/wails/plugin/%s.js", pluginName)
a.pluginScripts[pluginScriptName] = script
}

func GetStartURL(userURL string) (string, error) {
devServerURL := GetDevServerURL()
if devServerURL != "" {
// Parse the port
parsedURL, err := url.Parse(devServerURL)
if err != nil {
return "", fmt.Errorf("Error parsing environment variable 'FRONTEND_DEVSERVER_URL`: " + err.Error() + ". Please check your `Taskfile.yml` file")
}
port := parsedURL.Port()
if port != "" {
startURL += ":" + port
}
} else {
if userURL != "" {
// parse the url
parsedURL, err := url.Parse(userURL)
if err != nil {
return "", fmt.Errorf("Error parsing URL: " + err.Error())
}
if parsedURL.Scheme == "" {
startURL = path.Join(startURL, userURL)
// if the original URL had a trailing slash, add it back
if strings.HasSuffix(userURL, "/") {
startURL = startURL + "/"
}
} else {
startURL = userURL
}
}
}
return startURL, nil
}
3 changes: 3 additions & 0 deletions v3/internal/assetserver/assetserver_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package assetserver

var startURL = "http://wails.localhost"
33 changes: 3 additions & 30 deletions v3/pkg/application/webview_window_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"fmt"
"github.com/wailsapp/wails/v3/internal/assetserver"
"net/url"
"path"
"strconv"
"strings"
"sync"
Expand Down Expand Up @@ -1457,35 +1456,9 @@ func (w *windowsWebviewWindow) setupChromium() {
chromium.Init(script)
chromium.NavigateToString(w.parent.options.HTML)
} else {
var startURL = "http://wails.localhost"
devServerURL := assetserver.GetDevServerURL()
if devServerURL != "" {
// Parse the port
parsedURL, err := url.Parse(devServerURL)
if err != nil {
globalApplication.fatal("Error parsing environment variable 'FRONTEND_DEVSERVER_URL`: " + err.Error() + ". Please check your `Taskfile.yml` file")
}
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
}
}
startURL, err := assetserver.GetStartURL(w.parent.options.URL)
if err != nil {
globalApplication.fatal(err.Error())
}
chromium.Navigate(startURL)
}
Expand Down

0 comments on commit c82facd

Please sign in to comment.