wails

为 Wails 提供专家级指导。Wails 是用于构建桌面应用的 Go 框架,支持使用 Web 前端技术。帮助开发者构建轻量、快速的桌面应用,后端使用 Go,前端可用任意 Web 框架(如 React、Vue、Svelte),并通过自动生成的 TypeScript 绑定实现前后端通信。

仓库最近推送
GitHub Stars
219
Forks
38
Issues / PRs
1

安装方式

先用 Prompt 核对来源与依赖。也可下载安装包。

用 AI 助手安装

复制提示词,让助手先核对固定版本和依赖。

查看 Prompt收起 Prompt
先检查当前 Agent 是否已安装 SkillPI Skill Finder。如果尚未安装,请按官方仓库的说明安装并启用:https://github.com/Findskills/skillpi。然后使用 Skill Finder 打开此 SkillPI 详情页并定位 "wails":https://skillpi.com/zh/skills/deepskill-74b8513353332dfed8ae574fdf69931cabceee1d5b88e84dc937560f69c6ed7d。安装前核对上游来源和版本:https://github.com/TerminalSkills/skills。来源不一致时停止并说明差异。核对通过后,用 Skill Finder 安装目标 Skill,并报告安装路径和来源版本。

来源与配置

github.com

配置方式待核实

请查看原始来源中的适用工具、依赖和权限要求。

安装实测待补充

为 Wails 提供专家级指导。Wails 是用于构建桌面应用的 Go 框架,支持使用 Web 前端技术。帮助开发者构建轻量、快速的桌面应用,后端使用 Go,前端可用任意 Web 框架(如 React、Vue、Svelte),并通过自动生成的 TypeScript 绑定实现前后端通信。

0 下载

介绍来源: third_party · TerminalSkills · 1.0.0 参考来源

SkillPi 解读

能完成的任务
翻译待完成,请参阅来源文档。
软件、账号及付费要求
贝什
实测状态
未测试

文件浏览

在原站浏览文件 ↗

原始 SKILL.md

打开原文 ↗
Frontmatter
name: wails
description: Expert guidance for Wails, the Go framework for building desktop applications with web frontends. Helps developers build lightweight, fast desktop apps where the backend is Go and the frontend is any web framework (React, Vue, Svelte), communicating through auto-generated TypeScript bindings.
license: Apache-2.0
compatibility: No special requirements
metadata:
  author: terminal-skills
  version: 1.0.0
  category: development
  tags:
  - desktop
  - go
  - golang
  - cross-platform
  - native

Wails — Desktop Apps with Go and Web Frontend

Overview

Wails, the Go framework for building desktop applications with web frontends. Helps developers build lightweight, fast desktop apps where the backend is Go and the frontend is any web framework (React, Vue, Svelte), communicating through auto-generated TypeScript bindings.

Instructions

Project Setup

# Install Wails CLI
go install github.com/wailsapp/wails/v2/cmd/wails@latest

# Check system dependencies
wails doctor

# Create a new project (React + TypeScript)
wails init -n my-app -t react-ts
cd my-app

# Development mode (hot reload for frontend + backend)
wails dev

# Build production binary
wails build                         # Outputs to build/bin/
wails build -platform darwin/amd64  # Cross-compile
wails build -nsis                   # Windows installer

Go Backend

// app.go — Application backend with methods exposed to frontend
// Methods on the App struct are automatically callable from JavaScript.

package main

import (
    "context"
    "database/sql"
    "fmt"
    "os"
    "path/filepath"

    _ "modernc.org/sqlite"
)

// App struct — any exported method becomes available in the frontend
type App struct {
    ctx context.Context
    db  *sql.DB
}

// startup is called when the app starts — initialize resources here
func (a *App) startup(ctx context.Context) {
    a.ctx = ctx

    // Open SQLite database in user's app data directory
    homeDir, _ := os.UserHomeDir()
    dbPath := filepath.Join(homeDir, ".my-app", "data.db")
    os.MkdirAll(filepath.Dir(dbPath), 0755)

    db, err := sql.Open("sqlite", dbPath)
    if err != nil {
        fmt.Printf("Failed to open database: %v\n", err)
        return
    }
    a.db = db

    // Create tables
    a.db.Exec(`CREATE TABLE IF NOT EXISTS notes (
        id INTEGER PRIMARY KEY AUTOINCREMENT,
        title TEXT NOT NULL,
        content TEXT NOT NULL DEFAULT '',
        created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
        updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
    )`)
}

// Note is a data model — returned to frontend as typed TypeScript interface
type Note struct {
    ID        int64  `json:"id"`
    Title     string `json:"title"`
    Content   string `json:"content"`
    CreatedAt string `json:"createdAt"`
    UpdatedAt string `json:"updatedAt"`
}

