Skip to content

fix: 修复 Wails 构建时前端嵌入问题#45

Merged
awsl233777 merged 1 commit intomainfrom
refactor/wails-launcher-separation
Jan 15, 2026
Merged

fix: 修复 Wails 构建时前端嵌入问题#45
awsl233777 merged 1 commit intomainfrom
refactor/wails-launcher-separation

Conversation

@awsl233777
Copy link
Collaborator

@awsl233777 awsl233777 commented Jan 15, 2026

PR Type

enhancement, other


Description

  • Add support for embedded static files

  • Update CI workflow to build frontend

  • Implement new static file serving methods


Diagram Walkthrough

flowchart LR
  A["Main Application"] -- "uses" --> B["StaticFS"]
  B -- "serves" --> C["Static Files"]
  D["CI Workflow"] -- "builds" --> E["Frontend Assets"]
Loading

File Walkthrough

Relevant files
Enhancement
static.go
Enhance static file handling                                                         

internal/handler/static.go

  • Introduced StaticFS for embedded files
  • Added methods for serving files from disk or embedded
  • Implemented MIME type detection
+76/-0   
main.go
Configure embedded assets                                                               

main.go

  • Set StaticFS to serve embedded files
  • Embedded web/dist assets for HTTP server
+10/-0   
Other
ci-wails-build.yml
Update CI workflow for frontend                                                   

.github/workflows/ci-wails-build.yml

  • Added step to build frontend assets
  • Ensured frontend dependencies are installed
+9/-0     

- CI 工作流添加 pnpm build 步骤构建 web 前端
- static.go 支持嵌入式文件系统和磁盘文件系统双模式
- 桌面应用嵌入 web/dist 到二进制,CLI 模式从磁盘读取

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@awsl233777 awsl233777 merged commit e91f5b7 into main Jan 15, 2026
1 check passed
@awsl233777 awsl233777 deleted the refactor/wails-launcher-separation branch January 15, 2026 15:06
@github-actions
Copy link
Contributor

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 4 🔵🔵🔵🔵⚪
🧪 No relevant tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Possible Issue

The handling of the embedded static files may not properly manage errors when reading files. Ensure that error handling is robust to avoid potential crashes or unexpected behavior.

func newEmbeddedStaticHandler(fsys fs.FS) http.Handler {
	// Read index.html for SPA fallback
	indexContent, _ := fs.ReadFile(fsys, "index.html")

	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		// Clean the URL path
		urlPath := path.Clean(r.URL.Path)
		if urlPath == "/" || urlPath == "." {
			urlPath = "index.html"
		} else {
			urlPath = strings.TrimPrefix(urlPath, "/")
		}

		// Try to read the file
		content, err := fs.ReadFile(fsys, urlPath)
		if err != nil {
			// File not found, serve index.html for SPA routing
			if indexContent != nil {
				w.Header().Set("Content-Type", "text/html; charset=utf-8")
				w.WriteHeader(http.StatusOK)
				w.Write(indexContent)
				return
			}
			http.NotFound(w, r)
			return
		}

		// Set content type and serve
		w.Header().Set("Content-Type", getMimeType(urlPath))
		w.WriteHeader(http.StatusOK)
		w.Write(content)
	})
}
Initialization Check

The initialization of StaticFS should include error handling to ensure that the application can gracefully handle cases where the embedded filesystem cannot be set.

if subFS, err := fs.Sub(webDistAssets, "web/dist"); err == nil {
	handler.StaticFS = subFS
}

@github-actions
Copy link
Contributor

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
Possible issue
Handle error from file read

The error returned from fs.ReadFile should be handled to avoid potential issues if
the file cannot be read. Consider logging the error or returning an appropriate HTTP
error response.

internal/handler/static.go [70]

-indexContent, _ := fs.ReadFile(fsys, "index.html")
+indexContent, err := fs.ReadFile(fsys, "index.html")
+if err != nil {
+    http.Error(w, "Internal Server Error", http.StatusInternalServerError)
+    return
+}
Suggestion importance[1-10]: 8

__

Why: The suggestion addresses a potential issue by ensuring that errors from fs.ReadFile are handled, which is crucial for robust error management in the application. This improves the reliability of the code significantly.

Medium

SurviveM pushed a commit to SurviveM/maxx that referenced this pull request Jan 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant