Compare commits

...

6 Commits

Author SHA1 Message Date
Lea Anthony 62d97f85ec v2.5.1 2023-05-16 19:43:41 +10:00
stffabi 496461920f [v2] DevServer improvements and fixes (#2664)
* [assetserver, darwin] Fix copying request headers by using strdup

* [assetserver, linux] Fake some basic http headers for legacy webkit2 versions to support proxying requests to other servers

This fixes the devserver on v2 for newer vite versions that use the custom
scheme.

* [v2, windows] 304 responses are going to hang the WebView2 so prevent them by removing cache related headers in the request.

* [v2, dev] Now uses the custom schemes `wails://` on macOS and Linux for all Vite versions.

Prevent missing reload after fast multiple savings on Linux and Windows.
2023-05-16 09:35:48 +02:00
stffabi 22b53192e6 [v2, webview2loader] Prevent env and registry overrides when using the go loader (#2668) 2023-05-15 21:12:16 +02:00
Lea Anthony c1a0e1338f Add PR template 2023-05-14 08:46:57 +10:00
Lea Anthony 7266f2a78a Add PR template 2023-05-14 08:42:03 +10:00
Lea Anthony 774cbdec38 Update changelog.mdx 2023-05-13 14:49:07 +10:00
15 changed files with 187 additions and 53 deletions
+37
View File
@@ -0,0 +1,37 @@
# Description
Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change.
Fixes # (issue)
## Type of change
Please delete options that are not relevant.
- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
- [ ] This change requires a documentation update
# How Has This Been Tested?
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration using `wails doctor`.
- [ ] Windows
- [ ] macOS
- [ ] Linux
## Test Configuration
Please paste the output of `wails doctor`. If you are unable to run this command, please describe your environment in as much detail as possible.
# Checklist:
- [ ] I have updated `website/src/pages/changelog.mdx` with details of this PR
- [ ] My code follows the general coding style of this project
- [ ] I have performed a self-review of my own code
- [ ] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [ ] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my feature works
- [ ] New and existing unit tests pass locally with my changes
-3
View File
@@ -318,9 +318,6 @@ func restartApp(buildOptions *build.Options, debugBinaryProcess *process.Process
os.Setenv("assetdir", f.AssetDir)
os.Setenv("devserver", f.DevServer)
os.Setenv("frontenddevserverurl", f.FrontendDevServerURL)
if legacyUseDevServerInsteadofCustomScheme {
os.Setenv("legacyusedevsererinsteadofcustomscheme", "true")
}
// Start up new binary with correct args
newProcess := process.NewProcess(appBinary, args...)
+1 -1
View File
@@ -1 +1 @@
v2.5.0
v2.5.1
+5 -7
View File
@@ -106,15 +106,13 @@ func CreateApp(appoptions *options.App) (*App, error) {
}
if frontendDevServerURL != "" {
if os.Getenv("legacyusedevsererinsteadofcustomscheme") != "" {
startURL, err := url.Parse("http://" + devServer)
if err != nil {
return nil, err
}
ctx = context.WithValue(ctx, "starturl", startURL)
_, port, err := net.SplitHostPort(devServer)
if err != nil {
return nil, fmt.Errorf("unable to determine port of DevServer: %s", err)
}
ctx = context.WithValue(ctx, "assetserverport", port)
ctx = context.WithValue(ctx, "frontenddevserverurl", frontendDevServerURL)
externalURL, err := url.Parse(frontendDevServerURL)
@@ -19,6 +19,7 @@ import (
"fmt"
"html/template"
"log"
"net"
"net/url"
"unsafe"
@@ -78,6 +79,10 @@ func NewFrontend(ctx context.Context, appoptions *options.App, myLogger *logger.
if _starturl, _ := ctx.Value("starturl").(*url.URL); _starturl != nil {
result.startURL = _starturl
} else {
if port, _ := ctx.Value("assetserverport").(string); port != "" {
result.startURL.Host = net.JoinHostPort(result.startURL.Host+".localhost", port)
}
var bindings string
var err error
if _obfuscated, _ := ctx.Value("obfuscated").(bool); !_obfuscated {
@@ -78,6 +78,7 @@ import (
"encoding/json"
"fmt"
"log"
"net"
"net/url"
"os"
"runtime"
@@ -149,6 +150,10 @@ func NewFrontend(ctx context.Context, appoptions *options.App, myLogger *logger.
if _starturl, _ := ctx.Value("starturl").(*url.URL); _starturl != nil {
result.startURL = _starturl
} else {
if port, _ := ctx.Value("assetserverport").(string); port != "" {
result.startURL.Host = net.JoinHostPort(result.startURL.Host+".localhost", port)
}
var bindings string
var err error
if _obfuscated, _ := ctx.Value("obfuscated").(bool); !_obfuscated {
@@ -9,6 +9,7 @@ import (
"fmt"
"io"
"log"
"net"
"net/http"
"net/http/httptest"
"net/url"
@@ -92,6 +93,10 @@ func NewFrontend(ctx context.Context, appoptions *options.App, myLogger *logger.
return result
}
if port, _ := ctx.Value("assetserverport").(string); port != "" {
result.startURL.Host = net.JoinHostPort(result.startURL.Host, port)
}
var bindings string
var err error
if _obfuscated, _ := ctx.Value("obfuscated").(bool); !_obfuscated {
@@ -589,8 +594,16 @@ func (f *Frontend) processRequest(req *edge.ICoreWebView2WebResourceRequest, arg
headers = append(headers, fmt.Sprintf("%s: %s", k, strings.Join(v, ",")))
}
code := rw.Code
if code == http.StatusNotModified {
// WebView2 has problems when a request returns a 304 status code and the WebView2 is going to hang for other
// requests including IPC calls.
f.logger.Error("%s: AssetServer returned 304 - StatusNotModified which are going to hang WebView2, changed code to 505 - StatusInternalServerError", uri)
code = http.StatusInternalServerError
}
env := f.chromium.Environment()
response, err := env.CreateWebResourceResponse(rw.Body.Bytes(), rw.Code, http.StatusText(rw.Code), strings.Join(headers, "\n"))
response, err := env.CreateWebResourceResponse(rw.Body.Bytes(), code, http.StatusText(code), strings.Join(headers, "\n"))
if err != nil {
f.logger.Error("CreateWebResourceResponse Error: %s", err)
return
@@ -829,6 +842,12 @@ func coreWebview2RequestToHttpRequest(coreReq *edge.ICoreWebView2WebResourceRequ
}
}
// WebView2 has problems when a request returns a 304 status code and the WebView2 is going to hang for other
// requests including IPC calls.
// So prevent 304 status codes by removing the headers that are used in combinationwith caching.
header.Del("If-Modified-Since")
header.Del("If-None-Match")
method, err := coreReq.GetMethod()
if err != nil {
return nil, fmt.Errorf("GetMethod Error: %s", err)
@@ -4,6 +4,7 @@ package webviewloader
import (
"fmt"
"os"
"path/filepath"
"syscall"
"unsafe"
@@ -14,6 +15,7 @@ import (
func init() {
fmt.Println("DEB | Using go webview2loader")
preventEnvAndRegistryOverrides()
}
type webView2RunTimeType int32
@@ -104,6 +106,8 @@ func createWebViewEnvironmentWithClientDll(lpLibFileName string, runtimeType web
envCompletedCom := combridge.New[iCoreWebView2CreateCoreWebView2EnvironmentCompletedHandler](envCompletedHandler)
defer envCompletedCom.Close()
preventEnvAndRegistryOverrides()
const unknown = 1
hr, _, err := createProc.Call(
uintptr(unknown),
@@ -157,3 +161,16 @@ func (r *environmentCreatedHandler) EnvironmentCompleted(errorCode HRESULT, crea
return HRESULT(windows.S_OK)
}
func preventEnvAndRegistryOverrides() {
// Setting these env variables to empty string also prevents registry overrides because webview2
// checks for existence and not for empty value
os.Setenv("WEBVIEW2_PIPE_FOR_SCRIPT_DEBUGGER", "")
os.Setenv("WEBVIEW2_ADDITIONAL_BROWSER_ARGUMENTS", "")
os.Setenv("WEBVIEW2_RELEASE_CHANNEL_PREFERENCE", "0")
// The following seems not be be required because those are only used by the webview2loader which
// in this case is implemented on our own. But nevertheless set them to empty to be consistent.
os.Setenv("WEBVIEW2_BROWSER_EXECUTABLE_FOLDER", "")
os.Setenv("WEBVIEW2_USER_DATA_FOLDER", "")
}
+6 -2
View File
@@ -97,13 +97,17 @@ func (d *DevWebServer) Run(ctx context.Context) error {
log.Fatal(err)
}
assetServer, err := assetserver.NewDevAssetServer(assetHandler, wsHandler, bindingsJSON, ctx.Value("assetdir") != nil, myLogger, runtime.RuntimeAssetsBundle)
assetServer, err := assetserver.NewDevAssetServer(assetHandler, bindingsJSON, ctx.Value("assetdir") != nil, myLogger, runtime.RuntimeAssetsBundle)
if err != nil {
log.Fatal(err)
}
d.server.Any("/*", func(c echo.Context) error {
assetServer.ServeHTTP(c.Response(), c.Request())
if c.IsWebSocket() {
wsHandler.ServeHTTP(c.Response(), c.Request())
} else {
assetServer.ServeHTTP(c.Response(), c.Request())
}
return nil
})
+2 -7
View File
@@ -32,7 +32,6 @@ type RuntimeHandler interface {
type AssetServer struct {
handler http.Handler
wsHandler http.Handler
runtimeJS []byte
ipcJS func(*http.Request) []byte
@@ -107,12 +106,8 @@ func (d *AssetServer) AddPluginScript(pluginName string, script string) {
func (d *AssetServer) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
if isWebSocket(req) {
// Forward WebSockets to the distinct websocket handler if it exists
if wsHandler := d.wsHandler; wsHandler != nil {
wsHandler.ServeHTTP(rw, req)
} else {
rw.WriteHeader(http.StatusNotImplemented)
}
// WebSockets are not supported by the AssetServer
rw.WriteHeader(http.StatusNotImplemented)
return
}
+1 -2
View File
@@ -13,13 +13,12 @@ The assetserver for the dev mode.
Depending on the UserAgent it injects a websocket based IPC script into `index.html` or the default desktop IPC. The
default desktop IPC is injected when the webview accesses the devserver.
*/
func NewDevAssetServer(handler http.Handler, wsHandler http.Handler, bindingsJSON string, servingFromDisk bool, logger Logger, runtime RuntimeAssets) (*AssetServer, error) {
func NewDevAssetServer(handler http.Handler, bindingsJSON string, servingFromDisk bool, logger Logger, runtime RuntimeAssets) (*AssetServer, error) {
result, err := NewAssetServerWithHandler(handler, bindingsJSON, servingFromDisk, logger, runtime)
if err != nil {
return nil, err
}
result.wsHandler = wsHandler
result.appendSpinnerToBody = true
result.ipcJS = func(req *http.Request) []byte {
if strings.Contains(req.UserAgent(), WailsUserAgentValue) {
+2 -3
View File
@@ -8,6 +8,7 @@ package webview
#import <Foundation/Foundation.h>
#import <WebKit/WebKit.h>
#include <string.h>
static void URLSchemeTaskRetain(void *wkUrlSchemeTask) {
id<WKURLSchemeTask> urlSchemeTask = (id<WKURLSchemeTask>) wkUrlSchemeTask;
@@ -44,9 +45,7 @@ static const char * URLSchemeTaskRequestHeadersJSON(void *wkUrlSchemeTask) {
NSString* headerString = [[[NSString alloc] initWithData:headerData encoding:NSUTF8StringEncoding] autorelease];
const char * headerJSON = [headerString UTF8String];
char * headersOut = malloc(strlen(headerJSON));
strcpy(headersOut, headerJSON);
return headersOut;
return strdup(headerJSON);
}
}
+6 -1
View File
@@ -24,7 +24,12 @@ func webkit_uri_scheme_request_get_http_method(_ *C.WebKitURISchemeRequest) stri
}
func webkit_uri_scheme_request_get_http_headers(_ *C.WebKitURISchemeRequest) http.Header {
return http.Header{}
// Fake some basic default headers that are needed if e.g. request are being proxied to the an external sever, like
// we do in the devserver.
h := http.Header{}
h.Add("Accept", "*/*")
h.Add("User-Agent", "wails.io/605.1.15")
return h
}
func webkit_uri_scheme_request_get_http_body(_ *C.WebKitURISchemeRequest) io.ReadCloser {
+65 -26
View File
@@ -2,10 +2,12 @@ package main
import (
"encoding/json"
"github.com/samber/lo"
"os"
"os/exec"
"strconv"
"strings"
"time"
"github.com/wailsapp/wails/v2/internal/s"
)
@@ -43,45 +45,82 @@ func runCommand(name string, arg ...string) {
checkError(err)
}
func IsPointRelease(currentVersion string, newVersion string) bool {
// The first n-1 parts of the version should be the same
if currentVersion[:len(currentVersion)-2] != newVersion[:len(newVersion)-2] {
return false
}
// split on the last dot in the string
currentVersionSplit := strings.Split(currentVersion, ".")
newVersionSplit := strings.Split(newVersion, ".")
// compare the
// if the last part of the version is the same, it's a point release
currentMinor := lo.Must(strconv.Atoi(currentVersionSplit[len(currentVersionSplit)-1]))
newMinor := lo.Must(strconv.Atoi(newVersionSplit[len(newVersionSplit)-1]))
return newMinor == currentMinor+1
}
func main() {
var newVersion string
var isPointRelease bool
if len(os.Args) > 1 {
newVersion = os.Args[1]
err := os.WriteFile(versionFile, []byte(newVersion), 0755)
currentVersion, err := os.ReadFile(versionFile)
checkError(err)
err = os.WriteFile(versionFile, []byte(newVersion), 0755)
checkError(err)
isPointRelease = IsPointRelease(string(currentVersion), newVersion)
} else {
newVersion = updateVersion()
}
// Update ChangeLog
s.CD("../../../website")
runCommand("npx", "-y", "pnpm", "install")
s.ECHO("Generating new Docs for version: " + newVersion)
runCommand("npx", "pnpm", "run", "docusaurus", "docs:version", newVersion)
runCommand("npx", "pnpm", "run", "write-translations")
// Load the version list/*
versionsData, err := os.ReadFile("versions.json")
// Read in `src/pages/changelog.mdx`
changelogData, err := os.ReadFile("src/pages/changelog.mdx")
checkError(err)
var versions []string
err = json.Unmarshal(versionsData, &versions)
checkError(err)
oldestVersion := versions[len(versions)-1]
s.ECHO(oldestVersion)
versions = versions[0 : len(versions)-1]
newVersions, err := json.Marshal(&versions)
checkError(err)
err = os.WriteFile("versions.json", newVersions, 0755)
changelog := string(changelogData)
// Split on the line that has `## [Unreleased]`
changelogSplit := strings.Split(changelog, "## [Unreleased]")
// Get today's date in YYYY-MM-DD format
today := time.Now().Format("2006-01-02")
// Add the new version to the top of the changelog
newChangelog := changelogSplit[0] + "## [Unreleased]\n\n## [" + newVersion + "] - " + today + changelogSplit[1]
// Write the changelog back
err = os.WriteFile("src/pages/changelog.mdx", []byte(newChangelog), 0755)
checkError(err)
s.ECHO("Removing old version: " + oldestVersion)
s.CD("versioned_docs")
s.RMDIR("version-" + oldestVersion)
s.CD("../versioned_sidebars")
s.RM("version-" + oldestVersion + "-sidebars.json")
s.CD("..")
if !isPointRelease {
runCommand("npx", "-y", "pnpm", "install")
runCommand("npx", "pnpm", "run", "build")
s.ECHO("Generating new Docs for version: " + newVersion)
runCommand("npx", "pnpm", "run", "docusaurus", "docs:version", newVersion)
runCommand("npx", "pnpm", "run", "write-translations")
// Load the version list/*
versionsData, err := os.ReadFile("versions.json")
checkError(err)
var versions []string
err = json.Unmarshal(versionsData, &versions)
checkError(err)
oldestVersion := versions[len(versions)-1]
s.ECHO(oldestVersion)
versions = versions[0 : len(versions)-1]
newVersions, err := json.Marshal(&versions)
checkError(err)
err = os.WriteFile("versions.json", newVersions, 0755)
checkError(err)
s.ECHO("Removing old version: " + oldestVersion)
s.CD("versioned_docs")
s.RMDIR("version-" + oldestVersion)
s.CD("../versioned_sidebars")
s.RM("version-" + oldestVersion + "-sidebars.json")
s.CD("..")
runCommand("npx", "pnpm", "run", "build")
}
}
+15
View File
@@ -14,6 +14,21 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
## [v2.5.1] - 2023-05-16
### Breaking Changes
- The Go WebView2Loader allowed env variable and registry overrides to change the behaviour of WebView2. This is not possible when using the native WebView2Loader with Wails and should not be possible according to [PR](https://github.com/wailsapp/wails/pull/1771). Changed by @stffabi in [PR](https://github.com/wailsapp/wails/pull/2668)
- `wails dev` now uses the custom schemes `wails://` on macOS and Linux for all Vite versions. This also fixes missing reloads after multiple fast savings on Linux and Windows. Changed by @stffabi in [PR](https://github.com/wailsapp/wails/pull/2664)
### Fixed
- Fixed segfaults during fast reloads of requests on macOS. Fixed by @stffabi in [PR](https://github.com/wailsapp/wails/pull/2664)
- Fixed devserver on Linux for older WebKit2GTK versions < 2.36. Fixed by @stffabi in [PR](https://github.com/wailsapp/wails/pull/2664)
- Fixed devserver on Windows that might have triggered the WebView2 into a hang. Fixed by @stffabi in [PR](https://github.com/wailsapp/wails/pull/2664)
## v2.5.0 - 2023-05-13
### Breaking Changes
- `wails dev` now uses the custom schemes `wails://` on macOS and Linux if Vite >= `v3.0.0` is used. This makes the dev application consistent in behaviour with the final production application and fixes some long-standing inconsistencies. Changed by @stffabi in [PR](https://github.com/wailsapp/wails/pull/2610)