mirror of
https://wget.la/https://github.com/leookun/cursor-byok
synced 2026-08-18 03:57:06 +08:00
fix: gate WebView sandbox opt-out behind environment variable
This commit is contained in:
+13
-3
@@ -8,7 +8,9 @@ import (
|
||||
"encoding/pem"
|
||||
"io/fs"
|
||||
"net"
|
||||
"os"
|
||||
goruntime "runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -37,6 +39,8 @@ const (
|
||||
appName = "Cursor助手"
|
||||
// adRefreshInterval 表示后台广告拉取间隔。
|
||||
adRefreshInterval = 3 * time.Minute
|
||||
// disableWebViewSandboxEnv allows affected VDI users to opt out of the WebView2 sandbox.
|
||||
disableWebViewSandboxEnv = "CURSOR_BYOK_DISABLE_WEBVIEW_SANDBOX"
|
||||
)
|
||||
|
||||
// EmbeddedResources 定义了当前模块中的 EmbeddedResources 类型。
|
||||
@@ -135,9 +139,7 @@ func Run(resources EmbeddedResources) error {
|
||||
Handler: application.AssetFileServerFS(resources.Assets),
|
||||
},
|
||||
Windows: application.WindowsOptions{
|
||||
// VDI 环境(如 VMware Horizon)会阻止 WebView2 创建沙箱受限令牌的renderer 进程,导致主窗口白屏。
|
||||
// --no-sandbox 跳过受限沙箱创建,使渲染进程可以正常启动。
|
||||
AdditionalBrowserArgs: []string{"--no-sandbox"},
|
||||
AdditionalBrowserArgs: windowsAdditionalBrowserArgs(),
|
||||
},
|
||||
Mac: application.MacOptions{
|
||||
ActivationPolicy: application.ActivationPolicyAccessory,
|
||||
@@ -420,6 +422,14 @@ func Run(resources EmbeddedResources) error {
|
||||
return app.Run()
|
||||
}
|
||||
|
||||
func windowsAdditionalBrowserArgs() []string {
|
||||
disableSandbox, err := strconv.ParseBool(strings.TrimSpace(os.Getenv(disableWebViewSandboxEnv)))
|
||||
if err != nil || !disableSandbox {
|
||||
return nil
|
||||
}
|
||||
return []string{"--no-sandbox"}
|
||||
}
|
||||
|
||||
func browserReachableLoopbackBaseURL(listenAddr string) string {
|
||||
host, port, err := net.SplitHostPort(strings.TrimSpace(listenAddr))
|
||||
if err != nil || strings.TrimSpace(port) == "" {
|
||||
|
||||
Reference in New Issue
Block a user