// GetNotes returns all notes — callable from frontend as GetNotes()
func (a *App) GetNotes() ([]Note, error) {
    rows, err := a.db.Query("SELECT id, title, content, created_at, updated_at FROM notes ORDER BY updated_at DESC")
    if err != nil {
        return nil, err
    }
    defer rows.Close()

    var notes []Note
    for rows.Next() {
        var n Note
        rows.Scan(&n.ID, &n.Title, &n.Content, &n.CreatedAt, &n.UpdatedAt)
        notes = append(notes, n)
    }
    return notes, nil
}

// CreateNote creates a new note — frontend calls CreateNote(title)
func (a *App) CreateNote(title string) (*Note, error) {
    result, err := a.db.Exec("INSERT INTO notes (title) VALUES (?)", title)
    if err != nil {
        return nil, err
    }
    id, _ := result.LastInsertId()
    return &Note{ID: id, Title: title, Content: ""}, nil
}

// UpdateNote saves note content — called on every edit
func (a *App) UpdateNote(id int64, title, content string) error {
    _, err := a.db.Exec(
        "UPDATE notes SET title = ?, content = ?, updated_at = CURRENT_TIMESTAMP WHERE id = ?",
        title, content, id,
    )
    return err
}

// DeleteNote removes a note
func (a *App) DeleteNote(id int64) error {
    _, err := a.db.Exec("DELETE FROM notes WHERE id = ?", id)
    return err
}

// OpenFile opens a native file dialog and returns the file content
func (a *App) OpenFile() (string, error) {
    selection, err := runtime.OpenFileDialog(a.ctx, runtime.OpenDialogOptions{
        Title: "Open File",
        Filters: []runtime.FileFilter{
            {DisplayName: "Text Files", Pattern: "*.txt;*.md"},
        },
    })
    if err != nil {
        return "", err
    }
    data, err := os.ReadFile(selection)
    return string(data), err
}

Frontend (React + TypeScript)

// frontend/src/App.tsx — React frontend with auto-generated bindings
// Wails generates TypeScript types from Go structs and functions.

import { useState, useEffect } from "react";
// These imports are auto-generated by Wails from Go code
import { GetNotes, CreateNote, UpdateNote, DeleteNote } from "../wailsjs/go/main/App";
import { main } from "../wailsjs/go/models";

function App() {
  const [notes, setNotes] = useState<main.Note[]>([]);
  const [selectedNote, setSelectedNote] = useState<main.Note | null>(null);

  useEffect(() => {
    loadNotes();
  }, []);

  async function loadNotes() {
    const result = await GetNotes();       // Calls Go method, returns typed Note[]
    setNotes(result || []);
  }

  async function handleCreate() {
    const note = await CreateNote("Untitled");  // Go returns *Note, TS gets main.Note
    if (note) {
      setNotes([note, ...notes]);
      setSelectedNote(note);
    }
  }

  async function handleSave(id: number, title: string, content: string) {
    await UpdateNote(id, title, content);  // Calls Go, saves to SQLite
    loadNotes();
  }

  async function handleDelete(id: number) {
    await DeleteNote(id);
    setSelectedNote(null);
    loadNotes();
  }

  return (
    <div className="app">
      <aside className="sidebar">
        <button onClick={handleCreate}>+ New Note</button>
        <ul>
          {notes.map((note) => (
            <li
              key={note.id}
              className={selectedNote?.id === note.id ? "active" : ""}
              onClick={() => setSelectedNote(note)}
            >
              <strong>{note.title}</strong>
              <small>{note.updatedAt}</small>
            </li>
          ))}
        </ul>
      </aside>

      <main className="editor">
        {selectedNote ? (
          <NoteEditor
            note={selectedNote}
            onSave={handleSave}
            onDelete={handleDelete}
          />
        ) : (
          <p>Select or create a note</p>
        )}
      </main>
    </div>
  );
}

System Tray and Menus

// main.go — Native menus and system tray
package main

import (
    "embed"
    "github.com/wailsapp/wails/v2"
    "github.com/wailsapp/wails/v2/pkg/menu"
    "github.com/wailsapp/wails/v2/pkg/options"
    "github.com/wailsapp/wails/v2/pkg/options/assetserver"
)

//go:embed all:frontend/dist
var assets embed.FS

func main() {
    app := &App{}

    appMenu := menu.NewMenu()
    fileMenu := appMenu.AddSubmenu("File")
    fileMenu.AddText("New Note", keys.CmdOrCtrl("n"), func(_ *menu.CallbackData) {
        // Emit event to frontend
        runtime.EventsEmit(app.ctx, "menu:new-note")
    })
    fileMenu.AddSeparator()
    fileMenu.AddText("Quit", keys.CmdOrCtrl("q"), func(_ *menu.CallbackData) {
        runtime.Quit(app.ctx)
    })

    err := wails.Run(&options.App{
        Title:     "My Notes",
        Width:     1024,
        Height:    768,
        MinWidth:  600,
        MinHeight: 400,
        AssetServer: &assetserver.Options{
            Assets: assets,
        },
        OnStartup: app.startup,
        Menu:      appMenu,
        Bind:      []interface{}{app},
    })
    if err != nil {
        panic(err)
    }
}

Installation

# Prerequisites: Go 1.21+, Node.js 16+
go install github.com/wailsapp/wails/v2/cmd/wails@latest

# macOS also needs Xcode command line tools
xcode-select --install

# Linux needs webkit2gtk
sudo apt install libgtk-3-dev libwebkit2gtk-4.0-dev

Examples

Example 1: Setting up Wails with a custom configuration

User request:

I just installed Wails. Help me configure it for my TypeScript + React workflow with my preferred keybindings.

The agent creates the configuration file with TypeScript-aware settings, configures relevant plugins/extensions for React development, sets up keyboard shortcuts matching the user's preferences, and verifies the setup works correctly.

Example 2: Extending Wails with custom functionality

User request:

I want to add a custom go backend to Wails. How do I build one?

The agent scaffolds the extension/plugin project, implements the core functionality following Wails's API patterns, adds configuration options, and provides testing instructions to verify it works end-to-end.

Guidelines

  1. Go for backend, web for UI — Keep business logic, file I/O, database access in Go; keep UI rendering in the frontend
  2. Auto-generated bindings — Never write API boilerplate; Wails generates TypeScript types from Go structs automatically
  3. Embed assets — Use //go:embed to bundle the frontend into the binary; single-file distribution
  4. Events for async — Use runtime.EventsEmit for Go→frontend communication (progress updates, background task results)
  5. Native dialogs — Use Wails' runtime dialogs (file picker, message box) instead of HTML modals for native feel
  6. SQLite for local data — Ship with SQLite for offline-first apps; it's a single file in the user's app data directory
  7. Dev mode for iteration — wails dev provides hot reload for both Go and frontend; iterate fast
  8. Cross-compile — Build for all platforms from one machine with wails build -platform; test on each OS before release

当前收录版本

1.0.0

核对来源版本 ↗

质量评测

满分100 · 来自 SkillPi LAB 实验室的评测报告。

场景价值95/100

亮点

  • Wails 是一个成熟的 Go 桌面应用开发框架,Skill 提供了完整的端到端指导
  • 包含项目初始化、前后端通信、数据库集成、系统托盘、原生菜单等核心功能
  • 附带详细代码示例,对 Go 桌面开发者具有极高实用价值
触发精准90/100

亮点

  • description 明确描述了 Wails 框架的核心功能和使用场景
  • 触发词精准完整,覆盖多种变体,边界清晰
结构规范90/100

亮点

  • 文档结构清晰,包含项目设置、Go 后端、前端、系统托盘等完整示例
  • frontmatter 完整,单文件≤500行
  • Phase/步骤清晰,有出口条件,含端到端示例
执行可靠85/100

待提升项

  • 部分错误处理可更详细 原报告严重程度:轻微

    代码示例中的错误处理较为基础,部分场景可添加更详细的错误处理和用户反馈机制

    改进建议:建议在关键操作(如数据库操作、文件读写)中添加更完善的错误处理和用户提示

亮点

  • 工具来源明确,参数正确
  • 覆盖主要异常,不可逆操作有确认机制
  • 代码示例完整,工具链清晰
证据可验 (前四项均值)90/100

取前四项原始分值的算术平均,四舍五入取整。可通过收录报告核对各项评分与说明,运行记录需单独查证。

正文静态检测

100 / 100 · skillpi-20261123-no-r3-v1

正文未命中当前规则。

分数仅反映正文中的规则命中,供使用前参考。附件与运行行为不在此评分范围内。

权限与使用前检查

根据当前主文档自动整理,命中内容可能是示例或防护说明;不是实际权限声明,也未覆盖附件、外部依赖或运行行为。

  • 读取本地文件

    限定到你选择的文件或项目目录;避免读取无关的个人资料、密钥和配置文件。

    主文档提及 · 第 163 行
  • 安装或获取外部依赖

    使用官方来源并锁定版本,在隔离环境检查安装脚本。当前文档检查不覆盖后续下载的代码。

    主文档提及 · 第 305 行
  • 管理员或提升权限

    确认确有必要再提升权限;不要关闭防护、绕过证书验证或扩大整个系统的访问权限。

    主文档提及 · 第 305 行

本站展示提示不会授予权限。涉及文件改动、密钥、外部发送或费用时,仍由你使用的工具按需确认。

安全评级与访问范围

safe · 静态证据核验,不代表运行安全保证。

贝什

使用前请由宿主核对并授权实际文件读写、外部服务和联网目的地;本站的核验不会授予任何运行权限。