初始化
3
.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
build/bin
|
||||
node_modules
|
||||
frontend/dist
|
||||
10
.idea/.gitignore
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
# 默认忽略的文件
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# 已忽略包含查询文件的默认文件夹
|
||||
/queries/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
||||
# 基于编辑器的 HTTP 客户端请求
|
||||
/httpRequests/
|
||||
11
.idea/go.imports.xml
generated
Normal file
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="GoImports">
|
||||
<option name="excludedPackages">
|
||||
<array>
|
||||
<option value="github.com/pkg/errors" />
|
||||
<option value="golang.org/x/net/context" />
|
||||
</array>
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
||||
8
.idea/modules.xml
generated
Normal file
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/view.iml" filepath="$PROJECT_DIR$/.idea/view.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
||||
6
.idea/vcs.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
9
.idea/view.iml
generated
Normal file
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="WEB_MODULE" version="4">
|
||||
<component name="Go" enabled="true" />
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$" />
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
||||
51
README.md
Normal file
@@ -0,0 +1,51 @@
|
||||
# Code Count
|
||||
|
||||
Code Count is a Wails v2 desktop application for local source-code and Git analytics. The Go backend scans source files with gocloc, reads Git history through the installed `git` executable, and persists analysis snapshots in SQLite. The Vue 3 frontend provides Chinese/English and light/dark themes.
|
||||
|
||||
## Requirements
|
||||
|
||||
- Go 1.25+
|
||||
- Node.js 20+
|
||||
- Wails CLI 2.12+
|
||||
- Git (optional; required only for Git analytics)
|
||||
|
||||
## Development
|
||||
|
||||
```powershell
|
||||
cd frontend
|
||||
npm install
|
||||
cd ..
|
||||
wails dev
|
||||
```
|
||||
|
||||
The database is created under the operating system's user configuration directory in `CodeCount/code-count.db`. Its location can be changed from Settings.
|
||||
|
||||
## Tests and builds
|
||||
|
||||
```powershell
|
||||
go test ./...
|
||||
cd frontend
|
||||
npm run build
|
||||
cd ..
|
||||
wails build
|
||||
```
|
||||
|
||||
Windows builds produce `build/bin/code-count.exe`. Run `wails build -platform darwin/universal` on macOS to create the macOS application bundle.
|
||||
|
||||
## About
|
||||
|
||||
This is the official Wails Vue template.
|
||||
|
||||
You can configure the project by editing `wails.json`. More information about the project settings can be found
|
||||
here: https://wails.io/docs/reference/project-config
|
||||
|
||||
## Live Development
|
||||
|
||||
To run in live development mode, run `wails dev` in the project directory. This will run a Vite development
|
||||
server that will provide very fast hot reload of your frontend changes. If you want to develop in a browser
|
||||
and have access to your Go methods, there is also a dev server that runs on http://localhost:34115. Connect
|
||||
to this in your browser, and you can call your Go code from devtools.
|
||||
|
||||
## Building
|
||||
|
||||
To build a redistributable, production mode package, use `wails build`.
|
||||
579
app.go
Normal file
@@ -0,0 +1,579 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
"view/platform"
|
||||
"view/service"
|
||||
|
||||
"github.com/wailsapp/wails/v2/pkg/runtime"
|
||||
)
|
||||
|
||||
type App struct {
|
||||
ctx context.Context
|
||||
store *Store
|
||||
bootstrapFile string
|
||||
bootstrap BootstrapStatus
|
||||
runtimeReady bool
|
||||
mu sync.Mutex
|
||||
tasks map[string]context.CancelFunc
|
||||
}
|
||||
|
||||
func NewApp() *App { return &App{tasks: map[string]context.CancelFunc{}} }
|
||||
func (a *App) startup(ctx context.Context) {
|
||||
a.ctx = ctx
|
||||
a.runtimeReady = true
|
||||
defaultPath, e := defaultDBPath()
|
||||
if e != nil {
|
||||
a.bootstrap = BootstrapStatus{State: BootstrapRecovery, ErrorCode: "DB_DEFAULT_PATH_FAILED", ErrorDetail: e.Error()}
|
||||
return
|
||||
}
|
||||
a.bootstrapFile, e = bootstrapPath()
|
||||
if e != nil {
|
||||
a.bootstrap = BootstrapStatus{State: BootstrapRecovery, DefaultPath: defaultPath, ErrorCode: "BOOTSTRAP_PATH_FAILED", ErrorDetail: e.Error()}
|
||||
return
|
||||
}
|
||||
c, e := readBootstrap(a.bootstrapFile)
|
||||
if e != nil {
|
||||
if os.IsNotExist(e) {
|
||||
if _, se := os.Stat(defaultPath); se == nil {
|
||||
c = BootstrapConfig{DatabasePath: defaultPath, Initialized: true}
|
||||
_ = writeBootstrap(a.bootstrapFile, c)
|
||||
} else {
|
||||
a.bootstrap = BootstrapStatus{State: BootstrapSetup, DefaultPath: defaultPath, DatabasePath: defaultPath}
|
||||
return
|
||||
}
|
||||
} else {
|
||||
a.bootstrap = BootstrapStatus{State: BootstrapRecovery, DefaultPath: defaultPath, DatabasePath: defaultPath, ErrorCode: "BOOTSTRAP_INVALID", ErrorDetail: e.Error()}
|
||||
return
|
||||
}
|
||||
}
|
||||
if _, e = os.Stat(c.DatabasePath); e != nil {
|
||||
code := "DB_FILE_UNREADABLE"
|
||||
if os.IsNotExist(e) {
|
||||
code = "DB_FILE_MISSING"
|
||||
}
|
||||
a.bootstrap = BootstrapStatus{State: BootstrapRecovery, DefaultPath: defaultPath, DatabasePath: c.DatabasePath, ErrorCode: code, ErrorDetail: e.Error()}
|
||||
return
|
||||
}
|
||||
s, e := OpenStore(c.DatabasePath)
|
||||
if e != nil {
|
||||
a.bootstrap = bootstrapFailure(defaultPath, c.DatabasePath, e)
|
||||
runtime.LogError(ctx, e.Error())
|
||||
return
|
||||
}
|
||||
a.store = s
|
||||
a.bootstrap = BootstrapStatus{State: BootstrapReady, DefaultPath: defaultPath, DatabasePath: c.DatabasePath}
|
||||
a.store.Log("info", "系统", "应用程序启动", "")
|
||||
a.store.Log("info", "数据库", "桌面运行时已连接", s.path)
|
||||
}
|
||||
|
||||
func (a *App) GetBootstrapStatus() BootstrapStatus { return a.bootstrap }
|
||||
func (a *App) SelectInitialDatabaseFile(defaultPath string) (string, error) {
|
||||
if strings.TrimSpace(defaultPath) == "" {
|
||||
defaultPath = a.bootstrap.DefaultPath
|
||||
}
|
||||
return runtime.SaveFileDialog(a.ctx, runtime.SaveDialogOptions{Title: "Initialize Code Count database", DefaultDirectory: filepath.Dir(defaultPath), DefaultFilename: filepath.Base(defaultPath), Filters: []runtime.FileFilter{{DisplayName: "SQLite Database", Pattern: "*.db"}}})
|
||||
}
|
||||
func (a *App) InitializeDatabase(path string) (BootstrapStatus, error) {
|
||||
a.mu.Lock()
|
||||
defer a.mu.Unlock()
|
||||
s, e := createValidatedStore(path)
|
||||
if e != nil {
|
||||
a.bootstrap = bootstrapFailure(a.bootstrap.DefaultPath, path, e)
|
||||
return a.bootstrap, e
|
||||
}
|
||||
if a.store != nil {
|
||||
_ = a.store.db.Close()
|
||||
}
|
||||
a.store = s
|
||||
if e = writeBootstrap(a.bootstrapFile, BootstrapConfig{DatabasePath: s.path, Initialized: true}); e != nil {
|
||||
_ = s.db.Close()
|
||||
a.store = nil
|
||||
a.bootstrap = bootstrapFailure(a.bootstrap.DefaultPath, path, coded("BOOTSTRAP_WRITE_FAILED", e))
|
||||
return a.bootstrap, e
|
||||
}
|
||||
a.bootstrap = BootstrapStatus{State: BootstrapReady, DefaultPath: a.bootstrap.DefaultPath, DatabasePath: s.path}
|
||||
a.store.Log("info", "数据库", "数据库初始化成功", s.path)
|
||||
return a.bootstrap, nil
|
||||
}
|
||||
func (a *App) RetryDatabase() (BootstrapStatus, error) {
|
||||
return a.InitializeDatabase(a.bootstrap.DatabasePath)
|
||||
}
|
||||
func (a *App) shutdown(context.Context) {
|
||||
if a.store != nil && a.store.db != nil {
|
||||
_ = a.store.db.Close()
|
||||
}
|
||||
}
|
||||
func (a *App) ready() error {
|
||||
if a.store == nil {
|
||||
return errors.New("DATABASE_NOT_READY")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (a *App) SelectDirectory() (string, error) {
|
||||
if e := a.ready(); e != nil {
|
||||
return "", e
|
||||
}
|
||||
return runtime.OpenDirectoryDialog(a.ctx, runtime.OpenDialogOptions{Title: a.localized("选择代码目录", "Select code directory")})
|
||||
}
|
||||
|
||||
// ListWSLDistros 返回本机可用的 WSL 发行版,供前端创建 UNC 项目路径。
|
||||
func (a *App) ListWSLDistros() ([]string, error) { return platform.ListWSLDistros(a.ctx) }
|
||||
|
||||
// SelectWSLDirectory 从指定发行版根目录打开原生目录选择器。
|
||||
func (a *App) SelectWSLDirectory(distro string) (string, error) {
|
||||
if strings.TrimSpace(distro) == "" {
|
||||
return "", errors.New("WSL_DISTRO_REQUIRED")
|
||||
}
|
||||
root := "\\\\wsl.localhost\\" + distro + "\\"
|
||||
return runtime.OpenDirectoryDialog(a.ctx, runtime.OpenDialogOptions{Title: a.localized("选择 WSL 代码目录", "Select WSL code directory"), DefaultDirectory: root})
|
||||
}
|
||||
|
||||
func (a *App) localized(zh, en string) string {
|
||||
if a.store != nil {
|
||||
if s, e := a.store.Settings(); e == nil && s.Locale == "en" {
|
||||
return en
|
||||
}
|
||||
}
|
||||
return zh
|
||||
}
|
||||
func (a *App) SelectDatabaseFile() (string, error) {
|
||||
return runtime.SaveFileDialog(a.ctx, runtime.SaveDialogOptions{Title: "Select database location", DefaultFilename: "code-count.db", Filters: []runtime.FileFilter{{DisplayName: "SQLite Database", Pattern: "*.db"}}})
|
||||
}
|
||||
func (a *App) ListProjects() ([]Project, error) {
|
||||
if e := a.ready(); e != nil {
|
||||
return nil, e
|
||||
}
|
||||
return a.store.ListProjects(0)
|
||||
}
|
||||
func (a *App) ListProjectsByGroup(groupID int64) ([]Project, error) {
|
||||
if e := a.ready(); e != nil {
|
||||
return nil, e
|
||||
}
|
||||
return a.store.ListProjects(groupID)
|
||||
}
|
||||
func (a *App) ListProjectGroups() ([]ProjectGroup, error) {
|
||||
if e := a.ready(); e != nil {
|
||||
return nil, e
|
||||
}
|
||||
return a.store.ListProjectGroups()
|
||||
}
|
||||
func (a *App) SaveProjectGroup(id int64, name string) (ProjectGroup, error) {
|
||||
if e := a.ready(); e != nil {
|
||||
return ProjectGroup{}, e
|
||||
}
|
||||
g, e := a.store.SaveProjectGroup(id, name)
|
||||
if e == nil {
|
||||
a.store.Log("info", "project", "Project group saved", g.Name)
|
||||
}
|
||||
return g, e
|
||||
}
|
||||
func (a *App) DeleteProjectGroup(id int64) error {
|
||||
if e := a.ready(); e != nil {
|
||||
return e
|
||||
}
|
||||
e := a.store.DeleteProjectGroup(id)
|
||||
if e == nil {
|
||||
a.store.Log("info", "project", "Project group deleted", fmt.Sprint(id))
|
||||
}
|
||||
return e
|
||||
}
|
||||
func (a *App) GetProject(id int64) (Project, error) {
|
||||
if e := a.ready(); e != nil {
|
||||
return Project{}, e
|
||||
}
|
||||
return a.store.GetProject(id)
|
||||
}
|
||||
func (a *App) SaveProject(id int64, in ProjectInput) (Project, error) {
|
||||
if e := a.ready(); e != nil {
|
||||
if a.runtimeReady {
|
||||
runtime.LogError(a.ctx, "SaveProject: "+e.Error())
|
||||
}
|
||||
return Project{}, e
|
||||
}
|
||||
p, e := a.store.SaveProject(id, in)
|
||||
if e == nil {
|
||||
a.store.Log("info", "项目", "项目保存成功", p.Path)
|
||||
if a.runtimeReady {
|
||||
runtime.LogInfo(a.ctx, "Project saved: "+p.Path)
|
||||
}
|
||||
} else {
|
||||
a.store.Log("error", "项目", "项目保存失败", in.Path+" | "+e.Error())
|
||||
if a.runtimeReady {
|
||||
runtime.LogError(a.ctx, "Project save failed: "+in.Path+" | "+e.Error())
|
||||
}
|
||||
}
|
||||
return p, e
|
||||
}
|
||||
|
||||
func (a *App) ReportClientError(category, message, detail string) {
|
||||
if a.store != nil {
|
||||
a.store.Log("error", category, message, detail)
|
||||
}
|
||||
if a.runtimeReady {
|
||||
runtime.LogError(a.ctx, category+": "+message+" | "+detail)
|
||||
}
|
||||
}
|
||||
func (a *App) DeleteProject(id int64) error {
|
||||
if e := a.ready(); e != nil {
|
||||
return e
|
||||
}
|
||||
e := a.store.DeleteProject(id)
|
||||
if e == nil {
|
||||
a.store.Log("info", "项目", "项目删除成功", fmt.Sprint(id))
|
||||
}
|
||||
return e
|
||||
}
|
||||
func (a *App) GetDashboard() (Dashboard, error) {
|
||||
if e := a.ready(); e != nil {
|
||||
return Dashboard{}, e
|
||||
}
|
||||
return a.store.Dashboard(0)
|
||||
}
|
||||
func (a *App) GetDashboardByGroup(groupID int64) (Dashboard, error) {
|
||||
if e := a.ready(); e != nil {
|
||||
return Dashboard{}, e
|
||||
}
|
||||
return a.store.Dashboard(groupID)
|
||||
}
|
||||
func (a *App) GetStructure(id int64) (StructureStats, error) {
|
||||
if e := a.ready(); e != nil {
|
||||
return StructureStats{}, e
|
||||
}
|
||||
return a.store.Structure(id)
|
||||
}
|
||||
|
||||
func (a *App) GetProjectInsights(id int64) (ProjectInsights, error) {
|
||||
if e := a.ready(); e != nil {
|
||||
return ProjectInsights{}, e
|
||||
}
|
||||
x, e := a.store.Insights(id)
|
||||
if e == nil {
|
||||
return x, nil
|
||||
}
|
||||
if errors.Is(e, sql.ErrNoRows) {
|
||||
return a.RefreshProjectInsights(id)
|
||||
}
|
||||
return ProjectInsights{}, e
|
||||
}
|
||||
|
||||
func (a *App) RefreshProjectInsights(id int64) (ProjectInsights, error) {
|
||||
if e := a.ready(); e != nil {
|
||||
return ProjectInsights{}, e
|
||||
}
|
||||
p, e := a.store.GetProject(id)
|
||||
if e != nil {
|
||||
return ProjectInsights{}, e
|
||||
}
|
||||
structure, e := a.store.Structure(id)
|
||||
if e != nil {
|
||||
return ProjectInsights{}, e
|
||||
}
|
||||
git, _ := a.store.GitStats(id)
|
||||
x, e := (service.InsightService{}).Analyze(a.ctx, p, structure, git)
|
||||
if e != nil {
|
||||
a.store.Log("error", "项目检查", "深度检查失败", p.Name+" | "+e.Error())
|
||||
return x, e
|
||||
}
|
||||
if e = a.store.ReplaceInsights(id, x); e != nil {
|
||||
a.store.Log("error", "项目检查", "保存检查结果失败", p.Name+" | "+e.Error())
|
||||
return x, e
|
||||
}
|
||||
a.store.Log("info", "项目检查", "深度检查完成", fmt.Sprintf("%s | %d 分 | %d 个问题", p.Name, x.HealthScore, len(x.Issues)))
|
||||
return x, nil
|
||||
}
|
||||
|
||||
func (a *App) GetGitStats(id int64) (GitStats, error) {
|
||||
if e := a.ready(); e != nil {
|
||||
return GitStats{}, e
|
||||
}
|
||||
return a.store.GitStats(id)
|
||||
}
|
||||
|
||||
// GetGitDiagnostics 分步检查 Git/WSL 状态,用于解释 Git 统计为空或失败的原因。
|
||||
func (a *App) GetGitDiagnostics(id int64) (GitDiagnostics, error) {
|
||||
if e := a.ready(); e != nil {
|
||||
return GitDiagnostics{}, e
|
||||
}
|
||||
p, e := a.store.GetProject(id)
|
||||
if e != nil {
|
||||
return GitDiagnostics{}, e
|
||||
}
|
||||
d := (GitAnalyzer{}).Diagnostics(a.ctx, p.Path, "")
|
||||
if d.Available {
|
||||
a.store.Log("info", "Git分析", "Git 诊断完成", p.Name+" | "+d.WorkspaceBranch)
|
||||
} else {
|
||||
a.store.Log("warning", "Git分析", "Git 诊断失败", p.Name+" | "+d.ErrorCode+" | "+d.Detail)
|
||||
}
|
||||
return d, nil
|
||||
}
|
||||
|
||||
// GetGitStatsForRef 只改变统计视图,不执行 checkout。
|
||||
func (a *App) GetGitStatsForRef(id int64, ref string) (GitStats, error) {
|
||||
p, e := a.store.GetProject(id)
|
||||
if e != nil {
|
||||
return GitStats{}, e
|
||||
}
|
||||
a.store.Log("info", "Git分析", "查询分支统计", p.Name+" | "+ref)
|
||||
g, e := (GitAnalyzer{}).AnalyzeRef(a.ctx, p.Path, ref)
|
||||
if e != nil {
|
||||
a.store.Log("error", "Git分析", "查询分支统计失败", e.Error())
|
||||
}
|
||||
return g, e
|
||||
}
|
||||
|
||||
// GetCommitDetails 按需查询提交涉及的文件,避免 Git 首页一次加载所有明细。
|
||||
func (a *App) GetCommitDetails(id int64, hash string) (GitCommitDetail, error) {
|
||||
p, e := a.store.GetProject(id)
|
||||
if e != nil {
|
||||
return GitCommitDetail{}, e
|
||||
}
|
||||
return (GitAnalyzer{}).CommitDetail(a.ctx, p.Path, hash)
|
||||
}
|
||||
|
||||
// CheckoutBranch 安全切换工作区分支;服务层会拒绝任何脏工作区。
|
||||
func (a *App) CheckoutBranch(id int64, ref string) (CheckoutResult, error) {
|
||||
p, e := a.store.GetProject(id)
|
||||
if e != nil {
|
||||
return CheckoutResult{}, e
|
||||
}
|
||||
result, e := (GitAnalyzer{}).CheckoutBranch(a.ctx, p.Path, ref)
|
||||
if e != nil {
|
||||
a.store.Log("error", "Git分析", "切换分支失败", p.Name+" | "+ref+" | "+e.Error())
|
||||
return result, e
|
||||
}
|
||||
a.store.Log("info", "Git分析", "切换分支成功", p.Name+" | "+result.Branch)
|
||||
return result, nil
|
||||
}
|
||||
func (a *App) GetRules() ([]ExclusionRule, error) {
|
||||
if e := a.ready(); e != nil {
|
||||
return nil, e
|
||||
}
|
||||
return a.store.Rules()
|
||||
}
|
||||
func (a *App) AddRule(pattern, category string) (ExclusionRule, error) {
|
||||
if e := a.ready(); e != nil {
|
||||
return ExclusionRule{}, e
|
||||
}
|
||||
return a.store.AddRule(pattern, category)
|
||||
}
|
||||
func (a *App) DeleteRule(id int64) error {
|
||||
if e := a.ready(); e != nil {
|
||||
return e
|
||||
}
|
||||
return a.store.DeleteRule(id)
|
||||
}
|
||||
func (a *App) GetLogs(level string) ([]LogEntry, error) {
|
||||
if e := a.ready(); e != nil {
|
||||
return nil, e
|
||||
}
|
||||
return a.store.Logs(level)
|
||||
}
|
||||
func (a *App) ClearLogs() error {
|
||||
if e := a.ready(); e != nil {
|
||||
return e
|
||||
}
|
||||
return a.store.ClearLogs()
|
||||
}
|
||||
func (a *App) GetSettings() (AppSettings, error) {
|
||||
if e := a.ready(); e != nil {
|
||||
return AppSettings{}, e
|
||||
}
|
||||
return a.store.Settings()
|
||||
}
|
||||
func (a *App) SaveSettings(x AppSettings) error {
|
||||
if e := a.ready(); e != nil {
|
||||
return e
|
||||
}
|
||||
return a.store.SaveSettings(x)
|
||||
}
|
||||
func (a *App) ClearData(mode string, projectID int64) error {
|
||||
if e := a.ready(); e != nil {
|
||||
return e
|
||||
}
|
||||
return a.store.ClearData(mode, projectID)
|
||||
}
|
||||
|
||||
func (a *App) MigrateDatabase(target string) error {
|
||||
if e := a.ready(); e != nil {
|
||||
return e
|
||||
}
|
||||
if target == "" {
|
||||
return errors.New("PATH_REQUIRED")
|
||||
}
|
||||
target = filepath.Clean(target)
|
||||
if target == a.store.path {
|
||||
return nil
|
||||
}
|
||||
if e := os.MkdirAll(filepath.Dir(target), 0755); e != nil {
|
||||
return e
|
||||
}
|
||||
tmp := target + ".tmp"
|
||||
_ = os.Remove(tmp)
|
||||
_, _ = a.store.db.Exec(`PRAGMA wal_checkpoint(FULL)`)
|
||||
src, e := os.Open(a.store.path)
|
||||
if e != nil {
|
||||
return e
|
||||
}
|
||||
defer src.Close()
|
||||
dst, e := os.Create(tmp)
|
||||
if e != nil {
|
||||
return e
|
||||
}
|
||||
if _, e = dst.ReadFrom(src); e != nil {
|
||||
dst.Close()
|
||||
os.Remove(tmp)
|
||||
return e
|
||||
}
|
||||
_ = dst.Sync()
|
||||
dst.Close()
|
||||
check, e := OpenStore(tmp)
|
||||
if e != nil {
|
||||
os.Remove(tmp)
|
||||
return e
|
||||
}
|
||||
var result string
|
||||
e = check.db.QueryRow(`PRAGMA integrity_check`).Scan(&result)
|
||||
check.db.Close()
|
||||
if e != nil || result != "ok" {
|
||||
os.Remove(tmp)
|
||||
return errors.New("DATABASE_INTEGRITY_FAILED")
|
||||
}
|
||||
if e = os.Rename(tmp, target); e != nil {
|
||||
return e
|
||||
}
|
||||
next, e := OpenStore(target)
|
||||
if e != nil {
|
||||
return e
|
||||
}
|
||||
old := a.store
|
||||
a.store = next
|
||||
_ = old.db.Close()
|
||||
if e = writeBootstrap(a.bootstrapFile, BootstrapConfig{DatabasePath: target, Initialized: true}); e != nil {
|
||||
return coded("BOOTSTRAP_WRITE_FAILED", e)
|
||||
}
|
||||
a.bootstrap = BootstrapStatus{State: BootstrapReady, DefaultPath: a.bootstrap.DefaultPath, DatabasePath: target}
|
||||
a.store.Log("info", "数据库", "数据库迁移成功", target)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *App) StartAnalysis(projectID int64, kind string) (string, error) {
|
||||
if e := a.ready(); e != nil {
|
||||
return "", e
|
||||
}
|
||||
p, e := a.store.GetProject(projectID)
|
||||
if e != nil {
|
||||
return "", e
|
||||
}
|
||||
taskID := fmt.Sprintf("%d-%s", projectID, kind)
|
||||
a.mu.Lock()
|
||||
if _, ok := a.tasks[taskID]; ok {
|
||||
a.mu.Unlock()
|
||||
return "", errors.New("TASK_ALREADY_RUNNING")
|
||||
}
|
||||
ctx, cancel := context.WithCancel(a.ctx)
|
||||
a.tasks[taskID] = cancel
|
||||
a.mu.Unlock()
|
||||
go func() {
|
||||
defer func() {
|
||||
if recovered := recover(); recovered != nil {
|
||||
detail := fmt.Sprintf("%v", recovered)
|
||||
a.store.Log("error", "代码分析", "后台分析异常", p.Name+" | "+detail)
|
||||
runtime.EventsEmit(a.ctx, "analysis:progress", TaskEvent{TaskID: taskID, ProjectID: projectID, Stage: "error", Progress: 100, MessageKey: "task.failed", Params: map[string]any{"project": p.Name}})
|
||||
}
|
||||
a.mu.Lock()
|
||||
delete(a.tasks, taskID)
|
||||
a.mu.Unlock()
|
||||
}()
|
||||
emit := func(stage string, progress int, messageKey string) {
|
||||
runtime.EventsEmit(a.ctx, "analysis:progress", TaskEvent{TaskID: taskID, ProjectID: projectID, Stage: stage, Progress: progress, MessageKey: messageKey, Params: map[string]any{"project": p.Name}})
|
||||
}
|
||||
emit("start", 2, "task.start")
|
||||
a.store.Log("info", "代码分析", "开始分析项目", p.Name)
|
||||
var err error
|
||||
if kind == "all" || kind == "code" {
|
||||
rules, _ := a.store.Rules()
|
||||
var ls []LanguageStat
|
||||
var fs []FileEntry
|
||||
ls, fs, err = (Scanner{}).Analyze(ctx, p.Path, rules, func(n int, s string) { emit(s, n, s) })
|
||||
if err == nil {
|
||||
err = a.store.ReplaceScan(projectID, ls, fs)
|
||||
}
|
||||
}
|
||||
if err == nil && (kind == "all" || kind == "git") {
|
||||
emit("git", 80, "task.git")
|
||||
var g GitStats
|
||||
g, err = (GitAnalyzer{}).Analyze(ctx, p.Path)
|
||||
if err == nil {
|
||||
err = a.store.ReplaceGit(projectID, g)
|
||||
} else if kind == "all" && (err.Error() == "NOT_GIT_REPOSITORY" || err.Error() == "GIT_NOT_INSTALLED") {
|
||||
a.store.Log("warning", "Git分析", "已跳过 Git 分析", err.Error())
|
||||
err = nil
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
level, stage := "error", "error"
|
||||
if errors.Is(err, context.Canceled) {
|
||||
level, stage = "warning", "cancelled"
|
||||
}
|
||||
a.store.Log(level, "代码分析", "项目分析失败", p.Name+" | "+err.Error())
|
||||
emit(stage, 100, "task.failed")
|
||||
return
|
||||
}
|
||||
a.store.Log("info", "代码分析", "项目分析完成", p.Name)
|
||||
emit("completed", 100, "task.completed")
|
||||
}()
|
||||
return taskID, nil
|
||||
}
|
||||
func (a *App) CancelAnalysis(taskID string) error {
|
||||
a.mu.Lock()
|
||||
defer a.mu.Unlock()
|
||||
if c, ok := a.tasks[taskID]; ok {
|
||||
c()
|
||||
return nil
|
||||
}
|
||||
return errors.New("TASK_NOT_FOUND")
|
||||
}
|
||||
func (a *App) StartBatchAnalysis() ([]string, error) {
|
||||
return a.StartBatchAnalysisByGroup(0)
|
||||
}
|
||||
func (a *App) StartBatchAnalysisByGroup(groupID int64) ([]string, error) {
|
||||
ps, e := a.store.ListProjects(groupID)
|
||||
if e != nil {
|
||||
return nil, e
|
||||
}
|
||||
ids := make([]string, 0, len(ps))
|
||||
for _, p := range ps {
|
||||
ids = append(ids, fmt.Sprintf("%d-all", p.ID))
|
||||
}
|
||||
go func() {
|
||||
for _, p := range ps {
|
||||
tid, e := a.StartAnalysis(p.ID, "all")
|
||||
if e != nil {
|
||||
continue
|
||||
}
|
||||
for {
|
||||
a.mu.Lock()
|
||||
_, running := a.tasks[tid]
|
||||
a.mu.Unlock()
|
||||
if !running {
|
||||
break
|
||||
}
|
||||
select {
|
||||
case <-a.ctx.Done():
|
||||
return
|
||||
case <-time.After(100 * time.Millisecond):
|
||||
}
|
||||
}
|
||||
}
|
||||
}()
|
||||
return ids, nil
|
||||
}
|
||||
59
app_test.go
Normal file
@@ -0,0 +1,59 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestAppSaveProjectWritesProjectAndLog(t *testing.T) {
|
||||
s, e := OpenStore(filepath.Join(t.TempDir(), "app.db"))
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
defer s.db.Close()
|
||||
a := &App{ctx: context.Background(), store: s, tasks: map[string]context.CancelFunc{}}
|
||||
dir := t.TempDir()
|
||||
p, e := a.SaveProject(0, ProjectInput{Name: "saved", Path: dir})
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
if p.Path != dir {
|
||||
t.Fatalf("path=%q", p.Path)
|
||||
}
|
||||
projects, e := s.ListProjects(0)
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
if len(projects) != 1 {
|
||||
t.Fatalf("projects=%d", len(projects))
|
||||
}
|
||||
logs, e := s.Logs("all")
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
if len(logs) == 0 || logs[0].Message != "项目保存成功" {
|
||||
t.Fatalf("missing save log: %#v", logs)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAppSaveProjectFailureIsLogged(t *testing.T) {
|
||||
s, e := OpenStore(filepath.Join(t.TempDir(), "app.db"))
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
defer s.db.Close()
|
||||
a := &App{ctx: context.Background(), store: s, tasks: map[string]context.CancelFunc{}}
|
||||
_, e = a.SaveProject(0, ProjectInput{Name: "missing", Path: filepath.Join(t.TempDir(), "missing")})
|
||||
if e == nil {
|
||||
t.Fatal("invalid project saved")
|
||||
}
|
||||
logs, e := s.Logs("error")
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
if len(logs) == 0 || !strings.Contains(logs[0].Detail, "PROJECT_PATH_NOT_FOUND") {
|
||||
t.Fatalf("missing failure log: %#v", logs)
|
||||
}
|
||||
}
|
||||
138
bootstrap.go
Normal file
@@ -0,0 +1,138 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const (
|
||||
BootstrapReady = "ready"
|
||||
BootstrapSetup = "setup_required"
|
||||
BootstrapRecovery = "recovery_required"
|
||||
)
|
||||
|
||||
type BootstrapConfig struct {
|
||||
DatabasePath string `json:"databasePath"`
|
||||
Initialized bool `json:"initialized"`
|
||||
}
|
||||
|
||||
type BootstrapStatus struct {
|
||||
State string `json:"state"`
|
||||
DatabasePath string `json:"databasePath"`
|
||||
DefaultPath string `json:"defaultPath"`
|
||||
ErrorCode string `json:"errorCode,omitempty"`
|
||||
ErrorDetail string `json:"errorDetail,omitempty"`
|
||||
}
|
||||
|
||||
type CodedError struct{ Code, Detail string }
|
||||
|
||||
func (e *CodedError) Error() string {
|
||||
if e.Detail == "" {
|
||||
return e.Code
|
||||
}
|
||||
return e.Code + ": " + e.Detail
|
||||
}
|
||||
func coded(code string, err error) error {
|
||||
if err == nil {
|
||||
return &CodedError{Code: code}
|
||||
}
|
||||
return &CodedError{Code: code, Detail: err.Error()}
|
||||
}
|
||||
|
||||
func bootstrapPath() (string, error) {
|
||||
d, e := os.UserConfigDir()
|
||||
if e != nil {
|
||||
return "", e
|
||||
}
|
||||
return filepath.Join(d, "CodeCount", "bootstrap.json"), nil
|
||||
}
|
||||
func readBootstrap(path string) (BootstrapConfig, error) {
|
||||
b, e := os.ReadFile(path)
|
||||
if e != nil {
|
||||
return BootstrapConfig{}, e
|
||||
}
|
||||
var c BootstrapConfig
|
||||
if e = json.Unmarshal(b, &c); e != nil {
|
||||
return c, e
|
||||
}
|
||||
if !c.Initialized || strings.TrimSpace(c.DatabasePath) == "" {
|
||||
return c, errors.New("invalid bootstrap configuration")
|
||||
}
|
||||
return c, nil
|
||||
}
|
||||
func writeBootstrap(path string, c BootstrapConfig) error {
|
||||
if e := os.MkdirAll(filepath.Dir(path), 0755); e != nil {
|
||||
return e
|
||||
}
|
||||
b, e := json.MarshalIndent(c, "", " ")
|
||||
if e != nil {
|
||||
return e
|
||||
}
|
||||
tmp := path + ".tmp"
|
||||
if e = os.WriteFile(tmp, b, 0600); e != nil {
|
||||
return e
|
||||
}
|
||||
if e = os.Rename(tmp, path); e != nil {
|
||||
_ = os.Remove(tmp)
|
||||
return e
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func createValidatedStore(target string) (*Store, error) {
|
||||
target = filepath.Clean(strings.TrimSpace(target))
|
||||
if target == "" {
|
||||
return nil, coded("DB_PATH_REQUIRED", nil)
|
||||
}
|
||||
dir := filepath.Dir(target)
|
||||
if e := os.MkdirAll(dir, 0755); e != nil {
|
||||
return nil, coded("DB_DIRECTORY_UNWRITABLE", e)
|
||||
}
|
||||
probe := filepath.Join(dir, ".code-count-write-test")
|
||||
if e := os.WriteFile(probe, []byte("ok"), 0600); e != nil {
|
||||
return nil, coded("DB_DIRECTORY_UNWRITABLE", e)
|
||||
}
|
||||
_ = os.Remove(probe)
|
||||
if _, e := os.Stat(target); e == nil {
|
||||
return OpenStore(target)
|
||||
} else if !os.IsNotExist(e) {
|
||||
return nil, coded("DB_FILE_UNREADABLE", e)
|
||||
}
|
||||
tmp := target + ".initializing"
|
||||
_ = os.Remove(tmp)
|
||||
_ = os.Remove(tmp + "-wal")
|
||||
_ = os.Remove(tmp + "-shm")
|
||||
s, e := OpenStore(tmp)
|
||||
if e != nil {
|
||||
return nil, coded("DB_INITIALIZE_FAILED", e)
|
||||
}
|
||||
var result string
|
||||
e = s.db.QueryRow(`PRAGMA integrity_check`).Scan(&result)
|
||||
_ = s.db.Close()
|
||||
if e != nil || result != "ok" {
|
||||
_ = os.Remove(tmp)
|
||||
return nil, coded("DB_INTEGRITY_FAILED", e)
|
||||
}
|
||||
if e = os.Rename(tmp, target); e != nil {
|
||||
_ = os.Remove(tmp)
|
||||
return nil, coded("DB_INITIALIZE_FAILED", e)
|
||||
}
|
||||
s, e = OpenStore(target)
|
||||
if e != nil {
|
||||
return nil, coded("DB_OPEN_FAILED", e)
|
||||
}
|
||||
return s, nil
|
||||
}
|
||||
|
||||
func bootstrapFailure(defaultPath, path string, e error) BootstrapStatus {
|
||||
code := "DB_OPEN_FAILED"
|
||||
var ce *CodedError
|
||||
if errors.As(e, &ce) {
|
||||
code = ce.Code
|
||||
}
|
||||
return BootstrapStatus{State: BootstrapRecovery, DatabasePath: path, DefaultPath: defaultPath, ErrorCode: code, ErrorDetail: fmt.Sprint(e)}
|
||||
}
|
||||
54
bootstrap_test.go
Normal file
@@ -0,0 +1,54 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestBootstrapRoundTrip(t *testing.T) {
|
||||
p := filepath.Join(t.TempDir(), "bootstrap.json")
|
||||
want := BootstrapConfig{DatabasePath: filepath.Join(t.TempDir(), "data.db"), Initialized: true}
|
||||
if e := writeBootstrap(p, want); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
got, e := readBootstrap(p)
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
if got != want {
|
||||
t.Fatalf("got %#v want %#v", got, want)
|
||||
}
|
||||
}
|
||||
func TestInvalidBootstrap(t *testing.T) {
|
||||
p := filepath.Join(t.TempDir(), "bootstrap.json")
|
||||
if e := os.WriteFile(p, []byte("{"), 0600); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
if _, e := readBootstrap(p); e == nil {
|
||||
t.Fatal("invalid bootstrap accepted")
|
||||
}
|
||||
}
|
||||
func TestCreateValidatedStore(t *testing.T) {
|
||||
p := filepath.Join(t.TempDir(), "nested", "code-count.db")
|
||||
s, e := createValidatedStore(p)
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
defer s.db.Close()
|
||||
if _, e = os.Stat(p); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
var result string
|
||||
if e = s.db.QueryRow(`PRAGMA integrity_check`).Scan(&result); e != nil || result != "ok" {
|
||||
t.Fatalf("integrity: %q %v", result, e)
|
||||
}
|
||||
if _, e = os.Stat(p + ".initializing"); !os.IsNotExist(e) {
|
||||
t.Fatal("temporary database remains")
|
||||
}
|
||||
}
|
||||
func TestCreateValidatedStoreRejectsEmptyPath(t *testing.T) {
|
||||
if _, e := createValidatedStore(""); e == nil {
|
||||
t.Fatal("empty path accepted")
|
||||
}
|
||||
}
|
||||
BIN
browser-blocked.png
Normal file
|
After Width: | Height: | Size: 51 KiB |
35
build/README.md
Normal file
@@ -0,0 +1,35 @@
|
||||
# Build Directory
|
||||
|
||||
The build directory is used to house all the build files and assets for your application.
|
||||
|
||||
The structure is:
|
||||
|
||||
* bin - Output directory
|
||||
* darwin - macOS specific files
|
||||
* windows - Windows specific files
|
||||
|
||||
## Mac
|
||||
|
||||
The `darwin` directory holds files specific to Mac builds.
|
||||
These may be customised and used as part of the build. To return these files to the default state, simply delete them
|
||||
and
|
||||
build with `wails build`.
|
||||
|
||||
The directory contains the following files:
|
||||
|
||||
- `Info.plist` - the main plist file used for Mac builds. It is used when building using `wails build`.
|
||||
- `Info.dev.plist` - same as the main plist file but used when building using `wails dev`.
|
||||
|
||||
## Windows
|
||||
|
||||
The `windows` directory contains the manifest and rc files used when building with `wails build`.
|
||||
These may be customised for your application. To return these files to the default state, simply delete them and
|
||||
build with `wails build`.
|
||||
|
||||
- `icon.ico` - The icon used for the application. This is used when building using `wails build`. If you wish to
|
||||
use a different icon, simply replace this file with your own. If it is missing, a new `icon.ico` file
|
||||
will be created using the `appicon.png` file in the build directory.
|
||||
- `installer/*` - The files used to create the Windows installer. These are used when building using `wails build`.
|
||||
- `info.json` - Application details used for Windows builds. The data here will be used by the Windows installer,
|
||||
as well as the application itself (right click the exe -> properties -> details)
|
||||
- `wails.exe.manifest` - The main application manifest file.
|
||||
BIN
build/appicon.png
Normal file
|
After Width: | Height: | Size: 130 KiB |
BIN
build/bin.rar
Normal file
68
build/darwin/Info.dev.plist
Normal file
@@ -0,0 +1,68 @@
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>APPL</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>{{.Info.ProductName}}</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>{{.OutputFilename}}</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>com.wails.{{.Name}}</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>{{.Info.ProductVersion}}</string>
|
||||
<key>CFBundleGetInfoString</key>
|
||||
<string>{{.Info.Comments}}</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>{{.Info.ProductVersion}}</string>
|
||||
<key>CFBundleIconFile</key>
|
||||
<string>iconfile</string>
|
||||
<key>LSMinimumSystemVersion</key>
|
||||
<string>10.13.0</string>
|
||||
<key>NSHighResolutionCapable</key>
|
||||
<string>true</string>
|
||||
<key>NSHumanReadableCopyright</key>
|
||||
<string>{{.Info.Copyright}}</string>
|
||||
{{if .Info.FileAssociations}}
|
||||
<key>CFBundleDocumentTypes</key>
|
||||
<array>
|
||||
{{range .Info.FileAssociations}}
|
||||
<dict>
|
||||
<key>CFBundleTypeExtensions</key>
|
||||
<array>
|
||||
<string>{{.Ext}}</string>
|
||||
</array>
|
||||
<key>CFBundleTypeName</key>
|
||||
<string>{{.Name}}</string>
|
||||
<key>CFBundleTypeRole</key>
|
||||
<string>{{.Role}}</string>
|
||||
<key>CFBundleTypeIconFile</key>
|
||||
<string>{{.IconName}}</string>
|
||||
</dict>
|
||||
{{end}}
|
||||
</array>
|
||||
{{end}}
|
||||
{{if .Info.Protocols}}
|
||||
<key>CFBundleURLTypes</key>
|
||||
<array>
|
||||
{{range .Info.Protocols}}
|
||||
<dict>
|
||||
<key>CFBundleURLName</key>
|
||||
<string>com.wails.{{.Scheme}}</string>
|
||||
<key>CFBundleURLSchemes</key>
|
||||
<array>
|
||||
<string>{{.Scheme}}</string>
|
||||
</array>
|
||||
<key>CFBundleTypeRole</key>
|
||||
<string>{{.Role}}</string>
|
||||
</dict>
|
||||
{{end}}
|
||||
</array>
|
||||
{{end}}
|
||||
<key>NSAppTransportSecurity</key>
|
||||
<dict>
|
||||
<key>NSAllowsLocalNetworking</key>
|
||||
<true/>
|
||||
</dict>
|
||||
</dict>
|
||||
</plist>
|
||||
63
build/darwin/Info.plist
Normal file
@@ -0,0 +1,63 @@
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>APPL</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>{{.Info.ProductName}}</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>{{.OutputFilename}}</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>com.wails.{{.Name}}</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>{{.Info.ProductVersion}}</string>
|
||||
<key>CFBundleGetInfoString</key>
|
||||
<string>{{.Info.Comments}}</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>{{.Info.ProductVersion}}</string>
|
||||
<key>CFBundleIconFile</key>
|
||||
<string>iconfile</string>
|
||||
<key>LSMinimumSystemVersion</key>
|
||||
<string>10.13.0</string>
|
||||
<key>NSHighResolutionCapable</key>
|
||||
<string>true</string>
|
||||
<key>NSHumanReadableCopyright</key>
|
||||
<string>{{.Info.Copyright}}</string>
|
||||
{{if .Info.FileAssociations}}
|
||||
<key>CFBundleDocumentTypes</key>
|
||||
<array>
|
||||
{{range .Info.FileAssociations}}
|
||||
<dict>
|
||||
<key>CFBundleTypeExtensions</key>
|
||||
<array>
|
||||
<string>{{.Ext}}</string>
|
||||
</array>
|
||||
<key>CFBundleTypeName</key>
|
||||
<string>{{.Name}}</string>
|
||||
<key>CFBundleTypeRole</key>
|
||||
<string>{{.Role}}</string>
|
||||
<key>CFBundleTypeIconFile</key>
|
||||
<string>{{.IconName}}</string>
|
||||
</dict>
|
||||
{{end}}
|
||||
</array>
|
||||
{{end}}
|
||||
{{if .Info.Protocols}}
|
||||
<key>CFBundleURLTypes</key>
|
||||
<array>
|
||||
{{range .Info.Protocols}}
|
||||
<dict>
|
||||
<key>CFBundleURLName</key>
|
||||
<string>com.wails.{{.Scheme}}</string>
|
||||
<key>CFBundleURLSchemes</key>
|
||||
<array>
|
||||
<string>{{.Scheme}}</string>
|
||||
</array>
|
||||
<key>CFBundleTypeRole</key>
|
||||
<string>{{.Role}}</string>
|
||||
</dict>
|
||||
{{end}}
|
||||
</array>
|
||||
{{end}}
|
||||
</dict>
|
||||
</plist>
|
||||
BIN
build/windows/icon.ico
Normal file
|
After Width: | Height: | Size: 20 KiB |
15
build/windows/info.json
Normal file
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"fixed": {
|
||||
"file_version": "{{.Info.ProductVersion}}"
|
||||
},
|
||||
"info": {
|
||||
"0000": {
|
||||
"ProductVersion": "{{.Info.ProductVersion}}",
|
||||
"CompanyName": "{{.Info.CompanyName}}",
|
||||
"FileDescription": "{{.Info.ProductName}}",
|
||||
"LegalCopyright": "{{.Info.Copyright}}",
|
||||
"ProductName": "{{.Info.ProductName}}",
|
||||
"Comments": "{{.Info.Comments}}"
|
||||
}
|
||||
}
|
||||
}
|
||||
114
build/windows/installer/project.nsi
Normal file
@@ -0,0 +1,114 @@
|
||||
Unicode true
|
||||
|
||||
####
|
||||
## Please note: Template replacements don't work in this file. They are provided with default defines like
|
||||
## mentioned underneath.
|
||||
## If the keyword is not defined, "wails_tools.nsh" will populate them with the values from ProjectInfo.
|
||||
## If they are defined here, "wails_tools.nsh" will not touch them. This allows to use this project.nsi manually
|
||||
## from outside of Wails for debugging and development of the installer.
|
||||
##
|
||||
## For development first make a wails nsis build to populate the "wails_tools.nsh":
|
||||
## > wails build --target windows/amd64 --nsis
|
||||
## Then you can call makensis on this file with specifying the path to your binary:
|
||||
## For a AMD64 only installer:
|
||||
## > makensis -DARG_WAILS_AMD64_BINARY=..\..\bin\app.exe
|
||||
## For a ARM64 only installer:
|
||||
## > makensis -DARG_WAILS_ARM64_BINARY=..\..\bin\app.exe
|
||||
## For a installer with both architectures:
|
||||
## > makensis -DARG_WAILS_AMD64_BINARY=..\..\bin\app-amd64.exe -DARG_WAILS_ARM64_BINARY=..\..\bin\app-arm64.exe
|
||||
####
|
||||
## The following information is taken from the ProjectInfo file, but they can be overwritten here.
|
||||
####
|
||||
## !define INFO_PROJECTNAME "MyProject" # Default "{{.Name}}"
|
||||
## !define INFO_COMPANYNAME "MyCompany" # Default "{{.Info.CompanyName}}"
|
||||
## !define INFO_PRODUCTNAME "MyProduct" # Default "{{.Info.ProductName}}"
|
||||
## !define INFO_PRODUCTVERSION "1.0.0" # Default "{{.Info.ProductVersion}}"
|
||||
## !define INFO_COPYRIGHT "Copyright" # Default "{{.Info.Copyright}}"
|
||||
###
|
||||
## !define PRODUCT_EXECUTABLE "Application.exe" # Default "${INFO_PROJECTNAME}.exe"
|
||||
## !define UNINST_KEY_NAME "UninstKeyInRegistry" # Default "${INFO_COMPANYNAME}${INFO_PRODUCTNAME}"
|
||||
####
|
||||
## !define REQUEST_EXECUTION_LEVEL "admin" # Default "admin" see also https://nsis.sourceforge.io/Docs/Chapter4.html
|
||||
####
|
||||
## Include the wails tools
|
||||
####
|
||||
!include "wails_tools.nsh"
|
||||
|
||||
# The version information for this two must consist of 4 parts
|
||||
VIProductVersion "${INFO_PRODUCTVERSION}.0"
|
||||
VIFileVersion "${INFO_PRODUCTVERSION}.0"
|
||||
|
||||
VIAddVersionKey "CompanyName" "${INFO_COMPANYNAME}"
|
||||
VIAddVersionKey "FileDescription" "${INFO_PRODUCTNAME} Installer"
|
||||
VIAddVersionKey "ProductVersion" "${INFO_PRODUCTVERSION}"
|
||||
VIAddVersionKey "FileVersion" "${INFO_PRODUCTVERSION}"
|
||||
VIAddVersionKey "LegalCopyright" "${INFO_COPYRIGHT}"
|
||||
VIAddVersionKey "ProductName" "${INFO_PRODUCTNAME}"
|
||||
|
||||
# Enable HiDPI support. https://nsis.sourceforge.io/Reference/ManifestDPIAware
|
||||
ManifestDPIAware true
|
||||
|
||||
!include "MUI.nsh"
|
||||
|
||||
!define MUI_ICON "..\icon.ico"
|
||||
!define MUI_UNICON "..\icon.ico"
|
||||
# !define MUI_WELCOMEFINISHPAGE_BITMAP "resources\leftimage.bmp" #Include this to add a bitmap on the left side of the Welcome Page. Must be a size of 164x314
|
||||
!define MUI_FINISHPAGE_NOAUTOCLOSE # Wait on the INSTFILES page so the user can take a look into the details of the installation steps
|
||||
!define MUI_ABORTWARNING # This will warn the user if they exit from the installer.
|
||||
|
||||
!insertmacro MUI_PAGE_WELCOME # Welcome to the installer page.
|
||||
# !insertmacro MUI_PAGE_LICENSE "resources\eula.txt" # Adds a EULA page to the installer
|
||||
!insertmacro MUI_PAGE_DIRECTORY # In which folder install page.
|
||||
!insertmacro MUI_PAGE_INSTFILES # Installing page.
|
||||
!insertmacro MUI_PAGE_FINISH # Finished installation page.
|
||||
|
||||
!insertmacro MUI_UNPAGE_INSTFILES # Uinstalling page
|
||||
|
||||
!insertmacro MUI_LANGUAGE "English" # Set the Language of the installer
|
||||
|
||||
## The following two statements can be used to sign the installer and the uninstaller. The path to the binaries are provided in %1
|
||||
#!uninstfinalize 'signtool --file "%1"'
|
||||
#!finalize 'signtool --file "%1"'
|
||||
|
||||
Name "${INFO_PRODUCTNAME}"
|
||||
OutFile "..\..\bin\${INFO_PROJECTNAME}-${ARCH}-installer.exe" # Name of the installer's file.
|
||||
InstallDir "$PROGRAMFILES64\${INFO_COMPANYNAME}\${INFO_PRODUCTNAME}" # Default installing folder ($PROGRAMFILES is Program Files folder).
|
||||
ShowInstDetails show # This will always show the installation details.
|
||||
|
||||
Function .onInit
|
||||
!insertmacro wails.checkArchitecture
|
||||
FunctionEnd
|
||||
|
||||
Section
|
||||
!insertmacro wails.setShellContext
|
||||
|
||||
!insertmacro wails.webview2runtime
|
||||
|
||||
SetOutPath $INSTDIR
|
||||
|
||||
!insertmacro wails.files
|
||||
|
||||
CreateShortcut "$SMPROGRAMS\${INFO_PRODUCTNAME}.lnk" "$INSTDIR\${PRODUCT_EXECUTABLE}"
|
||||
CreateShortCut "$DESKTOP\${INFO_PRODUCTNAME}.lnk" "$INSTDIR\${PRODUCT_EXECUTABLE}"
|
||||
|
||||
!insertmacro wails.associateFiles
|
||||
!insertmacro wails.associateCustomProtocols
|
||||
|
||||
!insertmacro wails.writeUninstaller
|
||||
SectionEnd
|
||||
|
||||
Section "uninstall"
|
||||
!insertmacro wails.setShellContext
|
||||
|
||||
RMDir /r "$AppData\${PRODUCT_EXECUTABLE}" # Remove the WebView2 DataPath
|
||||
|
||||
RMDir /r $INSTDIR
|
||||
|
||||
Delete "$SMPROGRAMS\${INFO_PRODUCTNAME}.lnk"
|
||||
Delete "$DESKTOP\${INFO_PRODUCTNAME}.lnk"
|
||||
|
||||
!insertmacro wails.unassociateFiles
|
||||
!insertmacro wails.unassociateCustomProtocols
|
||||
|
||||
!insertmacro wails.deleteUninstaller
|
||||
SectionEnd
|
||||
249
build/windows/installer/wails_tools.nsh
Normal file
@@ -0,0 +1,249 @@
|
||||
# DO NOT EDIT - Generated automatically by `wails build`
|
||||
|
||||
!include "x64.nsh"
|
||||
!include "WinVer.nsh"
|
||||
!include "FileFunc.nsh"
|
||||
|
||||
!ifndef INFO_PROJECTNAME
|
||||
!define INFO_PROJECTNAME "{{.Name}}"
|
||||
!endif
|
||||
!ifndef INFO_COMPANYNAME
|
||||
!define INFO_COMPANYNAME "{{.Info.CompanyName}}"
|
||||
!endif
|
||||
!ifndef INFO_PRODUCTNAME
|
||||
!define INFO_PRODUCTNAME "{{.Info.ProductName}}"
|
||||
!endif
|
||||
!ifndef INFO_PRODUCTVERSION
|
||||
!define INFO_PRODUCTVERSION "{{.Info.ProductVersion}}"
|
||||
!endif
|
||||
!ifndef INFO_COPYRIGHT
|
||||
!define INFO_COPYRIGHT "{{.Info.Copyright}}"
|
||||
!endif
|
||||
!ifndef PRODUCT_EXECUTABLE
|
||||
!define PRODUCT_EXECUTABLE "${INFO_PROJECTNAME}.exe"
|
||||
!endif
|
||||
!ifndef UNINST_KEY_NAME
|
||||
!define UNINST_KEY_NAME "${INFO_COMPANYNAME}${INFO_PRODUCTNAME}"
|
||||
!endif
|
||||
!define UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${UNINST_KEY_NAME}"
|
||||
|
||||
!ifndef REQUEST_EXECUTION_LEVEL
|
||||
!define REQUEST_EXECUTION_LEVEL "admin"
|
||||
!endif
|
||||
|
||||
RequestExecutionLevel "${REQUEST_EXECUTION_LEVEL}"
|
||||
|
||||
!ifdef ARG_WAILS_AMD64_BINARY
|
||||
!define SUPPORTS_AMD64
|
||||
!endif
|
||||
|
||||
!ifdef ARG_WAILS_ARM64_BINARY
|
||||
!define SUPPORTS_ARM64
|
||||
!endif
|
||||
|
||||
!ifdef SUPPORTS_AMD64
|
||||
!ifdef SUPPORTS_ARM64
|
||||
!define ARCH "amd64_arm64"
|
||||
!else
|
||||
!define ARCH "amd64"
|
||||
!endif
|
||||
!else
|
||||
!ifdef SUPPORTS_ARM64
|
||||
!define ARCH "arm64"
|
||||
!else
|
||||
!error "Wails: Undefined ARCH, please provide at least one of ARG_WAILS_AMD64_BINARY or ARG_WAILS_ARM64_BINARY"
|
||||
!endif
|
||||
!endif
|
||||
|
||||
!macro wails.checkArchitecture
|
||||
!ifndef WAILS_WIN10_REQUIRED
|
||||
!define WAILS_WIN10_REQUIRED "This product is only supported on Windows 10 (Server 2016) and later."
|
||||
!endif
|
||||
|
||||
!ifndef WAILS_ARCHITECTURE_NOT_SUPPORTED
|
||||
!define WAILS_ARCHITECTURE_NOT_SUPPORTED "This product can't be installed on the current Windows architecture. Supports: ${ARCH}"
|
||||
!endif
|
||||
|
||||
${If} ${AtLeastWin10}
|
||||
!ifdef SUPPORTS_AMD64
|
||||
${if} ${IsNativeAMD64}
|
||||
Goto ok
|
||||
${EndIf}
|
||||
!endif
|
||||
|
||||
!ifdef SUPPORTS_ARM64
|
||||
${if} ${IsNativeARM64}
|
||||
Goto ok
|
||||
${EndIf}
|
||||
!endif
|
||||
|
||||
IfSilent silentArch notSilentArch
|
||||
silentArch:
|
||||
SetErrorLevel 65
|
||||
Abort
|
||||
notSilentArch:
|
||||
MessageBox MB_OK "${WAILS_ARCHITECTURE_NOT_SUPPORTED}"
|
||||
Quit
|
||||
${else}
|
||||
IfSilent silentWin notSilentWin
|
||||
silentWin:
|
||||
SetErrorLevel 64
|
||||
Abort
|
||||
notSilentWin:
|
||||
MessageBox MB_OK "${WAILS_WIN10_REQUIRED}"
|
||||
Quit
|
||||
${EndIf}
|
||||
|
||||
ok:
|
||||
!macroend
|
||||
|
||||
!macro wails.files
|
||||
!ifdef SUPPORTS_AMD64
|
||||
${if} ${IsNativeAMD64}
|
||||
File "/oname=${PRODUCT_EXECUTABLE}" "${ARG_WAILS_AMD64_BINARY}"
|
||||
${EndIf}
|
||||
!endif
|
||||
|
||||
!ifdef SUPPORTS_ARM64
|
||||
${if} ${IsNativeARM64}
|
||||
File "/oname=${PRODUCT_EXECUTABLE}" "${ARG_WAILS_ARM64_BINARY}"
|
||||
${EndIf}
|
||||
!endif
|
||||
!macroend
|
||||
|
||||
!macro wails.writeUninstaller
|
||||
WriteUninstaller "$INSTDIR\uninstall.exe"
|
||||
|
||||
SetRegView 64
|
||||
WriteRegStr HKLM "${UNINST_KEY}" "Publisher" "${INFO_COMPANYNAME}"
|
||||
WriteRegStr HKLM "${UNINST_KEY}" "DisplayName" "${INFO_PRODUCTNAME}"
|
||||
WriteRegStr HKLM "${UNINST_KEY}" "DisplayVersion" "${INFO_PRODUCTVERSION}"
|
||||
WriteRegStr HKLM "${UNINST_KEY}" "DisplayIcon" "$INSTDIR\${PRODUCT_EXECUTABLE}"
|
||||
WriteRegStr HKLM "${UNINST_KEY}" "UninstallString" "$\"$INSTDIR\uninstall.exe$\""
|
||||
WriteRegStr HKLM "${UNINST_KEY}" "QuietUninstallString" "$\"$INSTDIR\uninstall.exe$\" /S"
|
||||
|
||||
${GetSize} "$INSTDIR" "/S=0K" $0 $1 $2
|
||||
IntFmt $0 "0x%08X" $0
|
||||
WriteRegDWORD HKLM "${UNINST_KEY}" "EstimatedSize" "$0"
|
||||
!macroend
|
||||
|
||||
!macro wails.deleteUninstaller
|
||||
Delete "$INSTDIR\uninstall.exe"
|
||||
|
||||
SetRegView 64
|
||||
DeleteRegKey HKLM "${UNINST_KEY}"
|
||||
!macroend
|
||||
|
||||
!macro wails.setShellContext
|
||||
${If} ${REQUEST_EXECUTION_LEVEL} == "admin"
|
||||
SetShellVarContext all
|
||||
${else}
|
||||
SetShellVarContext current
|
||||
${EndIf}
|
||||
!macroend
|
||||
|
||||
# Install webview2 by launching the bootstrapper
|
||||
# See https://docs.microsoft.com/en-us/microsoft-edge/webview2/concepts/distribution#online-only-deployment
|
||||
!macro wails.webview2runtime
|
||||
!ifndef WAILS_INSTALL_WEBVIEW_DETAILPRINT
|
||||
!define WAILS_INSTALL_WEBVIEW_DETAILPRINT "Installing: WebView2 Runtime"
|
||||
!endif
|
||||
|
||||
SetRegView 64
|
||||
# If the admin key exists and is not empty then webview2 is already installed
|
||||
ReadRegStr $0 HKLM "SOFTWARE\WOW6432Node\Microsoft\EdgeUpdate\Clients\{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}" "pv"
|
||||
${If} $0 != ""
|
||||
Goto ok
|
||||
${EndIf}
|
||||
|
||||
${If} ${REQUEST_EXECUTION_LEVEL} == "user"
|
||||
# If the installer is run in user level, check the user specific key exists and is not empty then webview2 is already installed
|
||||
ReadRegStr $0 HKCU "Software\Microsoft\EdgeUpdate\Clients\{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}" "pv"
|
||||
${If} $0 != ""
|
||||
Goto ok
|
||||
${EndIf}
|
||||
${EndIf}
|
||||
|
||||
SetDetailsPrint both
|
||||
DetailPrint "${WAILS_INSTALL_WEBVIEW_DETAILPRINT}"
|
||||
SetDetailsPrint listonly
|
||||
|
||||
InitPluginsDir
|
||||
CreateDirectory "$pluginsdir\webview2bootstrapper"
|
||||
SetOutPath "$pluginsdir\webview2bootstrapper"
|
||||
File "tmp\MicrosoftEdgeWebview2Setup.exe"
|
||||
ExecWait '"$pluginsdir\webview2bootstrapper\MicrosoftEdgeWebview2Setup.exe" /silent /install'
|
||||
|
||||
SetDetailsPrint both
|
||||
ok:
|
||||
!macroend
|
||||
|
||||
# Copy of APP_ASSOCIATE and APP_UNASSOCIATE macros from here https://gist.github.com/nikku/281d0ef126dbc215dd58bfd5b3a5cd5b
|
||||
!macro APP_ASSOCIATE EXT FILECLASS DESCRIPTION ICON COMMANDTEXT COMMAND
|
||||
; Backup the previously associated file class
|
||||
ReadRegStr $R0 SHELL_CONTEXT "Software\Classes\.${EXT}" ""
|
||||
WriteRegStr SHELL_CONTEXT "Software\Classes\.${EXT}" "${FILECLASS}_backup" "$R0"
|
||||
|
||||
WriteRegStr SHELL_CONTEXT "Software\Classes\.${EXT}" "" "${FILECLASS}"
|
||||
|
||||
WriteRegStr SHELL_CONTEXT "Software\Classes\${FILECLASS}" "" `${DESCRIPTION}`
|
||||
WriteRegStr SHELL_CONTEXT "Software\Classes\${FILECLASS}\DefaultIcon" "" `${ICON}`
|
||||
WriteRegStr SHELL_CONTEXT "Software\Classes\${FILECLASS}\shell" "" "open"
|
||||
WriteRegStr SHELL_CONTEXT "Software\Classes\${FILECLASS}\shell\open" "" `${COMMANDTEXT}`
|
||||
WriteRegStr SHELL_CONTEXT "Software\Classes\${FILECLASS}\shell\open\command" "" `${COMMAND}`
|
||||
!macroend
|
||||
|
||||
!macro APP_UNASSOCIATE EXT FILECLASS
|
||||
; Backup the previously associated file class
|
||||
ReadRegStr $R0 SHELL_CONTEXT "Software\Classes\.${EXT}" `${FILECLASS}_backup`
|
||||
WriteRegStr SHELL_CONTEXT "Software\Classes\.${EXT}" "" "$R0"
|
||||
|
||||
DeleteRegKey SHELL_CONTEXT `Software\Classes\${FILECLASS}`
|
||||
!macroend
|
||||
|
||||
!macro wails.associateFiles
|
||||
; Create file associations
|
||||
{{range .Info.FileAssociations}}
|
||||
!insertmacro APP_ASSOCIATE "{{.Ext}}" "{{.Name}}" "{{.Description}}" "$INSTDIR\{{.IconName}}.ico" "Open with ${INFO_PRODUCTNAME}" "$INSTDIR\${PRODUCT_EXECUTABLE} $\"%1$\""
|
||||
|
||||
File "..\{{.IconName}}.ico"
|
||||
{{end}}
|
||||
!macroend
|
||||
|
||||
!macro wails.unassociateFiles
|
||||
; Delete app associations
|
||||
{{range .Info.FileAssociations}}
|
||||
!insertmacro APP_UNASSOCIATE "{{.Ext}}" "{{.Name}}"
|
||||
|
||||
Delete "$INSTDIR\{{.IconName}}.ico"
|
||||
{{end}}
|
||||
!macroend
|
||||
|
||||
!macro CUSTOM_PROTOCOL_ASSOCIATE PROTOCOL DESCRIPTION ICON COMMAND
|
||||
DeleteRegKey SHELL_CONTEXT "Software\Classes\${PROTOCOL}"
|
||||
WriteRegStr SHELL_CONTEXT "Software\Classes\${PROTOCOL}" "" "${DESCRIPTION}"
|
||||
WriteRegStr SHELL_CONTEXT "Software\Classes\${PROTOCOL}" "URL Protocol" ""
|
||||
WriteRegStr SHELL_CONTEXT "Software\Classes\${PROTOCOL}\DefaultIcon" "" "${ICON}"
|
||||
WriteRegStr SHELL_CONTEXT "Software\Classes\${PROTOCOL}\shell" "" ""
|
||||
WriteRegStr SHELL_CONTEXT "Software\Classes\${PROTOCOL}\shell\open" "" ""
|
||||
WriteRegStr SHELL_CONTEXT "Software\Classes\${PROTOCOL}\shell\open\command" "" "${COMMAND}"
|
||||
!macroend
|
||||
|
||||
!macro CUSTOM_PROTOCOL_UNASSOCIATE PROTOCOL
|
||||
DeleteRegKey SHELL_CONTEXT "Software\Classes\${PROTOCOL}"
|
||||
!macroend
|
||||
|
||||
!macro wails.associateCustomProtocols
|
||||
; Create custom protocols associations
|
||||
{{range .Info.Protocols}}
|
||||
!insertmacro CUSTOM_PROTOCOL_ASSOCIATE "{{.Scheme}}" "{{.Description}}" "$INSTDIR\${PRODUCT_EXECUTABLE},0" "$INSTDIR\${PRODUCT_EXECUTABLE} $\"%1$\""
|
||||
|
||||
{{end}}
|
||||
!macroend
|
||||
|
||||
!macro wails.unassociateCustomProtocols
|
||||
; Delete app custom protocol associations
|
||||
{{range .Info.Protocols}}
|
||||
!insertmacro CUSTOM_PROTOCOL_UNASSOCIATE "{{.Scheme}}"
|
||||
{{end}}
|
||||
!macroend
|
||||
15
build/windows/wails.exe.manifest
Normal file
@@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3">
|
||||
<assemblyIdentity type="win32" name="com.wails.{{.Name}}" version="{{.Info.ProductVersion}}.0" processorArchitecture="*"/>
|
||||
<dependency>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" processorArchitecture="*" publicKeyToken="6595b64144ccf1df" language="*"/>
|
||||
</dependentAssembly>
|
||||
</dependency>
|
||||
<asmv3:application>
|
||||
<asmv3:windowsSettings>
|
||||
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true/pm</dpiAware> <!-- fallback for Windows 7 and 8 -->
|
||||
<dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">permonitorv2,permonitor</dpiAwareness> <!-- falls back to per-monitor if per-monitor v2 is not supported -->
|
||||
</asmv3:windowsSettings>
|
||||
</asmv3:application>
|
||||
</assembly>
|
||||
BIN
dashboard-1024.png
Normal file
|
After Width: | Height: | Size: 73 KiB |
BIN
dashboard-glass.png
Normal file
|
After Width: | Height: | Size: 498 KiB |
BIN
dashboard-v2.png
Normal file
|
After Width: | Height: | Size: 411 KiB |
BIN
dashboard.png
Normal file
|
After Width: | Height: | Size: 101 KiB |
BIN
database-settings.png
Normal file
|
After Width: | Height: | Size: 343 KiB |
BIN
database-setup.png
Normal file
|
After Width: | Height: | Size: 262 KiB |
739
database.go
Normal file
@@ -0,0 +1,739 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
_ "modernc.org/sqlite"
|
||||
)
|
||||
|
||||
type Store struct {
|
||||
mu sync.RWMutex
|
||||
db *sql.DB
|
||||
path string
|
||||
}
|
||||
|
||||
func defaultDBPath() (string, error) {
|
||||
dir, err := os.UserConfigDir()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
dir = filepath.Join(dir, "CodeCount")
|
||||
if err = os.MkdirAll(dir, 0755); err != nil {
|
||||
return "", err
|
||||
}
|
||||
return filepath.Join(dir, "code-count.db"), nil
|
||||
}
|
||||
|
||||
func OpenStore(path string) (*Store, error) {
|
||||
if path == "" {
|
||||
var err error
|
||||
path, err = defaultDBPath()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if err := os.MkdirAll(filepath.Dir(path), 0755); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
db, err := sql.Open("sqlite", path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
db.SetMaxOpenConns(1)
|
||||
s := &Store{db: db, path: path}
|
||||
if err = s.migrate(); err != nil {
|
||||
db.Close()
|
||||
return nil, err
|
||||
}
|
||||
return s, nil
|
||||
}
|
||||
|
||||
func (s *Store) migrate() error {
|
||||
stmts := []string{
|
||||
`PRAGMA journal_mode=WAL`, `PRAGMA foreign_keys=ON`,
|
||||
`CREATE TABLE IF NOT EXISTS schema_migrations(version INTEGER PRIMARY KEY, applied_at TEXT NOT NULL)`,
|
||||
`CREATE TABLE IF NOT EXISTS settings(key TEXT PRIMARY KEY, value TEXT NOT NULL)`,
|
||||
`CREATE TABLE IF NOT EXISTS project_groups(id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT NOT NULL UNIQUE, created_at TEXT NOT NULL, updated_at TEXT NOT NULL)`,
|
||||
`CREATE TABLE IF NOT EXISTS projects(id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT NOT NULL, path TEXT NOT NULL UNIQUE, description TEXT NOT NULL DEFAULT '', group_id INTEGER NOT NULL DEFAULT 1, created_at TEXT NOT NULL, updated_at TEXT NOT NULL)`,
|
||||
`CREATE TABLE IF NOT EXISTS analysis_runs(id INTEGER PRIMARY KEY AUTOINCREMENT, project_id INTEGER NOT NULL, kind TEXT NOT NULL, status TEXT NOT NULL, started_at TEXT NOT NULL, completed_at TEXT, error TEXT, FOREIGN KEY(project_id) REFERENCES projects(id) ON DELETE CASCADE)`,
|
||||
`CREATE TABLE IF NOT EXISTS language_stats(project_id INTEGER NOT NULL, name TEXT NOT NULL, files INTEGER NOT NULL, code INTEGER NOT NULL, comments INTEGER NOT NULL, blanks INTEGER NOT NULL, PRIMARY KEY(project_id,name), FOREIGN KEY(project_id) REFERENCES projects(id) ON DELETE CASCADE)`,
|
||||
`CREATE TABLE IF NOT EXISTS file_entries(project_id INTEGER NOT NULL, path TEXT NOT NULL, name TEXT NOT NULL, extension TEXT NOT NULL, size INTEGER NOT NULL, is_dir INTEGER NOT NULL, parent TEXT NOT NULL, PRIMARY KEY(project_id,path), FOREIGN KEY(project_id) REFERENCES projects(id) ON DELETE CASCADE)`,
|
||||
`CREATE TABLE IF NOT EXISTS git_commits(project_id INTEGER NOT NULL, hash TEXT NOT NULL, author TEXT NOT NULL, email TEXT NOT NULL, message TEXT NOT NULL, committed_at TEXT NOT NULL, added INTEGER NOT NULL, deleted INTEGER NOT NULL, PRIMARY KEY(project_id,hash), FOREIGN KEY(project_id) REFERENCES projects(id) ON DELETE CASCADE)`,
|
||||
`CREATE TABLE IF NOT EXISTS git_refs(project_id INTEGER NOT NULL, name TEXT NOT NULL, hash TEXT NOT NULL, kind TEXT NOT NULL, is_current INTEGER NOT NULL, PRIMARY KEY(project_id,name), FOREIGN KEY(project_id) REFERENCES projects(id) ON DELETE CASCADE)`,
|
||||
`CREATE TABLE IF NOT EXISTS commit_refs(project_id INTEGER NOT NULL, commit_hash TEXT NOT NULL, ref_name TEXT NOT NULL, PRIMARY KEY(project_id,commit_hash,ref_name), FOREIGN KEY(project_id) REFERENCES projects(id) ON DELETE CASCADE)`,
|
||||
`CREATE TABLE IF NOT EXISTS contributors(project_id INTEGER NOT NULL, email TEXT NOT NULL, name TEXT NOT NULL, commits INTEGER NOT NULL, added INTEGER NOT NULL, deleted INTEGER NOT NULL, PRIMARY KEY(project_id,email), FOREIGN KEY(project_id) REFERENCES projects(id) ON DELETE CASCADE)`,
|
||||
`CREATE TABLE IF NOT EXISTS project_insights(project_id INTEGER PRIMARY KEY, health_score INTEGER NOT NULL, generated_at TEXT NOT NULL, high INTEGER NOT NULL, medium INTEGER NOT NULL, low INTEGER NOT NULL, todo_count INTEGER NOT NULL, long_files INTEGER NOT NULL, large_files INTEGER NOT NULL, FOREIGN KEY(project_id) REFERENCES projects(id) ON DELETE CASCADE)`,
|
||||
`CREATE TABLE IF NOT EXISTS insight_issues(project_id INTEGER NOT NULL, idx INTEGER NOT NULL, severity TEXT NOT NULL, type TEXT NOT NULL, title TEXT NOT NULL, detail TEXT NOT NULL, path TEXT NOT NULL DEFAULT '', line INTEGER NOT NULL DEFAULT 0, suggestion TEXT NOT NULL DEFAULT '', evidence TEXT NOT NULL DEFAULT '', PRIMARY KEY(project_id,idx), FOREIGN KEY(project_id) REFERENCES projects(id) ON DELETE CASCADE)`,
|
||||
`CREATE TABLE IF NOT EXISTS exclusion_rules(id INTEGER PRIMARY KEY AUTOINCREMENT, pattern TEXT NOT NULL UNIQUE, category TEXT NOT NULL, builtin INTEGER NOT NULL DEFAULT 0)`,
|
||||
`CREATE TABLE IF NOT EXISTS app_logs(id INTEGER PRIMARY KEY AUTOINCREMENT, level TEXT NOT NULL, category TEXT NOT NULL, message TEXT NOT NULL, detail TEXT NOT NULL DEFAULT '', created_at TEXT NOT NULL)`,
|
||||
}
|
||||
for _, q := range stmts {
|
||||
if _, err := s.db.Exec(q); err != nil {
|
||||
return fmt.Errorf("database migration: %w", err)
|
||||
}
|
||||
}
|
||||
if ok, err := s.columnExists("projects", "group_id"); err != nil {
|
||||
return err
|
||||
} else if !ok {
|
||||
if _, err = s.db.Exec(`ALTER TABLE projects ADD COLUMN group_id INTEGER NOT NULL DEFAULT 1`); err != nil {
|
||||
return fmt.Errorf("database migration: %w", err)
|
||||
}
|
||||
}
|
||||
_, _ = s.db.Exec(`INSERT OR IGNORE INTO project_groups(id,name,created_at,updated_at) VALUES(1,'My Projects',?,?)`, time.Now().Format(time.RFC3339), time.Now().Format(time.RFC3339))
|
||||
_, _ = s.db.Exec(`UPDATE projects SET group_id=1 WHERE group_id IS NULL OR group_id=0`)
|
||||
defaults := map[string][]string{"general": {".git", ".idea", ".vscode", "node_modules", "dist", "coverage", "*.min.js", "*.min.css", ".DS_Store"}, "php": {"vendor", "storage/framework", "bootstrap/cache", ".phpunit.cache"}, "go": {"go.sum"}, "vue": {".nuxt", ".next", ".output", "unpackage"}}
|
||||
for category, patterns := range defaults {
|
||||
for _, p := range patterns {
|
||||
_, _ = s.db.Exec(`INSERT OR IGNORE INTO exclusion_rules(pattern,category,builtin) VALUES(?,?,1)`, p, category)
|
||||
}
|
||||
}
|
||||
_, _ = s.db.Exec(`INSERT OR IGNORE INTO settings(key,value) VALUES('theme','dark'),('locale','zh-CN'),('gitScope','current'),('autoRefresh','true'),('glassOpacity','55'),('loadingStyle','fullscreen-orbit')`)
|
||||
_, _ = s.db.Exec(`UPDATE settings SET value='fullscreen-orbit' WHERE key='loadingStyle' AND value IN ('bar','fullscreen') AND NOT EXISTS(SELECT 1 FROM settings WHERE key='loadingStyleSet' AND value='true')`)
|
||||
_, _ = s.db.Exec(`INSERT OR IGNORE INTO schema_migrations(version,applied_at) VALUES(1,?)`, time.Now().Format(time.RFC3339))
|
||||
// 旧版本曾写入英文日志;迁移时转换已知固定文案,Git 提交消息等用户内容不做修改。
|
||||
translations := map[string]string{"Application started": "应用程序启动", "Desktop runtime connected": "桌面运行时已连接", "Project saved": "项目保存成功", "Project save failed": "项目保存失败", "Project deleted": "项目删除成功", "Analysis completed": "项目分析完成", "Analysis failed": "项目分析失败", "Database initialized": "数据库初始化成功", "Database migrated": "数据库迁移成功"}
|
||||
for en, zh := range translations {
|
||||
_, _ = s.db.Exec(`UPDATE app_logs SET message=? WHERE message=?`, zh, en)
|
||||
}
|
||||
_, _ = s.db.Exec(`UPDATE app_logs SET category='系统' WHERE category='system'`)
|
||||
_, _ = s.db.Exec(`UPDATE app_logs SET category='数据库' WHERE category='database'`)
|
||||
_, _ = s.db.Exec(`UPDATE app_logs SET category='项目' WHERE category='project'`)
|
||||
_, _ = s.db.Exec(`UPDATE app_logs SET category='代码分析' WHERE category='analysis'`)
|
||||
_, _ = s.db.Exec(`UPDATE app_logs SET category='Git分析' WHERE category='git'`)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Store) columnExists(table, column string) (bool, error) {
|
||||
rows, err := s.db.Query(`PRAGMA table_info(` + table + `)`)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
defer rows.Close()
|
||||
for rows.Next() {
|
||||
var cid int
|
||||
var name, typ string
|
||||
var notNull, pk int
|
||||
var dflt sql.NullString
|
||||
if err = rows.Scan(&cid, &name, &typ, ¬Null, &dflt, &pk); err != nil {
|
||||
return false, err
|
||||
}
|
||||
if name == column {
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
return false, rows.Err()
|
||||
}
|
||||
|
||||
func normalizePath(p string) (string, error) {
|
||||
p = strings.TrimSpace(p)
|
||||
if p == "" {
|
||||
return "", errors.New("PATH_REQUIRED")
|
||||
}
|
||||
a, e := filepath.Abs(p)
|
||||
if e != nil {
|
||||
return "", e
|
||||
}
|
||||
a = filepath.Clean(a)
|
||||
if st, e := os.Stat(a); e != nil {
|
||||
if os.IsNotExist(e) {
|
||||
return "", coded("PROJECT_PATH_NOT_FOUND", e)
|
||||
}
|
||||
return "", coded("PROJECT_PATH_UNREADABLE", e)
|
||||
} else if !st.IsDir() {
|
||||
return "", coded("PROJECT_PATH_NOT_DIRECTORY", nil)
|
||||
}
|
||||
d, e := os.Open(a)
|
||||
if e != nil {
|
||||
return "", coded("PROJECT_PATH_UNREADABLE", e)
|
||||
}
|
||||
_, e = d.Readdirnames(1)
|
||||
_ = d.Close()
|
||||
if e != nil && !errors.Is(e, io.EOF) {
|
||||
return "", coded("PROJECT_PATH_UNREADABLE", e)
|
||||
}
|
||||
return a, nil
|
||||
}
|
||||
func now() string { return time.Now().Format(time.RFC3339) }
|
||||
|
||||
func (s *Store) ListProjectGroups() ([]ProjectGroup, error) {
|
||||
rows, e := s.db.Query(`SELECT id,name,created_at,updated_at FROM project_groups ORDER BY id=1 DESC, name COLLATE NOCASE`)
|
||||
if e != nil {
|
||||
return nil, e
|
||||
}
|
||||
defer rows.Close()
|
||||
out := []ProjectGroup{}
|
||||
for rows.Next() {
|
||||
var g ProjectGroup
|
||||
if e = rows.Scan(&g.ID, &g.Name, &g.CreatedAt, &g.UpdatedAt); e != nil {
|
||||
return nil, e
|
||||
}
|
||||
out = append(out, g)
|
||||
}
|
||||
return out, rows.Err()
|
||||
}
|
||||
func (s *Store) SaveProjectGroup(id int64, name string) (ProjectGroup, error) {
|
||||
name = strings.TrimSpace(name)
|
||||
if name == "" {
|
||||
return ProjectGroup{}, errors.New("PROJECT_GROUP_NAME_REQUIRED")
|
||||
}
|
||||
t := now()
|
||||
if id == 0 {
|
||||
r, e := s.db.Exec(`INSERT INTO project_groups(name,created_at,updated_at) VALUES(?,?,?)`, name, t, t)
|
||||
if e != nil {
|
||||
if strings.Contains(strings.ToLower(e.Error()), "unique") {
|
||||
return ProjectGroup{}, errors.New("PROJECT_GROUP_DUPLICATE")
|
||||
}
|
||||
return ProjectGroup{}, e
|
||||
}
|
||||
id, _ = r.LastInsertId()
|
||||
} else {
|
||||
if id == 1 {
|
||||
return ProjectGroup{}, errors.New("PROJECT_GROUP_DEFAULT_READONLY")
|
||||
}
|
||||
_, e := s.db.Exec(`UPDATE project_groups SET name=?,updated_at=? WHERE id=?`, name, t, id)
|
||||
if e != nil {
|
||||
if strings.Contains(strings.ToLower(e.Error()), "unique") {
|
||||
return ProjectGroup{}, errors.New("PROJECT_GROUP_DUPLICATE")
|
||||
}
|
||||
return ProjectGroup{}, e
|
||||
}
|
||||
}
|
||||
var g ProjectGroup
|
||||
e := s.db.QueryRow(`SELECT id,name,created_at,updated_at FROM project_groups WHERE id=?`, id).Scan(&g.ID, &g.Name, &g.CreatedAt, &g.UpdatedAt)
|
||||
return g, e
|
||||
}
|
||||
func (s *Store) DeleteProjectGroup(id int64) error {
|
||||
if id == 1 {
|
||||
return errors.New("PROJECT_GROUP_DEFAULT_READONLY")
|
||||
}
|
||||
tx, e := s.db.Begin()
|
||||
if e != nil {
|
||||
return e
|
||||
}
|
||||
defer tx.Rollback()
|
||||
if _, e = tx.Exec(`UPDATE projects SET group_id=1,updated_at=? WHERE group_id=?`, now(), id); e != nil {
|
||||
return e
|
||||
}
|
||||
if _, e = tx.Exec(`DELETE FROM project_groups WHERE id=?`, id); e != nil {
|
||||
return e
|
||||
}
|
||||
return tx.Commit()
|
||||
}
|
||||
func (s *Store) ListProjects(groupID int64) ([]Project, error) {
|
||||
q := `SELECT p.id,p.name,p.path,p.description,p.group_id,COALESCE(g.name,''),p.created_at,p.updated_at FROM projects p LEFT JOIN project_groups g ON g.id=p.group_id`
|
||||
args := []any{}
|
||||
if groupID > 0 {
|
||||
q += ` WHERE p.group_id=?`
|
||||
args = append(args, groupID)
|
||||
}
|
||||
q += ` ORDER BY p.updated_at DESC`
|
||||
rows, e := s.db.Query(q, args...)
|
||||
if e != nil {
|
||||
return nil, e
|
||||
}
|
||||
out := []Project{}
|
||||
for rows.Next() {
|
||||
var p Project
|
||||
if e = rows.Scan(&p.ID, &p.Name, &p.Path, &p.Description, &p.GroupID, &p.GroupName, &p.CreatedAt, &p.UpdatedAt); e != nil {
|
||||
rows.Close()
|
||||
return nil, e
|
||||
}
|
||||
out = append(out, p)
|
||||
}
|
||||
if e = rows.Err(); e != nil {
|
||||
rows.Close()
|
||||
return nil, e
|
||||
}
|
||||
if e = rows.Close(); e != nil {
|
||||
return nil, e
|
||||
}
|
||||
for i := range out {
|
||||
out[i].Stats, _ = s.projectStats(out[i].ID)
|
||||
out[i].Languages, _ = s.languages(out[i].ID)
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
func (s *Store) GetProject(id int64) (Project, error) {
|
||||
var p Project
|
||||
e := s.db.QueryRow(`SELECT p.id,p.name,p.path,p.description,p.group_id,COALESCE(g.name,''),p.created_at,p.updated_at FROM projects p LEFT JOIN project_groups g ON g.id=p.group_id WHERE p.id=?`, id).Scan(&p.ID, &p.Name, &p.Path, &p.Description, &p.GroupID, &p.GroupName, &p.CreatedAt, &p.UpdatedAt)
|
||||
if e != nil {
|
||||
return p, e
|
||||
}
|
||||
p.Stats, _ = s.projectStats(id)
|
||||
p.Languages, _ = s.languages(id)
|
||||
return p, nil
|
||||
}
|
||||
func (s *Store) SaveProject(id int64, in ProjectInput) (Project, error) {
|
||||
p, e := normalizePath(in.Path)
|
||||
if e != nil {
|
||||
return Project{}, e
|
||||
}
|
||||
name := strings.TrimSpace(in.Name)
|
||||
if name == "" {
|
||||
name = filepath.Base(p)
|
||||
}
|
||||
groupID := in.GroupID
|
||||
if groupID <= 0 {
|
||||
groupID = 1
|
||||
}
|
||||
var exists int
|
||||
if e = s.db.QueryRow(`SELECT COUNT(*) FROM project_groups WHERE id=?`, groupID).Scan(&exists); e != nil {
|
||||
return Project{}, e
|
||||
}
|
||||
if exists == 0 {
|
||||
return Project{}, errors.New("PROJECT_GROUP_NOT_FOUND")
|
||||
}
|
||||
t := now()
|
||||
if id == 0 {
|
||||
r, e := s.db.Exec(`INSERT INTO projects(name,path,description,group_id,created_at,updated_at) VALUES(?,?,?,?,?,?)`, name, p, in.Description, groupID, t, t)
|
||||
if e != nil {
|
||||
if strings.Contains(strings.ToLower(e.Error()), "unique") {
|
||||
return Project{}, coded("PROJECT_PATH_DUPLICATE", e)
|
||||
}
|
||||
return Project{}, coded("PROJECT_SAVE_FAILED", e)
|
||||
}
|
||||
id, _ = r.LastInsertId()
|
||||
} else {
|
||||
_, e = s.db.Exec(`UPDATE projects SET name=?,path=?,description=?,group_id=?,updated_at=? WHERE id=?`, name, p, in.Description, groupID, t, id)
|
||||
if e != nil {
|
||||
return Project{}, e
|
||||
}
|
||||
}
|
||||
return s.GetProject(id)
|
||||
}
|
||||
func (s *Store) DeleteProject(id int64) error {
|
||||
_, e := s.db.Exec(`DELETE FROM projects WHERE id=?`, id)
|
||||
return e
|
||||
}
|
||||
func (s *Store) projectStats(id int64) (ProjectStats, error) {
|
||||
var x ProjectStats
|
||||
e := s.db.QueryRow(`SELECT COALESCE(SUM(code+comments+blanks),0),COALESCE(SUM(code),0),COALESCE(SUM(comments),0),COALESCE(SUM(blanks),0),COALESCE(SUM(files),0) FROM language_stats WHERE project_id=?`, id).Scan(&x.TotalLines, &x.CodeLines, &x.CommentLines, &x.BlankLines, &x.FileCount)
|
||||
if e != nil {
|
||||
return x, e
|
||||
}
|
||||
_ = s.db.QueryRow(`SELECT COUNT(*),COALESCE(SUM(added),0),COALESCE(SUM(deleted),0),COUNT(DISTINCT email) FROM git_commits WHERE project_id=?`, id).Scan(&x.CommitCount, &x.AddedLines, &x.DeletedLines, &x.ContributorCount)
|
||||
_ = s.db.QueryRow(`SELECT COALESCE(MAX(completed_at),'') FROM analysis_runs WHERE project_id=? AND status='completed'`, id).Scan(&x.LastAnalyzed)
|
||||
return x, nil
|
||||
}
|
||||
func (s *Store) languages(id int64) ([]LanguageStat, error) {
|
||||
r, e := s.db.Query(`SELECT name,files,code,comments,blanks FROM language_stats WHERE project_id=? ORDER BY code DESC`, id)
|
||||
if e != nil {
|
||||
return nil, e
|
||||
}
|
||||
defer r.Close()
|
||||
o := []LanguageStat{}
|
||||
for r.Next() {
|
||||
var x LanguageStat
|
||||
if e = r.Scan(&x.Name, &x.Files, &x.Code, &x.Comments, &x.Blanks); e != nil {
|
||||
return nil, e
|
||||
}
|
||||
o = append(o, x)
|
||||
}
|
||||
return o, r.Err()
|
||||
}
|
||||
func (s *Store) Dashboard(groupID int64) (Dashboard, error) {
|
||||
var d Dashboard
|
||||
if groupID > 0 {
|
||||
e := s.db.QueryRow(`SELECT COUNT(*),COALESCE((SELECT SUM(ls.code+ls.comments+ls.blanks) FROM language_stats ls JOIN projects p ON p.id=ls.project_id WHERE p.group_id=?),0),COALESCE((SELECT COUNT(*) FROM git_commits gc JOIN projects p ON p.id=gc.project_id WHERE p.group_id=?),0) FROM projects WHERE group_id=?`, groupID, groupID, groupID).Scan(&d.Projects, &d.TotalLines, &d.Commits)
|
||||
return d, e
|
||||
}
|
||||
e := s.db.QueryRow(`SELECT COUNT(*),COALESCE((SELECT SUM(code+comments+blanks) FROM language_stats),0),COALESCE((SELECT COUNT(*) FROM git_commits),0) FROM projects`).Scan(&d.Projects, &d.TotalLines, &d.Commits)
|
||||
return d, e
|
||||
}
|
||||
|
||||
func (s *Store) ReplaceScan(id int64, langs []LanguageStat, files []FileEntry) error {
|
||||
tx, e := s.db.Begin()
|
||||
if e != nil {
|
||||
return e
|
||||
}
|
||||
defer tx.Rollback()
|
||||
if _, e = tx.Exec(`DELETE FROM language_stats WHERE project_id=?`, id); e != nil {
|
||||
return e
|
||||
}
|
||||
if _, e = tx.Exec(`DELETE FROM file_entries WHERE project_id=?`, id); e != nil {
|
||||
return e
|
||||
}
|
||||
for _, x := range langs {
|
||||
if _, e = tx.Exec(`INSERT INTO language_stats VALUES(?,?,?,?,?,?)`, id, x.Name, x.Files, x.Code, x.Comments, x.Blanks); e != nil {
|
||||
return e
|
||||
}
|
||||
}
|
||||
for _, x := range files {
|
||||
if _, e = tx.Exec(`INSERT INTO file_entries VALUES(?,?,?,?,?,?,?)`, id, x.Path, x.Name, x.Extension, x.Size, boolInt(x.IsDir), x.Parent); e != nil {
|
||||
return e
|
||||
}
|
||||
}
|
||||
_, e = tx.Exec(`INSERT INTO analysis_runs(project_id,kind,status,started_at,completed_at) VALUES(?,'scan','completed',?,?)`, id, now(), now())
|
||||
if e != nil {
|
||||
return e
|
||||
}
|
||||
return tx.Commit()
|
||||
}
|
||||
func boolInt(v bool) int {
|
||||
if v {
|
||||
return 1
|
||||
}
|
||||
return 0
|
||||
}
|
||||
func (s *Store) Structure(id int64) (StructureStats, error) {
|
||||
r, e := s.db.Query(`SELECT path,name,extension,size,is_dir,parent FROM file_entries WHERE project_id=? ORDER BY path`, id)
|
||||
if e != nil {
|
||||
return StructureStats{}, e
|
||||
}
|
||||
defer r.Close()
|
||||
x := StructureStats{Files: []FileEntry{}, LargeFiles: []FileEntry{}}
|
||||
fm := map[string]*FolderStat{}
|
||||
em := map[string]*ExtensionStat{}
|
||||
for r.Next() {
|
||||
var f FileEntry
|
||||
var d int
|
||||
if e = r.Scan(&f.Path, &f.Name, &f.Extension, &f.Size, &d, &f.Parent); e != nil {
|
||||
return x, e
|
||||
}
|
||||
f.IsDir = d == 1
|
||||
x.Files = append(x.Files, f)
|
||||
if f.IsDir {
|
||||
x.TotalDirs++
|
||||
continue
|
||||
}
|
||||
x.TotalFiles++
|
||||
x.TotalSize += f.Size
|
||||
if f.Size >= 1024*1024 {
|
||||
x.LargeFiles = append(x.LargeFiles, f)
|
||||
}
|
||||
top := strings.Split(filepath.ToSlash(f.Path), "/")[0]
|
||||
if top == f.Name {
|
||||
top = "/"
|
||||
}
|
||||
if fm[top] == nil {
|
||||
fm[top] = &FolderStat{Name: top}
|
||||
}
|
||||
fm[top].Files++
|
||||
fm[top].Size += f.Size
|
||||
ext := f.Extension
|
||||
if ext == "" {
|
||||
ext = "(no extension)"
|
||||
}
|
||||
if em[ext] == nil {
|
||||
em[ext] = &ExtensionStat{Extension: ext}
|
||||
}
|
||||
em[ext].Files++
|
||||
em[ext].Size += f.Size
|
||||
}
|
||||
for _, v := range fm {
|
||||
x.Folders = append(x.Folders, *v)
|
||||
}
|
||||
for _, v := range em {
|
||||
x.Extensions = append(x.Extensions, *v)
|
||||
}
|
||||
sort.Slice(x.Folders, func(i, j int) bool { return x.Folders[i].Size > x.Folders[j].Size })
|
||||
sort.Slice(x.Extensions, func(i, j int) bool { return x.Extensions[i].Size > x.Extensions[j].Size })
|
||||
sort.Slice(x.LargeFiles, func(i, j int) bool { return x.LargeFiles[i].Size > x.LargeFiles[j].Size })
|
||||
return x, r.Err()
|
||||
}
|
||||
|
||||
func (s *Store) Rules() ([]ExclusionRule, error) {
|
||||
r, e := s.db.Query(`SELECT id,pattern,category,builtin FROM exclusion_rules ORDER BY category,builtin DESC,pattern`)
|
||||
if e != nil {
|
||||
return nil, e
|
||||
}
|
||||
defer r.Close()
|
||||
o := []ExclusionRule{}
|
||||
for r.Next() {
|
||||
var x ExclusionRule
|
||||
var b int
|
||||
if e = r.Scan(&x.ID, &x.Pattern, &x.Category, &b); e != nil {
|
||||
return nil, e
|
||||
}
|
||||
x.Builtin = b == 1
|
||||
o = append(o, x)
|
||||
}
|
||||
return o, r.Err()
|
||||
}
|
||||
func (s *Store) AddRule(pattern, category string) (ExclusionRule, error) {
|
||||
pattern = strings.TrimSpace(pattern)
|
||||
if pattern == "" {
|
||||
return ExclusionRule{}, errors.New("PATTERN_REQUIRED")
|
||||
}
|
||||
if category == "" {
|
||||
category = "custom"
|
||||
}
|
||||
r, e := s.db.Exec(`INSERT INTO exclusion_rules(pattern,category,builtin) VALUES(?,?,0)`, pattern, category)
|
||||
if e != nil {
|
||||
return ExclusionRule{}, e
|
||||
}
|
||||
id, _ := r.LastInsertId()
|
||||
return ExclusionRule{ID: id, Pattern: pattern, Category: category}, nil
|
||||
}
|
||||
func (s *Store) DeleteRule(id int64) error {
|
||||
r, e := s.db.Exec(`DELETE FROM exclusion_rules WHERE id=? AND builtin=0`, id)
|
||||
if e != nil {
|
||||
return e
|
||||
}
|
||||
n, _ := r.RowsAffected()
|
||||
if n == 0 {
|
||||
return errors.New("BUILTIN_RULE")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (s *Store) Log(level, category, message, detail string) {
|
||||
_, _ = s.db.Exec(`INSERT INTO app_logs(level,category,message,detail,created_at) VALUES(?,?,?,?,?)`, level, category, message, detail, now())
|
||||
}
|
||||
func (s *Store) Logs(level string) ([]LogEntry, error) {
|
||||
q := `SELECT id,level,category,message,detail,created_at FROM app_logs`
|
||||
args := []any{}
|
||||
if level != "" && level != "all" {
|
||||
q += ` WHERE level=?`
|
||||
args = append(args, level)
|
||||
}
|
||||
q += ` ORDER BY id DESC LIMIT 500`
|
||||
r, e := s.db.Query(q, args...)
|
||||
if e != nil {
|
||||
return nil, e
|
||||
}
|
||||
defer r.Close()
|
||||
o := []LogEntry{}
|
||||
for r.Next() {
|
||||
var x LogEntry
|
||||
if e = r.Scan(&x.ID, &x.Level, &x.Category, &x.Message, &x.Detail, &x.CreatedAt); e != nil {
|
||||
return nil, e
|
||||
}
|
||||
o = append(o, x)
|
||||
}
|
||||
return o, r.Err()
|
||||
}
|
||||
func (s *Store) ClearLogs() error { _, e := s.db.Exec(`DELETE FROM app_logs`); return e }
|
||||
func (s *Store) Settings() (AppSettings, error) {
|
||||
x := AppSettings{DatabasePath: s.path, Theme: "dark", Locale: "zh-CN", GitScope: "current", AutoRefresh: true, GlassOpacity: 55, LoadingStyle: "fullscreen-orbit"}
|
||||
r, e := s.db.Query(`SELECT key,value FROM settings`)
|
||||
if e != nil {
|
||||
return x, e
|
||||
}
|
||||
defer r.Close()
|
||||
for r.Next() {
|
||||
var k, v string
|
||||
_ = r.Scan(&k, &v)
|
||||
switch k {
|
||||
case "theme":
|
||||
x.Theme = v
|
||||
case "locale":
|
||||
x.Locale = v
|
||||
case "gitScope":
|
||||
x.GitScope = v
|
||||
case "autoRefresh":
|
||||
x.AutoRefresh = v == "true"
|
||||
case "glassOpacity":
|
||||
if n, err := strconv.Atoi(v); err == nil && n >= 30 && n <= 75 {
|
||||
x.GlassOpacity = n
|
||||
}
|
||||
case "loadingStyle":
|
||||
if validLoadingStyle(v) {
|
||||
x.LoadingStyle = v
|
||||
}
|
||||
}
|
||||
}
|
||||
return x, nil
|
||||
}
|
||||
func (s *Store) SaveSettings(x AppSettings) error {
|
||||
if x.GlassOpacity < 30 || x.GlassOpacity > 75 {
|
||||
x.GlassOpacity = 55
|
||||
}
|
||||
if !validLoadingStyle(x.LoadingStyle) {
|
||||
x.LoadingStyle = "fullscreen-orbit"
|
||||
}
|
||||
vals := map[string]string{"theme": x.Theme, "locale": x.Locale, "gitScope": x.GitScope, "autoRefresh": fmt.Sprint(x.AutoRefresh), "glassOpacity": strconv.Itoa(x.GlassOpacity), "loadingStyle": x.LoadingStyle, "loadingStyleSet": "true"}
|
||||
tx, e := s.db.Begin()
|
||||
if e != nil {
|
||||
return e
|
||||
}
|
||||
defer tx.Rollback()
|
||||
for k, v := range vals {
|
||||
if _, e = tx.Exec(`INSERT INTO settings(key,value) VALUES(?,?) ON CONFLICT(key) DO UPDATE SET value=excluded.value`, k, v); e != nil {
|
||||
return e
|
||||
}
|
||||
}
|
||||
return tx.Commit()
|
||||
}
|
||||
|
||||
func validLoadingStyle(v string) bool {
|
||||
switch v {
|
||||
case "bar", "fullscreen", "fullscreen-orbit", "fullscreen-grid", "fullscreen-warp":
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
func (s *Store) ClearData(mode string, projectID int64) error {
|
||||
tx, e := s.db.Begin()
|
||||
if e != nil {
|
||||
return e
|
||||
}
|
||||
defer tx.Rollback()
|
||||
tables := []string{"language_stats", "file_entries", "git_commits", "git_refs", "commit_refs", "contributors", "project_insights", "insight_issues", "analysis_runs"}
|
||||
if mode == "all" {
|
||||
tables = append(tables, "projects")
|
||||
}
|
||||
for _, t := range tables {
|
||||
q := "DELETE FROM " + t
|
||||
args := []any{}
|
||||
if mode == "project" && t != "projects" {
|
||||
q += " WHERE project_id=?"
|
||||
args = append(args, projectID)
|
||||
}
|
||||
if _, e = tx.Exec(q, args...); e != nil {
|
||||
return e
|
||||
}
|
||||
}
|
||||
if mode == "all" {
|
||||
if _, e = tx.Exec(`DELETE FROM project_groups WHERE id<>1`); e != nil {
|
||||
return e
|
||||
}
|
||||
}
|
||||
return tx.Commit()
|
||||
}
|
||||
|
||||
func (s *Store) ReplaceGit(id int64, g GitStats) error {
|
||||
tx, e := s.db.Begin()
|
||||
if e != nil {
|
||||
return e
|
||||
}
|
||||
defer tx.Rollback()
|
||||
for _, t := range []string{"git_commits", "git_refs", "commit_refs", "contributors"} {
|
||||
if _, e = tx.Exec("DELETE FROM "+t+" WHERE project_id=?", id); e != nil {
|
||||
return e
|
||||
}
|
||||
}
|
||||
for _, c := range g.Commits {
|
||||
if _, e = tx.Exec(`INSERT INTO git_commits VALUES(?,?,?,?,?,?,?,?)`, id, c.Hash, c.Author, c.Email, c.Message, c.Date, c.Added, c.Deleted); e != nil {
|
||||
return e
|
||||
}
|
||||
}
|
||||
for _, r := range g.Refs {
|
||||
if _, e = tx.Exec(`INSERT INTO git_refs VALUES(?,?,?,?,?)`, id, r.Name, r.Hash, r.Kind, boolInt(r.Current)); e != nil {
|
||||
return e
|
||||
}
|
||||
}
|
||||
for _, c := range g.Contributors {
|
||||
if _, e = tx.Exec(`INSERT INTO contributors VALUES(?,?,?,?,?,?)`, id, c.Email, c.Name, c.Commits, c.Added, c.Deleted); e != nil {
|
||||
return e
|
||||
}
|
||||
}
|
||||
_, e = tx.Exec(`INSERT INTO analysis_runs(project_id,kind,status,started_at,completed_at) VALUES(?,'git','completed',?,?)`, id, now(), now())
|
||||
if e != nil {
|
||||
return e
|
||||
}
|
||||
return tx.Commit()
|
||||
}
|
||||
func (s *Store) GitStats(id int64) (GitStats, error) {
|
||||
g := GitStats{Available: true, Commits: []GitCommit{}, Refs: []GitRef{}, Contributors: []Contributor{}, Heatmap: []HeatDay{}}
|
||||
r, e := s.db.Query(`SELECT hash,author,email,message,committed_at,added,deleted FROM git_commits WHERE project_id=? ORDER BY committed_at DESC`, id)
|
||||
if e != nil {
|
||||
return g, e
|
||||
}
|
||||
for r.Next() {
|
||||
var c GitCommit
|
||||
if e = r.Scan(&c.Hash, &c.Author, &c.Email, &c.Message, &c.Date, &c.Added, &c.Deleted); e != nil {
|
||||
r.Close()
|
||||
return g, e
|
||||
}
|
||||
g.Commits = append(g.Commits, c)
|
||||
g.Added += c.Added
|
||||
g.Deleted += c.Deleted
|
||||
}
|
||||
r.Close()
|
||||
rr, e := s.db.Query(`SELECT name,hash,kind,is_current FROM git_refs WHERE project_id=? ORDER BY is_current DESC,kind,name`, id)
|
||||
if e != nil {
|
||||
return g, e
|
||||
}
|
||||
for rr.Next() {
|
||||
var x GitRef
|
||||
var c int
|
||||
_ = rr.Scan(&x.Name, &x.Hash, &x.Kind, &c)
|
||||
x.Current = c == 1
|
||||
if x.Current {
|
||||
g.CurrentBranch = x.Name
|
||||
}
|
||||
g.Refs = append(g.Refs, x)
|
||||
}
|
||||
rr.Close()
|
||||
g.WorkspaceBranch = g.CurrentBranch
|
||||
g.ViewRef = g.CurrentBranch
|
||||
cr, e := s.db.Query(`SELECT name,email,commits,added,deleted FROM contributors WHERE project_id=? ORDER BY commits DESC`, id)
|
||||
if e != nil {
|
||||
return g, e
|
||||
}
|
||||
for cr.Next() {
|
||||
var x Contributor
|
||||
_ = cr.Scan(&x.Name, &x.Email, &x.Commits, &x.Added, &x.Deleted)
|
||||
g.Contributors = append(g.Contributors, x)
|
||||
}
|
||||
cr.Close()
|
||||
g.CommitCount = int64(len(g.Commits))
|
||||
g.ContributorCount = int64(len(g.Contributors))
|
||||
cut := time.Now().AddDate(-1, 0, 0)
|
||||
hm := map[string]int64{}
|
||||
for _, c := range g.Commits {
|
||||
if t, e := time.Parse(time.RFC3339, c.Date); e == nil && t.After(cut) {
|
||||
hm[t.Local().Format("2006-01-02")]++
|
||||
}
|
||||
}
|
||||
for d, c := range hm {
|
||||
g.Heatmap = append(g.Heatmap, HeatDay{Date: d, Count: c})
|
||||
}
|
||||
sort.Slice(g.Heatmap, func(i, j int) bool { return g.Heatmap[i].Date < g.Heatmap[j].Date })
|
||||
return g, nil
|
||||
}
|
||||
|
||||
func (s *Store) Insights(id int64) (ProjectInsights, error) {
|
||||
x := ProjectInsights{ProjectID: id, Issues: []InsightIssue{}}
|
||||
e := s.db.QueryRow(`SELECT health_score,generated_at,high,medium,low,todo_count,long_files,large_files FROM project_insights WHERE project_id=?`, id).Scan(&x.HealthScore, &x.GeneratedAt, &x.Summary.High, &x.Summary.Medium, &x.Summary.Low, &x.Summary.TodoCount, &x.Summary.LongFiles, &x.Summary.LargeFiles)
|
||||
if e != nil {
|
||||
return x, e
|
||||
}
|
||||
r, e := s.db.Query(`SELECT severity,type,title,detail,path,line,suggestion,evidence FROM insight_issues WHERE project_id=? ORDER BY idx`, id)
|
||||
if e != nil {
|
||||
return x, e
|
||||
}
|
||||
defer r.Close()
|
||||
for r.Next() {
|
||||
var issue InsightIssue
|
||||
if e = r.Scan(&issue.Severity, &issue.Type, &issue.Title, &issue.Detail, &issue.Path, &issue.Line, &issue.Suggestion, &issue.Evidence); e != nil {
|
||||
return x, e
|
||||
}
|
||||
x.Issues = append(x.Issues, issue)
|
||||
}
|
||||
return x, nil
|
||||
}
|
||||
|
||||
func (s *Store) ReplaceInsights(id int64, x ProjectInsights) error {
|
||||
tx, e := s.db.Begin()
|
||||
if e != nil {
|
||||
return e
|
||||
}
|
||||
defer tx.Rollback()
|
||||
if _, e = tx.Exec(`DELETE FROM insight_issues WHERE project_id=?`, id); e != nil {
|
||||
return e
|
||||
}
|
||||
if _, e = tx.Exec(`DELETE FROM project_insights WHERE project_id=?`, id); e != nil {
|
||||
return e
|
||||
}
|
||||
if _, e = tx.Exec(`INSERT INTO project_insights VALUES(?,?,?,?,?,?,?,?,?)`, id, x.HealthScore, x.GeneratedAt, x.Summary.High, x.Summary.Medium, x.Summary.Low, x.Summary.TodoCount, x.Summary.LongFiles, x.Summary.LargeFiles); e != nil {
|
||||
return e
|
||||
}
|
||||
for i, issue := range x.Issues {
|
||||
if _, e = tx.Exec(`INSERT INTO insight_issues VALUES(?,?,?,?,?,?,?,?,?,?)`, id, i, issue.Severity, issue.Type, issue.Title, issue.Detail, issue.Path, issue.Line, issue.Suggestion, issue.Evidence); e != nil {
|
||||
return e
|
||||
}
|
||||
}
|
||||
return tx.Commit()
|
||||
}
|
||||
239
database_test.go
Normal file
@@ -0,0 +1,239 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestStoreProjectAndSnapshot(t *testing.T) {
|
||||
s, e := OpenStore(filepath.Join(t.TempDir(), "test.db"))
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
defer s.db.Close()
|
||||
dir := t.TempDir()
|
||||
p, e := s.SaveProject(0, ProjectInput{Name: "demo", Path: dir})
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
if _, e = s.SaveProject(0, ProjectInput{Name: "duplicate", Path: dir}); e == nil {
|
||||
t.Fatal("duplicate path accepted")
|
||||
}
|
||||
e = s.ReplaceScan(p.ID, []LanguageStat{{Name: "Go", Files: 1, Code: 2, Comments: 1, Blanks: 1}}, []FileEntry{{Path: "main.go", Name: "main.go", Extension: ".go", Size: 20}})
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
got, e := s.GetProject(p.ID)
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
if got.Stats.TotalLines != 4 || got.Stats.FileCount != 1 {
|
||||
t.Fatalf("unexpected stats: %#v", got.Stats)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNormalizePath(t *testing.T) {
|
||||
if _, e := normalizePath(filepath.Join(t.TempDir(), "missing")); e == nil {
|
||||
t.Fatal("missing directory accepted")
|
||||
}
|
||||
d := t.TempDir()
|
||||
p, e := normalizePath(d)
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
if _, e = os.Stat(p); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDuplicateProjectReturnsStableCode(t *testing.T) {
|
||||
s, e := OpenStore(filepath.Join(t.TempDir(), "test.db"))
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
defer s.db.Close()
|
||||
dir := t.TempDir()
|
||||
if _, e = s.SaveProject(0, ProjectInput{Name: "one", Path: dir}); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
if _, e = s.SaveProject(0, ProjectInput{Name: "two", Path: dir}); e == nil || !strings.HasPrefix(e.Error(), "PROJECT_PATH_DUPLICATE") {
|
||||
t.Fatalf("unexpected error: %v", e)
|
||||
}
|
||||
}
|
||||
|
||||
func TestProjectGroupsFilterProjectsAndDashboard(t *testing.T) {
|
||||
s, e := OpenStore(filepath.Join(t.TempDir(), "groups.db"))
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
defer s.db.Close()
|
||||
g, e := s.SaveProjectGroup(0, "Backend")
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
dir1 := t.TempDir()
|
||||
dir2 := t.TempDir()
|
||||
p1, e := s.SaveProject(0, ProjectInput{Name: "api", Path: dir1, GroupID: g.ID})
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
if _, e = s.SaveProject(0, ProjectInput{Name: "web", Path: dir2}); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
if e = s.ReplaceScan(p1.ID, []LanguageStat{{Name: "Go", Files: 2, Code: 10, Comments: 1, Blanks: 1}}, nil); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
projects, e := s.ListProjects(g.ID)
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
if len(projects) != 1 || projects[0].GroupID != g.ID || projects[0].GroupName != "Backend" {
|
||||
t.Fatalf("unexpected grouped projects: %#v", projects)
|
||||
}
|
||||
d, e := s.Dashboard(g.ID)
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
if d.Projects != 1 || d.TotalLines != 12 {
|
||||
t.Fatalf("unexpected dashboard: %#v", d)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDeleteProjectGroupMovesProjectsToDefault(t *testing.T) {
|
||||
s, e := OpenStore(filepath.Join(t.TempDir(), "groups.db"))
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
defer s.db.Close()
|
||||
g, e := s.SaveProjectGroup(0, "Temp")
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
p, e := s.SaveProject(0, ProjectInput{Name: "demo", Path: t.TempDir(), GroupID: g.ID})
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
if e = s.DeleteProjectGroup(g.ID); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
got, e := s.GetProject(p.ID)
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
if got.GroupID != 1 {
|
||||
t.Fatalf("groupId=%d want 1", got.GroupID)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSettingsReturnsActiveDatabasePath(t *testing.T) {
|
||||
dbPath := filepath.Join(t.TempDir(), "active.db")
|
||||
s, e := OpenStore(dbPath)
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
defer s.db.Close()
|
||||
settings, e := s.Settings()
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
if settings.DatabasePath != dbPath {
|
||||
t.Fatalf("databasePath=%q want %q", settings.DatabasePath, dbPath)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGlassOpacityPersistsAndValidates(t *testing.T) {
|
||||
s, e := OpenStore(filepath.Join(t.TempDir(), "settings.db"))
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
defer s.db.Close()
|
||||
if e = s.SaveSettings(AppSettings{Theme: "dark", Locale: "zh-CN", GitScope: "current", AutoRefresh: true, GlassOpacity: 30}); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
got, e := s.Settings()
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
if got.GlassOpacity != 30 {
|
||||
t.Fatalf("glassOpacity=%d", got.GlassOpacity)
|
||||
}
|
||||
if e = s.SaveSettings(AppSettings{GlassOpacity: 99}); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
got, e = s.Settings()
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
if got.GlassOpacity != 55 {
|
||||
t.Fatalf("invalid opacity did not reset: %d", got.GlassOpacity)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoadingStylePersistsAndValidates(t *testing.T) {
|
||||
s, e := OpenStore(filepath.Join(t.TempDir(), "settings.db"))
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
defer s.db.Close()
|
||||
if e = s.SaveSettings(AppSettings{Theme: "dark", Locale: "zh-CN", GitScope: "current", AutoRefresh: true, GlassOpacity: 55, LoadingStyle: "fullscreen-grid"}); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
got, e := s.Settings()
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
if got.LoadingStyle != "fullscreen-grid" {
|
||||
t.Fatalf("loadingStyle=%q", got.LoadingStyle)
|
||||
}
|
||||
if e = s.SaveSettings(AppSettings{GlassOpacity: 55, LoadingStyle: "floating"}); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
got, e = s.Settings()
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
if got.LoadingStyle != "fullscreen-orbit" {
|
||||
t.Fatalf("invalid loadingStyle did not reset: %q", got.LoadingStyle)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLegacyLoadingStyleDefaultMigratesOnce(t *testing.T) {
|
||||
db := filepath.Join(t.TempDir(), "settings.db")
|
||||
s, e := OpenStore(db)
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
if _, e = s.db.Exec(`UPDATE settings SET value='bar' WHERE key='loadingStyle'`); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
s.db.Close()
|
||||
s, e = OpenStore(db)
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
got, e := s.Settings()
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
if got.LoadingStyle != "fullscreen-orbit" {
|
||||
t.Fatalf("legacy loadingStyle=%q", got.LoadingStyle)
|
||||
}
|
||||
if e = s.SaveSettings(AppSettings{GlassOpacity: 55, LoadingStyle: "bar"}); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
s.db.Close()
|
||||
s, e = OpenStore(db)
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
defer s.db.Close()
|
||||
got, e = s.Settings()
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
if got.LoadingStyle != "bar" {
|
||||
t.Fatalf("explicit loadingStyle=%q", got.LoadingStyle)
|
||||
}
|
||||
}
|
||||
BIN
desktop-final.png
Normal file
|
After Width: | Height: | Size: 396 KiB |
BIN
final-dashboard-v3.png
Normal file
|
After Width: | Height: | Size: 407 KiB |
BIN
final-git-v3.png
Normal file
|
After Width: | Height: | Size: 341 KiB |
8
frontend/README.md
Normal file
@@ -0,0 +1,8 @@
|
||||
# Vue 3 + Vite
|
||||
|
||||
This template should help get you started developing with Vue 3 in Vite. The template uses Vue 3 `<script setup>` SFCs,
|
||||
check out the [script setup docs](https://v3.vuejs.org/api/sfc-script-setup.html#sfc-script-setup) to learn more.
|
||||
|
||||
## Recommended IDE Setup
|
||||
|
||||
- [VS Code](https://code.visualstudio.com/) + [Volar](https://marketplace.visualstudio.com/items?itemName=Vue.volar)
|
||||
13
frontend/index.html
Normal file
@@ -0,0 +1,13 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8"/>
|
||||
<meta content="width=device-width, initial-scale=1.0" name="viewport"/>
|
||||
<title>view</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
<script src="./src/main.js" type="module"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
1025
frontend/package-lock.json
generated
Normal file
23
frontend/package.json
Normal file
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"name": "frontend",
|
||||
"private": true,
|
||||
"version": "0.0.0",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "vite build",
|
||||
"preview": "vite preview"
|
||||
},
|
||||
"dependencies": {
|
||||
"echarts": "^6.1.0",
|
||||
"lucide-vue-next": "^1.0.0",
|
||||
"pinia": "^4.0.1",
|
||||
"vue": "^3.2.37",
|
||||
"vue-i18n": "^9.14.5",
|
||||
"vue-router": "^4.6.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@vitejs/plugin-vue": "^3.0.3",
|
||||
"vite": "^3.0.7"
|
||||
}
|
||||
}
|
||||
1
frontend/package.json.md5
Normal file
@@ -0,0 +1 @@
|
||||
737ba6354d6500f88d51c323cdf11056
|
||||
142
frontend/src/App.vue
Normal file
@@ -0,0 +1,142 @@
|
||||
<script setup>
|
||||
import { computed, onMounted, onUnmounted, ref, watch } from 'vue'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { LayoutDashboard, ScrollText, Settings, X, Database, SlidersHorizontal } from 'lucide-vue-next'
|
||||
import { useAppStore } from './store'
|
||||
import DatabaseSetup from './components/DatabaseSetup.vue'
|
||||
import BrowserBlocked from './components/BrowserBlocked.vue'
|
||||
import AnalysisCanvas from './components/AnalysisCanvas.vue'
|
||||
import { isNative } from './api'
|
||||
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
const store = useAppStore()
|
||||
const { t, locale } = useI18n()
|
||||
const native = isNative()
|
||||
const quickOpen = ref(false)
|
||||
const displayedTask = ref(null)
|
||||
let off
|
||||
let loadingHoldTimer
|
||||
|
||||
const activeTask = computed(() => Object.values(store.tasks).find(x => !['completed', 'error', 'cancelled'].includes(x.stage)))
|
||||
const visibleTask = computed(() => activeTask.value || displayedTask.value)
|
||||
const activeTaskProject = computed(() => visibleTask.value?.params?.project || store.projects.find(p => p.id === visibleTask.value?.projectId)?.name || '')
|
||||
const loadingStyle = computed(() => store.settings.loadingStyle === 'fullscreen' ? 'fullscreen-orbit' : (store.settings.loadingStyle || 'fullscreen-orbit'))
|
||||
const useFullscreenLoading = computed(() => loadingStyle.value !== 'bar')
|
||||
|
||||
async function updateSetting(key, value) {
|
||||
const next = await store.saveSettings({ [key]: value })
|
||||
if (key === 'locale') locale.value = next.locale
|
||||
}
|
||||
|
||||
function openSettings() {
|
||||
quickOpen.value = false
|
||||
router.push('/settings')
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
if (!native) return
|
||||
off = store.listen()
|
||||
await store.boot()
|
||||
locale.value = store.settings.locale || 'zh-CN'
|
||||
})
|
||||
onUnmounted(() => {
|
||||
clearTimeout(loadingHoldTimer)
|
||||
off?.()
|
||||
})
|
||||
watch(() => store.settings.locale, v => {
|
||||
if (v) locale.value = v
|
||||
})
|
||||
watch(activeTask, task => {
|
||||
clearTimeout(loadingHoldTimer)
|
||||
if (task) {
|
||||
displayedTask.value = task
|
||||
return
|
||||
}
|
||||
loadingHoldTimer = setTimeout(() => {
|
||||
displayedTask.value = null
|
||||
}, 900)
|
||||
}, { immediate: true })
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<BrowserBlocked v-if="!native" />
|
||||
<DatabaseSetup v-else-if="store.bootstrap.state !== 'ready' && store.bootstrap.state !== 'loading'" :status="store.bootstrap" />
|
||||
<div v-else-if="store.bootstrap.state === 'ready'" class="shell">
|
||||
<aside class="sidebar">
|
||||
<div class="brand">
|
||||
<span class="brand-mark animated-logo" aria-hidden="true">
|
||||
<svg viewBox="0 0 48 48" role="img">
|
||||
<defs>
|
||||
<linearGradient id="logoGlow" x1="0" x2="1" y1="0" y2="1">
|
||||
<stop offset="0%" stop-color="#6ee7ff" />
|
||||
<stop offset="48%" stop-color="#8b5cf6" />
|
||||
<stop offset="100%" stop-color="#34d399" />
|
||||
</linearGradient>
|
||||
</defs>
|
||||
<rect class="logo-frame" x="6" y="6" width="36" height="36" rx="9" />
|
||||
<path class="logo-track" d="M17 18l-6 6 6 6M31 18l6 6-6 6M27 14l-6 20" />
|
||||
<path class="logo-spark" d="M12 10h8M28 38h8" />
|
||||
</svg>
|
||||
</span>
|
||||
<b>{{ t('app') }}</b>
|
||||
</div>
|
||||
<nav aria-label="Primary">
|
||||
<RouterLink to="/" :class="{ active: route.path === '/' }"><LayoutDashboard /><span>{{ t('dashboard') }}</span></RouterLink>
|
||||
<RouterLink to="/logs" :class="{ active: route.path === '/logs' }"><ScrollText /><span>{{ t('logs') }}</span></RouterLink>
|
||||
<RouterLink to="/settings" :class="{ active: route.path === '/settings' }"><Settings /><span>{{ t('settings') }}</span></RouterLink>
|
||||
</nav>
|
||||
<div class="sidebar-bottom">
|
||||
<span class="version"><i />v1.0.0</span>
|
||||
<button class="quick-settings-btn" :title="t('quickSettings')" @click="quickOpen = !quickOpen"><SlidersHorizontal /></button>
|
||||
<section v-if="quickOpen" class="quick-settings popover-glass">
|
||||
<header>
|
||||
<b>{{ t('quickSettings') }}</b>
|
||||
<button @click="quickOpen = false" aria-label="Close"><X /></button>
|
||||
</header>
|
||||
<label>
|
||||
<span>{{ t('language') }}</span>
|
||||
<select :value="store.settings.locale" @change="updateSetting('locale', $event.target.value)">
|
||||
<option value="zh-CN">中文</option>
|
||||
<option value="en">English</option>
|
||||
</select>
|
||||
</label>
|
||||
<label>
|
||||
<span>{{ t('theme') }}</span>
|
||||
<select :value="store.settings.theme" @change="updateSetting('theme', $event.target.value)">
|
||||
<option value="dark">{{ t('themeDark') }}</option>
|
||||
<option value="light">{{ t('themeLight') }}</option>
|
||||
<option value="system">{{ t('themeSystem') }}</option>
|
||||
</select>
|
||||
</label>
|
||||
<label>
|
||||
<span>{{ t('glassOpacity') }} · {{ store.settings.glassOpacity }}%</span>
|
||||
<input type="range" min="30" max="75" :value="store.settings.glassOpacity" @input="updateSetting('glassOpacity', Number($event.target.value))" />
|
||||
</label>
|
||||
<button class="btn secondary full" @click="openSettings"><Settings />{{ t('openSettings') }}</button>
|
||||
</section>
|
||||
</div>
|
||||
</aside>
|
||||
<main><RouterView /></main>
|
||||
<div v-if="visibleTask && !useFullscreenLoading" class="taskbar">
|
||||
<div><b>{{ activeTaskProject || visibleTask.stage }}</b><span>{{ t(visibleTask.messageKey || 'task.start', visibleTask.params || {}) }}</span></div>
|
||||
<div class="progress"><i :style="{ width: visibleTask.progress + '%' }" /></div>
|
||||
<b>{{ visibleTask.progress }}%</b>
|
||||
</div>
|
||||
<div v-if="visibleTask && useFullscreenLoading" class="analysis-loading" :class="[loadingStyle, { holding: !activeTask }]">
|
||||
<AnalysisCanvas :progress="visibleTask.progress" :variant="loadingStyle" />
|
||||
<section>
|
||||
<b>{{ activeTaskProject || t('analyzingProject') }}</b>
|
||||
<span>{{ t(visibleTask.messageKey || 'task.start', visibleTask.params || {}) }}</span>
|
||||
<div class="progress"><i :style="{ width: visibleTask.progress + '%' }" /></div>
|
||||
<strong>{{ visibleTask.progress }}%</strong>
|
||||
</section>
|
||||
</div>
|
||||
<div v-if="store.toast" class="toast" :class="[store.toast.type, { muted: store.toast.muted, leaving: store.toast.leaving }]">
|
||||
{{ store.toast.key ? t(store.toast.key, store.toast.params || {}) : store.toast.text }}
|
||||
<button @click="store.closeToast()" aria-label="Close"><X /></button>
|
||||
</div>
|
||||
</div>
|
||||
<div v-else class="boot-loading"><Database class="spin" />正在检查数据库...</div>
|
||||
</template>
|
||||
12
frontend/src/api.js
Normal file
@@ -0,0 +1,12 @@
|
||||
export const isNative=()=>Boolean(window.go?.main?.App)
|
||||
|
||||
export async function call(name,...args){
|
||||
const fn=window.go?.main?.App?.[name]
|
||||
if(fn)return fn(...args)
|
||||
throw new Error(`NATIVE_RUNTIME_REQUIRED: ${name}`)
|
||||
}
|
||||
|
||||
export function on(name,cb){
|
||||
if(window.runtime?.EventsOn)return window.runtime.EventsOn(name,cb)
|
||||
return()=>{}
|
||||
}
|
||||
93
frontend/src/assets/fonts/OFL.txt
Normal file
@@ -0,0 +1,93 @@
|
||||
Copyright 2016 The Nunito Project Authors (contact@sansoxygen.com),
|
||||
|
||||
This Font Software is licensed under the SIL Open Font License, Version 1.1.
|
||||
This license is copied below, and is also available with a FAQ at:
|
||||
http://scripts.sil.org/OFL
|
||||
|
||||
|
||||
-----------------------------------------------------------
|
||||
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
|
||||
-----------------------------------------------------------
|
||||
|
||||
PREAMBLE
|
||||
The goals of the Open Font License (OFL) are to stimulate worldwide
|
||||
development of collaborative font projects, to support the font creation
|
||||
efforts of academic and linguistic communities, and to provide a free and
|
||||
open framework in which fonts may be shared and improved in partnership
|
||||
with others.
|
||||
|
||||
The OFL allows the licensed fonts to be used, studied, modified and
|
||||
redistributed freely as long as they are not sold by themselves. The
|
||||
fonts, including any derivative works, can be bundled, embedded,
|
||||
redistributed and/or sold with any software provided that any reserved
|
||||
names are not used by derivative works. The fonts and derivatives,
|
||||
however, cannot be released under any other type of license. The
|
||||
requirement for fonts to remain under this license does not apply
|
||||
to any document created using the fonts or their derivatives.
|
||||
|
||||
DEFINITIONS
|
||||
"Font Software" refers to the set of files released by the Copyright
|
||||
Holder(s) under this license and clearly marked as such. This may
|
||||
include source files, build scripts and documentation.
|
||||
|
||||
"Reserved Font Name" refers to any names specified as such after the
|
||||
copyright statement(s).
|
||||
|
||||
"Original Version" refers to the collection of Font Software components as
|
||||
distributed by the Copyright Holder(s).
|
||||
|
||||
"Modified Version" refers to any derivative made by adding to, deleting,
|
||||
or substituting -- in part or in whole -- any of the components of the
|
||||
Original Version, by changing formats or by porting the Font Software to a
|
||||
new environment.
|
||||
|
||||
"Author" refers to any designer, engineer, programmer, technical
|
||||
writer or other person who contributed to the Font Software.
|
||||
|
||||
PERMISSION & CONDITIONS
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of the Font Software, to use, study, copy, merge, embed, modify,
|
||||
redistribute, and sell modified and unmodified copies of the Font
|
||||
Software, subject to the following conditions:
|
||||
|
||||
1) Neither the Font Software nor any of its individual components,
|
||||
in Original or Modified Versions, may be sold by itself.
|
||||
|
||||
2) Original or Modified Versions of the Font Software may be bundled,
|
||||
redistributed and/or sold with any software, provided that each copy
|
||||
contains the above copyright notice and this license. These can be
|
||||
included either as stand-alone text files, human-readable headers or
|
||||
in the appropriate machine-readable metadata fields within text or
|
||||
binary files as long as those fields can be easily viewed by the user.
|
||||
|
||||
3) No Modified Version of the Font Software may use the Reserved Font
|
||||
Name(s) unless explicit written permission is granted by the corresponding
|
||||
Copyright Holder. This restriction only applies to the primary font name as
|
||||
presented to the users.
|
||||
|
||||
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
|
||||
Software shall not be used to promote, endorse or advertise any
|
||||
Modified Version, except to acknowledge the contribution(s) of the
|
||||
Copyright Holder(s) and the Author(s) or with their explicit written
|
||||
permission.
|
||||
|
||||
5) The Font Software, modified or unmodified, in part or in whole,
|
||||
must be distributed entirely under this license, and must not be
|
||||
distributed under any other license. The requirement for fonts to
|
||||
remain under this license does not apply to any document created
|
||||
using the Font Software.
|
||||
|
||||
TERMINATION
|
||||
This license becomes null and void if any of the above conditions are
|
||||
not met.
|
||||
|
||||
DISCLAIMER
|
||||
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
|
||||
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
|
||||
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
|
||||
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
|
||||
OTHER DEALINGS IN THE FONT SOFTWARE.
|
||||
BIN
frontend/src/assets/fonts/nunito-v16-latin-regular.woff2
Normal file
BIN
frontend/src/assets/images/logo-universal.png
Normal file
|
After Width: | Height: | Size: 136 KiB |
355
frontend/src/components/AnalysisCanvas.vue
Normal file
@@ -0,0 +1,355 @@
|
||||
<script setup>
|
||||
import { onMounted, onUnmounted, ref, watch } from 'vue'
|
||||
|
||||
const props = defineProps({
|
||||
progress: { type: Number, default: 0 },
|
||||
variant: { type: String, default: 'fullscreen-orbit' }
|
||||
})
|
||||
|
||||
const canvas = ref(null)
|
||||
let frame = 0
|
||||
let ctx
|
||||
let dpr = 1
|
||||
let width = 0
|
||||
let height = 0
|
||||
let reduceMotion = false
|
||||
|
||||
function resize() {
|
||||
const el = canvas.value
|
||||
if (!el) return
|
||||
dpr = Math.min(window.devicePixelRatio || 1, 2)
|
||||
const box = el.getBoundingClientRect()
|
||||
width = Math.max(1, Math.floor(box.width))
|
||||
height = Math.max(1, Math.floor(box.height))
|
||||
el.width = Math.floor(width * dpr)
|
||||
el.height = Math.floor(height * dpr)
|
||||
ctx = el.getContext('2d')
|
||||
ctx.setTransform(dpr, 0, 0, dpr, 0, 0)
|
||||
}
|
||||
|
||||
function draw(now = 0) {
|
||||
if (!ctx) return
|
||||
const t = now * 0.001
|
||||
const cx = width / 2
|
||||
const cy = height / 2
|
||||
const p = Math.max(0, Math.min(100, Number(props.progress || 0))) / 100
|
||||
ctx.clearRect(0, 0, width, height)
|
||||
|
||||
const variant = props.variant === 'fullscreen' ? 'fullscreen-orbit' : props.variant
|
||||
const bg = ctx.createRadialGradient(cx, cy, 20, cx, cy, Math.max(width, height) * 0.65)
|
||||
bg.addColorStop(0, 'rgba(115,103,245,.28)')
|
||||
bg.addColorStop(.52, 'rgba(67,201,150,.12)')
|
||||
bg.addColorStop(1, 'rgba(0,0,0,0)')
|
||||
ctx.fillStyle = bg
|
||||
ctx.fillRect(0, 0, width, height)
|
||||
|
||||
if (variant === 'fullscreen-grid') drawGrid(t, p, cx, cy)
|
||||
else if (variant === 'fullscreen-warp') drawWarp(t, p, cx, cy)
|
||||
else drawOrbit(t, p, cx, cy)
|
||||
|
||||
if (!reduceMotion) frame = requestAnimationFrame(draw)
|
||||
}
|
||||
|
||||
function drawOrbit(t, p, cx, cy) {
|
||||
|
||||
ctx.save()
|
||||
ctx.translate(cx, cy)
|
||||
const base = Math.min(width, height) * 0.24
|
||||
for (let ring = 0; ring < 3; ring++) {
|
||||
const radius = base + ring * 22
|
||||
const phase = reduceMotion ? ring * 1.7 : t * (0.55 + ring * 0.12) + ring * 1.7
|
||||
ctx.beginPath()
|
||||
ctx.arc(0, 0, radius, phase, phase + Math.PI * (1.2 + p * 0.7))
|
||||
ctx.strokeStyle = ring === 1 ? 'rgba(83,214,162,.7)' : 'rgba(125,113,255,.72)'
|
||||
ctx.lineWidth = ring === 0 ? 4 : 2
|
||||
ctx.shadowColor = ring === 1 ? '#53d6a2' : '#7d71ff'
|
||||
ctx.shadowBlur = 16
|
||||
ctx.stroke()
|
||||
}
|
||||
|
||||
const nodes = 34
|
||||
for (let i = 0; i < nodes; i++) {
|
||||
const a = (Math.PI * 2 * i) / nodes + (reduceMotion ? 0 : t * 0.45)
|
||||
const pulse = Math.sin(t * 2 + i) * 0.5 + 0.5
|
||||
const r = base + 58 + Math.sin(i * 1.9 + t) * 8
|
||||
const x = Math.cos(a) * r
|
||||
const y = Math.sin(a) * r
|
||||
ctx.beginPath()
|
||||
ctx.arc(x, y, 1.5 + pulse * 2.2, 0, Math.PI * 2)
|
||||
ctx.fillStyle = i / nodes <= p ? 'rgba(83,214,162,.95)' : 'rgba(145,136,255,.38)'
|
||||
ctx.shadowColor = i / nodes <= p ? '#53d6a2' : '#9188ff'
|
||||
ctx.shadowBlur = 12
|
||||
ctx.fill()
|
||||
}
|
||||
|
||||
const beamAngle = reduceMotion ? -0.8 : t * 1.2
|
||||
const beam = ctx.createLinearGradient(-base, 0, base, 0)
|
||||
beam.addColorStop(0, 'rgba(110,231,255,0)')
|
||||
beam.addColorStop(.5, 'rgba(110,231,255,.52)')
|
||||
beam.addColorStop(1, 'rgba(110,231,255,0)')
|
||||
ctx.rotate(beamAngle)
|
||||
ctx.fillStyle = beam
|
||||
ctx.fillRect(-base * 1.6, -8, base * 3.2, 16)
|
||||
ctx.restore()
|
||||
|
||||
ctx.save()
|
||||
ctx.translate(cx, cy)
|
||||
ctx.beginPath()
|
||||
ctx.arc(0, 0, base * 0.72, 0, Math.PI * 2)
|
||||
const core = ctx.createRadialGradient(0, 0, 0, 0, 0, base * 0.75)
|
||||
core.addColorStop(0, 'rgba(255,255,255,.96)')
|
||||
core.addColorStop(.25, 'rgba(110,231,255,.9)')
|
||||
core.addColorStop(.6, 'rgba(115,103,245,.42)')
|
||||
core.addColorStop(1, 'rgba(115,103,245,0)')
|
||||
ctx.fillStyle = core
|
||||
ctx.shadowColor = '#6ee7ff'
|
||||
ctx.shadowBlur = 26
|
||||
ctx.fill()
|
||||
ctx.restore()
|
||||
|
||||
}
|
||||
|
||||
function drawGrid(t, p, cx, cy) {
|
||||
const gap = 34
|
||||
const base = Math.min(width, height) * 0.2
|
||||
const scanY = reduceMotion ? cy : (height * ((t * 0.2) % 1))
|
||||
const horizon = cy - Math.min(height * 0.12, 90)
|
||||
|
||||
ctx.save()
|
||||
ctx.translate(cx, horizon)
|
||||
ctx.lineWidth = 1
|
||||
for (let i = -14; i <= 14; i++) {
|
||||
const a = i / 14
|
||||
const x = a * width * 0.74
|
||||
const g = ctx.createLinearGradient(0, 0, x, height)
|
||||
g.addColorStop(0, 'rgba(110,231,255,.26)')
|
||||
g.addColorStop(1, 'rgba(110,231,255,0)')
|
||||
ctx.strokeStyle = g
|
||||
ctx.beginPath()
|
||||
ctx.moveTo(0, 0)
|
||||
ctx.lineTo(x, height)
|
||||
ctx.stroke()
|
||||
}
|
||||
for (let i = 1; i < 12; i++) {
|
||||
const y = Math.pow(i / 12, 1.8) * height * 0.78
|
||||
const w = width * (0.12 + i * 0.075)
|
||||
ctx.strokeStyle = `rgba(83,214,162,${0.22 - i * 0.012})`
|
||||
ctx.beginPath()
|
||||
ctx.moveTo(-w, y)
|
||||
ctx.lineTo(w, y)
|
||||
ctx.stroke()
|
||||
}
|
||||
ctx.restore()
|
||||
|
||||
ctx.save()
|
||||
ctx.translate((reduceMotion ? 0 : -t * 34) % gap, (reduceMotion ? 0 : t * 20) % gap)
|
||||
ctx.lineWidth = 1
|
||||
for (let x = -gap; x < width + gap; x += gap) {
|
||||
const hot = Math.max(0, 1 - Math.abs(x - cx) / (width * 0.48))
|
||||
ctx.strokeStyle = `rgba(110,231,255,${0.04 + hot * 0.16})`
|
||||
ctx.beginPath(); ctx.moveTo(x, -gap); ctx.lineTo(x, height + gap); ctx.stroke()
|
||||
}
|
||||
for (let y = -gap; y < height + gap; y += gap) {
|
||||
const hot = Math.max(0, 1 - Math.abs(y - cy) / (height * 0.48))
|
||||
ctx.strokeStyle = `rgba(83,214,162,${0.035 + hot * 0.14})`
|
||||
ctx.beginPath(); ctx.moveTo(-gap, y); ctx.lineTo(width + gap, y); ctx.stroke()
|
||||
}
|
||||
ctx.restore()
|
||||
|
||||
const scan = ctx.createLinearGradient(0, scanY - 60, 0, scanY + 60)
|
||||
scan.addColorStop(0, 'rgba(110,231,255,0)')
|
||||
scan.addColorStop(.5, 'rgba(110,231,255,.22)')
|
||||
scan.addColorStop(1, 'rgba(110,231,255,0)')
|
||||
ctx.fillStyle = scan
|
||||
ctx.fillRect(0, scanY - 60, width, 120)
|
||||
|
||||
const beamX = reduceMotion ? cx : width * ((t * 0.13 + .22) % 1)
|
||||
const beam = ctx.createLinearGradient(beamX - 90, 0, beamX + 90, 0)
|
||||
beam.addColorStop(0, 'rgba(83,214,162,0)')
|
||||
beam.addColorStop(.5, 'rgba(83,214,162,.16)')
|
||||
beam.addColorStop(1, 'rgba(83,214,162,0)')
|
||||
ctx.fillStyle = beam
|
||||
ctx.fillRect(beamX - 90, 0, 180, height)
|
||||
|
||||
const count = 132
|
||||
for (let i = 0; i < count; i++) {
|
||||
const seed = i * 97.13
|
||||
const x = (Math.sin(seed) * 0.5 + 0.5) * width
|
||||
const y = ((Math.cos(seed * 1.7) * 0.5 + 0.5) * height + (reduceMotion ? 0 : t * (18 + i % 7))) % height
|
||||
const dist = Math.hypot(x - cx, y - cy)
|
||||
const active = i / count <= p
|
||||
ctx.beginPath()
|
||||
ctx.arc(x, y, active ? 2.4 : 1.2, 0, Math.PI * 2)
|
||||
ctx.fillStyle = active ? 'rgba(83,214,162,.95)' : `rgba(145,136,255,${Math.max(.12, .48 - dist / width)})`
|
||||
ctx.shadowColor = active ? '#53d6a2' : '#9188ff'
|
||||
ctx.shadowBlur = active ? 16 : 8
|
||||
ctx.fill()
|
||||
}
|
||||
|
||||
ctx.save()
|
||||
ctx.globalCompositeOperation = 'lighter'
|
||||
for (let i = 0; i < 34; i++) {
|
||||
const a = i * 2.399
|
||||
const r = base * (1.4 + (i % 9) * 0.13)
|
||||
const x1 = cx + Math.cos(a + t * 0.18) * r
|
||||
const y1 = cy + Math.sin(a + t * 0.12) * r * 0.58
|
||||
const x2 = cx + Math.cos(a + 1.2 + t * 0.1) * (r + base * 0.45)
|
||||
const y2 = cy + Math.sin(a + 1.2 + t * 0.16) * (r + base * 0.45) * 0.58
|
||||
const active = i / 34 <= p
|
||||
ctx.strokeStyle = active ? 'rgba(83,214,162,.34)' : 'rgba(110,231,255,.12)'
|
||||
ctx.lineWidth = active ? 1.5 : 1
|
||||
ctx.beginPath()
|
||||
ctx.moveTo(x1, y1)
|
||||
ctx.lineTo(x2, y2)
|
||||
ctx.stroke()
|
||||
}
|
||||
ctx.restore()
|
||||
|
||||
ctx.save()
|
||||
ctx.translate(cx, cy)
|
||||
ctx.rotate(reduceMotion ? 0 : t * 0.28)
|
||||
for (let i = 0; i < 5; i++) {
|
||||
const r = base + i * 18 + (reduceMotion ? 0 : Math.sin(t * 1.2 + i) * 5)
|
||||
ctx.beginPath()
|
||||
for (let v = 0; v < 6; v++) {
|
||||
const a = Math.PI / 6 + (Math.PI * 2 * v) / 6
|
||||
const x = Math.cos(a) * r
|
||||
const y = Math.sin(a) * r
|
||||
if (v === 0) ctx.moveTo(x, y)
|
||||
else ctx.lineTo(x, y)
|
||||
}
|
||||
ctx.closePath()
|
||||
ctx.strokeStyle = i % 2 ? 'rgba(83,214,162,.46)' : 'rgba(110,231,255,.52)'
|
||||
ctx.lineWidth = 2
|
||||
ctx.shadowColor = i % 2 ? '#53d6a2' : '#6ee7ff'
|
||||
ctx.shadowBlur = 14
|
||||
ctx.stroke()
|
||||
}
|
||||
ctx.rotate(reduceMotion ? 0 : -t * 0.64)
|
||||
for (let i = 0; i < 16; i++) {
|
||||
const a = (Math.PI * 2 * i) / 16
|
||||
const len = base * (0.42 + (i % 4) * 0.09)
|
||||
ctx.strokeStyle = i / 16 < p ? 'rgba(83,214,162,.78)' : 'rgba(145,136,255,.22)'
|
||||
ctx.lineWidth = 2
|
||||
ctx.beginPath()
|
||||
ctx.moveTo(Math.cos(a) * base * 0.35, Math.sin(a) * base * 0.35)
|
||||
ctx.lineTo(Math.cos(a) * (base * 0.35 + len), Math.sin(a) * (base * 0.35 + len))
|
||||
ctx.stroke()
|
||||
}
|
||||
const core = ctx.createRadialGradient(0, 0, 0, 0, 0, base * 0.85)
|
||||
core.addColorStop(0, 'rgba(255,255,255,.9)')
|
||||
core.addColorStop(.18, 'rgba(110,231,255,.68)')
|
||||
core.addColorStop(.42, 'rgba(83,214,162,.28)')
|
||||
core.addColorStop(1, 'rgba(83,214,162,0)')
|
||||
ctx.fillStyle = core
|
||||
ctx.shadowColor = '#6ee7ff'
|
||||
ctx.shadowBlur = 28
|
||||
ctx.beginPath()
|
||||
ctx.arc(0, 0, base * 0.8, 0, Math.PI * 2)
|
||||
ctx.fill()
|
||||
ctx.restore()
|
||||
}
|
||||
|
||||
function drawWarp(t, p, cx, cy) {
|
||||
const rays = 144
|
||||
const maxR = Math.hypot(width, height) * 0.58
|
||||
ctx.save()
|
||||
ctx.translate(cx, cy)
|
||||
ctx.rotate(reduceMotion ? 0 : Math.sin(t * 0.22) * 0.08)
|
||||
const tunnel = ctx.createRadialGradient(0, 0, 8, 0, 0, Math.min(width, height) * 0.48)
|
||||
tunnel.addColorStop(0, 'rgba(255,255,255,.7)')
|
||||
tunnel.addColorStop(.12, 'rgba(110,231,255,.24)')
|
||||
tunnel.addColorStop(.55, 'rgba(124,108,255,.1)')
|
||||
tunnel.addColorStop(1, 'rgba(0,0,0,0)')
|
||||
ctx.fillStyle = tunnel
|
||||
ctx.fillRect(-width / 2, -height / 2, width, height)
|
||||
|
||||
for (let i = 0; i < 12; i++) {
|
||||
const phase = reduceMotion ? 0 : (t * 0.48 + i * 0.09) % 1
|
||||
const r = 30 + ((i / 12 + phase) % 1) * maxR
|
||||
const alpha = Math.max(0, 0.5 - r / maxR * 0.45)
|
||||
ctx.beginPath()
|
||||
ctx.ellipse(0, 0, r * 1.34, r * 0.7, t * 0.08 + i * 0.42, 0, Math.PI * 2)
|
||||
ctx.strokeStyle = `rgba(110,231,255,${alpha})`
|
||||
ctx.lineWidth = 1 + (1 - r / maxR) * 3
|
||||
ctx.shadowColor = '#6ee7ff'
|
||||
ctx.shadowBlur = 14
|
||||
ctx.stroke()
|
||||
}
|
||||
|
||||
for (let i = 0; i < rays; i++) {
|
||||
const a = (Math.PI * 2 * i) / rays
|
||||
const speed = reduceMotion ? 0 : (t * (110 + (i % 11) * 10))
|
||||
const start = 20 + ((i * 23 + speed) % 210)
|
||||
const len = 80 + p * 170 + (i % 5) * 18
|
||||
const alpha = 0.1 + p * 0.52
|
||||
const g = ctx.createLinearGradient(Math.cos(a) * start, Math.sin(a) * start, Math.cos(a) * (start + len), Math.sin(a) * (start + len))
|
||||
g.addColorStop(0, 'rgba(110,231,255,0)')
|
||||
g.addColorStop(.45, `rgba(124,108,255,${alpha})`)
|
||||
g.addColorStop(.78, `rgba(110,231,255,${alpha * .58})`)
|
||||
g.addColorStop(1, 'rgba(83,214,162,0)')
|
||||
ctx.strokeStyle = g
|
||||
ctx.lineWidth = 1 + (i % 3)
|
||||
ctx.beginPath()
|
||||
ctx.moveTo(Math.cos(a) * start, Math.sin(a) * start)
|
||||
ctx.lineTo(Math.cos(a) * (start + len), Math.sin(a) * (start + len))
|
||||
ctx.stroke()
|
||||
}
|
||||
for (let i = 0; i < 9; i++) {
|
||||
const r = 34 + i * 31 + (reduceMotion ? 0 : Math.sin(t * 1.5 + i) * 7)
|
||||
ctx.beginPath()
|
||||
ctx.ellipse(0, 0, r * 1.42, r * 0.68, (reduceMotion ? 0 : t * 0.32) + i, 0, Math.PI * 2)
|
||||
ctx.strokeStyle = i % 2 ? 'rgba(83,214,162,.38)' : 'rgba(145,136,255,.45)'
|
||||
ctx.lineWidth = 2
|
||||
ctx.shadowColor = i % 2 ? '#53d6a2' : '#9188ff'
|
||||
ctx.shadowBlur = 15
|
||||
ctx.stroke()
|
||||
}
|
||||
|
||||
ctx.globalCompositeOperation = 'lighter'
|
||||
for (let i = 0; i < 48; i++) {
|
||||
const a = (Math.PI * 2 * i) / 48 + (reduceMotion ? 0 : t * 0.24)
|
||||
const r = 54 + ((i * 41 + (reduceMotion ? 0 : t * 150)) % 340)
|
||||
const x = Math.cos(a) * r
|
||||
const y = Math.sin(a) * r * 0.68
|
||||
const active = i / 48 < p
|
||||
ctx.beginPath()
|
||||
ctx.arc(x, y, active ? 3.4 : 1.7, 0, Math.PI * 2)
|
||||
ctx.fillStyle = active ? 'rgba(110,231,255,.92)' : 'rgba(145,136,255,.3)'
|
||||
ctx.shadowColor = active ? '#6ee7ff' : '#9188ff'
|
||||
ctx.shadowBlur = active ? 18 : 10
|
||||
ctx.fill()
|
||||
}
|
||||
|
||||
const core = ctx.createRadialGradient(0, 0, 0, 0, 0, Math.min(width, height) * 0.16)
|
||||
core.addColorStop(0, 'rgba(255,255,255,.94)')
|
||||
core.addColorStop(.16, 'rgba(110,231,255,.9)')
|
||||
core.addColorStop(.44, 'rgba(124,108,255,.34)')
|
||||
core.addColorStop(1, 'rgba(124,108,255,0)')
|
||||
ctx.fillStyle = core
|
||||
ctx.beginPath()
|
||||
ctx.arc(0, 0, Math.min(width, height) * 0.18, 0, Math.PI * 2)
|
||||
ctx.fill()
|
||||
ctx.restore()
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
reduceMotion = window.matchMedia?.('(prefers-reduced-motion: reduce)').matches || false
|
||||
resize()
|
||||
window.addEventListener('resize', resize)
|
||||
draw()
|
||||
})
|
||||
|
||||
onUnmounted(() => {
|
||||
cancelAnimationFrame(frame)
|
||||
window.removeEventListener('resize', resize)
|
||||
})
|
||||
|
||||
watch(() => props.progress, () => {
|
||||
if (reduceMotion) draw()
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<canvas ref="canvas" class="analysis-canvas" aria-hidden="true" />
|
||||
</template>
|
||||
2
frontend/src/components/BrowserBlocked.vue
Normal file
@@ -0,0 +1,2 @@
|
||||
<script setup>import{MonitorX,Box}from'lucide-vue-next'</script>
|
||||
<template><div class="browser-blocked"><section class="blocked-card"><span><MonitorX/></span><small>DESKTOP RUNTIME REQUIRED</small><h1>请在 Code Count 桌面程序中打开</h1><p>当前页面是普通浏览器预览,无法访问本地目录、SQLite 数据库或 Git。请关闭此页面并运行 <code>build/bin/code-count.exe</code>。</p><div><Box/>本地功能已在浏览器中停用,数据不会被模拟或丢弃。</div></section></div></template>
|
||||
6
frontend/src/components/ChartView.vue
Normal file
@@ -0,0 +1,6 @@
|
||||
<script setup>
|
||||
import { onBeforeUnmount,onMounted,ref,watch } from 'vue';import * as echarts from 'echarts'
|
||||
const props=defineProps({option:{type:Object,required:true}}),emit=defineEmits(['click','datazoom']),el=ref(), chart=ref();let ro
|
||||
onMounted(()=>{chart.value=echarts.init(el.value);chart.value.setOption(props.option);chart.value.on('click',e=>emit('click',e));chart.value.on('datazoom',e=>emit('datazoom',e));ro=new ResizeObserver(()=>chart.value?.resize());ro.observe(el.value)})
|
||||
watch(()=>props.option,v=>chart.value?.setOption(v,true),{deep:true});onBeforeUnmount(()=>{ro?.disconnect();chart.value?.dispose()})
|
||||
</script><template><div ref="el" class="chart"/></template>
|
||||
4
frontend/src/components/CommitDrawer.vue
Normal file
@@ -0,0 +1,4 @@
|
||||
<script setup>
|
||||
import{Copy,X,FileCode2}from'lucide-vue-next';import{useI18n}from'vue-i18n'
|
||||
defineProps({detail:Object,loading:Boolean});const emit=defineEmits(['close']),{t}=useI18n();async function copy(v){await navigator.clipboard.writeText(v)}
|
||||
</script><template><div class="drawer-mask" @click.self="emit('close')"><aside class="commit-drawer"><header><div><small>{{t('commitDetail')}}</small><h2>{{detail?.message||'...'}}</h2></div><button @click="emit('close')"><X/></button></header><div v-if="loading" class="empty">Loading...</div><template v-else-if="detail"><div class="commit-meta"><code>{{detail.hash}}</code><button :title="t('copyHash')" @click="copy(detail.hash)"><Copy/></button><span>{{detail.author}} · {{detail.email}}</span><time>{{detail.date}}</time><b class="positive">+{{detail.added}}</b><b class="negative">-{{detail.deleted}}</b></div><h3>{{t('filesChanged')}} ({{detail.files?.length||0}})</h3><div class="change-file" v-for="f in detail.files" :key="f.path"><FileCode2/><span>{{f.path}}</span><small>{{f.status}}</small><b class="positive">+{{f.added}}</b><b class="negative">-{{f.deleted}}</b></div></template></aside></div></template>
|
||||
10
frontend/src/components/DatabaseSetup.vue
Normal file
@@ -0,0 +1,10 @@
|
||||
<script setup>
|
||||
import{computed,ref}from'vue';import{Database,FolderOpen,RefreshCw,ShieldCheck,TriangleAlert}from'lucide-vue-next';import{call}from'../api';import{useAppStore}from'../store'
|
||||
const props=defineProps({status:{type:Object,required:true}}),store=useAppStore(),path=ref(props.status.databasePath||props.status.defaultPath||''),busy=ref(false),error=ref('')
|
||||
const recovery=computed(()=>props.status.state==='recovery_required')
|
||||
const messages={BOOTSTRAP_INVALID:'数据库位置配置已损坏,请重新选择保存位置。',DB_OPEN_FAILED:'无法打开数据库,请检查文件权限或重新选择位置。',DB_FILE_MISSING:'原数据库文件不存在,请选择新位置创建数据库。',DB_FILE_UNREADABLE:'数据库文件不可读取,请重新选择位置。',DB_DIRECTORY_UNWRITABLE:'该目录不可写,请选择其他位置。',DB_INTEGRITY_FAILED:'数据库文件已损坏,请选择新位置创建数据库。'}
|
||||
async function browse(){const p=await call('SelectInitialDatabaseFile',path.value);if(p)path.value=p}
|
||||
async function initialize(retry=false){busy.value=true;error.value='';try{store.bootstrap=retry?await call('RetryDatabase'):await call('InitializeDatabase',path.value);if(store.bootstrap.state==='ready')await store.refresh()}catch(e){error.value=messages[String(e).split(':')[0]]||String(e);store.bootstrap=await call('GetBootstrapStatus')}finally{busy.value=false}}
|
||||
</script>
|
||||
<template><div class="setup-screen"><section class="setup-card glass"><div class="setup-icon"><Database/></div><span class="setup-kicker"><ShieldCheck/>本地数据存储</span><h1>{{recovery?'恢复数据库连接':'初始化 Code Count'}}</h1><p>{{recovery?'上次使用的数据库当前不可用。你可以重试,或选择新的 SQLite 数据库位置。':'选择统计数据和项目配置的保存位置。后续启动将自动使用此数据库。'}}</p><div v-if="recovery" class="setup-warning"><TriangleAlert/><div><b>{{messages[status.errorCode]||status.errorCode}}</b><small>{{status.errorDetail}}</small></div></div><label>数据库文件<div class="setup-path"><input v-model="path"/><button title="选择位置" @click="browse"><FolderOpen/></button></div></label><small class="setup-default">默认位置:{{status.defaultPath}}</small><p v-if="error" class="form-error">{{error}}</p><div class="setup-actions"><button v-if="recovery" class="btn secondary" :disabled="busy" @click="initialize(true)"><RefreshCw :class="{spin:busy}"/>重试原位置</button><button class="btn primary" :disabled="busy||!path" @click="initialize(false)"><Database/>{{busy?'正在初始化...':'初始化数据库'}}</button></div></section></div></template>
|
||||
<style scoped>.setup-screen{background-color:var(--bg);background-image:linear-gradient(rgba(123,115,255,.055) 1px,transparent 1px),linear-gradient(90deg,rgba(123,115,255,.045) 1px,transparent 1px),linear-gradient(135deg,rgba(67,201,150,.08),transparent 36%,rgba(91,86,192,.11) 72%,transparent);background-size:40px 40px,40px 40px,100% 100%}</style>
|
||||
64
frontend/src/components/GitHeatmap.vue
Normal file
@@ -0,0 +1,64 @@
|
||||
<script setup>
|
||||
import { computed, ref } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
|
||||
const props = defineProps({ days: { type: Array, default: () => [] }, selected: String })
|
||||
const emit = defineEmits(['select'])
|
||||
const { locale } = useI18n()
|
||||
const hover = ref(null)
|
||||
const weekMs = 7 * 24 * 60 * 60 * 1000
|
||||
|
||||
const matrix = computed(() => {
|
||||
const end = new Date()
|
||||
end.setHours(0, 0, 0, 0)
|
||||
const start = new Date(end)
|
||||
start.setDate(start.getDate() - 364)
|
||||
start.setDate(start.getDate() - start.getDay())
|
||||
const counts = new Map(props.days.map(x => [x.date, Number(x.count || 0)]))
|
||||
const cells = []
|
||||
for (let d = new Date(start); d <= end; d.setDate(d.getDate() + 1)) {
|
||||
const date = d.toISOString().slice(0, 10)
|
||||
const count = counts.get(date) || 0
|
||||
cells.push({ date, count, week: Math.floor((d - start) / weekMs), dow: d.getDay(), level: Math.min(4, count === 0 ? 0 : count < 2 ? 1 : count < 5 ? 2 : count < 10 ? 3 : 4) })
|
||||
}
|
||||
const labels = []
|
||||
let lastMonth = -1
|
||||
for (let d = new Date(start); d <= end; d.setDate(d.getDate() + 7)) {
|
||||
const m = d.getMonth()
|
||||
if (m !== lastMonth) {
|
||||
labels.push({ week: Math.floor((d - start) / weekMs), text: d.toLocaleString(locale.value === 'zh-CN' ? 'zh-CN' : 'en', { month: 'short' }) })
|
||||
lastMonth = m
|
||||
}
|
||||
}
|
||||
return { cells, labels, weeks: Math.max(53, ...cells.map(x => x.week + 1)) }
|
||||
})
|
||||
|
||||
function pick(cell) {
|
||||
if (!cell.date) return
|
||||
emit('select', cell.date === props.selected ? '' : cell.date)
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="heat-grid-wrap" :style="{ '--weeks': matrix.weeks }">
|
||||
<div class="heat-months">
|
||||
<span v-for="m in matrix.labels" :key="m.week + m.text" :style="{ gridColumnStart: m.week + 1 }">{{ m.text }}</span>
|
||||
</div>
|
||||
<div class="heat-body">
|
||||
<div class="heat-weekdays"><span>S</span><span>M</span><span>T</span><span>W</span><span>T</span><span>F</span><span>S</span></div>
|
||||
<div class="heat-grid">
|
||||
<button
|
||||
v-for="cell in matrix.cells"
|
||||
:key="cell.date"
|
||||
class="heat-cell"
|
||||
:class="['l' + cell.level, { selected: cell.date === props.selected }]"
|
||||
:style="{ gridColumnStart: cell.week + 1, gridRowStart: cell.dow + 1 }"
|
||||
@mouseenter="hover = cell"
|
||||
@mouseleave="hover = null"
|
||||
@click="pick(cell)"
|
||||
/>
|
||||
</div>
|
||||
<div v-if="hover" class="heat-tooltip">{{ hover.date }} · {{ hover.count }} {{ locale === 'zh-CN' ? '次提交' : 'commits' }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
7
frontend/src/components/GitTrend.vue
Normal file
@@ -0,0 +1,7 @@
|
||||
<script setup>
|
||||
import{computed,ref}from'vue';import{useI18n}from'vue-i18n';import ChartView from './ChartView.vue'
|
||||
const props=defineProps({commits:{type:Array,default:()=>[]}}),emit=defineEmits(['select']),mode=ref('day'),{t}=useI18n()
|
||||
function bucket(date){const d=new Date(date);if(mode.value==='month')return date.slice(0,7);if(mode.value==='week'){const x=new Date(d);x.setDate(d.getDate()-((d.getDay()+6)%7));return x.toISOString().slice(0,10)};return date.slice(0,10)}
|
||||
const option=computed(()=>{const map={};props.commits.forEach(c=>{const k=bucket(c.date);map[k]=(map[k]||0)+1});const rows=Object.entries(map).sort();return{tooltip:{trigger:'axis'},grid:{left:34,right:18,top:18,bottom:48},dataZoom:[{type:'inside'},{type:'slider',height:16,bottom:5}],xAxis:{type:'category',data:rows.map(x=>x[0]),axisLabel:{color:'#929bac'}},yAxis:{type:'value',axisLabel:{color:'#929bac'},splitLine:{lineStyle:{color:'rgba(146,155,172,.15)'}}},series:[{type:'line',smooth:true,data:rows.map(x=>x[1]),areaStyle:{color:'rgba(123,115,255,.15)'},lineStyle:{color:'#7b73ff'},symbolSize:7}]}})
|
||||
</script><template><div class="git-trend"><div class="segments"><button v-for="m in ['day','week','month']" :key="m" :class="{active:mode===m}" @click="mode=m">{{t(m)}}</button></div><ChartView :option="option" @click="e=>emit('select',e.name)"/></div></template>
|
||||
|
||||
71
frontend/src/components/HelloWorld.vue
Normal file
@@ -0,0 +1,71 @@
|
||||
<script setup>
|
||||
import {reactive} from 'vue'
|
||||
import {Greet} from '../../wailsjs/go/main/App'
|
||||
|
||||
const data = reactive({
|
||||
name: "",
|
||||
resultText: "Please enter your name below 👇",
|
||||
})
|
||||
|
||||
function greet() {
|
||||
Greet(data.name).then(result => {
|
||||
data.resultText = result
|
||||
})
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<main>
|
||||
<div id="result" class="result">{{ data.resultText }}</div>
|
||||
<div id="input" class="input-box">
|
||||
<input id="name" v-model="data.name" autocomplete="off" class="input" type="text"/>
|
||||
<button class="btn" @click="greet">Greet</button>
|
||||
</div>
|
||||
</main>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.result {
|
||||
height: 20px;
|
||||
line-height: 20px;
|
||||
margin: 1.5rem auto;
|
||||
}
|
||||
|
||||
.input-box .btn {
|
||||
width: 60px;
|
||||
height: 30px;
|
||||
line-height: 30px;
|
||||
border-radius: 3px;
|
||||
border: none;
|
||||
margin: 0 0 0 20px;
|
||||
padding: 0 8px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.input-box .btn:hover {
|
||||
background-image: linear-gradient(to top, #cfd9df 0%, #e2ebf0 100%);
|
||||
color: #333333;
|
||||
}
|
||||
|
||||
.input-box .input {
|
||||
border: none;
|
||||
border-radius: 3px;
|
||||
outline: none;
|
||||
height: 30px;
|
||||
line-height: 30px;
|
||||
padding: 0 10px;
|
||||
background-color: rgba(240, 240, 240, 1);
|
||||
-webkit-font-smoothing: antialiased;
|
||||
}
|
||||
|
||||
.input-box .input:hover {
|
||||
border: none;
|
||||
background-color: rgba(255, 255, 255, 1);
|
||||
}
|
||||
|
||||
.input-box .input:focus {
|
||||
border: none;
|
||||
background-color: rgba(255, 255, 255, 1);
|
||||
}
|
||||
</style>
|
||||
10
frontend/src/components/StatCard.vue
Normal file
@@ -0,0 +1,10 @@
|
||||
<script setup>
|
||||
defineProps({ label: String, value: [String, Number], icon: Object, tone: { type: String, default: 'violet' } })
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section class="stat-card shine-card">
|
||||
<span class="stat-icon" :class="tone"><component :is="icon" /></span>
|
||||
<div class="stat-copy"><strong class="stat-value">{{ value ?? 0 }}</strong><small>{{ label }}</small></div>
|
||||
</section>
|
||||
</template>
|
||||
1
frontend/src/database.css
Normal file
@@ -0,0 +1 @@
|
||||
.db-title{display:flex;align-items:center;justify-content:space-between}.db-title h2{display:flex;align-items:center;gap:9px}.db-title h2 svg{width:20px;color:#9188ff}.db-connected{display:flex;align-items:center;gap:6px;color:var(--green);font-size:13px}.db-connected svg{width:16px}.preview-notice{display:flex;gap:12px;margin-top:18px;padding:14px;border:1px solid rgba(79,157,245,.3);background:rgba(79,157,245,.09);border-radius:7px;color:var(--blue)}.preview-notice>svg{width:20px;flex:none}.preview-notice b,.preview-notice small{display:block}.preview-notice small{color:var(--muted);margin-top:4px}.database-panel .db-path{display:grid;grid-template-columns:90px minmax(0,1fr) 38px;align-items:center;gap:10px;border:1px solid var(--glass-border);border-radius:7px;background:var(--glass-soft);padding:12px 12px 12px 16px}.db-path>span{font-weight:bold}.db-path code{display:block;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;color:#9188ff}.db-path button{height:34px;border:0;border-radius:6px;background:rgba(123,115,255,.14);color:#9188ff;display:grid;place-items:center;cursor:pointer}.db-path button:disabled{opacity:.4;cursor:not-allowed}.db-path button svg{width:16px}.db-message{color:var(--green);font-size:13px}.migrate:disabled{opacity:.45;cursor:not-allowed}.database-panel{animation:card-enter .45s both}
|
||||
4
frontend/src/git.css
Normal file
@@ -0,0 +1,4 @@
|
||||
*{scrollbar-width:thin;scrollbar-color:rgba(145,136,255,.55) transparent}::-webkit-scrollbar{width:9px;height:9px}::-webkit-scrollbar-track{background:transparent}::-webkit-scrollbar-thumb{background:rgba(145,136,255,.38);border:2px solid transparent;background-clip:padding-box;border-radius:8px}::-webkit-scrollbar-thumb:hover{background:rgba(145,136,255,.7);border:2px solid transparent;background-clip:padding-box}
|
||||
.wsl-picker{display:flex;gap:8px;margin:12px 24px 0}.wsl-picker select{flex:1;background:var(--glass-soft);border:1px solid var(--border);border-radius:7px;color:var(--text);padding:0 10px}.icon-actions button:disabled{opacity:.5;cursor:not-allowed}
|
||||
.page{overflow-x:hidden}.project-title>div:first-child{min-width:0;flex:1}.project-title p{max-width:100%!important}.icon-actions{flex:none}.project-card{min-width:0}
|
||||
.git-context{display:flex;align-items:center;gap:18px;margin:-8px 0 18px;padding:11px 15px;border:1px solid var(--glass-border);border-radius:7px;background:var(--glass-soft);color:var(--muted)}.git-context span{display:flex;align-items:center;gap:7px}.git-context svg{width:17px;color:#9188ff}.git-context b{color:var(--text)}.heat-panel{height:255px}.heat-panel .chart{height:185px}.branch.interactive{position:relative;padding-right:52px;cursor:pointer;transition:border-color .2s,background .2s}.branch.interactive:hover,.branch.interactive.selected{background:rgba(123,115,255,.12);outline:1px solid rgba(145,136,255,.35)}.checkout-btn{position:absolute;right:12px;top:20px;width:32px;height:32px;border:0;border-radius:6px;background:rgba(123,115,255,.15);color:#9188ff;display:grid;place-items:center;cursor:pointer}.checkout-btn svg{width:16px}.commit{width:100%;border:0;color:var(--text);text-align:left;cursor:pointer}.commit:hover{outline:1px solid rgba(145,136,255,.3)}.git-trend{position:relative}.git-trend>.segments{position:absolute;right:0;top:-38px;z-index:2}.git-trend .chart{height:280px}.drawer-mask{position:fixed;inset:0;z-index:60;background:rgba(0,0,0,.55);backdrop-filter:blur(5px);display:flex;justify-content:flex-end;animation:overlay-in .2s}.commit-drawer{width:min(620px,90vw);height:100%;overflow:auto;background:var(--glass-strong);border-left:1px solid var(--glass-border);box-shadow:-20px 0 50px rgba(0,0,0,.3);padding:26px;animation:drawer-in .3s cubic-bezier(.16,1,.3,1)}.commit-drawer header{display:flex;justify-content:space-between;gap:20px;border-bottom:1px solid var(--border);padding-bottom:18px}.commit-drawer header small{color:var(--muted)}.commit-drawer h2{margin:7px 0 0;font-size:20px}.commit-drawer header button,.commit-meta button{border:0;background:var(--glass-soft);color:var(--text);width:34px;height:34px;border-radius:6px;display:grid;place-items:center;cursor:pointer}.commit-drawer svg{width:17px}.commit-meta{display:grid;grid-template-columns:1fr auto auto auto;gap:10px;align-items:center;margin:20px 0;padding:15px;background:var(--glass-soft);border-radius:7px}.commit-meta code{min-width:0;overflow:hidden;text-overflow:ellipsis}.commit-meta span,.commit-meta time{grid-column:1/3;color:var(--muted)}.change-file{display:grid;grid-template-columns:22px 1fr auto auto auto;gap:10px;align-items:center;padding:11px;border-bottom:1px solid var(--border)}.change-file span{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.change-file small{color:var(--muted)}@keyframes drawer-in{from{transform:translateX(100%)}to{transform:none}}@media(prefers-reduced-motion:reduce){.commit-drawer{animation:none}}
|
||||
354
frontend/src/main.js
Normal file
@@ -0,0 +1,354 @@
|
||||
import { createApp } from 'vue'
|
||||
import { createPinia } from 'pinia'
|
||||
import { createRouter, createWebHashHistory } from 'vue-router'
|
||||
import { createI18n } from 'vue-i18n'
|
||||
import App from './App.vue'
|
||||
import Dashboard from './views/Dashboard.vue'
|
||||
import ProjectDetail from './views/ProjectDetail.vue'
|
||||
import Logs from './views/Logs.vue'
|
||||
import Settings from './views/Settings.vue'
|
||||
import './style.css'
|
||||
import './motion.css'
|
||||
import './database.css'
|
||||
import './runtime.css'
|
||||
import './git.css'
|
||||
import './polish.css'
|
||||
|
||||
const zh = {
|
||||
app: 'Code Count',
|
||||
dashboard: '仪表盘',
|
||||
logs: '运行日志',
|
||||
settings: '设置',
|
||||
projects: '我的项目',
|
||||
addProject: '添加项目',
|
||||
batch: '批量统计',
|
||||
analyzingProject: '正在统计项目',
|
||||
search: '搜索项目...',
|
||||
totalProjects: '项目总数',
|
||||
totalLines: '代码总行数',
|
||||
commits: 'Git 提交数',
|
||||
code: '代码统计',
|
||||
git: 'Git 分析',
|
||||
structure: '项目结构',
|
||||
insights: '检查',
|
||||
analyze: '重新分析',
|
||||
analyzeGit: '重新分析 Git',
|
||||
empty: '暂无数据',
|
||||
back: '返回',
|
||||
refreshProject: '更新此项目',
|
||||
edit: '编辑',
|
||||
delete: '删除',
|
||||
add: '新增',
|
||||
save: '保存',
|
||||
cancel: '取消',
|
||||
browse: '浏览',
|
||||
selectWSL: '选择 WSL 目录',
|
||||
noWSL: '未发现可用的 WSL 发行版',
|
||||
dashboardSubtitle: '管理和分析你的代码项目',
|
||||
projectName: '项目名称',
|
||||
projectPath: '项目路径',
|
||||
description: '描述(可选)',
|
||||
addProjectTitle: '添加项目',
|
||||
editProjectTitle: '编辑项目',
|
||||
projectGroup: '项目组',
|
||||
allProjectGroups: '全部项目组',
|
||||
myProjectGroup: '我的项目组',
|
||||
addProjectGroup: '新增项目组',
|
||||
editProjectGroup: '编辑项目组',
|
||||
deleteProjectGroup: '删除项目组',
|
||||
projectGroupName: '项目组名称',
|
||||
saveProjectGroup: '保存项目组',
|
||||
saveProject: '保存项目',
|
||||
saving: '正在保存...',
|
||||
pathRequired: '请选择项目目录',
|
||||
unanalyzed: '尚未分析',
|
||||
totalLineCount: '总行数',
|
||||
codeLines: '代码行',
|
||||
commentLines: '注释行',
|
||||
blankLines: '空行',
|
||||
fileCount: '文件数',
|
||||
languageDistribution: '语言分布',
|
||||
languageDetails: '语言详情',
|
||||
files: '文件',
|
||||
lines: '行',
|
||||
workspaceBranch: '工作区分支',
|
||||
viewRef: '统计视图',
|
||||
switchView: '查看统计',
|
||||
checkout: '切换工作区',
|
||||
checkoutConfirm: '确认将工作区切换到分支 {ref}?未提交或未跟踪改动会导致操作被拒绝。',
|
||||
dirty: '工作区存在未提交或未跟踪文件,已拒绝切换',
|
||||
branchChanged: '工作区分支已切换',
|
||||
commitDetail: '提交详情',
|
||||
copyHash: '复制哈希',
|
||||
filesChanged: '变更文件',
|
||||
clearFilter: '清除筛选',
|
||||
selectedDate: '已筛选 {date}',
|
||||
day: '日',
|
||||
week: '周',
|
||||
month: '月',
|
||||
commitCount: '总提交数',
|
||||
addedLines: '新增行数',
|
||||
deletedLines: '删除行数',
|
||||
contributors: '贡献者数',
|
||||
activityHeatmap: '活跃度热力图',
|
||||
branches: '分支信息',
|
||||
recentCommits: '最近提交',
|
||||
commitTrend: '提交趋势',
|
||||
contributorRanking: '贡献者排行',
|
||||
commitsUnit: '提交',
|
||||
gitUnavailable: 'Git 数据不可用',
|
||||
gitUnavailableHint: '当前项目的 Git 信息读取失败,代码统计不会受影响。',
|
||||
gitDetail: '诊断详情',
|
||||
totalFiles: '总文件数',
|
||||
folderCount: '文件夹数',
|
||||
totalSize: '总大小',
|
||||
largeFiles: '大文件数',
|
||||
directoryStructure: '目录结构',
|
||||
folderSize: '文件夹大小',
|
||||
largeFileDetection: '大文件检测(≥ 1 MB)',
|
||||
noLargeFiles: '未发现大文件',
|
||||
deepInsights: '深度检查',
|
||||
deepInsightsHint: '基于代码结构、源码标记和 Git 活跃度识别维护风险。',
|
||||
healthScore: '健康分',
|
||||
highRisk: '高风险',
|
||||
mediumRisk: '中风险',
|
||||
lowRisk: '低风险',
|
||||
issueList: '问题列表',
|
||||
allSeverity: '全部级别',
|
||||
allTypes: '全部类型',
|
||||
noIssues: '暂无风险项',
|
||||
insightDone: '深度检查完成',
|
||||
severity: { high: '高风险', medium: '中风险', low: '低风险' },
|
||||
quickSettings: '快捷设置',
|
||||
language: '语言',
|
||||
theme: '主题',
|
||||
themeDark: '暗色',
|
||||
themeLight: '浅色',
|
||||
themeSystem: '跟随系统',
|
||||
glassOpacity: '卡片透明度',
|
||||
loadingStyle: '统计 Loading 样式',
|
||||
openSettings: '打开设置页',
|
||||
logSubtitle: '查看应用运行状态和错误信息',
|
||||
autoRefresh: '自动刷新',
|
||||
refresh: '刷新',
|
||||
clearLogs: '清空日志',
|
||||
allLogs: '全部日志',
|
||||
runLogs: '运行日志',
|
||||
errorLogs: '错误日志',
|
||||
totalLogs: '总日志',
|
||||
info: '信息',
|
||||
warning: '警告',
|
||||
error: '错误',
|
||||
noLogs: '暂无日志记录',
|
||||
errors: {
|
||||
PROJECT_PATH_NOT_FOUND: '项目目录不存在',
|
||||
PROJECT_PATH_UNREADABLE: '项目目录不可读取',
|
||||
PROJECT_PATH_NOT_DIRECTORY: '选择的路径不是目录',
|
||||
PROJECT_PATH_DUPLICATE: '该项目目录已经添加',
|
||||
PROJECT_GROUP_NOT_FOUND: '项目组不存在',
|
||||
PROJECT_GROUP_NAME_REQUIRED: '请输入项目组名称',
|
||||
PROJECT_GROUP_DEFAULT_READONLY: '默认项目组不能修改或删除',
|
||||
PROJECT_GROUP_DUPLICATE: '项目组名称已存在',
|
||||
DATABASE_NOT_READY: '数据库尚未初始化',
|
||||
PROJECT_SAVE_FAILED: '项目保存失败',
|
||||
NOT_GIT_REPOSITORY: '该目录不是 Git 仓库',
|
||||
GIT_NOT_INSTALLED: '系统未安装 Git',
|
||||
WSL_NOT_INSTALLED: '系统未安装 WSL',
|
||||
WSL_DISTRO_NOT_FOUND: '未找到对应 WSL 发行版',
|
||||
WSL_GIT_NOT_INSTALLED: 'WSL 发行版内未安装 Git',
|
||||
WSL_PATH_UNREADABLE: 'WSL 路径不可访问',
|
||||
GIT_PERMISSION_DENIED: 'Git 没有权限读取该仓库',
|
||||
GIT_SAFE_DIRECTORY: 'Git 拒绝读取该仓库,请检查 safe.directory 配置',
|
||||
GIT_REF_NOT_FOUND: '未找到该分支或引用',
|
||||
GIT_COMMAND_FAILED: 'Git 命令执行失败'
|
||||
},
|
||||
task: {
|
||||
start: '开始分析 {project}',
|
||||
scan: '正在扫描文件',
|
||||
count: '正在统计代码',
|
||||
save: '正在保存统计结果',
|
||||
git: '正在读取 Git 历史',
|
||||
completed: '分析完成',
|
||||
failed: '分析失败',
|
||||
cancelled: '分析已取消'
|
||||
}
|
||||
}
|
||||
|
||||
const en = {
|
||||
app: 'Code Count',
|
||||
dashboard: 'Dashboard',
|
||||
logs: 'Activity Log',
|
||||
settings: 'Settings',
|
||||
projects: 'Projects',
|
||||
addProject: 'Add project',
|
||||
batch: 'Analyze all',
|
||||
analyzingProject: 'Analyzing project',
|
||||
search: 'Search projects...',
|
||||
totalProjects: 'Projects',
|
||||
totalLines: 'Total lines',
|
||||
commits: 'Git commits',
|
||||
code: 'Code stats',
|
||||
git: 'Git analysis',
|
||||
structure: 'Structure',
|
||||
insights: 'Check',
|
||||
analyze: 'Analyze again',
|
||||
analyzeGit: 'Analyze Git again',
|
||||
empty: 'No data',
|
||||
back: 'Back',
|
||||
refreshProject: 'Update this project',
|
||||
edit: 'Edit',
|
||||
delete: 'Delete',
|
||||
add: 'Add',
|
||||
save: 'Save',
|
||||
cancel: 'Cancel',
|
||||
browse: 'Browse',
|
||||
selectWSL: 'Select WSL directory',
|
||||
noWSL: 'No WSL distribution found',
|
||||
dashboardSubtitle: 'Manage and analyze your code projects',
|
||||
projectName: 'Project name',
|
||||
projectPath: 'Project path',
|
||||
description: 'Description (optional)',
|
||||
addProjectTitle: 'Add project',
|
||||
editProjectTitle: 'Edit project',
|
||||
projectGroup: 'Project group',
|
||||
allProjectGroups: 'All project groups',
|
||||
myProjectGroup: 'My project group',
|
||||
addProjectGroup: 'Add project group',
|
||||
editProjectGroup: 'Edit project group',
|
||||
deleteProjectGroup: 'Delete project group',
|
||||
projectGroupName: 'Project group name',
|
||||
saveProjectGroup: 'Save project group',
|
||||
saveProject: 'Save project',
|
||||
saving: 'Saving...',
|
||||
pathRequired: 'Please select a project directory',
|
||||
unanalyzed: 'Not analyzed yet',
|
||||
totalLineCount: 'Total lines',
|
||||
codeLines: 'Code lines',
|
||||
commentLines: 'Comment lines',
|
||||
blankLines: 'Blank lines',
|
||||
fileCount: 'Files',
|
||||
languageDistribution: 'Language distribution',
|
||||
languageDetails: 'Language details',
|
||||
files: 'files',
|
||||
lines: 'lines',
|
||||
workspaceBranch: 'Workspace branch',
|
||||
viewRef: 'Statistics view',
|
||||
switchView: 'View statistics',
|
||||
checkout: 'Switch workspace',
|
||||
checkoutConfirm: 'Switch the workspace to {ref}? Uncommitted or untracked changes will be rejected.',
|
||||
dirty: 'The worktree has uncommitted or untracked files',
|
||||
branchChanged: 'Workspace branch changed',
|
||||
commitDetail: 'Commit details',
|
||||
copyHash: 'Copy hash',
|
||||
filesChanged: 'Changed files',
|
||||
clearFilter: 'Clear filter',
|
||||
selectedDate: 'Filtered by {date}',
|
||||
day: 'Day',
|
||||
week: 'Week',
|
||||
month: 'Month',
|
||||
commitCount: 'Commits',
|
||||
addedLines: 'Added lines',
|
||||
deletedLines: 'Deleted lines',
|
||||
contributors: 'Contributors',
|
||||
activityHeatmap: 'Activity heatmap',
|
||||
branches: 'Branches',
|
||||
recentCommits: 'Recent commits',
|
||||
commitTrend: 'Commit trend',
|
||||
contributorRanking: 'Contributor ranking',
|
||||
commitsUnit: 'commits',
|
||||
gitUnavailable: 'Git data unavailable',
|
||||
gitUnavailableHint: 'Git history could not be read for this project. Code statistics are unaffected.',
|
||||
gitDetail: 'Diagnostic detail',
|
||||
totalFiles: 'Total files',
|
||||
folderCount: 'Folders',
|
||||
totalSize: 'Total size',
|
||||
largeFiles: 'Large files',
|
||||
directoryStructure: 'Directory structure',
|
||||
folderSize: 'Folder size',
|
||||
largeFileDetection: 'Large files (≥ 1 MB)',
|
||||
noLargeFiles: 'No large files found',
|
||||
deepInsights: 'Deep inspection',
|
||||
deepInsightsHint: 'Find maintainability risks from structure, source markers, and Git activity.',
|
||||
healthScore: 'Health',
|
||||
highRisk: 'high',
|
||||
mediumRisk: 'medium',
|
||||
lowRisk: 'low',
|
||||
issueList: 'Issues',
|
||||
allSeverity: 'All severity',
|
||||
allTypes: 'All types',
|
||||
noIssues: 'No issues found',
|
||||
insightDone: 'Inspection completed',
|
||||
severity: { high: 'High', medium: 'Medium', low: 'Low' },
|
||||
quickSettings: 'Quick settings',
|
||||
language: 'Language',
|
||||
theme: 'Theme',
|
||||
themeDark: 'Dark',
|
||||
themeLight: 'Light',
|
||||
themeSystem: 'System',
|
||||
glassOpacity: 'Card opacity',
|
||||
loadingStyle: 'Analysis loading style',
|
||||
openSettings: 'Open settings',
|
||||
logSubtitle: 'View application status and errors',
|
||||
autoRefresh: 'Auto refresh',
|
||||
refresh: 'Refresh',
|
||||
clearLogs: 'Clear logs',
|
||||
allLogs: 'All logs',
|
||||
runLogs: 'Run logs',
|
||||
errorLogs: 'Error logs',
|
||||
totalLogs: 'Total logs',
|
||||
info: 'Info',
|
||||
warning: 'Warning',
|
||||
error: 'Error',
|
||||
noLogs: 'No logs yet',
|
||||
errors: {
|
||||
PROJECT_PATH_NOT_FOUND: 'Project directory does not exist',
|
||||
PROJECT_PATH_UNREADABLE: 'Project directory is not readable',
|
||||
PROJECT_PATH_NOT_DIRECTORY: 'Selected path is not a directory',
|
||||
PROJECT_PATH_DUPLICATE: 'This project path already exists',
|
||||
PROJECT_GROUP_NOT_FOUND: 'Project group does not exist',
|
||||
PROJECT_GROUP_NAME_REQUIRED: 'Enter a project group name',
|
||||
PROJECT_GROUP_DEFAULT_READONLY: 'The default project group cannot be changed or deleted',
|
||||
PROJECT_GROUP_DUPLICATE: 'Project group name already exists',
|
||||
DATABASE_NOT_READY: 'Database is not initialized',
|
||||
PROJECT_SAVE_FAILED: 'Failed to save project',
|
||||
NOT_GIT_REPOSITORY: 'This directory is not a Git repository',
|
||||
GIT_NOT_INSTALLED: 'Git is not installed',
|
||||
WSL_NOT_INSTALLED: 'WSL is not installed',
|
||||
WSL_DISTRO_NOT_FOUND: 'WSL distribution was not found',
|
||||
WSL_GIT_NOT_INSTALLED: 'Git is not installed inside the WSL distribution',
|
||||
WSL_PATH_UNREADABLE: 'WSL path is not accessible',
|
||||
GIT_PERMISSION_DENIED: 'Git does not have permission to read this repository',
|
||||
GIT_SAFE_DIRECTORY: 'Git refused this repository; check safe.directory',
|
||||
GIT_REF_NOT_FOUND: 'Branch or ref was not found',
|
||||
GIT_COMMAND_FAILED: 'Git command failed'
|
||||
},
|
||||
task: {
|
||||
start: 'Analyzing {project}',
|
||||
scan: 'Scanning files',
|
||||
count: 'Counting code',
|
||||
save: 'Saving statistics',
|
||||
git: 'Reading Git history',
|
||||
completed: 'Analysis completed',
|
||||
failed: 'Analysis failed',
|
||||
cancelled: 'Analysis cancelled'
|
||||
}
|
||||
}
|
||||
|
||||
const saved = JSON.parse(localStorage.getItem('cc-settings') || '{}')
|
||||
let theme = new URLSearchParams(location.search).get('theme') || saved.theme || 'dark'
|
||||
if (theme === 'system') theme = matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light'
|
||||
document.documentElement.dataset.theme = theme
|
||||
document.documentElement.style.setProperty('--glass-user-opacity', String((saved.glassOpacity || 55) / 100))
|
||||
|
||||
const i18n = createI18n({ legacy: false, locale: saved.locale || 'zh-CN', fallbackLocale: 'en', messages: { 'zh-CN': zh, en } })
|
||||
const router = createRouter({
|
||||
history: createWebHashHistory(),
|
||||
routes: [
|
||||
{ path: '/', component: Dashboard },
|
||||
{ path: '/project/:id', component: ProjectDetail },
|
||||
{ path: '/logs', component: Logs },
|
||||
{ path: '/settings', component: Settings }
|
||||
]
|
||||
})
|
||||
|
||||
createApp(App).use(createPinia()).use(router).use(i18n).mount('#app')
|
||||
9
frontend/src/motion.css
Normal file
@@ -0,0 +1,9 @@
|
||||
html{--glass-user-opacity:.55;--glass:rgba(27,35,48,var(--glass-user-opacity));--glass-strong:rgba(32,41,57,calc(var(--glass-user-opacity) + .12));--glass-soft:rgba(40,50,69,calc(var(--glass-user-opacity) - .1));--glass-border:rgba(164,178,211,.18);--glass-highlight:rgba(255,255,255,.07);--glass-shadow:0 18px 42px rgba(0,0,0,.22);--glass-blur:24px}
|
||||
html[data-theme=light]{--glass:rgba(255,255,255,calc(.72 + var(--glass-user-opacity) * .28));--glass-strong:rgba(255,255,255,calc(.8 + var(--glass-user-opacity) * .2));--glass-soft:rgba(244,247,252,calc(.64 + var(--glass-user-opacity) * .3));--glass-border:rgba(56,70,98,.16);--glass-highlight:rgba(255,255,255,.85);--glass-shadow:0 18px 42px rgba(40,53,78,.12)}
|
||||
main,.setup-screen{background-color:var(--bg);background-image:linear-gradient(rgba(123,115,255,.055) 1px,transparent 1px),linear-gradient(90deg,rgba(123,115,255,.045) 1px,transparent 1px),linear-gradient(135deg,rgba(67,201,150,.08),transparent 36%,rgba(91,86,192,.11) 72%,transparent);background-size:40px 40px,40px 40px,100% 100%;background-attachment:fixed}main{position:relative;isolation:isolate}.sidebar,.stat-card,.project-card,.panel,.modal,.taskbar,.toast,.tabs,.search,.setup-card{background:linear-gradient(135deg,var(--glass-highlight),transparent 42%),var(--glass);border-color:var(--glass-border);box-shadow:inset 0 1px 0 var(--glass-highlight),var(--glass-shadow);backdrop-filter:blur(var(--glass-blur)) saturate(145%);-webkit-backdrop-filter:blur(var(--glass-blur)) saturate(145%)}.sidebar{background:linear-gradient(145deg,var(--glass-highlight),transparent 38%),var(--glass-strong)}.modal,.setup-card{background:linear-gradient(135deg,var(--glass-highlight),transparent 45%),var(--glass-strong)}
|
||||
.page{animation:page-enter .48s cubic-bezier(.2,.8,.2,1) both}.page-head,.project-head{animation:fade-rise .42s .04s both}.stats-grid>.stat-card,.project-grid>*{animation:card-enter .5s cubic-bezier(.16,1,.3,1) both}.stats-grid>:nth-child(1),.project-grid>:nth-child(1){animation-delay:.08s}.stats-grid>:nth-child(2),.project-grid>:nth-child(2){animation-delay:.13s}.stats-grid>:nth-child(3),.project-grid>:nth-child(3){animation-delay:.18s}.stats-grid>:nth-child(4),.project-grid>:nth-child(4){animation-delay:.23s}.stats-grid>:nth-child(5),.project-grid>:nth-child(5){animation-delay:.28s}.project-grid>:nth-child(n+6){animation-delay:.32s}
|
||||
.stat-card,.panel,.project-card,.add-card{transition:transform .26s cubic-bezier(.2,.8,.2,1),border-color .26s,box-shadow .26s,background-color .26s}.stat-card:hover,.panel:hover{border-color:rgba(130,120,255,.38);box-shadow:inset 0 1px 0 var(--glass-highlight),0 22px 46px rgba(0,0,0,.25);transform:translateY(-2px)}.project-card:hover,.add-card:hover{transform:translateY(-5px);border-color:rgba(130,120,255,.6);box-shadow:inset 0 1px 0 var(--glass-highlight),0 25px 52px rgba(0,0,0,.3);background:var(--glass-strong)}
|
||||
.stat-card strong{animation:number-arrive .55s .2s both}.overlay{animation:overlay-in .24s both}.modal{animation:modal-in .32s cubic-bezier(.16,1,.3,1) both}.toast{animation:toast-in .36s cubic-bezier(.16,1,.3,1) both}.taskbar{animation:task-in .38s cubic-bezier(.16,1,.3,1) both}.taskbar .progress i{transition:width .4s cubic-bezier(.2,.8,.2,1);position:relative;overflow:hidden}.taskbar .progress i:after{content:"";position:absolute;inset:0;background:rgba(255,255,255,.35);animation:progress-sweep 1.2s linear infinite}.heatmap i[class]:not(.l0){animation:heat-in .38s both}.heatmap i:nth-child(5n){animation-delay:.08s}.heatmap i:nth-child(7n){animation-delay:.14s}.spin{animation:spin .9s linear infinite}.btn,.tabs button,.icon-actions button{transition:background-color .2s,border-color .2s,color .2s,box-shadow .2s,transform .2s}.btn:active,.tabs button:active{transform:translateY(1px)}button:focus-visible,input:focus-visible,textarea:focus-visible,select:focus-visible,a:focus-visible{outline:2px solid #9188ff;outline-offset:2px}
|
||||
.boot-loading,.setup-screen{min-height:100vh;display:grid;place-items:center;background:var(--bg)}.boot-loading{gap:12px;color:var(--muted)}.boot-loading svg{width:28px}.setup-screen{padding:32px}.setup-card{width:min(620px,100%);padding:42px;border:1px solid var(--glass-border);border-radius:10px;animation:setup-in .55s cubic-bezier(.16,1,.3,1) both}.setup-icon{width:62px;height:62px;display:grid;place-items:center;background:rgba(115,103,245,.18);color:#9188ff;border:1px solid rgba(145,136,255,.28);border-radius:10px;margin-bottom:24px}.setup-icon svg{width:30px}.setup-kicker{display:flex;align-items:center;gap:7px;color:#9b94ff;font-size:13px;font-weight:bold}.setup-kicker svg{width:16px}.setup-card h1{font-size:30px;margin:10px 0}.setup-card>p{color:var(--muted);line-height:1.65}.setup-card label{display:block;margin-top:26px;font-size:13px;font-weight:bold}.setup-path{display:grid;grid-template-columns:1fr 44px;margin-top:8px}.setup-path input{height:44px;border:1px solid var(--border);border-radius:7px 0 0 7px;background:var(--glass-soft);color:var(--text);padding:0 13px;min-width:0}.setup-path button{border:1px solid var(--border);border-left:0;border-radius:0 7px 7px 0;background:var(--glass-soft);color:var(--text);cursor:pointer}.setup-path svg{width:19px}.setup-default{display:block;color:var(--muted);margin-top:8px;overflow-wrap:anywhere}.setup-warning{display:flex;gap:12px;background:rgba(240,94,104,.1);border:1px solid rgba(240,94,104,.28);padding:14px;border-radius:8px;margin-top:20px;color:var(--red)}.setup-warning svg{width:20px;flex:none}.setup-warning b,.setup-warning small{display:block}.setup-warning small{margin-top:5px;opacity:.8;overflow-wrap:anywhere}.setup-actions{display:flex;justify-content:flex-end;gap:10px;margin-top:28px}
|
||||
@keyframes page-enter{from{opacity:0;transform:translateY(12px)}to{opacity:1;transform:none}}@keyframes fade-rise{from{opacity:0;transform:translateY(8px)}to{opacity:1;transform:none}}@keyframes card-enter{from{opacity:0;transform:translateY(18px)}to{opacity:1;transform:none}}@keyframes number-arrive{from{opacity:0;transform:translateY(7px)}to{opacity:1;transform:none}}@keyframes overlay-in{from{opacity:0}to{opacity:1}}@keyframes modal-in{from{opacity:0;transform:translateY(14px) scale(.97)}to{opacity:1;transform:none}}@keyframes toast-in{from{opacity:0;transform:translateX(24px)}to{opacity:1;transform:none}}@keyframes task-in{from{opacity:0;transform:translate(-50%,18px)}to{opacity:1;transform:translate(-50%,0)}}@keyframes progress-sweep{from{transform:translateX(-100%)}to{transform:translateX(100%)}}@keyframes heat-in{from{opacity:0;transform:scale(.35)}to{opacity:1;transform:none}}@keyframes setup-in{from{opacity:0;transform:translateY(22px) scale(.98)}to{opacity:1;transform:none}}@keyframes spin{to{transform:rotate(360deg)}}
|
||||
@media(prefers-reduced-motion:reduce){.page,.page-head,.project-head,.stats-grid>*,.project-grid>*,.modal,.overlay,.toast,.taskbar,.setup-card,.stat-card strong,.heatmap i{animation:none!important}.stat-card:hover,.panel:hover,.project-card:hover,.add-card:hover{transform:none}.taskbar .progress i:after{display:none}}
|
||||
183
frontend/src/polish.css
Normal file
@@ -0,0 +1,183 @@
|
||||
main{position:relative;overflow:visible}
|
||||
main::before{content:"";position:fixed;inset:0 0 0 232px;pointer-events:none;background:linear-gradient(90deg,rgba(255,255,255,.035) 1px,transparent 1px),linear-gradient(180deg,rgba(255,255,255,.03) 1px,transparent 1px);background-size:80px 80px;mask-image:linear-gradient(90deg,transparent,black 14%,black 86%,transparent);animation:gridDrift 18s linear infinite;opacity:.55}
|
||||
main::after{content:"";position:fixed;inset:0 0 0 232px;pointer-events:none;background:linear-gradient(115deg,transparent 0 35%,rgba(124,115,255,.1) 45%,transparent 56%);transform:translateX(-35%);animation:ambientSweep 12s ease-in-out infinite}
|
||||
.page{position:relative;z-index:1}
|
||||
.sticky-head{position:sticky;top:0;z-index:8;margin:-12px -10px 24px;padding:18px 20px;border:1px solid rgba(255,255,255,.08);border-radius:8px;background:color-mix(in srgb,var(--surface) calc(var(--glass-user-opacity, .55) * 100%),transparent);backdrop-filter:blur(24px) saturate(140%);box-shadow:0 16px 38px rgba(0,0,0,.22)}
|
||||
.project-head.sticky-head{margin:-12px -10px 16px}
|
||||
.animated-logo{background:linear-gradient(135deg,rgba(115,103,245,.95),rgba(52,211,153,.82));box-shadow:0 10px 28px rgba(115,103,245,.34)}
|
||||
.animated-logo svg{width:40px;height:40px;overflow:visible}
|
||||
.logo-frame{fill:rgba(255,255,255,.08);stroke:url(#logoGlow);stroke-width:1.5}
|
||||
.logo-track{fill:none;stroke:#fff;stroke-width:3;stroke-linecap:round;stroke-linejoin:round;stroke-dasharray:68;animation:logoTrace 3.2s ease-in-out infinite}
|
||||
.logo-spark{fill:none;stroke:url(#logoGlow);stroke-width:2.5;stroke-linecap:round;stroke-dasharray:8 12;animation:logoSpark 2.2s linear infinite}
|
||||
.sidebar-bottom{position:relative;margin-top:auto;border-top:1px solid var(--border);padding:18px 8px 0;display:flex;align-items:center;gap:8px}
|
||||
.sidebar-bottom .version{margin:0;border:0;padding:0;flex:1}
|
||||
.quick-settings-btn{width:34px;height:34px;border:1px solid var(--border);border-radius:8px;background:var(--surface-2);color:var(--muted);display:grid;place-items:center;cursor:pointer;transition:color .2s,border-color .2s,background .2s}
|
||||
.quick-settings-btn:hover{color:var(--text);border-color:var(--primary)}
|
||||
.quick-settings-btn svg{width:17px}
|
||||
.quick-settings{position:absolute;left:0;bottom:48px;width:260px;padding:14px;border:1px solid var(--border);border-radius:8px;background:color-mix(in srgb,var(--surface-2) 82%,transparent);box-shadow:0 18px 42px rgba(0,0,0,.38);backdrop-filter:blur(24px) saturate(150%);display:grid;gap:12px;animation:popoverIn .18s ease-out}
|
||||
.quick-settings header{display:flex;justify-content:space-between;align-items:center}
|
||||
.quick-settings header button{border:0;background:transparent;color:var(--muted);cursor:pointer}
|
||||
.quick-settings header svg{width:16px}
|
||||
.quick-settings label{display:grid;gap:7px;color:var(--muted);font-size:12px}
|
||||
.quick-settings select,.quick-settings input[type=range]{width:100%;accent-color:var(--primary)}
|
||||
.quick-settings select{height:34px;border:1px solid var(--border);border-radius:7px;background:var(--surface);color:var(--text);padding:0 10px}
|
||||
.quick-settings .full{width:100%;justify-content:center}
|
||||
.shine-card{position:relative;overflow:hidden;isolation:isolate;transition:transform .22s ease,border-color .22s ease,box-shadow .22s ease,background .22s ease}
|
||||
.shine-card>*{position:relative;z-index:1}
|
||||
.shine-card::after{content:"";position:absolute;inset:-45%;z-index:0;pointer-events:none;background:linear-gradient(115deg,transparent 35%,rgba(255,255,255,.24) 49%,rgba(126,115,255,.18) 52%,transparent 64%);transform:translateX(-65%) rotate(8deg);opacity:0;transition:opacity .2s ease}
|
||||
.shine-card:hover{transform:translateY(-3px);border-color:color-mix(in srgb,var(--primary) 55%,var(--border));box-shadow:0 20px 44px rgba(0,0,0,.28),0 0 0 1px rgba(123,115,255,.14)}
|
||||
.shine-card:hover::after{opacity:1;animation:shineSweep .82s ease-out}
|
||||
.stat-card{min-width:0;padding:20px;gap:14px}
|
||||
.stat-copy{min-width:0;display:grid;gap:4px}
|
||||
.stat-card strong,.stat-value{font-size:clamp(22px,2.2vw,29px);line-height:1.05;word-break:keep-all;white-space:normal}
|
||||
.stat-card small{line-height:1.25}
|
||||
.metric-row{gap:12px}
|
||||
.metric-row>div{min-width:0}
|
||||
.metric-row b{font-size:clamp(19px,2vw,25px);line-height:1.05;white-space:nowrap}
|
||||
.metric-row span{display:block;white-space:nowrap}
|
||||
.project-metrics b{font-variant-numeric:tabular-nums;font-weight:900;letter-spacing:.2px;text-shadow:0 0 18px currentColor}
|
||||
.project-metrics .metric-total b{color:#72b7ff}
|
||||
.project-metrics .metric-code b{color:#55d6a2}
|
||||
.project-metrics .metric-files b{color:#b39cff}
|
||||
.project-metrics>div{padding:8px 6px;border-radius:8px;background:linear-gradient(180deg,rgba(255,255,255,.045),transparent)}
|
||||
.project-tools{display:flex;align-items:center;gap:12px;flex-wrap:wrap;justify-content:flex-end}
|
||||
.group-filter{height:38px;display:flex;align-items:center;gap:8px}
|
||||
.group-filter select{height:38px;min-width:180px;border:1px solid var(--border);border-radius:7px;background:var(--surface-2);color:var(--text);padding:0 11px;outline:none}
|
||||
.group-filter button{width:34px;height:34px;border:1px solid var(--border);border-radius:7px;background:var(--surface-2);color:var(--muted);display:grid;place-items:center;cursor:pointer;transition:color .2s,border-color .2s,background .2s}
|
||||
.group-filter button:hover{color:var(--text);border-color:var(--primary)}
|
||||
.group-filter svg{width:15px}
|
||||
.icon-actions{gap:6px}
|
||||
.icon-actions button{width:30px;height:30px;display:grid;place-items:center;border-radius:7px;transition:background .2s,color .2s}
|
||||
.icon-actions button:hover{background:var(--surface-3);color:var(--text)}
|
||||
.group-chip{display:inline-flex;align-items:center;width:max-content;max-width:180px;height:22px;margin:0 0 7px;padding:0 8px;border-radius:999px;background:rgba(115,103,245,.14);color:#a9a2ff;font-size:11px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
|
||||
.compact-modal{width:420px}
|
||||
.modal{display:flex;flex-direction:column;overflow:auto}
|
||||
.modal header{align-items:center;gap:18px;padding:24px 26px 20px}
|
||||
.modal header h2{font-size:22px;line-height:1.2}
|
||||
.modal header button{width:36px;height:36px;display:grid;place-items:center;border-radius:8px;line-height:1;flex:none;transition:background .2s,color .2s}
|
||||
.modal header button:hover{background:var(--surface-2);color:var(--text)}
|
||||
.modal>label{margin:0;padding:18px 26px 0;font-weight:800;color:var(--text)}
|
||||
.modal>label:first-of-type{padding-top:24px}
|
||||
.modal input,.modal textarea,.modal>label select{height:44px;margin-top:10px;border-color:rgba(145,136,255,.26);background:rgba(32,40,56,.92);box-shadow:inset 0 1px 0 rgba(255,255,255,.035);transition:border-color .2s,box-shadow .2s,background .2s}
|
||||
.modal input:focus,.modal textarea:focus,.modal>label select:focus{border-color:rgba(145,136,255,.72);box-shadow:0 0 0 3px rgba(115,103,245,.18),inset 0 1px 0 rgba(255,255,255,.05)}
|
||||
.modal textarea{min-height:92px;height:92px}
|
||||
.modal footer{gap:12px;padding:22px 26px;align-items:center}
|
||||
.modal footer .btn{min-width:88px;justify-content:center}
|
||||
.browse{gap:12px;align-items:flex-start}
|
||||
.browse .btn{min-width:96px;justify-content:center}
|
||||
.hidden-wsl-picker{display:none!important}
|
||||
.modal>label select{width:100%;border-radius:7px;color:var(--text);padding:0 12px;outline:none}
|
||||
.wsl-picker select{height:40px;min-width:180px;background:var(--surface-2);border:1px solid var(--border);border-radius:7px;color:var(--text);padding:0 10px;outline:none}
|
||||
.overlay{position:fixed;inset:0;width:100vw;min-height:100vh;min-height:100dvh;display:grid;place-items:center;padding:32px;z-index:80;overflow:auto}
|
||||
.modal{max-width:calc(100vw - 64px);max-height:calc(100vh - 64px);max-height:calc(100dvh - 64px)}
|
||||
.analysis-loading{position:fixed;inset:0;z-index:70;display:grid;place-items:center;padding:24px;background-color:#03070c;background-image:radial-gradient(circle at 50% 42%,rgba(83,214,162,.14),transparent 30%),linear-gradient(135deg,rgba(6,9,18,.96),rgba(3,7,12,.94));backdrop-filter:blur(16px) saturate(145%);-webkit-backdrop-filter:blur(16px) saturate(145%);overflow:hidden;isolation:isolate;transition:background-color .3s ease,background-image .3s ease}
|
||||
.analysis-loading.holding section{opacity:.88;transform:translateY(0)}
|
||||
.analysis-loading.fullscreen-grid{background-image:radial-gradient(circle at 50% 48%,rgba(110,231,255,.16),transparent 32%),radial-gradient(circle at 22% 22%,rgba(83,214,162,.1),transparent 28%),linear-gradient(135deg,rgba(7,12,24,.97),rgba(3,15,16,.95))}
|
||||
.analysis-loading.fullscreen-warp{background-image:radial-gradient(circle at 50% 50%,rgba(124,108,255,.24),transparent 34%),radial-gradient(circle at 72% 34%,rgba(110,231,255,.12),transparent 26%),linear-gradient(135deg,rgba(5,6,16,.98),rgba(3,7,12,.95))}
|
||||
.analysis-canvas{position:absolute;inset:0;width:100%;height:100%;opacity:.98}
|
||||
.analysis-loading section{position:relative;z-index:1;width:min(420px,calc(100vw - 48px));padding:0;display:grid;gap:13px;text-align:center;justify-items:center;overflow:visible;background:transparent;border:0;box-shadow:none;backdrop-filter:none;-webkit-backdrop-filter:none;transition:opacity .28s ease,transform .28s ease}
|
||||
.analysis-loading section::before{content:"";position:absolute;left:50%;top:50%;width:360px;height:240px;transform:translate(-50%,-50%);border-radius:50%;background:radial-gradient(circle,rgba(8,14,24,.58) 0 24%,rgba(8,14,24,.34) 45%,transparent 72%);filter:blur(12px);pointer-events:none;z-index:-1}
|
||||
.analysis-loading b{font-size:21px;max-width:100%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;text-shadow:0 0 18px rgba(110,231,255,.38),0 2px 14px rgba(0,0,0,.72)}
|
||||
.analysis-loading span{color:#b4bdcf;max-width:100%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;text-shadow:0 2px 12px rgba(0,0,0,.8)}
|
||||
.analysis-loading strong{color:var(--text);text-shadow:0 0 14px rgba(255,255,255,.28),0 2px 12px rgba(0,0,0,.74)}
|
||||
.analysis-loading .progress{position:relative;width:min(310px,100%);height:7px;border-radius:999px;background:linear-gradient(180deg,rgba(4,9,18,.78),rgba(18,26,42,.66));overflow:hidden;margin-top:8px;box-shadow:0 0 0 1px rgba(255,255,255,.06),0 0 28px rgba(115,103,245,.24),inset 0 1px 5px rgba(0,0,0,.5)}
|
||||
.analysis-loading .progress::before{content:"";position:absolute;inset:1px;border-radius:inherit;background:linear-gradient(90deg,rgba(110,231,255,.06),rgba(255,255,255,.16),rgba(83,214,162,.06));transform:translateX(-62%);animation:loadingTrackSweep 1.8s ease-in-out infinite}
|
||||
.analysis-loading .progress i{position:relative;display:block;height:100%;border-radius:inherit;background:linear-gradient(90deg,#6ee7ff,#7c6cff 42%,#53d6a2 72%,#6ee7ff);background-size:240% 100%;box-shadow:0 0 20px rgba(110,231,255,.76),0 0 34px rgba(83,214,162,.36);transition:width .48s cubic-bezier(.22,1,.36,1);animation:loadingBarFlow 1.2s linear infinite}
|
||||
.analysis-loading .progress i::before{content:"";position:absolute;right:-8px;top:50%;width:18px;height:18px;border-radius:50%;background:radial-gradient(circle,#fff 0 18%,#6ee7ff 34%,rgba(110,231,255,0) 72%);transform:translateY(-50%);filter:blur(.2px);box-shadow:0 0 18px rgba(110,231,255,.86)}
|
||||
.analysis-loading .progress i::after{content:"";position:absolute;inset:-3px;width:58px;background:linear-gradient(90deg,transparent,rgba(255,255,255,.86),transparent);filter:blur(1px);animation:loadingBarSweep 1.05s ease-in-out infinite}
|
||||
.loading-style-setting{display:grid;gap:12px;margin-top:4px;color:var(--text);font-weight:800}
|
||||
.loading-style-setting>span{display:flex;align-items:center;gap:8px}
|
||||
.loading-style-grid{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:12px}
|
||||
.loading-style-card{position:relative;min-height:118px;border:1px solid rgba(145,136,255,.2);border-radius:8px;background:linear-gradient(180deg,rgba(255,255,255,.055),rgba(255,255,255,.018)),var(--surface-2);color:var(--text);padding:14px 14px 13px;display:grid;grid-template-columns:46px 1fr;grid-template-rows:auto 1fr;column-gap:12px;row-gap:5px;text-align:left;cursor:pointer;outline:none;overflow:hidden;transition:border-color .2s ease,background .2s ease,box-shadow .2s ease,transform .2s ease}
|
||||
.loading-style-card:hover{border-color:rgba(110,231,255,.5);box-shadow:0 14px 30px rgba(0,0,0,.22)}
|
||||
.loading-style-card:focus-visible{box-shadow:0 0 0 3px rgba(110,231,255,.18),0 14px 30px rgba(0,0,0,.22)}
|
||||
.loading-style-card.active{border-color:rgba(110,231,255,.72);background:linear-gradient(180deg,rgba(110,231,255,.11),rgba(83,214,162,.045)),var(--surface-2);box-shadow:0 0 0 1px rgba(110,231,255,.16),0 18px 36px rgba(0,0,0,.24),0 0 28px rgba(110,231,255,.12)}
|
||||
.loading-style-card.active::after{content:"";position:absolute;right:12px;top:12px;width:9px;height:9px;border-radius:50%;background:#6ee7ff;box-shadow:0 0 14px rgba(110,231,255,.9)}
|
||||
.loading-style-preview{grid-row:1/3;width:46px;height:46px;border-radius:8px;border:1px solid rgba(255,255,255,.08);background:rgba(4,9,18,.52);display:grid;place-items:center;overflow:hidden;box-shadow:inset 0 0 18px rgba(0,0,0,.26)}
|
||||
.loading-style-preview i{position:relative;display:block;width:30px;height:30px;border-radius:50%}
|
||||
.loading-style-card b{align-self:end;font-size:14px;line-height:1.25;letter-spacing:0}
|
||||
.loading-style-card small{color:var(--muted);font-weight:600;line-height:1.35;word-break:break-word}
|
||||
.loading-style-card.fullscreen-orbit .loading-style-preview i{border:2px solid rgba(110,231,255,.72);box-shadow:0 0 0 7px rgba(124,108,255,.14),0 0 18px rgba(110,231,255,.48)}
|
||||
.loading-style-card.fullscreen-orbit .loading-style-preview i::before{content:"";position:absolute;inset:8px;border-radius:50%;background:#53d6a2;box-shadow:0 0 16px rgba(83,214,162,.78)}
|
||||
.loading-style-card.fullscreen-orbit .loading-style-preview i::after{content:"";position:absolute;width:7px;height:7px;border-radius:50%;background:#fff;right:-2px;top:9px;box-shadow:0 0 12px rgba(255,255,255,.9)}
|
||||
.loading-style-card.fullscreen-grid .loading-style-preview i{width:34px;height:34px;border-radius:4px;background:linear-gradient(90deg,rgba(110,231,255,.34) 1px,transparent 1px),linear-gradient(180deg,rgba(83,214,162,.3) 1px,transparent 1px);background-size:9px 9px}
|
||||
.loading-style-card.fullscreen-grid .loading-style-preview i::before{content:"";position:absolute;left:4px;right:4px;top:15px;height:4px;background:rgba(110,231,255,.75);box-shadow:0 0 12px rgba(110,231,255,.75)}
|
||||
.loading-style-card.fullscreen-grid .loading-style-preview i::after{content:"";position:absolute;width:7px;height:7px;right:6px;bottom:5px;border-radius:50%;background:#53d6a2;box-shadow:-17px -14px 0 rgba(124,108,255,.82),0 0 12px rgba(83,214,162,.8)}
|
||||
.loading-style-card.fullscreen-warp .loading-style-preview i{width:36px;height:36px;background:radial-gradient(circle,#fff 0 8%,#6ee7ff 11%,rgba(124,108,255,.32) 34%,transparent 62%);box-shadow:0 0 20px rgba(124,108,255,.62)}
|
||||
.loading-style-card.fullscreen-warp .loading-style-preview i::before,.loading-style-card.fullscreen-warp .loading-style-preview i::after{content:"";position:absolute;left:50%;top:50%;width:36px;height:2px;border-radius:999px;background:linear-gradient(90deg,transparent,#6ee7ff,transparent);transform:translate(-50%,-50%) rotate(32deg);box-shadow:0 0 10px rgba(110,231,255,.7)}
|
||||
.loading-style-card.fullscreen-warp .loading-style-preview i::after{transform:translate(-50%,-50%) rotate(-28deg);background:linear-gradient(90deg,transparent,#53d6a2,transparent)}
|
||||
.loading-style-card.bar .loading-style-preview i{width:34px;height:8px;border-radius:999px;background:rgba(255,255,255,.1);overflow:hidden}
|
||||
.loading-style-card.bar .loading-style-preview i::before{content:"";position:absolute;inset:0 38% 0 0;border-radius:inherit;background:linear-gradient(90deg,#6ee7ff,#53d6a2);box-shadow:0 0 12px rgba(110,231,255,.65)}
|
||||
.toast{transition:opacity .32s ease,transform .36s ease,filter .32s ease}
|
||||
.toast.muted{opacity:.72;filter:saturate(.82)}
|
||||
.toast.leaving{opacity:0;transform:translate(18px,-12px);pointer-events:none}
|
||||
.detail-sticky-head{display:grid;gap:16px;align-items:stretch}
|
||||
.detail-page{--detail-sticky-offset:16px;max-width:none;margin:0;padding:var(--detail-sticky-offset) 30px 60px}
|
||||
.detail-page .detail-sticky-head{position:sticky;top:var(--detail-sticky-offset);width:100%;z-index:24;margin:0 0 24px;border-radius:8px;border-top:1px solid rgba(255,255,255,.08);background:color-mix(in srgb,var(--surface) 88%,transparent);box-shadow:0 18px 42px rgba(0,0,0,.34),0 1px 0 rgba(255,255,255,.06)}
|
||||
.detail-head-row{display:flex;align-items:center;gap:28px;min-width:0}
|
||||
.detail-head-row>div{min-width:0}
|
||||
.detail-head-row p{white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
|
||||
.detail-tabs{margin:0;background:rgba(255,255,255,.045)}
|
||||
.heat-panel{height:auto;min-height:250px}
|
||||
.heat-grid-wrap{--cell:13px;--gap:4px;position:relative;margin-top:12px;overflow-x:auto;padding-bottom:8px}
|
||||
.heat-months{display:grid;grid-template-columns:repeat(var(--weeks),var(--cell));gap:var(--gap);margin-left:34px;margin-bottom:8px;min-width:calc(var(--weeks) * (var(--cell) + var(--gap)))}
|
||||
.heat-months span{font-size:12px;color:var(--muted);white-space:nowrap}
|
||||
.heat-body{position:relative;display:flex;gap:10px;align-items:flex-start}
|
||||
.heat-weekdays{display:grid;grid-template-rows:repeat(7,var(--cell));gap:var(--gap);width:24px;color:var(--muted);font-size:12px;line-height:var(--cell);text-align:right}
|
||||
.heat-grid{display:grid;grid-template-columns:repeat(var(--weeks),var(--cell));grid-template-rows:repeat(7,var(--cell));gap:var(--gap);min-width:calc(var(--weeks) * (var(--cell) + var(--gap)))}
|
||||
.heat-cell{width:var(--cell);height:var(--cell);border:1px solid rgba(255,255,255,.035);border-radius:3px;background:#26303d;cursor:pointer;padding:0;transition:transform .12s ease,border-color .12s ease,box-shadow .12s ease}
|
||||
.heat-cell:hover,.heat-cell.selected{transform:translateY(-1px);border-color:rgba(255,255,255,.45);box-shadow:0 0 0 2px rgba(123,115,255,.22)}
|
||||
.heat-cell.l1{background:#245140}.heat-cell.l2{background:#2e765b}.heat-cell.l3{background:#3cab7d}.heat-cell.l4{background:#55dfa1}
|
||||
html[data-theme=light] .heat-cell{background:#e7ecf3;border-color:#d9e0ea}
|
||||
html[data-theme=light] .heat-cell.l1{background:#b9efd4}html[data-theme=light] .heat-cell.l2{background:#81dfb4}html[data-theme=light] .heat-cell.l3{background:#42c990}html[data-theme=light] .heat-cell.l4{background:#159c68}
|
||||
.heat-tooltip{position:absolute;left:44px;bottom:-30px;z-index:3;border:1px solid var(--border);border-radius:7px;background:var(--surface-3);padding:6px 9px;color:var(--text);font-size:12px;box-shadow:0 10px 26px rgba(0,0,0,.28);pointer-events:none}
|
||||
.insights-hero{display:grid;grid-template-columns:auto 1fr auto;align-items:center;gap:22px}
|
||||
.score-ring{width:116px;height:116px;border-radius:50%;display:grid;place-items:center;background:radial-gradient(circle at center,var(--surface) 58%,transparent 59%),conic-gradient(var(--green) calc(var(--score,75)*1%),rgba(255,255,255,.08) 0);border:1px solid var(--border)}
|
||||
.score-ring strong{font-size:34px;line-height:1}
|
||||
.score-ring span{font-size:12px;color:var(--muted);margin-top:-22px}
|
||||
.insight-summary p{color:var(--muted);margin:8px 0 14px}
|
||||
.insight-counts{display:flex;gap:10px;flex-wrap:wrap}
|
||||
.insight-counts span,.issue-severity{border-radius:999px;padding:5px 9px;background:var(--surface-2);color:var(--muted);font-size:12px}
|
||||
.insight-counts .high,.issue-card.high .issue-severity{color:#ff8a95;background:rgba(240,94,104,.12)}
|
||||
.insight-counts .medium,.issue-card.medium .issue-severity{color:#ffd166;background:rgba(231,189,53,.12)}
|
||||
.insight-counts .low,.issue-card.low .issue-severity{color:#72b7ff;background:rgba(79,157,245,.12)}
|
||||
.insight-filter select{height:36px;border:1px solid var(--border);border-radius:7px;background:var(--surface-2);color:var(--text);padding:0 10px}
|
||||
.issue-list{display:grid;gap:10px;margin-top:16px;max-height:620px;overflow:auto;padding-right:6px}
|
||||
.issue-card{position:relative;display:grid;grid-template-columns:1fr;gap:10px;padding:16px 18px;border:1px solid var(--border);border-radius:8px;background:linear-gradient(180deg,rgba(255,255,255,.045),rgba(255,255,255,.015)),var(--surface-2);overflow:hidden}
|
||||
.issue-card::before{display:none}
|
||||
.issue-card.high{border-color:rgba(240,94,104,.34);background:linear-gradient(180deg,rgba(240,94,104,.055),rgba(255,255,255,.015)),var(--surface-2)}
|
||||
.issue-card.medium{border-color:rgba(231,189,53,.32);background:linear-gradient(180deg,rgba(231,189,53,.05),rgba(255,255,255,.015)),var(--surface-2)}
|
||||
.issue-card.low{border-color:rgba(79,157,245,.3);background:linear-gradient(180deg,rgba(79,157,245,.045),rgba(255,255,255,.015)),var(--surface-2)}
|
||||
.issue-severity{display:inline-flex;align-items:center;justify-content:center;width:max-content;align-self:start;justify-self:start;line-height:1;font-weight:800;text-transform:none}
|
||||
.issue-card h3{margin:0 0 6px;font-size:15px}
|
||||
.issue-card p{margin:0;color:var(--muted)}
|
||||
.issue-card small,.issue-card b,.issue-card code{display:block;margin-top:7px}
|
||||
.issue-card small{color:#8fb2ff;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;max-width:100%}
|
||||
.issue-card code{white-space:pre-wrap;word-break:break-word;background:rgba(0,0,0,.2);padding:8px;border-radius:6px;color:var(--muted);max-width:100%;overflow:hidden}
|
||||
.issue-card b{color:var(--text);font-weight:700}
|
||||
.git-error-panel{display:grid;grid-template-columns:42px 1fr auto;align-items:center;gap:14px;border-color:rgba(240,94,104,.42)}
|
||||
.git-error-panel>svg{width:30px;color:var(--red)}
|
||||
.git-error-panel h2{margin:0 0 6px}
|
||||
.git-error-panel p{margin:0;color:var(--muted)}
|
||||
.git-error-panel code{display:block;margin-top:8px;white-space:normal;word-break:break-word;color:#ffb4bc}
|
||||
.structure-panel,.structure-scroll-panel{max-height:560px;overflow:auto}
|
||||
.structure-panel .file-tree{height:auto;max-height:490px}
|
||||
.file-tree>div span,.folder-size b,.large-file small{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
||||
.file-tree>div{min-width:0}
|
||||
.large-file-panel{max-height:360px;overflow:auto}
|
||||
.large-file{border-radius:7px;gap:16px}
|
||||
.large-file>div{min-width:0}
|
||||
@keyframes shineSweep{from{transform:translateX(-65%) rotate(8deg)}to{transform:translateX(65%) rotate(8deg)}}
|
||||
@keyframes logoTrace{0%,100%{stroke-dashoffset:0}50%{stroke-dashoffset:68}}
|
||||
@keyframes logoSpark{to{stroke-dashoffset:-40}}
|
||||
@keyframes popoverIn{from{opacity:0;transform:translateY(8px) scale(.98)}to{opacity:1;transform:translateY(0) scale(1)}}
|
||||
@keyframes gridDrift{to{background-position:80px 80px}}
|
||||
@keyframes ambientSweep{0%,100%{transform:translateX(-40%);opacity:.18}50%{transform:translateX(22%);opacity:.34}}
|
||||
@keyframes loadingBarFlow{to{background-position:220% 0}}
|
||||
@keyframes loadingBarSweep{from{transform:translateX(-44px)}to{transform:translateX(290px)}}
|
||||
@keyframes loadingTrackSweep{0%,100%{transform:translateX(-62%);opacity:.35}50%{transform:translateX(62%);opacity:.9}}
|
||||
@media(max-width:1150px){main::before,main::after{inset-left:72px}.sidebar-bottom{padding-left:0;padding-right:0;justify-content:center}.quick-settings{left:0}.quick-settings-btn{width:40px;height:40px}.stats-grid.three,.stats-grid.four{grid-template-columns:repeat(2,minmax(0,1fr))}.project-card{padding:20px}}
|
||||
@media(max-width:980px){body{min-width:0}.page{padding:24px 24px 56px}.stats-grid.three,.stats-grid.four,.stats-grid.five{grid-template-columns:repeat(2,minmax(0,1fr))}.project-grid{grid-template-columns:1fr}.section-head{align-items:flex-start;gap:12px;flex-direction:column}.project-tools{width:100%;justify-content:flex-start}.group-filter{width:100%;flex-wrap:wrap;height:auto}.group-filter select{flex:1;min-width:160px}.search{width:100%}.git-error-panel{grid-template-columns:36px 1fr}.git-error-panel .btn{grid-column:1/3;width:max-content}}
|
||||
@media(max-width:720px){.loading-style-grid{grid-template-columns:1fr}.loading-style-card{min-height:104px}}
|
||||
@media(max-width:980px){.detail-page{--detail-sticky-offset:12px;padding:var(--detail-sticky-offset) 20px 56px}.insights-hero{grid-template-columns:1fr}.detail-head-row{align-items:flex-start;flex-direction:column;gap:10px}.detail-tabs{width:100%;overflow-x:auto}}
|
||||
@media(prefers-reduced-motion:reduce){main::before,main::after,.logo-track,.logo-spark,.shine-card:hover::after{animation:none!important}.shine-card:hover,.heat-cell:hover{transform:none}.toast{transition:opacity .2s ease}}
|
||||
3
frontend/src/runtime.css
Normal file
@@ -0,0 +1,3 @@
|
||||
.opacity-setting{align-items:center}.opacity-setting>span{display:flex;justify-content:space-between;gap:14px}.opacity-setting b{color:#9188ff}.opacity-setting input[type=range]{width:100%;accent-color:var(--primary);cursor:pointer}
|
||||
.browser-blocked{min-height:100vh;display:grid;place-items:center;padding:32px;background-color:var(--bg);background-image:linear-gradient(rgba(123,115,255,.055) 1px,transparent 1px),linear-gradient(90deg,rgba(123,115,255,.045) 1px,transparent 1px);background-size:40px 40px}.blocked-card{width:min(590px,100%);padding:42px;border:1px solid var(--glass-border);border-radius:10px;background:var(--glass-strong);box-shadow:var(--glass-shadow);backdrop-filter:blur(24px);text-align:left}.blocked-card>span{width:58px;height:58px;display:grid;place-items:center;border-radius:9px;background:rgba(240,94,104,.12);color:var(--red)}.blocked-card>span svg{width:28px}.blocked-card>small{display:block;color:var(--red);font-weight:bold;margin-top:24px}.blocked-card h1{font-size:28px;margin:10px 0}.blocked-card p{color:var(--muted);line-height:1.7}.blocked-card code{color:#9188ff}.blocked-card>div{display:flex;gap:9px;align-items:center;padding:13px;background:var(--glass-soft);border-radius:7px;color:var(--muted)}.blocked-card>div svg{width:18px;color:var(--green)}
|
||||
.btn:disabled{opacity:.55;cursor:not-allowed}
|
||||
118
frontend/src/store.js
Normal file
@@ -0,0 +1,118 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import { call, on } from './api'
|
||||
|
||||
export const useAppStore = defineStore('app', {
|
||||
state: () => ({
|
||||
bootstrap: { state: 'loading' },
|
||||
projects: [],
|
||||
projectGroups: [],
|
||||
selectedProjectGroupId: Number(localStorage.getItem('cc-project-group-id') || 0),
|
||||
dashboard: { projects: 0, totalLines: 0, commits: 0 },
|
||||
settings: { theme: 'dark', locale: 'zh-CN', glassOpacity: 55, gitScope: 'current', autoRefresh: true, loadingStyle: 'fullscreen-orbit' },
|
||||
tasks: {},
|
||||
batchTaskIds: [],
|
||||
toast: null,
|
||||
toastTimer: null,
|
||||
toastLeaveTimer: null,
|
||||
loading: false
|
||||
}),
|
||||
actions: {
|
||||
async boot() {
|
||||
this.bootstrap = await call('GetBootstrapStatus')
|
||||
if (this.bootstrap.state === 'ready') {
|
||||
this.settings = await call('GetSettings')
|
||||
this.applyAppearance(this.settings)
|
||||
await this.refresh()
|
||||
}
|
||||
},
|
||||
applyAppearance(settings) {
|
||||
this.settings = { ...this.settings, ...settings }
|
||||
let theme = this.settings.theme || 'dark'
|
||||
if (theme === 'system') theme = matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light'
|
||||
document.documentElement.dataset.theme = theme
|
||||
document.documentElement.style.setProperty('--glass-user-opacity', String((this.settings.glassOpacity || 55) / 100))
|
||||
localStorage.setItem('cc-settings', JSON.stringify(this.settings))
|
||||
},
|
||||
async saveSettings(patch) {
|
||||
const next = { ...this.settings, ...patch }
|
||||
await call('SaveSettings', next)
|
||||
this.applyAppearance(next)
|
||||
return next
|
||||
},
|
||||
showToast(payload) {
|
||||
clearTimeout(this.toastTimer)
|
||||
clearTimeout(this.toastLeaveTimer)
|
||||
this.toast = { ...payload, leaving: false, muted: false, id: Date.now() }
|
||||
this.toastTimer = setTimeout(() => {
|
||||
if (this.toast) this.toast.muted = true
|
||||
}, 3000)
|
||||
this.toastLeaveTimer = setTimeout(() => {
|
||||
if (this.toast) this.toast.leaving = true
|
||||
setTimeout(() => {
|
||||
this.toast = null
|
||||
}, 360)
|
||||
}, 5000)
|
||||
},
|
||||
closeToast() {
|
||||
clearTimeout(this.toastTimer)
|
||||
clearTimeout(this.toastLeaveTimer)
|
||||
if (this.toast) this.toast.leaving = true
|
||||
setTimeout(() => {
|
||||
this.toast = null
|
||||
}, 220)
|
||||
},
|
||||
async refresh() {
|
||||
this.loading = true
|
||||
try {
|
||||
this.projectGroups = await call('ListProjectGroups')
|
||||
if (this.selectedProjectGroupId && !this.projectGroups.some(g => g.id === this.selectedProjectGroupId)) {
|
||||
this.setProjectGroup(0)
|
||||
}
|
||||
const groupId = this.selectedProjectGroupId || 0
|
||||
;[this.projects, this.dashboard] = await Promise.all([
|
||||
groupId ? call('ListProjectsByGroup', groupId) : call('ListProjects'),
|
||||
groupId ? call('GetDashboardByGroup', groupId) : call('GetDashboard')
|
||||
])
|
||||
} finally {
|
||||
this.loading = false
|
||||
}
|
||||
},
|
||||
async changeProjectGroup(groupId) {
|
||||
this.setProjectGroup(groupId)
|
||||
await this.refresh()
|
||||
},
|
||||
setProjectGroup(groupId, persist = true) {
|
||||
this.selectedProjectGroupId = Number(groupId) || 0
|
||||
if (persist) localStorage.setItem('cc-project-group-id', String(this.selectedProjectGroupId))
|
||||
},
|
||||
listen() {
|
||||
return on('analysis:progress', e => {
|
||||
delete this.tasks.__batch_pending__
|
||||
this.tasks[e.taskId] = e
|
||||
if (['completed', 'error', 'cancelled'].includes(e.stage)) {
|
||||
if (this.batchTaskIds.includes(e.taskId)) {
|
||||
this.batchTaskIds = this.batchTaskIds.filter(id => id !== e.taskId)
|
||||
if (this.batchTaskIds.length) {
|
||||
this.tasks.__batch_pending__ = { taskId: '__batch_pending__', projectId: 0, stage: 'queued', progress: 100, messageKey: e.messageKey, params: e.params }
|
||||
}
|
||||
}
|
||||
this.showToast({ type: e.stage === 'completed' ? 'success' : 'error', key: e.messageKey, params: e.params })
|
||||
this.refresh()
|
||||
}
|
||||
})
|
||||
},
|
||||
async analyze(id, kind = 'all') {
|
||||
const task = await call('StartAnalysis', id, kind)
|
||||
this.tasks[task] = { taskId: task, projectId: id, stage: 'start', progress: 1, messageKey: 'task.start' }
|
||||
return task
|
||||
},
|
||||
async batchAnalyze(groupId = 0) {
|
||||
const ids = groupId ? await call('StartBatchAnalysisByGroup', groupId) : await call('StartBatchAnalysis')
|
||||
this.batchTaskIds = ids || []
|
||||
if (this.batchTaskIds.length && !Object.values(this.tasks).some(x => !['completed', 'error', 'cancelled'].includes(x.stage))) {
|
||||
this.tasks.__batch_pending__ = { taskId: '__batch_pending__', projectId: 0, stage: 'queued', progress: 1, messageKey: 'task.start' }
|
||||
}
|
||||
return this.batchTaskIds
|
||||
}
|
||||
}
|
||||
})
|
||||
1
frontend/src/style.css
Normal file
240
frontend/src/views/Dashboard.vue
Normal file
@@ -0,0 +1,240 @@
|
||||
<script setup>
|
||||
import { computed, reactive, ref } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { Folder, Code2, GitCommitHorizontal, Plus, RefreshCw, Search, Trash2, Pencil, FolderOpen } from 'lucide-vue-next'
|
||||
import StatCard from '../components/StatCard.vue'
|
||||
import { useAppStore } from '../store'
|
||||
import { call } from '../api'
|
||||
|
||||
const store = useAppStore()
|
||||
const router = useRouter()
|
||||
const { t } = useI18n()
|
||||
const search = ref('')
|
||||
const modal = ref(false)
|
||||
const groupModal = ref(false)
|
||||
const editing = ref(0)
|
||||
const groupEditing = ref(0)
|
||||
const saving = ref(false)
|
||||
const groupSaving = ref(false)
|
||||
const error = ref('')
|
||||
const groupError = ref('')
|
||||
const wslDistros = ref([])
|
||||
const wslDistro = ref('')
|
||||
const form = reactive({ name: '', path: '', description: '', groupId: 1 })
|
||||
const groupForm = reactive({ name: '' })
|
||||
const palette = ['#53d6a2', '#5da8ff', '#f7cb4d', '#a78bfa', '#ef6f8f']
|
||||
|
||||
const filtered = computed(() => {
|
||||
const q = search.value.trim().toLowerCase()
|
||||
if (!q) return store.projects
|
||||
return store.projects.filter(p => (p.name + ' ' + p.path + ' ' + (p.description || '')).toLowerCase().includes(q))
|
||||
})
|
||||
const filteredDashboard = computed(() => filtered.value.reduce((acc, p) => {
|
||||
acc.projects += 1
|
||||
acc.totalLines += Number(p.stats?.totalLines || 0)
|
||||
acc.commits += Number(p.stats?.commitCount || 0)
|
||||
return acc
|
||||
}, { projects: 0, totalLines: 0, commits: 0 }))
|
||||
|
||||
const fmt = n => {
|
||||
n = +n || 0
|
||||
return n >= 1e6 ? (n / 1e6).toFixed(1) + 'M' : n >= 1e3 ? (n / 1e3).toFixed(1) + 'K' : n.toString()
|
||||
}
|
||||
const total = p => p.languages?.reduce((s, x) => s + x.code, 0) || 0
|
||||
const projectRunning = id => Object.values(store.tasks).some(x => x.projectId === id && !['completed', 'error', 'cancelled'].includes(x.stage))
|
||||
const defaultGroupId = computed(() => store.projectGroups[0]?.id || 1)
|
||||
const groupLabel = g => g?.id === 1 ? t('myProjectGroup') : (g?.name || t('projectGroup'))
|
||||
const errorText = raw => {
|
||||
const code = ['PROJECT_PATH_NOT_FOUND', 'PROJECT_PATH_UNREADABLE', 'PROJECT_PATH_NOT_DIRECTORY', 'PROJECT_PATH_DUPLICATE', 'PROJECT_GROUP_NOT_FOUND', 'PROJECT_GROUP_NAME_REQUIRED', 'PROJECT_GROUP_DEFAULT_READONLY', 'PROJECT_GROUP_DUPLICATE', 'DATABASE_NOT_READY', 'PROJECT_SAVE_FAILED'].find(x => String(raw).includes(x))
|
||||
return code ? t(`errors.${code}`) : String(raw)
|
||||
}
|
||||
|
||||
function open(p) {
|
||||
editing.value = p?.id || 0
|
||||
Object.assign(form, p ? { name: p.name, path: p.path, description: p.description, groupId: p.groupId || defaultGroupId.value } : { name: '', path: '', description: '', groupId: store.selectedProjectGroupId || defaultGroupId.value })
|
||||
error.value = ''
|
||||
modal.value = true
|
||||
}
|
||||
function openGroup(g) {
|
||||
groupEditing.value = g?.id || 0
|
||||
groupForm.name = g?.name || ''
|
||||
groupError.value = ''
|
||||
groupModal.value = true
|
||||
}
|
||||
async function saveGroup() {
|
||||
if (groupSaving.value) return
|
||||
groupSaving.value = true
|
||||
groupError.value = ''
|
||||
try {
|
||||
const saved = await call('SaveProjectGroup', groupEditing.value, groupForm.name)
|
||||
groupModal.value = false
|
||||
await store.refresh()
|
||||
if (!groupEditing.value) await store.changeProjectGroup(saved.id)
|
||||
store.showToast({ type: 'success', text: t('saveProjectGroup') })
|
||||
} catch (e) {
|
||||
groupError.value = errorText(e)
|
||||
store.showToast({ type: 'error', text: groupError.value })
|
||||
} finally {
|
||||
groupSaving.value = false
|
||||
}
|
||||
}
|
||||
async function removeGroup(g) {
|
||||
if (!g) return
|
||||
if (g.id === 1) return
|
||||
if (confirm(`${t('delete')} ${g.name}?`)) {
|
||||
await call('DeleteProjectGroup', g.id)
|
||||
if (store.selectedProjectGroupId === g.id) store.setProjectGroup(0)
|
||||
await store.refresh()
|
||||
}
|
||||
}
|
||||
async function changeGroup(value) {
|
||||
await store.changeProjectGroup(Number(value))
|
||||
}
|
||||
async function browse() {
|
||||
const p = await call('SelectDirectory')
|
||||
if (p) {
|
||||
form.path = p
|
||||
if (!form.name) form.name = p.split(/[\\/]/).pop()
|
||||
}
|
||||
}
|
||||
async function loadWSL() {
|
||||
try {
|
||||
wslDistros.value = await call('ListWSLDistros')
|
||||
if (wslDistros.value.length) wslDistro.value = wslDistros.value[0]
|
||||
else store.showToast({ type: 'error', key: 'noWSL' })
|
||||
} catch {
|
||||
store.showToast({ type: 'error', key: 'noWSL' })
|
||||
}
|
||||
}
|
||||
async function browseWSL() {
|
||||
if (!wslDistro.value) return
|
||||
const p = await call('SelectWSLDirectory', wslDistro.value)
|
||||
if (p) {
|
||||
form.path = p
|
||||
if (!form.name) form.name = p.split(/[\\/]/).pop()
|
||||
}
|
||||
}
|
||||
async function save() {
|
||||
if (saving.value) return
|
||||
error.value = ''
|
||||
form.path = form.path.trim()
|
||||
if (!form.path) {
|
||||
error.value = t('pathRequired')
|
||||
return
|
||||
}
|
||||
saving.value = true
|
||||
try {
|
||||
await call('SaveProject', editing.value, { ...form, groupId: Number(form.groupId) || defaultGroupId.value })
|
||||
await store.refresh()
|
||||
modal.value = false
|
||||
store.showToast({ type: 'success', text: t('saveProject') })
|
||||
} catch (e) {
|
||||
error.value = errorText(e)
|
||||
store.showToast({ type: 'error', text: error.value })
|
||||
try { await call('ReportClientError', 'frontend', '项目保存失败', String(e)) } catch {}
|
||||
} finally {
|
||||
saving.value = false
|
||||
}
|
||||
}
|
||||
async function remove(p) {
|
||||
if (confirm(`${t('delete')} ${p.name}?`)) {
|
||||
await call('DeleteProject', p.id)
|
||||
await store.refresh()
|
||||
}
|
||||
}
|
||||
async function batch() {
|
||||
await store.batchAnalyze(store.selectedProjectGroupId)
|
||||
}
|
||||
async function refreshProject(p) {
|
||||
try {
|
||||
await store.analyze(p.id, 'all')
|
||||
} catch (e) {
|
||||
store.showToast({ type: 'error', text: errorText(e) })
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="page dashboard-page">
|
||||
<header class="page-head sticky-head">
|
||||
<div><h1>{{ t('dashboard') }}</h1><p>{{ t('dashboardSubtitle') }}</p></div>
|
||||
<div class="actions">
|
||||
<button class="btn secondary" @click="batch"><RefreshCw />{{ t('batch') }}</button>
|
||||
<button class="btn primary" @click="open()"><Plus />{{ t('addProject') }}</button>
|
||||
</div>
|
||||
</header>
|
||||
<div class="stats-grid three">
|
||||
<StatCard :icon="Folder" :value="filteredDashboard.projects" :label="t('totalProjects')" />
|
||||
<StatCard :icon="Code2" tone="green" :value="fmt(filteredDashboard.totalLines)" :label="t('totalLines')" />
|
||||
<StatCard :icon="GitCommitHorizontal" tone="blue" :value="fmt(filteredDashboard.commits)" :label="t('commits')" />
|
||||
</div>
|
||||
<div class="section-head">
|
||||
<h2>{{ t('projects') }}</h2>
|
||||
<div class="project-tools">
|
||||
<div class="group-filter">
|
||||
<select :value="store.selectedProjectGroupId" @change="changeGroup($event.target.value)">
|
||||
<option :value="0">{{ t('allProjectGroups') }}</option>
|
||||
<option v-for="g in store.projectGroups" :key="g.id" :value="g.id">{{ groupLabel(g) }}</option>
|
||||
</select>
|
||||
<button :title="t('addProjectGroup')" @click="openGroup()"><Plus /></button>
|
||||
<button v-if="store.selectedProjectGroupId && store.selectedProjectGroupId !== 1" :title="t('editProjectGroup')" @click="openGroup(store.projectGroups.find(g => g.id === store.selectedProjectGroupId))"><Pencil /></button>
|
||||
<button v-if="store.selectedProjectGroupId && store.selectedProjectGroupId !== 1" :title="t('deleteProjectGroup')" @click="removeGroup(store.projectGroups.find(g => g.id === store.selectedProjectGroupId))"><Trash2 /></button>
|
||||
</div>
|
||||
<label class="search"><Search /><input v-model="search" :placeholder="t('search')" /></label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="project-grid">
|
||||
<article v-for="p in filtered" :key="p.id" class="project-card shine-card" @click="router.push('/project/' + p.id)">
|
||||
<div class="project-title">
|
||||
<div><h3>{{ p.name }}</h3><span class="group-chip">{{ p.groupId === 1 ? t('myProjectGroup') : (p.groupName || t('projectGroup')) }}</span><p :title="p.path">{{ p.path }}</p></div>
|
||||
<div class="icon-actions">
|
||||
<button :title="t('refreshProject')" :disabled="projectRunning(p.id)" @click.stop="refreshProject(p)"><RefreshCw :class="{ spin: projectRunning(p.id) }" /></button>
|
||||
<button :title="t('edit')" @click.stop="open(p)"><Pencil /></button>
|
||||
<button :title="t('delete')" @click.stop="remove(p)"><Trash2 /></button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="metric-row project-metrics">
|
||||
<div class="metric-total"><b>{{ fmt(p.stats.totalLines) }}</b><span>{{ t('totalLineCount') }}</span></div>
|
||||
<div class="metric-code"><b>{{ fmt(p.stats.codeLines) }}</b><span>{{ t('codeLines') }}</span></div>
|
||||
<div class="metric-files"><b>{{ fmt(p.stats.fileCount) }}</b><span>{{ t('fileCount') }}</span></div>
|
||||
</div>
|
||||
<div class="language-bar"><i v-for="(x, i) in p.languages.slice(0, 5)" :key="x.name" :style="{ background: palette[i], width: (x.code / Math.max(1, total(p)) * 100) + '%' }" /></div>
|
||||
<div class="legend">
|
||||
<span v-for="(x, i) in p.languages.slice(0, 4)" :key="x.name"><i :style="{ background: palette[i] }" />{{ x.name }} {{ Math.round(x.code / Math.max(1, total(p)) * 100) }}%</span>
|
||||
<span v-if="!p.languages?.length">{{ t('unanalyzed') }}</span>
|
||||
</div>
|
||||
<footer><span>↳ {{ p.stats.commitCount }} {{ t('commitsUnit') }}</span><b class="positive">+{{ fmt(p.stats.addedLines) }}</b><b class="negative">-{{ fmt(p.stats.deletedLines) }}</b></footer>
|
||||
</article>
|
||||
<button class="add-card shine-card" @click="open()"><span><Plus /></span>{{ t('addProject') }}</button>
|
||||
</div>
|
||||
</div>
|
||||
<Teleport to="body">
|
||||
<div v-if="modal" class="overlay" @click.self="!saving && (modal = false)">
|
||||
<form class="modal" @submit.prevent="save">
|
||||
<header><h2>{{ editing ? t('editProjectTitle') : t('addProjectTitle') }}</h2><button type="button" :disabled="saving" @click="modal = false">×</button></header>
|
||||
<label>{{ t('projectName') }}<input v-model="form.name" :disabled="saving" /></label>
|
||||
<label>{{ t('projectGroup') }}<select v-model.number="form.groupId" :disabled="saving"><option v-for="g in store.projectGroups" :key="g.id" :value="g.id">{{ groupLabel(g) }}</option></select></label>
|
||||
<label>{{ t('projectPath') }}<div class="browse"><input v-model="form.path" :disabled="saving" required /><button type="button" class="btn secondary" :disabled="saving" @click="browse"><FolderOpen />{{ t('browse') }}</button></div></label>
|
||||
<div class="wsl-picker hidden-wsl-picker">
|
||||
<button v-if="!wslDistros.length" type="button" class="btn secondary" @click="loadWSL">{{ t('selectWSL') }}</button>
|
||||
<template v-else>
|
||||
<select v-model="wslDistro"><option v-for="d in wslDistros" :key="d">{{ d }}</option></select>
|
||||
<button type="button" class="btn secondary" @click="browseWSL"><FolderOpen />{{ t('selectWSL') }}</button>
|
||||
</template>
|
||||
</div>
|
||||
<label>{{ t('description') }}<textarea v-model="form.description" :disabled="saving" /></label>
|
||||
<p v-if="error" class="form-error">{{ error }}</p>
|
||||
<footer><button type="button" class="btn secondary" :disabled="saving" @click="modal = false">{{ t('cancel') }}</button><button class="btn primary" :disabled="saving"><RefreshCw v-if="saving" class="spin" />{{ saving ? t('saving') : t('saveProject') }}</button></footer>
|
||||
</form>
|
||||
</div>
|
||||
<div v-if="groupModal" class="overlay" @click.self="!groupSaving && (groupModal = false)">
|
||||
<form class="modal compact-modal" @submit.prevent="saveGroup">
|
||||
<header><h2>{{ groupEditing ? t('editProjectGroup') : t('addProjectGroup') }}</h2><button type="button" :disabled="groupSaving" @click="groupModal = false">×</button></header>
|
||||
<label>{{ t('projectGroupName') }}<input v-model="groupForm.name" :disabled="groupSaving" required /></label>
|
||||
<p v-if="groupError" class="form-error">{{ groupError }}</p>
|
||||
<footer><button type="button" class="btn secondary" :disabled="groupSaving" @click="groupModal = false">{{ t('cancel') }}</button><button class="btn primary" :disabled="groupSaving"><RefreshCw v-if="groupSaving" class="spin" />{{ groupSaving ? t('saving') : t('saveProjectGroup') }}</button></footer>
|
||||
</form>
|
||||
</div>
|
||||
</Teleport>
|
||||
</template>
|
||||
47
frontend/src/views/Logs.vue
Normal file
@@ -0,0 +1,47 @@
|
||||
<script setup>
|
||||
import { computed, onMounted, onUnmounted, ref } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { RefreshCw, Trash2, ScrollText, Info, TriangleAlert, CircleX } from 'lucide-vue-next'
|
||||
import { call } from '../api'
|
||||
import StatCard from '../components/StatCard.vue'
|
||||
|
||||
const { t } = useI18n()
|
||||
const logs = ref([])
|
||||
const filter = ref('all')
|
||||
const auto = ref(true)
|
||||
let timer
|
||||
const shown = computed(() => filter.value === 'all' ? logs.value : logs.value.filter(x => filter.value === 'run' ? x.level !== 'error' : x.level === 'error'))
|
||||
const counts = computed(() => ({
|
||||
all: logs.value.length,
|
||||
info: logs.value.filter(x => x.level === 'info').length,
|
||||
warning: logs.value.filter(x => x.level === 'warning').length,
|
||||
error: logs.value.filter(x => x.level === 'error').length
|
||||
}))
|
||||
async function load() { logs.value = await call('GetLogs', 'all') }
|
||||
async function clear() {
|
||||
if (confirm(t('clearLogs') + '?')) {
|
||||
await call('ClearLogs')
|
||||
await load()
|
||||
}
|
||||
}
|
||||
onMounted(async () => {
|
||||
await load()
|
||||
timer = setInterval(() => auto.value && load(), 5000)
|
||||
})
|
||||
onUnmounted(() => clearInterval(timer))
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="page">
|
||||
<header class="page-head sticky-head">
|
||||
<div><h1>{{ t('logs') }}</h1><p>{{ t('logSubtitle') }}</p></div>
|
||||
<div class="actions"><label class="toggle"><input type="checkbox" v-model="auto" />{{ t('autoRefresh') }}</label><button class="btn secondary" @click="load"><RefreshCw />{{ t('refresh') }}</button><button class="btn danger" @click="clear"><Trash2 />{{ t('clearLogs') }}</button></div>
|
||||
</header>
|
||||
<div class="stats-grid four"><StatCard :icon="ScrollText" :value="counts.all" :label="t('totalLogs')" /><StatCard :icon="Info" :value="counts.info" :label="t('info')" /><StatCard :icon="TriangleAlert" :value="counts.warning" :label="t('warning')" /><StatCard :icon="CircleX" :value="counts.error" :label="t('error')" /></div>
|
||||
<div class="tabs compact"><button :class="{ active: filter === 'all' }" @click="filter = 'all'">{{ t('allLogs') }}</button><button :class="{ active: filter === 'run' }" @click="filter = 'run'">{{ t('runLogs') }}</button><button :class="{ active: filter === 'error' }" @click="filter = 'error'">{{ t('errorLogs') }}</button></div>
|
||||
<section class="panel log-panel">
|
||||
<article class="log" v-for="x in shown" :key="x.id" :class="x.level"><span><Info v-if="x.level === 'info'" /><TriangleAlert v-else-if="x.level === 'warning'" /><CircleX v-else /></span><div><small>{{ x.category }}</small><b>{{ x.message }}</b><code v-if="x.detail">{{ x.detail }}</code></div><time>{{ x.createdAt?.replace('T', ' ').slice(0, 19) }}</time></article>
|
||||
<div v-if="!shown.length" class="empty"><ScrollText />{{ t('noLogs') }}</div>
|
||||
</section>
|
||||
</div>
|
||||
</template>
|
||||
210
frontend/src/views/ProjectDetail.vue
Normal file
@@ -0,0 +1,210 @@
|
||||
<script setup>
|
||||
import { computed, onMounted, ref } from 'vue'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { ArrowLeft, Code2, GitCommitHorizontal, FolderTree, RefreshCw, Files, MessageSquareText, Rows3, Users, Plus, Minus, HardDrive, Folder, FileWarning, GitBranch, ExternalLink, TriangleAlert, ClipboardCheck } from 'lucide-vue-next'
|
||||
import StatCard from '../components/StatCard.vue'
|
||||
import ChartView from '../components/ChartView.vue'
|
||||
import GitHeatmap from '../components/GitHeatmap.vue'
|
||||
import GitTrend from '../components/GitTrend.vue'
|
||||
import CommitDrawer from '../components/CommitDrawer.vue'
|
||||
import { call } from '../api'
|
||||
import { useAppStore } from '../store'
|
||||
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
const store = useAppStore()
|
||||
const { t } = useI18n()
|
||||
const tab = ref('code')
|
||||
const p = ref({ stats: {}, languages: [] })
|
||||
const git = ref({ commits: [], refs: [], contributors: [], heatmap: [] })
|
||||
const diag = ref(null)
|
||||
const structure = ref({ files: [], folders: [], largeFiles: [], extensions: [] })
|
||||
const insights = ref({ healthScore: 0, summary: {}, issues: [] })
|
||||
const loading = ref(true)
|
||||
const gitLoading = ref(false)
|
||||
const insightLoading = ref(false)
|
||||
const selectedDate = ref('')
|
||||
const issueSeverity = ref('all')
|
||||
const issueType = ref('all')
|
||||
const detail = ref(null)
|
||||
const detailLoading = ref(false)
|
||||
const colors = ['#7b73ff', '#4fd1a1', '#4da5ff', '#f4c84a', '#ef6683', '#23b5d3']
|
||||
|
||||
const fmt = n => {
|
||||
n = +n || 0
|
||||
return n >= 1e6 ? (n / 1e6).toFixed(1) + 'M' : n >= 1e3 ? (n / 1e3).toFixed(1) + 'K' : n.toString()
|
||||
}
|
||||
const bytes = n => n >= 1048576 ? (n / 1048576).toFixed(1) + ' MB' : n >= 1024 ? (n / 1024).toFixed(1) + ' KB' : (n || 0) + ' B'
|
||||
const pie = computed(() => ({
|
||||
backgroundColor: 'transparent',
|
||||
tooltip: { trigger: 'item' },
|
||||
series: [{ type: 'pie', radius: ['52%', '76%'], label: { show: false }, data: p.value.languages.map((x, i) => ({ name: x.name, value: x.code, itemStyle: { color: colors[i % colors.length] } })) }]
|
||||
}))
|
||||
const visibleCommits = computed(() => selectedDate.value ? git.value.commits.filter(c => c.date?.slice(0, 10) === selectedDate.value) : git.value.commits)
|
||||
const gitErrorCode = computed(() => git.value.error || diag.value?.errorCode || '')
|
||||
const gitErrorText = computed(() => gitErrorCode.value ? t(`errors.${gitErrorCode.value}`) : '')
|
||||
const issueTypes = computed(() => [...new Set((insights.value.issues || []).map(x => x.type))])
|
||||
const filteredIssues = computed(() => (insights.value.issues || []).filter(x => (issueSeverity.value === 'all' || x.severity === issueSeverity.value) && (issueType.value === 'all' || x.type === issueType.value)))
|
||||
|
||||
async function load() {
|
||||
loading.value = true
|
||||
;[p.value, git.value, structure.value, insights.value] = await Promise.all([call('GetProject', +route.params.id), call('GetGitStats', +route.params.id), call('GetStructure', +route.params.id), call('GetProjectInsights', +route.params.id)])
|
||||
try { diag.value = await call('GetGitDiagnostics', +route.params.id) } catch { diag.value = null }
|
||||
loading.value = false
|
||||
}
|
||||
async function refreshInsights() {
|
||||
insightLoading.value = true
|
||||
try {
|
||||
insights.value = await call('RefreshProjectInsights', +route.params.id)
|
||||
store.showToast({ type: 'success', key: 'insightDone' })
|
||||
} catch (e) {
|
||||
store.showToast({ type: 'error', text: String(e) })
|
||||
} finally {
|
||||
insightLoading.value = false
|
||||
}
|
||||
}
|
||||
async function analyze(kind = tab.value === 'git' ? 'git' : 'code') {
|
||||
await store.analyze(+route.params.id, kind)
|
||||
}
|
||||
async function selectRef(r) {
|
||||
gitLoading.value = true
|
||||
try {
|
||||
git.value = await call('GetGitStatsForRef', +route.params.id, r.name)
|
||||
diag.value = await call('GetGitDiagnostics', +route.params.id)
|
||||
selectedDate.value = ''
|
||||
} catch (e) {
|
||||
const code = String(e)
|
||||
store.showToast({ type: 'error', key: code ? `errors.${code}` : null, text: code })
|
||||
git.value = { ...git.value, available: false, error: code }
|
||||
} finally {
|
||||
gitLoading.value = false
|
||||
}
|
||||
}
|
||||
async function checkout(r) {
|
||||
if (!confirm(t('checkoutConfirm', { ref: r.name }))) return
|
||||
gitLoading.value = true
|
||||
try {
|
||||
await call('CheckoutBranch', +route.params.id, r.name)
|
||||
store.showToast({ type: 'success', key: 'branchChanged' })
|
||||
git.value = await call('GetGitStatsForRef', +route.params.id, '')
|
||||
await store.analyze(+route.params.id, 'git')
|
||||
} catch (e) {
|
||||
const raw = String(e)
|
||||
store.showToast({ type: 'error', key: raw.includes('GIT_WORKTREE_DIRTY') ? 'dirty' : `errors.${raw}`, text: raw })
|
||||
} finally {
|
||||
gitLoading.value = false
|
||||
}
|
||||
}
|
||||
async function showCommit(c) {
|
||||
detailLoading.value = true
|
||||
detail.value = { ...c, files: [] }
|
||||
try { detail.value = await call('GetCommitDetails', +route.params.id, c.hash) } finally { detailLoading.value = false }
|
||||
}
|
||||
onMounted(load)
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="page detail-page">
|
||||
<header class="project-head sticky-head detail-sticky-head">
|
||||
<div class="detail-head-row">
|
||||
<button class="back" @click="router.push('/')"><ArrowLeft />{{ t('back') }}</button>
|
||||
<div><h1>{{ p.name }}</h1><p>{{ p.path }}</p></div>
|
||||
</div>
|
||||
<div class="tabs detail-tabs">
|
||||
<button :class="{ active: tab === 'code' }" @click="tab = 'code'"><Code2 />{{ t('code') }}</button>
|
||||
<button :class="{ active: tab === 'git' }" @click="tab = 'git'"><GitCommitHorizontal />{{ t('git') }}</button>
|
||||
<button :class="{ active: tab === 'structure' }" @click="tab = 'structure'"><FolderTree />{{ t('structure') }}</button>
|
||||
<button :class="{ active: tab === 'insights' }" @click="tab = 'insights'"><ClipboardCheck />{{ t('insights') }}</button>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<template v-if="tab === 'code'">
|
||||
<div class="stats-grid five">
|
||||
<StatCard :icon="Rows3" :value="fmt(p.stats.totalLines)" :label="t('totalLineCount')" />
|
||||
<StatCard :icon="Code2" :value="fmt(p.stats.codeLines)" :label="t('codeLines')" />
|
||||
<StatCard :icon="MessageSquareText" :value="fmt(p.stats.commentLines)" :label="t('commentLines')" />
|
||||
<StatCard :icon="Rows3" :value="fmt(p.stats.blankLines)" :label="t('blankLines')" />
|
||||
<StatCard :icon="Files" :value="fmt(p.stats.fileCount)" :label="t('fileCount')" />
|
||||
</div>
|
||||
<div class="split">
|
||||
<section class="panel shine-card"><h2>{{ t('languageDistribution') }}</h2><ChartView v-if="p.languages.length" :option="pie" /><div v-else class="empty">{{ t('empty') }}</div></section>
|
||||
<section class="panel shine-card"><h2>{{ t('languageDetails') }}</h2><div class="language-list"><div v-for="(x, i) in p.languages" :key="x.name"><b><i :style="{ background: colors[i % colors.length] }" />{{ x.name }}</b><span>{{ x.files }} {{ t('files') }}</span><strong>{{ fmt(x.code) }} {{ t('lines') }}</strong></div></div></section>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<template v-else-if="tab === 'git'">
|
||||
<div class="git-context">
|
||||
<span><GitBranch />{{ t('workspaceBranch') }}: <b>{{ git.workspaceBranch || git.currentBranch || diag?.workspaceBranch || '-' }}</b></span>
|
||||
<span>{{ t('viewRef') }}: <b>{{ git.viewRef || git.currentBranch || diag?.viewRef || '-' }}</b></span>
|
||||
<RefreshCw v-if="gitLoading" class="spin" />
|
||||
</div>
|
||||
<section v-if="gitErrorCode" class="panel git-error-panel">
|
||||
<TriangleAlert />
|
||||
<div><h2>{{ t('gitUnavailable') }}</h2><p>{{ gitErrorText || t('gitUnavailableHint') }}</p><code v-if="diag?.detail">{{ t('gitDetail') }}: {{ diag.detail }}</code></div>
|
||||
<button class="btn secondary" @click="analyze('git')"><RefreshCw />{{ t('analyzeGit') }}</button>
|
||||
</section>
|
||||
<div class="stats-grid four">
|
||||
<StatCard :icon="GitCommitHorizontal" :value="git.commitCount" :label="t('commitCount')" />
|
||||
<StatCard :icon="Plus" tone="green" :value="'+' + fmt(git.added)" :label="t('addedLines')" />
|
||||
<StatCard :icon="Minus" tone="red" :value="'-' + fmt(git.deleted)" :label="t('deletedLines')" />
|
||||
<StatCard :icon="Users" tone="blue" :value="git.contributorCount" :label="t('contributors')" />
|
||||
</div>
|
||||
<section class="panel heat-panel shine-card"><div class="section-head"><h2>{{ t('activityHeatmap') }}</h2><button v-if="selectedDate" class="btn secondary" @click="selectedDate = ''">{{ t('selectedDate', { date: selectedDate }) }} · {{ t('clearFilter') }}</button></div><GitHeatmap :days="git.heatmap" :selected="selectedDate" @select="selectedDate = $event" /></section>
|
||||
<div class="split git-split">
|
||||
<section class="panel structure-scroll-panel"><h2>{{ t('branches') }}</h2><div class="branch interactive" v-for="r in git.refs" :key="r.name" :class="{ selected: r.name === git.viewRef }" @click="selectRef(r)"><span :class="{ current: r.current }"><GitCommitHorizontal />{{ r.name }}</span><code>{{ r.hash }}</code><small>{{ r.kind }}</small><button class="checkout-btn" :title="t('checkout')" @click.stop="checkout(r)"><ExternalLink /></button></div><div v-if="!git.refs?.length" class="empty">{{ t('empty') }}</div></section>
|
||||
<section class="panel structure-scroll-panel"><h2>{{ t('recentCommits') }}</h2><button class="commit" v-for="c in visibleCommits.slice(0, 30)" :key="c.hash" @click="showCommit(c)"><span class="avatar">{{ c.author?.[0] }}</span><div><b>{{ c.message }}</b><small>{{ c.author }} · {{ c.hash.slice(0, 7) }} · {{ c.date?.slice(0, 10) }}</small></div><span class="positive">+{{ c.added }}</span><span class="negative">-{{ c.deleted }}</span></button><div v-if="!visibleCommits.length" class="empty">{{ t('empty') }}</div></section>
|
||||
</div>
|
||||
<section class="panel trend shine-card"><h2>{{ t('commitTrend') }}</h2><GitTrend :commits="git.commits" @select="selectedDate = $event" /></section>
|
||||
<section class="panel shine-card"><h2>{{ t('contributorRanking') }}</h2><div class="contributor" v-for="(c, i) in git.contributors" :key="c.email"><b>#{{ i + 1 }}</b><span class="avatar">{{ c.name?.[0] }}</span><div><strong>{{ c.name }}</strong><small>{{ c.email }}</small></div><span>{{ c.commits }} {{ t('commitsUnit') }}</span><span class="positive">+{{ fmt(c.added) }}</span><span class="negative">-{{ fmt(c.deleted) }}</span></div><div v-if="!git.contributors?.length" class="empty">{{ t('empty') }}</div></section>
|
||||
<CommitDrawer v-if="detail" :detail="detail" :loading="detailLoading" @close="detail = null" />
|
||||
</template>
|
||||
|
||||
<template v-else-if="tab === 'structure'">
|
||||
<div class="stats-grid four">
|
||||
<StatCard :icon="Files" :value="structure.totalFiles" :label="t('totalFiles')" />
|
||||
<StatCard :icon="Folder" :value="structure.totalDirs" :label="t('folderCount')" />
|
||||
<StatCard :icon="HardDrive" :value="bytes(structure.totalSize || 0)" :label="t('totalSize')" />
|
||||
<StatCard :icon="FileWarning" tone="red" :value="structure.largeFiles?.length || 0" :label="t('largeFiles')" />
|
||||
</div>
|
||||
<div class="split structure-split">
|
||||
<section class="panel structure-panel"><h2>{{ t('directoryStructure') }}</h2><div class="file-tree"><div v-for="f in structure.files?.slice(0, 300)" :key="f.path" :style="{ paddingLeft: Math.min((f.path.split('/').length - 1) * 16, 160) + 'px' }"><Folder v-if="f.isDir" /><Files v-else /><span :title="f.path">{{ f.name }}</span><small>{{ f.isDir ? '' : bytes(f.size) }}</small></div></div></section>
|
||||
<section class="panel structure-panel"><h2>{{ t('folderSize') }}</h2><div class="folder-size" v-for="f in structure.folders" :key="f.name"><b :title="f.name">{{ f.name }}</b><span>{{ f.files }} {{ t('files') }}</span><i><em :style="{ width: (f.size / Math.max(1, structure.folders[0]?.size) * 100) + '%' }" /></i><strong>{{ bytes(f.size) }}</strong></div></section>
|
||||
</div>
|
||||
<section class="panel large-file-panel"><h2>{{ t('largeFileDetection') }}</h2><div class="large-file" v-for="f in structure.largeFiles" :key="f.path"><div><b>{{ f.name }}</b><small>{{ f.path }}</small></div><strong>{{ bytes(f.size) }}</strong></div><div v-if="!structure.largeFiles?.length" class="empty">{{ t('noLargeFiles') }}</div></section>
|
||||
</template>
|
||||
<template v-else>
|
||||
<section class="panel insights-hero shine-card">
|
||||
<div class="score-ring" :style="{ '--score': insights.healthScore || 0 }"><strong>{{ insights.healthScore || 0 }}</strong><span>{{ t('healthScore') }}</span></div>
|
||||
<div class="insight-summary">
|
||||
<h2>{{ t('deepInsights') }}</h2>
|
||||
<p>{{ t('deepInsightsHint') }}</p>
|
||||
<div class="insight-counts">
|
||||
<span class="high">{{ insights.summary?.high || 0 }} {{ t('highRisk') }}</span>
|
||||
<span class="medium">{{ insights.summary?.medium || 0 }} {{ t('mediumRisk') }}</span>
|
||||
<span class="low">{{ insights.summary?.low || 0 }} {{ t('lowRisk') }}</span>
|
||||
<span>{{ insights.summary?.todoCount || 0 }} TODO</span>
|
||||
</div>
|
||||
</div>
|
||||
<button class="btn secondary" :disabled="insightLoading" @click="refreshInsights"><RefreshCw :class="{ spin: insightLoading }" />{{ t('refresh') }}</button>
|
||||
</section>
|
||||
<section class="panel">
|
||||
<div class="section-head insight-filter">
|
||||
<h2>{{ t('issueList') }}</h2>
|
||||
<div class="actions">
|
||||
<select v-model="issueSeverity"><option value="all">{{ t('allSeverity') }}</option><option value="high">{{ t('highRisk') }}</option><option value="medium">{{ t('mediumRisk') }}</option><option value="low">{{ t('lowRisk') }}</option></select>
|
||||
<select v-model="issueType"><option value="all">{{ t('allTypes') }}</option><option v-for="type in issueTypes" :key="type" :value="type">{{ type }}</option></select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="issue-list">
|
||||
<article v-for="issue in filteredIssues" :key="issue.type + issue.path + issue.line + issue.title" class="issue-card" :class="issue.severity">
|
||||
<span class="issue-severity">{{ t('severity.' + issue.severity) }}</span>
|
||||
<div><h3>{{ issue.title }}</h3><p>{{ issue.detail }}</p><small v-if="issue.path">{{ issue.path }}<template v-if="issue.line">:{{ issue.line }}</template></small><code v-if="issue.evidence">{{ issue.evidence }}</code><b>{{ issue.suggestion }}</b></div>
|
||||
</article>
|
||||
<div v-if="!filteredIssues.length" class="empty"><ClipboardCheck />{{ t('noIssues') }}</div>
|
||||
</div>
|
||||
</section>
|
||||
</template>
|
||||
<div class="center-action"><button class="btn secondary" @click="analyze()"><RefreshCw />{{ t('analyze') }}</button></div>
|
||||
</div>
|
||||
</template>
|
||||
54
frontend/src/views/Settings.vue
Normal file
@@ -0,0 +1,54 @@
|
||||
<script setup>
|
||||
import { computed, onMounted, reactive, ref, watch } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { FileSliders, Database, Plus, Trash2, Upload, BarChart3, Folder, Languages, SunMoon, CheckCircle2, Info, Copy } from 'lucide-vue-next'
|
||||
import { call, isNative } from '../api'
|
||||
import { useAppStore } from '../store'
|
||||
|
||||
const tab=ref(new URLSearchParams(location.search).get('settingsTab')||'rules'),rules=ref([]),form=reactive({pattern:'',category:'custom'})
|
||||
const settings=reactive({theme:'dark',locale:'zh-CN',gitScope:'current',databasePath:'',autoRefresh:true,glassOpacity:55,loadingStyle:'fullscreen-orbit'})
|
||||
const store=useAppStore(),{locale}=useI18n(),native=isNative(),dbMessage=ref('')
|
||||
const groups=computed(()=>Object.groupBy?Object.groupBy(rules.value,x=>x.category):rules.value.reduce((a,x)=>((a[x.category]??=[]).push(x),a),{}))
|
||||
const loadingOptions=[
|
||||
{value:'fullscreen-orbit',title:'能量轨道',desc:'环形粒子、扫描光束和能量核心'},
|
||||
{value:'fullscreen-grid',title:'数据矩阵',desc:'流动数据网格和聚合节点'},
|
||||
{value:'fullscreen-warp',title:'光速跃迁',desc:'深空隧道、放射光束和跃迁环'},
|
||||
{value:'bar',title:'底部进度条',desc:'保留当前页面,只显示底部进度'}
|
||||
]
|
||||
|
||||
async function load(){
|
||||
rules.value=await call('GetRules')
|
||||
const [saved,bootstrap]=await Promise.all([call('GetSettings'),call('GetBootstrapStatus')])
|
||||
Object.assign(settings,saved)
|
||||
settings.databasePath=bootstrap.databasePath||saved.databasePath||bootstrap.defaultPath||''
|
||||
}
|
||||
async function add(){if(!form.pattern)return;await call('AddRule',form.pattern,form.category);form.pattern='';await load()}
|
||||
async function remove(r){if(!r.builtin){await call('DeleteRule',r.id);await load()}}
|
||||
async function save(){await call('SaveSettings',{...settings,databasePath:''});store.applyAppearance(settings);apply();localStorage.setItem('cc-settings',JSON.stringify(settings))}
|
||||
function apply(){locale.value=settings.locale;let theme=settings.theme;if(theme==='system')theme=matchMedia('(prefers-color-scheme: dark)').matches?'dark':'light';document.documentElement.dataset.theme=theme;document.documentElement.style.setProperty('--glass-user-opacity',String((settings.glassOpacity||55)/100))}
|
||||
async function migrate(){
|
||||
dbMessage.value=''
|
||||
try{
|
||||
const p=await call('SelectInitialDatabaseFile',settings.databasePath)
|
||||
if(!p)return
|
||||
await call('MigrateDatabase',p)
|
||||
const status=await call('GetBootstrapStatus')
|
||||
settings.databasePath=status.databasePath
|
||||
dbMessage.value='数据库已迁移并切换到新位置'
|
||||
store.showToast({type:'success',text:dbMessage.value})
|
||||
}catch(e){dbMessage.value=String(e);store.showToast({type:'error',text:'数据库迁移失败'})}
|
||||
}
|
||||
async function copyPath(){try{await navigator.clipboard.writeText(settings.databasePath);store.showToast({type:'success',text:'数据库路径已复制'})}catch{store.showToast({type:'error',text:'无法复制路径'})}}
|
||||
async function clear(mode){const id=mode==='project'?Number(prompt('项目 ID')):0;if(mode==='project'&&!id)return;if(confirm('此操作不可恢复,确认继续?')){await call('ClearData',mode,id);await store.refresh()}}
|
||||
watch(()=>[settings.theme,settings.locale,settings.glassOpacity,settings.loadingStyle],save)
|
||||
onMounted(async()=>{await load();apply()})
|
||||
</script>
|
||||
|
||||
<template><div class="page settings-page">
|
||||
<header class="page-head"><div><h1>设置</h1><p>管理排除规则、界面和数据库配置</p></div></header>
|
||||
<div class="tabs settings-tabs"><button :class="{active:tab==='rules'}" @click="tab='rules'"><FileSliders/>排除规则</button><button :class="{active:tab==='appearance'}" @click="tab='appearance'"><SunMoon/>界面设置</button><button :class="{active:tab==='database'}" @click="tab='database'"><Database/>数据管理</button></div>
|
||||
<template v-if="tab==='rules'"><section class="panel rule-add"><h2><Plus/>添加排除规则</h2><div><input v-model="form.pattern" placeholder="例如 *.log, cache, temp" @keyup.enter="add"/><select v-model="form.category"><option value="general">通用</option><option value="php">PHP</option><option value="go">Go</option><option value="vue">Vue/JS</option><option value="custom">自定义</option></select><button class="btn primary" @click="add"><Plus/>添加</button></div><small>支持 * 通配符;目录名会在任意层级匹配</small></section><section v-for="(items,name) in groups" :key="name" class="panel rule-group"><h2>{{name}} <small>{{items.length}} 条规则</small></h2><div><button v-for="r in items" :key="r.id" :class="{builtin:r.builtin}" @click="remove(r)">{{r.pattern}}<small v-if="r.builtin">默认</small><Trash2 v-else/></button></div></section></template>
|
||||
<template v-else-if="tab==='appearance'"><section class="panel form-panel"><h2><Languages/>语言与主题</h2><label>界面语言<select v-model="settings.locale"><option value="zh-CN">简体中文</option><option value="en">English</option></select></label><label>主题<select v-model="settings.theme"><option value="dark">暗色</option><option value="light">浅色</option><option value="system">跟随系统</option></select></label><label>Git 默认范围<select v-model="settings.gitScope"><option value="current">当前分支</option><option value="all">所有分支</option></select></label><div class="loading-style-setting"><span>统计 Loading 样式</span><div class="loading-style-grid" role="radiogroup" aria-label="统计 Loading 样式"><button v-for="option in loadingOptions" :key="option.value" type="button" role="radio" :aria-checked="settings.loadingStyle===option.value" :class="['loading-style-card',option.value,{active:settings.loadingStyle===option.value}]" @click="settings.loadingStyle=option.value"><span class="loading-style-preview" aria-hidden="true"><i/></span><b>{{option.title}}</b><small>{{option.desc}}</small></button></div></div><label class="opacity-setting"><span>卡片透明度 <b>{{settings.glassOpacity}}%</b></span><input v-model.number="settings.glassOpacity" type="range" min="30" max="75" step="1"/></label></section></template>
|
||||
<template v-else><section class="panel database-panel"><div class="db-title"><h2><Database/>数据库位置</h2><span class="db-connected"><CheckCircle2/>已连接</span></div><div v-if="!native" class="preview-notice"><Info/><div><b>当前是浏览器预览模式</b><small>浏览器无法访问本地数据库和文件选择器,请运行 code-count.exe 使用数据库功能。</small></div></div><div class="db-path"><span>当前位置</span><code :title="settings.databasePath">{{settings.databasePath||'未获取到数据库路径'}}</code><button title="复制路径" :disabled="!settings.databasePath" @click="copyPath"><Copy/></button></div><p v-if="dbMessage" class="db-message">{{dbMessage}}</p><button class="btn secondary migrate" :disabled="!native" @click="migrate"><Upload/>选择新位置并迁移</button></section>
|
||||
<section class="panel danger-zone"><h2><Trash2/>清空数据</h2><p>选择要清空的数据类型,此操作不可恢复。</p><div><button @click="clear('stats')"><BarChart3/><span><b>清空统计数据</b><small>删除分析记录,保留项目配置</small></span></button><button @click="clear('project')"><Folder/><span><b>清空单个项目</b><small>删除指定项目的统计数据</small></span></button><button class="danger" @click="clear('all')"><Trash2/><span><b>清空所有数据</b><small>删除所有项目和分析记录</small></span></button></div></section></template>
|
||||
</div></template>
|
||||
7
frontend/vite.config.js
Normal file
@@ -0,0 +1,7 @@
|
||||
import {defineConfig} from 'vite'
|
||||
import vue from '@vitejs/plugin-vue'
|
||||
|
||||
// https://vitejs.dev/config/
|
||||
export default defineConfig({
|
||||
plugins: [vue()]
|
||||
})
|
||||
84
frontend/wailsjs/go/main/App.d.ts
vendored
Normal file
@@ -0,0 +1,84 @@
|
||||
// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
|
||||
// This file is automatically generated. DO NOT EDIT
|
||||
import {model} from '../models';
|
||||
import {main} from '../models';
|
||||
|
||||
export function AddRule(arg1:string,arg2:string):Promise<model.ExclusionRule>;
|
||||
|
||||
export function CancelAnalysis(arg1:string):Promise<void>;
|
||||
|
||||
export function CheckoutBranch(arg1:number,arg2:string):Promise<model.CheckoutResult>;
|
||||
|
||||
export function ClearData(arg1:string,arg2:number):Promise<void>;
|
||||
|
||||
export function ClearLogs():Promise<void>;
|
||||
|
||||
export function DeleteProject(arg1:number):Promise<void>;
|
||||
|
||||
export function DeleteProjectGroup(arg1:number):Promise<void>;
|
||||
|
||||
export function DeleteRule(arg1:number):Promise<void>;
|
||||
|
||||
export function GetBootstrapStatus():Promise<main.BootstrapStatus>;
|
||||
|
||||
export function GetCommitDetails(arg1:number,arg2:string):Promise<model.GitCommitDetail>;
|
||||
|
||||
export function GetDashboard():Promise<model.Dashboard>;
|
||||
|
||||
export function GetDashboardByGroup(arg1:number):Promise<model.Dashboard>;
|
||||
|
||||
export function GetGitDiagnostics(arg1:number):Promise<model.GitDiagnostics>;
|
||||
|
||||
export function GetGitStats(arg1:number):Promise<model.GitStats>;
|
||||
|
||||
export function GetGitStatsForRef(arg1:number,arg2:string):Promise<model.GitStats>;
|
||||
|
||||
export function GetLogs(arg1:string):Promise<Array<model.LogEntry>>;
|
||||
|
||||
export function GetProject(arg1:number):Promise<model.Project>;
|
||||
|
||||
export function GetProjectInsights(arg1:number):Promise<model.ProjectInsights>;
|
||||
|
||||
export function GetRules():Promise<Array<model.ExclusionRule>>;
|
||||
|
||||
export function GetSettings():Promise<model.AppSettings>;
|
||||
|
||||
export function GetStructure(arg1:number):Promise<model.StructureStats>;
|
||||
|
||||
export function InitializeDatabase(arg1:string):Promise<main.BootstrapStatus>;
|
||||
|
||||
export function ListProjectGroups():Promise<Array<model.ProjectGroup>>;
|
||||
|
||||
export function ListProjects():Promise<Array<model.Project>>;
|
||||
|
||||
export function ListProjectsByGroup(arg1:number):Promise<Array<model.Project>>;
|
||||
|
||||
export function ListWSLDistros():Promise<Array<string>>;
|
||||
|
||||
export function MigrateDatabase(arg1:string):Promise<void>;
|
||||
|
||||
export function RefreshProjectInsights(arg1:number):Promise<model.ProjectInsights>;
|
||||
|
||||
export function ReportClientError(arg1:string,arg2:string,arg3:string):Promise<void>;
|
||||
|
||||
export function RetryDatabase():Promise<main.BootstrapStatus>;
|
||||
|
||||
export function SaveProject(arg1:number,arg2:model.ProjectInput):Promise<model.Project>;
|
||||
|
||||
export function SaveProjectGroup(arg1:number,arg2:string):Promise<model.ProjectGroup>;
|
||||
|
||||
export function SaveSettings(arg1:model.AppSettings):Promise<void>;
|
||||
|
||||
export function SelectDatabaseFile():Promise<string>;
|
||||
|
||||
export function SelectDirectory():Promise<string>;
|
||||
|
||||
export function SelectInitialDatabaseFile(arg1:string):Promise<string>;
|
||||
|
||||
export function SelectWSLDirectory(arg1:string):Promise<string>;
|
||||
|
||||
export function StartAnalysis(arg1:number,arg2:string):Promise<string>;
|
||||
|
||||
export function StartBatchAnalysis():Promise<Array<string>>;
|
||||
|
||||
export function StartBatchAnalysisByGroup(arg1:number):Promise<Array<string>>;
|
||||
163
frontend/wailsjs/go/main/App.js
Normal file
@@ -0,0 +1,163 @@
|
||||
// @ts-check
|
||||
// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
|
||||
// This file is automatically generated. DO NOT EDIT
|
||||
|
||||
export function AddRule(arg1, arg2) {
|
||||
return window['go']['main']['App']['AddRule'](arg1, arg2);
|
||||
}
|
||||
|
||||
export function CancelAnalysis(arg1) {
|
||||
return window['go']['main']['App']['CancelAnalysis'](arg1);
|
||||
}
|
||||
|
||||
export function CheckoutBranch(arg1, arg2) {
|
||||
return window['go']['main']['App']['CheckoutBranch'](arg1, arg2);
|
||||
}
|
||||
|
||||
export function ClearData(arg1, arg2) {
|
||||
return window['go']['main']['App']['ClearData'](arg1, arg2);
|
||||
}
|
||||
|
||||
export function ClearLogs() {
|
||||
return window['go']['main']['App']['ClearLogs']();
|
||||
}
|
||||
|
||||
export function DeleteProject(arg1) {
|
||||
return window['go']['main']['App']['DeleteProject'](arg1);
|
||||
}
|
||||
|
||||
export function DeleteProjectGroup(arg1) {
|
||||
return window['go']['main']['App']['DeleteProjectGroup'](arg1);
|
||||
}
|
||||
|
||||
export function DeleteRule(arg1) {
|
||||
return window['go']['main']['App']['DeleteRule'](arg1);
|
||||
}
|
||||
|
||||
export function GetBootstrapStatus() {
|
||||
return window['go']['main']['App']['GetBootstrapStatus']();
|
||||
}
|
||||
|
||||
export function GetCommitDetails(arg1, arg2) {
|
||||
return window['go']['main']['App']['GetCommitDetails'](arg1, arg2);
|
||||
}
|
||||
|
||||
export function GetDashboard() {
|
||||
return window['go']['main']['App']['GetDashboard']();
|
||||
}
|
||||
|
||||
export function GetDashboardByGroup(arg1) {
|
||||
return window['go']['main']['App']['GetDashboardByGroup'](arg1);
|
||||
}
|
||||
|
||||
export function GetGitDiagnostics(arg1) {
|
||||
return window['go']['main']['App']['GetGitDiagnostics'](arg1);
|
||||
}
|
||||
|
||||
export function GetGitStats(arg1) {
|
||||
return window['go']['main']['App']['GetGitStats'](arg1);
|
||||
}
|
||||
|
||||
export function GetGitStatsForRef(arg1, arg2) {
|
||||
return window['go']['main']['App']['GetGitStatsForRef'](arg1, arg2);
|
||||
}
|
||||
|
||||
export function GetLogs(arg1) {
|
||||
return window['go']['main']['App']['GetLogs'](arg1);
|
||||
}
|
||||
|
||||
export function GetProject(arg1) {
|
||||
return window['go']['main']['App']['GetProject'](arg1);
|
||||
}
|
||||
|
||||
export function GetProjectInsights(arg1) {
|
||||
return window['go']['main']['App']['GetProjectInsights'](arg1);
|
||||
}
|
||||
|
||||
export function GetRules() {
|
||||
return window['go']['main']['App']['GetRules']();
|
||||
}
|
||||
|
||||
export function GetSettings() {
|
||||
return window['go']['main']['App']['GetSettings']();
|
||||
}
|
||||
|
||||
export function GetStructure(arg1) {
|
||||
return window['go']['main']['App']['GetStructure'](arg1);
|
||||
}
|
||||
|
||||
export function InitializeDatabase(arg1) {
|
||||
return window['go']['main']['App']['InitializeDatabase'](arg1);
|
||||
}
|
||||
|
||||
export function ListProjectGroups() {
|
||||
return window['go']['main']['App']['ListProjectGroups']();
|
||||
}
|
||||
|
||||
export function ListProjects() {
|
||||
return window['go']['main']['App']['ListProjects']();
|
||||
}
|
||||
|
||||
export function ListProjectsByGroup(arg1) {
|
||||
return window['go']['main']['App']['ListProjectsByGroup'](arg1);
|
||||
}
|
||||
|
||||
export function ListWSLDistros() {
|
||||
return window['go']['main']['App']['ListWSLDistros']();
|
||||
}
|
||||
|
||||
export function MigrateDatabase(arg1) {
|
||||
return window['go']['main']['App']['MigrateDatabase'](arg1);
|
||||
}
|
||||
|
||||
export function RefreshProjectInsights(arg1) {
|
||||
return window['go']['main']['App']['RefreshProjectInsights'](arg1);
|
||||
}
|
||||
|
||||
export function ReportClientError(arg1, arg2, arg3) {
|
||||
return window['go']['main']['App']['ReportClientError'](arg1, arg2, arg3);
|
||||
}
|
||||
|
||||
export function RetryDatabase() {
|
||||
return window['go']['main']['App']['RetryDatabase']();
|
||||
}
|
||||
|
||||
export function SaveProject(arg1, arg2) {
|
||||
return window['go']['main']['App']['SaveProject'](arg1, arg2);
|
||||
}
|
||||
|
||||
export function SaveProjectGroup(arg1, arg2) {
|
||||
return window['go']['main']['App']['SaveProjectGroup'](arg1, arg2);
|
||||
}
|
||||
|
||||
export function SaveSettings(arg1) {
|
||||
return window['go']['main']['App']['SaveSettings'](arg1);
|
||||
}
|
||||
|
||||
export function SelectDatabaseFile() {
|
||||
return window['go']['main']['App']['SelectDatabaseFile']();
|
||||
}
|
||||
|
||||
export function SelectDirectory() {
|
||||
return window['go']['main']['App']['SelectDirectory']();
|
||||
}
|
||||
|
||||
export function SelectInitialDatabaseFile(arg1) {
|
||||
return window['go']['main']['App']['SelectInitialDatabaseFile'](arg1);
|
||||
}
|
||||
|
||||
export function SelectWSLDirectory(arg1) {
|
||||
return window['go']['main']['App']['SelectWSLDirectory'](arg1);
|
||||
}
|
||||
|
||||
export function StartAnalysis(arg1, arg2) {
|
||||
return window['go']['main']['App']['StartAnalysis'](arg1, arg2);
|
||||
}
|
||||
|
||||
export function StartBatchAnalysis() {
|
||||
return window['go']['main']['App']['StartBatchAnalysis']();
|
||||
}
|
||||
|
||||
export function StartBatchAnalysisByGroup(arg1) {
|
||||
return window['go']['main']['App']['StartBatchAnalysisByGroup'](arg1);
|
||||
}
|
||||
663
frontend/wailsjs/go/models.ts
Normal file
@@ -0,0 +1,663 @@
|
||||
export namespace main {
|
||||
|
||||
export class BootstrapStatus {
|
||||
state: string;
|
||||
databasePath: string;
|
||||
defaultPath: string;
|
||||
errorCode?: string;
|
||||
errorDetail?: string;
|
||||
|
||||
static createFrom(source: any = {}) {
|
||||
return new BootstrapStatus(source);
|
||||
}
|
||||
|
||||
constructor(source: any = {}) {
|
||||
if ('string' === typeof source) source = JSON.parse(source);
|
||||
this.state = source["state"];
|
||||
this.databasePath = source["databasePath"];
|
||||
this.defaultPath = source["defaultPath"];
|
||||
this.errorCode = source["errorCode"];
|
||||
this.errorDetail = source["errorDetail"];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export namespace model {
|
||||
|
||||
export class AppSettings {
|
||||
theme: string;
|
||||
locale: string;
|
||||
gitScope: string;
|
||||
databasePath: string;
|
||||
autoRefresh: boolean;
|
||||
glassOpacity: number;
|
||||
loadingStyle: string;
|
||||
|
||||
static createFrom(source: any = {}) {
|
||||
return new AppSettings(source);
|
||||
}
|
||||
|
||||
constructor(source: any = {}) {
|
||||
if ('string' === typeof source) source = JSON.parse(source);
|
||||
this.theme = source["theme"];
|
||||
this.locale = source["locale"];
|
||||
this.gitScope = source["gitScope"];
|
||||
this.databasePath = source["databasePath"];
|
||||
this.autoRefresh = source["autoRefresh"];
|
||||
this.glassOpacity = source["glassOpacity"];
|
||||
this.loadingStyle = source["loadingStyle"];
|
||||
}
|
||||
}
|
||||
export class CheckoutResult {
|
||||
branch: string;
|
||||
message: string;
|
||||
|
||||
static createFrom(source: any = {}) {
|
||||
return new CheckoutResult(source);
|
||||
}
|
||||
|
||||
constructor(source: any = {}) {
|
||||
if ('string' === typeof source) source = JSON.parse(source);
|
||||
this.branch = source["branch"];
|
||||
this.message = source["message"];
|
||||
}
|
||||
}
|
||||
export class Contributor {
|
||||
name: string;
|
||||
email: string;
|
||||
commits: number;
|
||||
added: number;
|
||||
deleted: number;
|
||||
|
||||
static createFrom(source: any = {}) {
|
||||
return new Contributor(source);
|
||||
}
|
||||
|
||||
constructor(source: any = {}) {
|
||||
if ('string' === typeof source) source = JSON.parse(source);
|
||||
this.name = source["name"];
|
||||
this.email = source["email"];
|
||||
this.commits = source["commits"];
|
||||
this.added = source["added"];
|
||||
this.deleted = source["deleted"];
|
||||
}
|
||||
}
|
||||
export class Dashboard {
|
||||
projects: number;
|
||||
totalLines: number;
|
||||
commits: number;
|
||||
|
||||
static createFrom(source: any = {}) {
|
||||
return new Dashboard(source);
|
||||
}
|
||||
|
||||
constructor(source: any = {}) {
|
||||
if ('string' === typeof source) source = JSON.parse(source);
|
||||
this.projects = source["projects"];
|
||||
this.totalLines = source["totalLines"];
|
||||
this.commits = source["commits"];
|
||||
}
|
||||
}
|
||||
export class ExclusionRule {
|
||||
id: number;
|
||||
pattern: string;
|
||||
category: string;
|
||||
builtin: boolean;
|
||||
|
||||
static createFrom(source: any = {}) {
|
||||
return new ExclusionRule(source);
|
||||
}
|
||||
|
||||
constructor(source: any = {}) {
|
||||
if ('string' === typeof source) source = JSON.parse(source);
|
||||
this.id = source["id"];
|
||||
this.pattern = source["pattern"];
|
||||
this.category = source["category"];
|
||||
this.builtin = source["builtin"];
|
||||
}
|
||||
}
|
||||
export class ExtensionStat {
|
||||
extension: string;
|
||||
files: number;
|
||||
size: number;
|
||||
|
||||
static createFrom(source: any = {}) {
|
||||
return new ExtensionStat(source);
|
||||
}
|
||||
|
||||
constructor(source: any = {}) {
|
||||
if ('string' === typeof source) source = JSON.parse(source);
|
||||
this.extension = source["extension"];
|
||||
this.files = source["files"];
|
||||
this.size = source["size"];
|
||||
}
|
||||
}
|
||||
export class FileEntry {
|
||||
path: string;
|
||||
name: string;
|
||||
extension: string;
|
||||
size: number;
|
||||
isDir: boolean;
|
||||
parent: string;
|
||||
|
||||
static createFrom(source: any = {}) {
|
||||
return new FileEntry(source);
|
||||
}
|
||||
|
||||
constructor(source: any = {}) {
|
||||
if ('string' === typeof source) source = JSON.parse(source);
|
||||
this.path = source["path"];
|
||||
this.name = source["name"];
|
||||
this.extension = source["extension"];
|
||||
this.size = source["size"];
|
||||
this.isDir = source["isDir"];
|
||||
this.parent = source["parent"];
|
||||
}
|
||||
}
|
||||
export class FolderStat {
|
||||
name: string;
|
||||
files: number;
|
||||
size: number;
|
||||
|
||||
static createFrom(source: any = {}) {
|
||||
return new FolderStat(source);
|
||||
}
|
||||
|
||||
constructor(source: any = {}) {
|
||||
if ('string' === typeof source) source = JSON.parse(source);
|
||||
this.name = source["name"];
|
||||
this.files = source["files"];
|
||||
this.size = source["size"];
|
||||
}
|
||||
}
|
||||
export class GitCommit {
|
||||
hash: string;
|
||||
author: string;
|
||||
email: string;
|
||||
message: string;
|
||||
date: string;
|
||||
added: number;
|
||||
deleted: number;
|
||||
|
||||
static createFrom(source: any = {}) {
|
||||
return new GitCommit(source);
|
||||
}
|
||||
|
||||
constructor(source: any = {}) {
|
||||
if ('string' === typeof source) source = JSON.parse(source);
|
||||
this.hash = source["hash"];
|
||||
this.author = source["author"];
|
||||
this.email = source["email"];
|
||||
this.message = source["message"];
|
||||
this.date = source["date"];
|
||||
this.added = source["added"];
|
||||
this.deleted = source["deleted"];
|
||||
}
|
||||
}
|
||||
export class GitFileChange {
|
||||
path: string;
|
||||
status: string;
|
||||
added: number;
|
||||
deleted: number;
|
||||
|
||||
static createFrom(source: any = {}) {
|
||||
return new GitFileChange(source);
|
||||
}
|
||||
|
||||
constructor(source: any = {}) {
|
||||
if ('string' === typeof source) source = JSON.parse(source);
|
||||
this.path = source["path"];
|
||||
this.status = source["status"];
|
||||
this.added = source["added"];
|
||||
this.deleted = source["deleted"];
|
||||
}
|
||||
}
|
||||
export class GitCommitDetail {
|
||||
hash: string;
|
||||
author: string;
|
||||
email: string;
|
||||
message: string;
|
||||
date: string;
|
||||
added: number;
|
||||
deleted: number;
|
||||
files: GitFileChange[];
|
||||
|
||||
static createFrom(source: any = {}) {
|
||||
return new GitCommitDetail(source);
|
||||
}
|
||||
|
||||
constructor(source: any = {}) {
|
||||
if ('string' === typeof source) source = JSON.parse(source);
|
||||
this.hash = source["hash"];
|
||||
this.author = source["author"];
|
||||
this.email = source["email"];
|
||||
this.message = source["message"];
|
||||
this.date = source["date"];
|
||||
this.added = source["added"];
|
||||
this.deleted = source["deleted"];
|
||||
this.files = this.convertValues(source["files"], GitFileChange);
|
||||
}
|
||||
|
||||
convertValues(a: any, classs: any, asMap: boolean = false): any {
|
||||
if (!a) {
|
||||
return a;
|
||||
}
|
||||
if (a.slice && a.map) {
|
||||
return (a as any[]).map(elem => this.convertValues(elem, classs));
|
||||
} else if ("object" === typeof a) {
|
||||
if (asMap) {
|
||||
for (const key of Object.keys(a)) {
|
||||
a[key] = new classs(a[key]);
|
||||
}
|
||||
return a;
|
||||
}
|
||||
return new classs(a);
|
||||
}
|
||||
return a;
|
||||
}
|
||||
}
|
||||
export class GitDiagnostics {
|
||||
available: boolean;
|
||||
errorCode?: string;
|
||||
detail?: string;
|
||||
isWsl: boolean;
|
||||
distro?: string;
|
||||
linuxPath?: string;
|
||||
workspaceBranch?: string;
|
||||
viewRef?: string;
|
||||
refCount: number;
|
||||
|
||||
static createFrom(source: any = {}) {
|
||||
return new GitDiagnostics(source);
|
||||
}
|
||||
|
||||
constructor(source: any = {}) {
|
||||
if ('string' === typeof source) source = JSON.parse(source);
|
||||
this.available = source["available"];
|
||||
this.errorCode = source["errorCode"];
|
||||
this.detail = source["detail"];
|
||||
this.isWsl = source["isWsl"];
|
||||
this.distro = source["distro"];
|
||||
this.linuxPath = source["linuxPath"];
|
||||
this.workspaceBranch = source["workspaceBranch"];
|
||||
this.viewRef = source["viewRef"];
|
||||
this.refCount = source["refCount"];
|
||||
}
|
||||
}
|
||||
|
||||
export class GitRef {
|
||||
name: string;
|
||||
hash: string;
|
||||
kind: string;
|
||||
current: boolean;
|
||||
|
||||
static createFrom(source: any = {}) {
|
||||
return new GitRef(source);
|
||||
}
|
||||
|
||||
constructor(source: any = {}) {
|
||||
if ('string' === typeof source) source = JSON.parse(source);
|
||||
this.name = source["name"];
|
||||
this.hash = source["hash"];
|
||||
this.kind = source["kind"];
|
||||
this.current = source["current"];
|
||||
}
|
||||
}
|
||||
export class HeatDay {
|
||||
date: string;
|
||||
count: number;
|
||||
|
||||
static createFrom(source: any = {}) {
|
||||
return new HeatDay(source);
|
||||
}
|
||||
|
||||
constructor(source: any = {}) {
|
||||
if ('string' === typeof source) source = JSON.parse(source);
|
||||
this.date = source["date"];
|
||||
this.count = source["count"];
|
||||
}
|
||||
}
|
||||
export class GitStats {
|
||||
available: boolean;
|
||||
error?: string;
|
||||
currentBranch: string;
|
||||
workspaceBranch: string;
|
||||
viewRef: string;
|
||||
commitCount: number;
|
||||
added: number;
|
||||
deleted: number;
|
||||
contributorCount: number;
|
||||
commits: GitCommit[];
|
||||
refs: GitRef[];
|
||||
contributors: Contributor[];
|
||||
heatmap: HeatDay[];
|
||||
|
||||
static createFrom(source: any = {}) {
|
||||
return new GitStats(source);
|
||||
}
|
||||
|
||||
constructor(source: any = {}) {
|
||||
if ('string' === typeof source) source = JSON.parse(source);
|
||||
this.available = source["available"];
|
||||
this.error = source["error"];
|
||||
this.currentBranch = source["currentBranch"];
|
||||
this.workspaceBranch = source["workspaceBranch"];
|
||||
this.viewRef = source["viewRef"];
|
||||
this.commitCount = source["commitCount"];
|
||||
this.added = source["added"];
|
||||
this.deleted = source["deleted"];
|
||||
this.contributorCount = source["contributorCount"];
|
||||
this.commits = this.convertValues(source["commits"], GitCommit);
|
||||
this.refs = this.convertValues(source["refs"], GitRef);
|
||||
this.contributors = this.convertValues(source["contributors"], Contributor);
|
||||
this.heatmap = this.convertValues(source["heatmap"], HeatDay);
|
||||
}
|
||||
|
||||
convertValues(a: any, classs: any, asMap: boolean = false): any {
|
||||
if (!a) {
|
||||
return a;
|
||||
}
|
||||
if (a.slice && a.map) {
|
||||
return (a as any[]).map(elem => this.convertValues(elem, classs));
|
||||
} else if ("object" === typeof a) {
|
||||
if (asMap) {
|
||||
for (const key of Object.keys(a)) {
|
||||
a[key] = new classs(a[key]);
|
||||
}
|
||||
return a;
|
||||
}
|
||||
return new classs(a);
|
||||
}
|
||||
return a;
|
||||
}
|
||||
}
|
||||
|
||||
export class InsightIssue {
|
||||
severity: string;
|
||||
type: string;
|
||||
title: string;
|
||||
detail: string;
|
||||
path?: string;
|
||||
line?: number;
|
||||
suggestion: string;
|
||||
evidence?: string;
|
||||
|
||||
static createFrom(source: any = {}) {
|
||||
return new InsightIssue(source);
|
||||
}
|
||||
|
||||
constructor(source: any = {}) {
|
||||
if ('string' === typeof source) source = JSON.parse(source);
|
||||
this.severity = source["severity"];
|
||||
this.type = source["type"];
|
||||
this.title = source["title"];
|
||||
this.detail = source["detail"];
|
||||
this.path = source["path"];
|
||||
this.line = source["line"];
|
||||
this.suggestion = source["suggestion"];
|
||||
this.evidence = source["evidence"];
|
||||
}
|
||||
}
|
||||
export class InsightSummary {
|
||||
high: number;
|
||||
medium: number;
|
||||
low: number;
|
||||
todoCount: number;
|
||||
longFiles: number;
|
||||
largeFiles: number;
|
||||
|
||||
static createFrom(source: any = {}) {
|
||||
return new InsightSummary(source);
|
||||
}
|
||||
|
||||
constructor(source: any = {}) {
|
||||
if ('string' === typeof source) source = JSON.parse(source);
|
||||
this.high = source["high"];
|
||||
this.medium = source["medium"];
|
||||
this.low = source["low"];
|
||||
this.todoCount = source["todoCount"];
|
||||
this.longFiles = source["longFiles"];
|
||||
this.largeFiles = source["largeFiles"];
|
||||
}
|
||||
}
|
||||
export class LanguageStat {
|
||||
name: string;
|
||||
files: number;
|
||||
code: number;
|
||||
comments: number;
|
||||
blanks: number;
|
||||
|
||||
static createFrom(source: any = {}) {
|
||||
return new LanguageStat(source);
|
||||
}
|
||||
|
||||
constructor(source: any = {}) {
|
||||
if ('string' === typeof source) source = JSON.parse(source);
|
||||
this.name = source["name"];
|
||||
this.files = source["files"];
|
||||
this.code = source["code"];
|
||||
this.comments = source["comments"];
|
||||
this.blanks = source["blanks"];
|
||||
}
|
||||
}
|
||||
export class LogEntry {
|
||||
id: number;
|
||||
level: string;
|
||||
category: string;
|
||||
message: string;
|
||||
detail: string;
|
||||
createdAt: string;
|
||||
|
||||
static createFrom(source: any = {}) {
|
||||
return new LogEntry(source);
|
||||
}
|
||||
|
||||
constructor(source: any = {}) {
|
||||
if ('string' === typeof source) source = JSON.parse(source);
|
||||
this.id = source["id"];
|
||||
this.level = source["level"];
|
||||
this.category = source["category"];
|
||||
this.message = source["message"];
|
||||
this.detail = source["detail"];
|
||||
this.createdAt = source["createdAt"];
|
||||
}
|
||||
}
|
||||
export class ProjectStats {
|
||||
totalLines: number;
|
||||
codeLines: number;
|
||||
commentLines: number;
|
||||
blankLines: number;
|
||||
fileCount: number;
|
||||
commitCount: number;
|
||||
addedLines: number;
|
||||
deletedLines: number;
|
||||
contributorCount: number;
|
||||
lastAnalyzed: string;
|
||||
|
||||
static createFrom(source: any = {}) {
|
||||
return new ProjectStats(source);
|
||||
}
|
||||
|
||||
constructor(source: any = {}) {
|
||||
if ('string' === typeof source) source = JSON.parse(source);
|
||||
this.totalLines = source["totalLines"];
|
||||
this.codeLines = source["codeLines"];
|
||||
this.commentLines = source["commentLines"];
|
||||
this.blankLines = source["blankLines"];
|
||||
this.fileCount = source["fileCount"];
|
||||
this.commitCount = source["commitCount"];
|
||||
this.addedLines = source["addedLines"];
|
||||
this.deletedLines = source["deletedLines"];
|
||||
this.contributorCount = source["contributorCount"];
|
||||
this.lastAnalyzed = source["lastAnalyzed"];
|
||||
}
|
||||
}
|
||||
export class Project {
|
||||
id: number;
|
||||
name: string;
|
||||
path: string;
|
||||
description: string;
|
||||
groupId: number;
|
||||
groupName: string;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
stats: ProjectStats;
|
||||
languages: LanguageStat[];
|
||||
|
||||
static createFrom(source: any = {}) {
|
||||
return new Project(source);
|
||||
}
|
||||
|
||||
constructor(source: any = {}) {
|
||||
if ('string' === typeof source) source = JSON.parse(source);
|
||||
this.id = source["id"];
|
||||
this.name = source["name"];
|
||||
this.path = source["path"];
|
||||
this.description = source["description"];
|
||||
this.groupId = source["groupId"];
|
||||
this.groupName = source["groupName"];
|
||||
this.createdAt = source["createdAt"];
|
||||
this.updatedAt = source["updatedAt"];
|
||||
this.stats = this.convertValues(source["stats"], ProjectStats);
|
||||
this.languages = this.convertValues(source["languages"], LanguageStat);
|
||||
}
|
||||
|
||||
convertValues(a: any, classs: any, asMap: boolean = false): any {
|
||||
if (!a) {
|
||||
return a;
|
||||
}
|
||||
if (a.slice && a.map) {
|
||||
return (a as any[]).map(elem => this.convertValues(elem, classs));
|
||||
} else if ("object" === typeof a) {
|
||||
if (asMap) {
|
||||
for (const key of Object.keys(a)) {
|
||||
a[key] = new classs(a[key]);
|
||||
}
|
||||
return a;
|
||||
}
|
||||
return new classs(a);
|
||||
}
|
||||
return a;
|
||||
}
|
||||
}
|
||||
export class ProjectGroup {
|
||||
id: number;
|
||||
name: string;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
|
||||
static createFrom(source: any = {}) {
|
||||
return new ProjectGroup(source);
|
||||
}
|
||||
|
||||
constructor(source: any = {}) {
|
||||
if ('string' === typeof source) source = JSON.parse(source);
|
||||
this.id = source["id"];
|
||||
this.name = source["name"];
|
||||
this.createdAt = source["createdAt"];
|
||||
this.updatedAt = source["updatedAt"];
|
||||
}
|
||||
}
|
||||
export class ProjectInput {
|
||||
name: string;
|
||||
path: string;
|
||||
description: string;
|
||||
groupId: number;
|
||||
|
||||
static createFrom(source: any = {}) {
|
||||
return new ProjectInput(source);
|
||||
}
|
||||
|
||||
constructor(source: any = {}) {
|
||||
if ('string' === typeof source) source = JSON.parse(source);
|
||||
this.name = source["name"];
|
||||
this.path = source["path"];
|
||||
this.description = source["description"];
|
||||
this.groupId = source["groupId"];
|
||||
}
|
||||
}
|
||||
export class ProjectInsights {
|
||||
projectId: number;
|
||||
healthScore: number;
|
||||
generatedAt: string;
|
||||
summary: InsightSummary;
|
||||
issues: InsightIssue[];
|
||||
|
||||
static createFrom(source: any = {}) {
|
||||
return new ProjectInsights(source);
|
||||
}
|
||||
|
||||
constructor(source: any = {}) {
|
||||
if ('string' === typeof source) source = JSON.parse(source);
|
||||
this.projectId = source["projectId"];
|
||||
this.healthScore = source["healthScore"];
|
||||
this.generatedAt = source["generatedAt"];
|
||||
this.summary = this.convertValues(source["summary"], InsightSummary);
|
||||
this.issues = this.convertValues(source["issues"], InsightIssue);
|
||||
}
|
||||
|
||||
convertValues(a: any, classs: any, asMap: boolean = false): any {
|
||||
if (!a) {
|
||||
return a;
|
||||
}
|
||||
if (a.slice && a.map) {
|
||||
return (a as any[]).map(elem => this.convertValues(elem, classs));
|
||||
} else if ("object" === typeof a) {
|
||||
if (asMap) {
|
||||
for (const key of Object.keys(a)) {
|
||||
a[key] = new classs(a[key]);
|
||||
}
|
||||
return a;
|
||||
}
|
||||
return new classs(a);
|
||||
}
|
||||
return a;
|
||||
}
|
||||
}
|
||||
|
||||
export class StructureStats {
|
||||
files: FileEntry[];
|
||||
totalFiles: number;
|
||||
totalDirs: number;
|
||||
totalSize: number;
|
||||
largeFiles: FileEntry[];
|
||||
folders: FolderStat[];
|
||||
extensions: ExtensionStat[];
|
||||
|
||||
static createFrom(source: any = {}) {
|
||||
return new StructureStats(source);
|
||||
}
|
||||
|
||||
constructor(source: any = {}) {
|
||||
if ('string' === typeof source) source = JSON.parse(source);
|
||||
this.files = this.convertValues(source["files"], FileEntry);
|
||||
this.totalFiles = source["totalFiles"];
|
||||
this.totalDirs = source["totalDirs"];
|
||||
this.totalSize = source["totalSize"];
|
||||
this.largeFiles = this.convertValues(source["largeFiles"], FileEntry);
|
||||
this.folders = this.convertValues(source["folders"], FolderStat);
|
||||
this.extensions = this.convertValues(source["extensions"], ExtensionStat);
|
||||
}
|
||||
|
||||
convertValues(a: any, classs: any, asMap: boolean = false): any {
|
||||
if (!a) {
|
||||
return a;
|
||||
}
|
||||
if (a.slice && a.map) {
|
||||
return (a as any[]).map(elem => this.convertValues(elem, classs));
|
||||
} else if ("object" === typeof a) {
|
||||
if (asMap) {
|
||||
for (const key of Object.keys(a)) {
|
||||
a[key] = new classs(a[key]);
|
||||
}
|
||||
return a;
|
||||
}
|
||||
return new classs(a);
|
||||
}
|
||||
return a;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
24
frontend/wailsjs/runtime/package.json
Normal file
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"name": "@wailsapp/runtime",
|
||||
"version": "2.0.0",
|
||||
"description": "Wails Javascript runtime library",
|
||||
"main": "runtime.js",
|
||||
"types": "runtime.d.ts",
|
||||
"scripts": {
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/wailsapp/wails.git"
|
||||
},
|
||||
"keywords": [
|
||||
"Wails",
|
||||
"Javascript",
|
||||
"Go"
|
||||
],
|
||||
"author": "Lea Anthony <lea.anthony@gmail.com>",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/wailsapp/wails/issues"
|
||||
},
|
||||
"homepage": "https://github.com/wailsapp/wails#readme"
|
||||
}
|
||||
330
frontend/wailsjs/runtime/runtime.d.ts
vendored
Normal file
@@ -0,0 +1,330 @@
|
||||
/*
|
||||
_ __ _ __
|
||||
| | / /___ _(_) /____
|
||||
| | /| / / __ `/ / / ___/
|
||||
| |/ |/ / /_/ / / (__ )
|
||||
|__/|__/\__,_/_/_/____/
|
||||
The electron alternative for Go
|
||||
(c) Lea Anthony 2019-present
|
||||
*/
|
||||
|
||||
export interface Position {
|
||||
x: number;
|
||||
y: number;
|
||||
}
|
||||
|
||||
export interface Size {
|
||||
w: number;
|
||||
h: number;
|
||||
}
|
||||
|
||||
export interface Screen {
|
||||
isCurrent: boolean;
|
||||
isPrimary: boolean;
|
||||
width : number
|
||||
height : number
|
||||
}
|
||||
|
||||
// Environment information such as platform, buildtype, ...
|
||||
export interface EnvironmentInfo {
|
||||
buildType: string;
|
||||
platform: string;
|
||||
arch: string;
|
||||
}
|
||||
|
||||
// [EventsEmit](https://wails.io/docs/reference/runtime/events#eventsemit)
|
||||
// emits the given event. Optional data may be passed with the event.
|
||||
// This will trigger any event listeners.
|
||||
export function EventsEmit(eventName: string, ...data: any): void;
|
||||
|
||||
// [EventsOn](https://wails.io/docs/reference/runtime/events#eventson) sets up a listener for the given event name.
|
||||
export function EventsOn(eventName: string, callback: (...data: any) => void): () => void;
|
||||
|
||||
// [EventsOnMultiple](https://wails.io/docs/reference/runtime/events#eventsonmultiple)
|
||||
// sets up a listener for the given event name, but will only trigger a given number times.
|
||||
export function EventsOnMultiple(eventName: string, callback: (...data: any) => void, maxCallbacks: number): () => void;
|
||||
|
||||
// [EventsOnce](https://wails.io/docs/reference/runtime/events#eventsonce)
|
||||
// sets up a listener for the given event name, but will only trigger once.
|
||||
export function EventsOnce(eventName: string, callback: (...data: any) => void): () => void;
|
||||
|
||||
// [EventsOff](https://wails.io/docs/reference/runtime/events#eventsoff)
|
||||
// unregisters the listener for the given event name.
|
||||
export function EventsOff(eventName: string, ...additionalEventNames: string[]): void;
|
||||
|
||||
// [EventsOffAll](https://wails.io/docs/reference/runtime/events#eventsoffall)
|
||||
// unregisters all listeners.
|
||||
export function EventsOffAll(): void;
|
||||
|
||||
// [LogPrint](https://wails.io/docs/reference/runtime/log#logprint)
|
||||
// logs the given message as a raw message
|
||||
export function LogPrint(message: string): void;
|
||||
|
||||
// [LogTrace](https://wails.io/docs/reference/runtime/log#logtrace)
|
||||
// logs the given message at the `trace` log level.
|
||||
export function LogTrace(message: string): void;
|
||||
|
||||
// [LogDebug](https://wails.io/docs/reference/runtime/log#logdebug)
|
||||
// logs the given message at the `debug` log level.
|
||||
export function LogDebug(message: string): void;
|
||||
|
||||
// [LogError](https://wails.io/docs/reference/runtime/log#logerror)
|
||||
// logs the given message at the `error` log level.
|
||||
export function LogError(message: string): void;
|
||||
|
||||
// [LogFatal](https://wails.io/docs/reference/runtime/log#logfatal)
|
||||
// logs the given message at the `fatal` log level.
|
||||
// The application will quit after calling this method.
|
||||
export function LogFatal(message: string): void;
|
||||
|
||||
// [LogInfo](https://wails.io/docs/reference/runtime/log#loginfo)
|
||||
// logs the given message at the `info` log level.
|
||||
export function LogInfo(message: string): void;
|
||||
|
||||
// [LogWarning](https://wails.io/docs/reference/runtime/log#logwarning)
|
||||
// logs the given message at the `warning` log level.
|
||||
export function LogWarning(message: string): void;
|
||||
|
||||
// [WindowReload](https://wails.io/docs/reference/runtime/window#windowreload)
|
||||
// Forces a reload by the main application as well as connected browsers.
|
||||
export function WindowReload(): void;
|
||||
|
||||
// [WindowReloadApp](https://wails.io/docs/reference/runtime/window#windowreloadapp)
|
||||
// Reloads the application frontend.
|
||||
export function WindowReloadApp(): void;
|
||||
|
||||
// [WindowSetAlwaysOnTop](https://wails.io/docs/reference/runtime/window#windowsetalwaysontop)
|
||||
// Sets the window AlwaysOnTop or not on top.
|
||||
export function WindowSetAlwaysOnTop(b: boolean): void;
|
||||
|
||||
// [WindowSetSystemDefaultTheme](https://wails.io/docs/next/reference/runtime/window#windowsetsystemdefaulttheme)
|
||||
// *Windows only*
|
||||
// Sets window theme to system default (dark/light).
|
||||
export function WindowSetSystemDefaultTheme(): void;
|
||||
|
||||
// [WindowSetLightTheme](https://wails.io/docs/next/reference/runtime/window#windowsetlighttheme)
|
||||
// *Windows only*
|
||||
// Sets window to light theme.
|
||||
export function WindowSetLightTheme(): void;
|
||||
|
||||
// [WindowSetDarkTheme](https://wails.io/docs/next/reference/runtime/window#windowsetdarktheme)
|
||||
// *Windows only*
|
||||
// Sets window to dark theme.
|
||||
export function WindowSetDarkTheme(): void;
|
||||
|
||||
// [WindowCenter](https://wails.io/docs/reference/runtime/window#windowcenter)
|
||||
// Centers the window on the monitor the window is currently on.
|
||||
export function WindowCenter(): void;
|
||||
|
||||
// [WindowSetTitle](https://wails.io/docs/reference/runtime/window#windowsettitle)
|
||||
// Sets the text in the window title bar.
|
||||
export function WindowSetTitle(title: string): void;
|
||||
|
||||
// [WindowFullscreen](https://wails.io/docs/reference/runtime/window#windowfullscreen)
|
||||
// Makes the window full screen.
|
||||
export function WindowFullscreen(): void;
|
||||
|
||||
// [WindowUnfullscreen](https://wails.io/docs/reference/runtime/window#windowunfullscreen)
|
||||
// Restores the previous window dimensions and position prior to full screen.
|
||||
export function WindowUnfullscreen(): void;
|
||||
|
||||
// [WindowIsFullscreen](https://wails.io/docs/reference/runtime/window#windowisfullscreen)
|
||||
// Returns the state of the window, i.e. whether the window is in full screen mode or not.
|
||||
export function WindowIsFullscreen(): Promise<boolean>;
|
||||
|
||||
// [WindowSetSize](https://wails.io/docs/reference/runtime/window#windowsetsize)
|
||||
// Sets the width and height of the window.
|
||||
export function WindowSetSize(width: number, height: number): void;
|
||||
|
||||
// [WindowGetSize](https://wails.io/docs/reference/runtime/window#windowgetsize)
|
||||
// Gets the width and height of the window.
|
||||
export function WindowGetSize(): Promise<Size>;
|
||||
|
||||
// [WindowSetMaxSize](https://wails.io/docs/reference/runtime/window#windowsetmaxsize)
|
||||
// Sets the maximum window size. Will resize the window if the window is currently larger than the given dimensions.
|
||||
// Setting a size of 0,0 will disable this constraint.
|
||||
export function WindowSetMaxSize(width: number, height: number): void;
|
||||
|
||||
// [WindowSetMinSize](https://wails.io/docs/reference/runtime/window#windowsetminsize)
|
||||
// Sets the minimum window size. Will resize the window if the window is currently smaller than the given dimensions.
|
||||
// Setting a size of 0,0 will disable this constraint.
|
||||
export function WindowSetMinSize(width: number, height: number): void;
|
||||
|
||||
// [WindowSetPosition](https://wails.io/docs/reference/runtime/window#windowsetposition)
|
||||
// Sets the window position relative to the monitor the window is currently on.
|
||||
export function WindowSetPosition(x: number, y: number): void;
|
||||
|
||||
// [WindowGetPosition](https://wails.io/docs/reference/runtime/window#windowgetposition)
|
||||
// Gets the window position relative to the monitor the window is currently on.
|
||||
export function WindowGetPosition(): Promise<Position>;
|
||||
|
||||
// [WindowHide](https://wails.io/docs/reference/runtime/window#windowhide)
|
||||
// Hides the window.
|
||||
export function WindowHide(): void;
|
||||
|
||||
// [WindowShow](https://wails.io/docs/reference/runtime/window#windowshow)
|
||||
// Shows the window, if it is currently hidden.
|
||||
export function WindowShow(): void;
|
||||
|
||||
// [WindowMaximise](https://wails.io/docs/reference/runtime/window#windowmaximise)
|
||||
// Maximises the window to fill the screen.
|
||||
export function WindowMaximise(): void;
|
||||
|
||||
// [WindowToggleMaximise](https://wails.io/docs/reference/runtime/window#windowtogglemaximise)
|
||||
// Toggles between Maximised and UnMaximised.
|
||||
export function WindowToggleMaximise(): void;
|
||||
|
||||
// [WindowUnmaximise](https://wails.io/docs/reference/runtime/window#windowunmaximise)
|
||||
// Restores the window to the dimensions and position prior to maximising.
|
||||
export function WindowUnmaximise(): void;
|
||||
|
||||
// [WindowIsMaximised](https://wails.io/docs/reference/runtime/window#windowismaximised)
|
||||
// Returns the state of the window, i.e. whether the window is maximised or not.
|
||||
export function WindowIsMaximised(): Promise<boolean>;
|
||||
|
||||
// [WindowMinimise](https://wails.io/docs/reference/runtime/window#windowminimise)
|
||||
// Minimises the window.
|
||||
export function WindowMinimise(): void;
|
||||
|
||||
// [WindowUnminimise](https://wails.io/docs/reference/runtime/window#windowunminimise)
|
||||
// Restores the window to the dimensions and position prior to minimising.
|
||||
export function WindowUnminimise(): void;
|
||||
|
||||
// [WindowIsMinimised](https://wails.io/docs/reference/runtime/window#windowisminimised)
|
||||
// Returns the state of the window, i.e. whether the window is minimised or not.
|
||||
export function WindowIsMinimised(): Promise<boolean>;
|
||||
|
||||
// [WindowIsNormal](https://wails.io/docs/reference/runtime/window#windowisnormal)
|
||||
// Returns the state of the window, i.e. whether the window is normal or not.
|
||||
export function WindowIsNormal(): Promise<boolean>;
|
||||
|
||||
// [WindowSetBackgroundColour](https://wails.io/docs/reference/runtime/window#windowsetbackgroundcolour)
|
||||
// Sets the background colour of the window to the given RGBA colour definition. This colour will show through for all transparent pixels.
|
||||
export function WindowSetBackgroundColour(R: number, G: number, B: number, A: number): void;
|
||||
|
||||
// [ScreenGetAll](https://wails.io/docs/reference/runtime/window#screengetall)
|
||||
// Gets the all screens. Call this anew each time you want to refresh data from the underlying windowing system.
|
||||
export function ScreenGetAll(): Promise<Screen[]>;
|
||||
|
||||
// [BrowserOpenURL](https://wails.io/docs/reference/runtime/browser#browseropenurl)
|
||||
// Opens the given URL in the system browser.
|
||||
export function BrowserOpenURL(url: string): void;
|
||||
|
||||
// [Environment](https://wails.io/docs/reference/runtime/intro#environment)
|
||||
// Returns information about the environment
|
||||
export function Environment(): Promise<EnvironmentInfo>;
|
||||
|
||||
// [Quit](https://wails.io/docs/reference/runtime/intro#quit)
|
||||
// Quits the application.
|
||||
export function Quit(): void;
|
||||
|
||||
// [Hide](https://wails.io/docs/reference/runtime/intro#hide)
|
||||
// Hides the application.
|
||||
export function Hide(): void;
|
||||
|
||||
// [Show](https://wails.io/docs/reference/runtime/intro#show)
|
||||
// Shows the application.
|
||||
export function Show(): void;
|
||||
|
||||
// [ClipboardGetText](https://wails.io/docs/reference/runtime/clipboard#clipboardgettext)
|
||||
// Returns the current text stored on clipboard
|
||||
export function ClipboardGetText(): Promise<string>;
|
||||
|
||||
// [ClipboardSetText](https://wails.io/docs/reference/runtime/clipboard#clipboardsettext)
|
||||
// Sets a text on the clipboard
|
||||
export function ClipboardSetText(text: string): Promise<boolean>;
|
||||
|
||||
// [OnFileDrop](https://wails.io/docs/reference/runtime/draganddrop#onfiledrop)
|
||||
// OnFileDrop listens to drag and drop events and calls the callback with the coordinates of the drop and an array of path strings.
|
||||
export function OnFileDrop(callback: (x: number, y: number ,paths: string[]) => void, useDropTarget: boolean) :void
|
||||
|
||||
// [OnFileDropOff](https://wails.io/docs/reference/runtime/draganddrop#dragandddropoff)
|
||||
// OnFileDropOff removes the drag and drop listeners and handlers.
|
||||
export function OnFileDropOff() :void
|
||||
|
||||
// Check if the file path resolver is available
|
||||
export function CanResolveFilePaths(): boolean;
|
||||
|
||||
// Resolves file paths for an array of files
|
||||
export function ResolveFilePaths(files: File[]): void
|
||||
|
||||
// Notification types
|
||||
export interface NotificationOptions {
|
||||
id: string;
|
||||
title: string;
|
||||
subtitle?: string; // macOS and Linux only
|
||||
body?: string;
|
||||
categoryId?: string;
|
||||
data?: { [key: string]: any };
|
||||
}
|
||||
|
||||
export interface NotificationAction {
|
||||
id?: string;
|
||||
title?: string;
|
||||
destructive?: boolean; // macOS-specific
|
||||
}
|
||||
|
||||
export interface NotificationCategory {
|
||||
id?: string;
|
||||
actions?: NotificationAction[];
|
||||
hasReplyField?: boolean;
|
||||
replyPlaceholder?: string;
|
||||
replyButtonTitle?: string;
|
||||
}
|
||||
|
||||
// [InitializeNotifications](https://wails.io/docs/reference/runtime/notification#initializenotifications)
|
||||
// Initializes the notification service for the application.
|
||||
// This must be called before sending any notifications.
|
||||
export function InitializeNotifications(): Promise<void>;
|
||||
|
||||
// [CleanupNotifications](https://wails.io/docs/reference/runtime/notification#cleanupnotifications)
|
||||
// Cleans up notification resources and releases any held connections.
|
||||
export function CleanupNotifications(): Promise<void>;
|
||||
|
||||
// [IsNotificationAvailable](https://wails.io/docs/reference/runtime/notification#isnotificationavailable)
|
||||
// Checks if notifications are available on the current platform.
|
||||
export function IsNotificationAvailable(): Promise<boolean>;
|
||||
|
||||
// [RequestNotificationAuthorization](https://wails.io/docs/reference/runtime/notification#requestnotificationauthorization)
|
||||
// Requests notification authorization from the user (macOS only).
|
||||
export function RequestNotificationAuthorization(): Promise<boolean>;
|
||||
|
||||
// [CheckNotificationAuthorization](https://wails.io/docs/reference/runtime/notification#checknotificationauthorization)
|
||||
// Checks the current notification authorization status (macOS only).
|
||||
export function CheckNotificationAuthorization(): Promise<boolean>;
|
||||
|
||||
// [SendNotification](https://wails.io/docs/reference/runtime/notification#sendnotification)
|
||||
// Sends a basic notification with the given options.
|
||||
export function SendNotification(options: NotificationOptions): Promise<void>;
|
||||
|
||||
// [SendNotificationWithActions](https://wails.io/docs/reference/runtime/notification#sendnotificationwithactions)
|
||||
// Sends a notification with action buttons. Requires a registered category.
|
||||
export function SendNotificationWithActions(options: NotificationOptions): Promise<void>;
|
||||
|
||||
// [RegisterNotificationCategory](https://wails.io/docs/reference/runtime/notification#registernotificationcategory)
|
||||
// Registers a notification category that can be used with SendNotificationWithActions.
|
||||
export function RegisterNotificationCategory(category: NotificationCategory): Promise<void>;
|
||||
|
||||
// [RemoveNotificationCategory](https://wails.io/docs/reference/runtime/notification#removenotificationcategory)
|
||||
// Removes a previously registered notification category.
|
||||
export function RemoveNotificationCategory(categoryId: string): Promise<void>;
|
||||
|
||||
// [RemoveAllPendingNotifications](https://wails.io/docs/reference/runtime/notification#removeallpendingnotifications)
|
||||
// Removes all pending notifications from the notification center.
|
||||
export function RemoveAllPendingNotifications(): Promise<void>;
|
||||
|
||||
// [RemovePendingNotification](https://wails.io/docs/reference/runtime/notification#removependingnotification)
|
||||
// Removes a specific pending notification by its identifier.
|
||||
export function RemovePendingNotification(identifier: string): Promise<void>;
|
||||
|
||||
// [RemoveAllDeliveredNotifications](https://wails.io/docs/reference/runtime/notification#removealldeliverednotifications)
|
||||
// Removes all delivered notifications from the notification center.
|
||||
export function RemoveAllDeliveredNotifications(): Promise<void>;
|
||||
|
||||
// [RemoveDeliveredNotification](https://wails.io/docs/reference/runtime/notification#removedeliverednotification)
|
||||
// Removes a specific delivered notification by its identifier.
|
||||
export function RemoveDeliveredNotification(identifier: string): Promise<void>;
|
||||
|
||||
// [RemoveNotification](https://wails.io/docs/reference/runtime/notification#removenotification)
|
||||
// Removes a notification by its identifier (cross-platform convenience function).
|
||||
export function RemoveNotification(identifier: string): Promise<void>;
|
||||
298
frontend/wailsjs/runtime/runtime.js
Normal file
@@ -0,0 +1,298 @@
|
||||
/*
|
||||
_ __ _ __
|
||||
| | / /___ _(_) /____
|
||||
| | /| / / __ `/ / / ___/
|
||||
| |/ |/ / /_/ / / (__ )
|
||||
|__/|__/\__,_/_/_/____/
|
||||
The electron alternative for Go
|
||||
(c) Lea Anthony 2019-present
|
||||
*/
|
||||
|
||||
export function LogPrint(message) {
|
||||
window.runtime.LogPrint(message);
|
||||
}
|
||||
|
||||
export function LogTrace(message) {
|
||||
window.runtime.LogTrace(message);
|
||||
}
|
||||
|
||||
export function LogDebug(message) {
|
||||
window.runtime.LogDebug(message);
|
||||
}
|
||||
|
||||
export function LogInfo(message) {
|
||||
window.runtime.LogInfo(message);
|
||||
}
|
||||
|
||||
export function LogWarning(message) {
|
||||
window.runtime.LogWarning(message);
|
||||
}
|
||||
|
||||
export function LogError(message) {
|
||||
window.runtime.LogError(message);
|
||||
}
|
||||
|
||||
export function LogFatal(message) {
|
||||
window.runtime.LogFatal(message);
|
||||
}
|
||||
|
||||
export function EventsOnMultiple(eventName, callback, maxCallbacks) {
|
||||
return window.runtime.EventsOnMultiple(eventName, callback, maxCallbacks);
|
||||
}
|
||||
|
||||
export function EventsOn(eventName, callback) {
|
||||
return EventsOnMultiple(eventName, callback, -1);
|
||||
}
|
||||
|
||||
export function EventsOff(eventName, ...additionalEventNames) {
|
||||
return window.runtime.EventsOff(eventName, ...additionalEventNames);
|
||||
}
|
||||
|
||||
export function EventsOffAll() {
|
||||
return window.runtime.EventsOffAll();
|
||||
}
|
||||
|
||||
export function EventsOnce(eventName, callback) {
|
||||
return EventsOnMultiple(eventName, callback, 1);
|
||||
}
|
||||
|
||||
export function EventsEmit(eventName) {
|
||||
let args = [eventName].slice.call(arguments);
|
||||
return window.runtime.EventsEmit.apply(null, args);
|
||||
}
|
||||
|
||||
export function WindowReload() {
|
||||
window.runtime.WindowReload();
|
||||
}
|
||||
|
||||
export function WindowReloadApp() {
|
||||
window.runtime.WindowReloadApp();
|
||||
}
|
||||
|
||||
export function WindowSetAlwaysOnTop(b) {
|
||||
window.runtime.WindowSetAlwaysOnTop(b);
|
||||
}
|
||||
|
||||
export function WindowSetSystemDefaultTheme() {
|
||||
window.runtime.WindowSetSystemDefaultTheme();
|
||||
}
|
||||
|
||||
export function WindowSetLightTheme() {
|
||||
window.runtime.WindowSetLightTheme();
|
||||
}
|
||||
|
||||
export function WindowSetDarkTheme() {
|
||||
window.runtime.WindowSetDarkTheme();
|
||||
}
|
||||
|
||||
export function WindowCenter() {
|
||||
window.runtime.WindowCenter();
|
||||
}
|
||||
|
||||
export function WindowSetTitle(title) {
|
||||
window.runtime.WindowSetTitle(title);
|
||||
}
|
||||
|
||||
export function WindowFullscreen() {
|
||||
window.runtime.WindowFullscreen();
|
||||
}
|
||||
|
||||
export function WindowUnfullscreen() {
|
||||
window.runtime.WindowUnfullscreen();
|
||||
}
|
||||
|
||||
export function WindowIsFullscreen() {
|
||||
return window.runtime.WindowIsFullscreen();
|
||||
}
|
||||
|
||||
export function WindowGetSize() {
|
||||
return window.runtime.WindowGetSize();
|
||||
}
|
||||
|
||||
export function WindowSetSize(width, height) {
|
||||
window.runtime.WindowSetSize(width, height);
|
||||
}
|
||||
|
||||
export function WindowSetMaxSize(width, height) {
|
||||
window.runtime.WindowSetMaxSize(width, height);
|
||||
}
|
||||
|
||||
export function WindowSetMinSize(width, height) {
|
||||
window.runtime.WindowSetMinSize(width, height);
|
||||
}
|
||||
|
||||
export function WindowSetPosition(x, y) {
|
||||
window.runtime.WindowSetPosition(x, y);
|
||||
}
|
||||
|
||||
export function WindowGetPosition() {
|
||||
return window.runtime.WindowGetPosition();
|
||||
}
|
||||
|
||||
export function WindowHide() {
|
||||
window.runtime.WindowHide();
|
||||
}
|
||||
|
||||
export function WindowShow() {
|
||||
window.runtime.WindowShow();
|
||||
}
|
||||
|
||||
export function WindowMaximise() {
|
||||
window.runtime.WindowMaximise();
|
||||
}
|
||||
|
||||
export function WindowToggleMaximise() {
|
||||
window.runtime.WindowToggleMaximise();
|
||||
}
|
||||
|
||||
export function WindowUnmaximise() {
|
||||
window.runtime.WindowUnmaximise();
|
||||
}
|
||||
|
||||
export function WindowIsMaximised() {
|
||||
return window.runtime.WindowIsMaximised();
|
||||
}
|
||||
|
||||
export function WindowMinimise() {
|
||||
window.runtime.WindowMinimise();
|
||||
}
|
||||
|
||||
export function WindowUnminimise() {
|
||||
window.runtime.WindowUnminimise();
|
||||
}
|
||||
|
||||
export function WindowSetBackgroundColour(R, G, B, A) {
|
||||
window.runtime.WindowSetBackgroundColour(R, G, B, A);
|
||||
}
|
||||
|
||||
export function ScreenGetAll() {
|
||||
return window.runtime.ScreenGetAll();
|
||||
}
|
||||
|
||||
export function WindowIsMinimised() {
|
||||
return window.runtime.WindowIsMinimised();
|
||||
}
|
||||
|
||||
export function WindowIsNormal() {
|
||||
return window.runtime.WindowIsNormal();
|
||||
}
|
||||
|
||||
export function BrowserOpenURL(url) {
|
||||
window.runtime.BrowserOpenURL(url);
|
||||
}
|
||||
|
||||
export function Environment() {
|
||||
return window.runtime.Environment();
|
||||
}
|
||||
|
||||
export function Quit() {
|
||||
window.runtime.Quit();
|
||||
}
|
||||
|
||||
export function Hide() {
|
||||
window.runtime.Hide();
|
||||
}
|
||||
|
||||
export function Show() {
|
||||
window.runtime.Show();
|
||||
}
|
||||
|
||||
export function ClipboardGetText() {
|
||||
return window.runtime.ClipboardGetText();
|
||||
}
|
||||
|
||||
export function ClipboardSetText(text) {
|
||||
return window.runtime.ClipboardSetText(text);
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for OnFileDrop returns a slice of file path strings when a drop is finished.
|
||||
*
|
||||
* @export
|
||||
* @callback OnFileDropCallback
|
||||
* @param {number} x - x coordinate of the drop
|
||||
* @param {number} y - y coordinate of the drop
|
||||
* @param {string[]} paths - A list of file paths.
|
||||
*/
|
||||
|
||||
/**
|
||||
* OnFileDrop listens to drag and drop events and calls the callback with the coordinates of the drop and an array of path strings.
|
||||
*
|
||||
* @export
|
||||
* @param {OnFileDropCallback} callback - Callback for OnFileDrop returns a slice of file path strings when a drop is finished.
|
||||
* @param {boolean} [useDropTarget=true] - Only call the callback when the drop finished on an element that has the drop target style. (--wails-drop-target)
|
||||
*/
|
||||
export function OnFileDrop(callback, useDropTarget) {
|
||||
return window.runtime.OnFileDrop(callback, useDropTarget);
|
||||
}
|
||||
|
||||
/**
|
||||
* OnFileDropOff removes the drag and drop listeners and handlers.
|
||||
*/
|
||||
export function OnFileDropOff() {
|
||||
return window.runtime.OnFileDropOff();
|
||||
}
|
||||
|
||||
export function CanResolveFilePaths() {
|
||||
return window.runtime.CanResolveFilePaths();
|
||||
}
|
||||
|
||||
export function ResolveFilePaths(files) {
|
||||
return window.runtime.ResolveFilePaths(files);
|
||||
}
|
||||
|
||||
export function InitializeNotifications() {
|
||||
return window.runtime.InitializeNotifications();
|
||||
}
|
||||
|
||||
export function CleanupNotifications() {
|
||||
return window.runtime.CleanupNotifications();
|
||||
}
|
||||
|
||||
export function IsNotificationAvailable() {
|
||||
return window.runtime.IsNotificationAvailable();
|
||||
}
|
||||
|
||||
export function RequestNotificationAuthorization() {
|
||||
return window.runtime.RequestNotificationAuthorization();
|
||||
}
|
||||
|
||||
export function CheckNotificationAuthorization() {
|
||||
return window.runtime.CheckNotificationAuthorization();
|
||||
}
|
||||
|
||||
export function SendNotification(options) {
|
||||
return window.runtime.SendNotification(options);
|
||||
}
|
||||
|
||||
export function SendNotificationWithActions(options) {
|
||||
return window.runtime.SendNotificationWithActions(options);
|
||||
}
|
||||
|
||||
export function RegisterNotificationCategory(category) {
|
||||
return window.runtime.RegisterNotificationCategory(category);
|
||||
}
|
||||
|
||||
export function RemoveNotificationCategory(categoryId) {
|
||||
return window.runtime.RemoveNotificationCategory(categoryId);
|
||||
}
|
||||
|
||||
export function RemoveAllPendingNotifications() {
|
||||
return window.runtime.RemoveAllPendingNotifications();
|
||||
}
|
||||
|
||||
export function RemovePendingNotification(identifier) {
|
||||
return window.runtime.RemovePendingNotification(identifier);
|
||||
}
|
||||
|
||||
export function RemoveAllDeliveredNotifications() {
|
||||
return window.runtime.RemoveAllDeliveredNotifications();
|
||||
}
|
||||
|
||||
export function RemoveDeliveredNotification(identifier) {
|
||||
return window.runtime.RemoveDeliveredNotification(identifier);
|
||||
}
|
||||
|
||||
export function RemoveNotification(identifier) {
|
||||
return window.runtime.RemoveNotification(identifier);
|
||||
}
|
||||
8
git.go
Normal file
@@ -0,0 +1,8 @@
|
||||
package main
|
||||
|
||||
import "view/service"
|
||||
|
||||
// GitAnalyzer 是 service.GitService 的兼容别名。
|
||||
type GitAnalyzer = service.GitService
|
||||
|
||||
func shortHash(s string) string { return service.ShortHash(s) }
|
||||
84
git_test.go
Normal file
@@ -0,0 +1,84 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestGitAnalyzer(t *testing.T) {
|
||||
if _, e := exec.LookPath("git"); e != nil {
|
||||
t.Skip("git unavailable")
|
||||
}
|
||||
d := t.TempDir()
|
||||
run := func(args ...string) {
|
||||
c := exec.Command("git", append([]string{"-C", d}, args...)...)
|
||||
c.Env = append(os.Environ(), "GIT_AUTHOR_NAME=Test User", "GIT_AUTHOR_EMAIL=test@example.com", "GIT_COMMITTER_NAME=Test User", "GIT_COMMITTER_EMAIL=test@example.com")
|
||||
if b, e := c.CombinedOutput(); e != nil {
|
||||
t.Fatalf("git %v: %v %s", args, e, b)
|
||||
}
|
||||
}
|
||||
run("init")
|
||||
if e := os.WriteFile(filepath.Join(d, "main.go"), []byte("package main\n"), 0644); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
run("add", ".")
|
||||
run("commit", "-m", "initial")
|
||||
g, e := (GitAnalyzer{}).Analyze(context.Background(), d)
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
if g.CommitCount != 1 || g.Added != 1 || g.ContributorCount != 1 {
|
||||
t.Fatalf("unexpected git stats: %#v", g)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGitRefDetailsAndSafeCheckout(t *testing.T) {
|
||||
if _, e := exec.LookPath("git"); e != nil {
|
||||
t.Skip("git unavailable")
|
||||
}
|
||||
d := t.TempDir()
|
||||
run := func(args ...string) {
|
||||
c := exec.Command("git", append([]string{"-C", d}, args...)...)
|
||||
c.Env = append(os.Environ(), "GIT_AUTHOR_NAME=Test User", "GIT_AUTHOR_EMAIL=test@example.com", "GIT_COMMITTER_NAME=Test User", "GIT_COMMITTER_EMAIL=test@example.com")
|
||||
if b, e := c.CombinedOutput(); e != nil {
|
||||
t.Fatalf("git %v: %v %s", args, e, b)
|
||||
}
|
||||
}
|
||||
run("init")
|
||||
if e := os.WriteFile(filepath.Join(d, "main.go"), []byte("package main\n"), 0644); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
run("add", ".")
|
||||
run("commit", "-m", "initial")
|
||||
run("switch", "-c", "feature")
|
||||
if e := os.WriteFile(filepath.Join(d, "main.go"), []byte("package main\n// feature\n"), 0644); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
run("add", ".")
|
||||
run("commit", "-m", "feature")
|
||||
g := GitAnalyzer{}
|
||||
stats, e := g.AnalyzeRef(context.Background(), d, "feature")
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
if stats.ViewRef != "feature" || stats.CommitCount != 2 {
|
||||
t.Fatalf("unexpected ref stats: %#v", stats)
|
||||
}
|
||||
detail, e := g.CommitDetail(context.Background(), d, stats.Commits[0].Hash)
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
if len(detail.Files) == 0 {
|
||||
t.Fatal("commit files missing")
|
||||
}
|
||||
if e = os.WriteFile(filepath.Join(d, "dirty.txt"), []byte("dirty"), 0644); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
if _, e = g.CheckoutBranch(context.Background(), d, "master"); e == nil || !strings.Contains(e.Error(), "GIT_WORKTREE_DIRTY") {
|
||||
t.Fatalf("dirty checkout error=%v", e)
|
||||
}
|
||||
}
|
||||
51
go.mod
Normal file
@@ -0,0 +1,51 @@
|
||||
module view
|
||||
|
||||
go 1.25.0
|
||||
|
||||
require (
|
||||
github.com/hhatto/gocloc v0.7.0
|
||||
github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06
|
||||
github.com/wailsapp/wails/v2 v2.12.0
|
||||
modernc.org/sqlite v1.53.0
|
||||
)
|
||||
|
||||
require (
|
||||
git.sr.ht/~jackmordaunt/go-toast/v2 v2.0.3 // indirect
|
||||
github.com/bep/debounce v1.2.1 // indirect
|
||||
github.com/dustin/go-humanize v1.0.1 // indirect
|
||||
github.com/go-enry/go-enry/v2 v2.8.0 // indirect
|
||||
github.com/go-enry/go-oniguruma v1.2.1 // indirect
|
||||
github.com/go-ole/go-ole v1.3.0 // indirect
|
||||
github.com/godbus/dbus/v5 v5.1.0 // indirect
|
||||
github.com/google/uuid v1.6.0 // indirect
|
||||
github.com/gorilla/websocket v1.5.3 // indirect
|
||||
github.com/jchv/go-winloader v0.0.0-20210711035445-715c2860da7e // indirect
|
||||
github.com/labstack/echo/v4 v4.13.3 // indirect
|
||||
github.com/labstack/gommon v0.4.2 // indirect
|
||||
github.com/leaanthony/go-ansi-parser v1.6.1 // indirect
|
||||
github.com/leaanthony/gosod v1.0.4 // indirect
|
||||
github.com/leaanthony/slicer v1.6.0 // indirect
|
||||
github.com/leaanthony/u v1.1.1 // indirect
|
||||
github.com/mattn/go-colorable v0.1.13 // indirect
|
||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||
github.com/ncruces/go-strftime v1.0.0 // indirect
|
||||
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c // indirect
|
||||
github.com/pkg/errors v0.9.1 // indirect
|
||||
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
|
||||
github.com/rivo/uniseg v0.4.7 // indirect
|
||||
github.com/samber/lo v1.49.1 // indirect
|
||||
github.com/tkrajina/go-reflector v0.5.8 // indirect
|
||||
github.com/valyala/bytebufferpool v1.0.0 // indirect
|
||||
github.com/valyala/fasttemplate v1.2.2 // indirect
|
||||
github.com/wailsapp/go-webview2 v1.0.22 // indirect
|
||||
github.com/wailsapp/mimetype v1.4.1 // indirect
|
||||
golang.org/x/crypto v0.33.0 // indirect
|
||||
golang.org/x/net v0.35.0 // indirect
|
||||
golang.org/x/sys v0.44.0 // indirect
|
||||
golang.org/x/text v0.22.0 // indirect
|
||||
modernc.org/libc v1.73.4 // indirect
|
||||
modernc.org/mathutil v1.7.1 // indirect
|
||||
modernc.org/memory v1.11.0 // indirect
|
||||
)
|
||||
|
||||
// replace github.com/wailsapp/wails/v2 v2.12.0 => C:\Users\admin\go\pkg\mod
|
||||
144
go.sum
Normal file
@@ -0,0 +1,144 @@
|
||||
git.sr.ht/~jackmordaunt/go-toast/v2 v2.0.3 h1:N3IGoHHp9pb6mj1cbXbuaSXV/UMKwmbKLf53nQmtqMA=
|
||||
git.sr.ht/~jackmordaunt/go-toast/v2 v2.0.3/go.mod h1:QtOLZGz8olr4qH2vWK0QH0w0O4T9fEIjMuWpKUsH7nc=
|
||||
github.com/bep/debounce v1.2.1 h1:v67fRdBA9UQu2NhLFXrSg0Brw7CexQekrBwDMM8bzeY=
|
||||
github.com/bep/debounce v1.2.1/go.mod h1:H8yggRPQKLUhUoqrJC1bO2xNya7vanpDl7xR3ISbCJ0=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
|
||||
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
|
||||
github.com/go-enry/go-enry/v2 v2.8.0 h1:KMW4mSG+8uUF6FaD3iPkFqyfC5tF8gRrsYImq6yhHzo=
|
||||
github.com/go-enry/go-enry/v2 v2.8.0/go.mod h1:GVzIiAytiS5uT/QiuakK7TF1u4xDab87Y8V5EJRpsIQ=
|
||||
github.com/go-enry/go-oniguruma v1.2.1 h1:k8aAMuJfMrqm/56SG2lV9Cfti6tC4x8673aHCcBk+eo=
|
||||
github.com/go-enry/go-oniguruma v1.2.1/go.mod h1:bWDhYP+S6xZQgiRL7wlTScFYBe023B6ilRZbCAD5Hf4=
|
||||
github.com/go-ole/go-ole v1.3.0 h1:Dt6ye7+vXGIKZ7Xtk4s6/xVdGDQynvom7xCFEdWr6uE=
|
||||
github.com/go-ole/go-ole v1.3.0/go.mod h1:5LS6F96DhAwUc7C+1HLexzMXY1xGRSryjyPPKW6zv78=
|
||||
github.com/godbus/dbus/v5 v5.1.0 h1:4KLkAxT3aOY8Li4FRJe/KvhoNFFxo0m6fNuFUO8QJUk=
|
||||
github.com/godbus/dbus/v5 v5.1.0/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
|
||||
github.com/google/pprof v0.0.0-20250317173921-a4b03ec1a45e h1:ijClszYn+mADRFY17kjQEVQ1XRhq2/JR1M3sGqeJoxs=
|
||||
github.com/google/pprof v0.0.0-20250317173921-a4b03ec1a45e/go.mod h1:boTsfXsheKC2y+lKOCMpSfarhxDeIzfZG1jqGcPl3cA=
|
||||
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg=
|
||||
github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
||||
github.com/hashicorp/golang-lru/v2 v2.0.7 h1:a+bsQ5rvGLjzHuww6tVxozPZFVghXaHOwFs4luLUK2k=
|
||||
github.com/hashicorp/golang-lru/v2 v2.0.7/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM=
|
||||
github.com/hhatto/gocloc v0.7.0 h1:PS+C3H7To0kr8dwNDz+ahKRt05pYkUdhR3YAhr/27RA=
|
||||
github.com/hhatto/gocloc v0.7.0/go.mod h1:H2qL5xyLUYpiUY8JSLHaXYhACYhRuM/j5HWEOR29hus=
|
||||
github.com/jchv/go-winloader v0.0.0-20210711035445-715c2860da7e h1:Q3+PugElBCf4PFpxhErSzU3/PY5sFL5Z6rfv4AbGAck=
|
||||
github.com/jchv/go-winloader v0.0.0-20210711035445-715c2860da7e/go.mod h1:alcuEEnZsY1WQsagKhZDsoPCRoOijYqhZvPwLG0kzVs=
|
||||
github.com/labstack/echo/v4 v4.13.3 h1:pwhpCPrTl5qry5HRdM5FwdXnhXSLSY+WE+YQSeCaafY=
|
||||
github.com/labstack/echo/v4 v4.13.3/go.mod h1:o90YNEeQWjDozo584l7AwhJMHN0bOC4tAfg+Xox9q5g=
|
||||
github.com/labstack/gommon v0.4.2 h1:F8qTUNXgG1+6WQmqoUWnz8WiEU60mXVVw0P4ht1WRA0=
|
||||
github.com/labstack/gommon v0.4.2/go.mod h1:QlUFxVM+SNXhDL/Z7YhocGIBYOiwB0mXm1+1bAPHPyU=
|
||||
github.com/leaanthony/debme v1.2.1 h1:9Tgwf+kjcrbMQ4WnPcEIUcQuIZYqdWftzZkBr+i/oOc=
|
||||
github.com/leaanthony/debme v1.2.1/go.mod h1:3V+sCm5tYAgQymvSOfYQ5Xx2JCr+OXiD9Jkw3otUjiA=
|
||||
github.com/leaanthony/go-ansi-parser v1.6.1 h1:xd8bzARK3dErqkPFtoF9F3/HgN8UQk0ed1YDKpEz01A=
|
||||
github.com/leaanthony/go-ansi-parser v1.6.1/go.mod h1:+vva/2y4alzVmmIEpk9QDhA7vLC5zKDTRwfZGOp3IWU=
|
||||
github.com/leaanthony/gosod v1.0.4 h1:YLAbVyd591MRffDgxUOU1NwLhT9T1/YiwjKZpkNFeaI=
|
||||
github.com/leaanthony/gosod v1.0.4/go.mod h1:GKuIL0zzPj3O1SdWQOdgURSuhkF+Urizzxh26t9f1cw=
|
||||
github.com/leaanthony/slicer v1.6.0 h1:1RFP5uiPJvT93TAHi+ipd3NACobkW53yUiBqZheE/Js=
|
||||
github.com/leaanthony/slicer v1.6.0/go.mod h1:o/Iz29g7LN0GqH3aMjWAe90381nyZlDNquK+mtH2Fj8=
|
||||
github.com/leaanthony/u v1.1.1 h1:TUFjwDGlNX+WuwVEzDqQwC2lOv0P4uhTQw7CMFdiK7M=
|
||||
github.com/leaanthony/u v1.1.1/go.mod h1:9+o6hejoRljvZ3BzdYlVL0JYCwtnAsVuN9pVTQcaRfI=
|
||||
github.com/matryer/is v1.4.0/go.mod h1:8I/i5uYgLzgsgEloJE1U6xx5HkBQpAZvepWuujKwMRU=
|
||||
github.com/matryer/is v1.4.1 h1:55ehd8zaGABKLXQUe2awZ99BD/PTc2ls+KV/dXphgEQ=
|
||||
github.com/matryer/is v1.4.1/go.mod h1:8I/i5uYgLzgsgEloJE1U6xx5HkBQpAZvepWuujKwMRU=
|
||||
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
|
||||
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
|
||||
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
|
||||
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
|
||||
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
||||
github.com/ncruces/go-strftime v1.0.0 h1:HMFp8mLCTPp341M/ZnA4qaf7ZlsbTc+miZjCLOFAw7w=
|
||||
github.com/ncruces/go-strftime v1.0.0/go.mod h1:Fwc5htZGVVkseilnfgOVb9mKy6w1naJmn9CehxcKcls=
|
||||
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c h1:+mdjkGKdHQG3305AYmdv1U2eRNDiU2ErMBj1gwrq8eQ=
|
||||
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c/go.mod h1:7rwL4CYBLnjLxUqIJNnCWiEdr3bn6IUYi15bNlnbCCU=
|
||||
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
||||
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE=
|
||||
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
|
||||
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
|
||||
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
|
||||
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
|
||||
github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06 h1:OkMGxebDjyw0ULyrTYWeN0UNCCkmCWfjPnIA2W6oviI=
|
||||
github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06/go.mod h1:+ePHsJ1keEjQtpvf9HHw0f4ZeJ0TLRsxhunSI2hYJSs=
|
||||
github.com/samber/lo v1.49.1 h1:4BIFyVfuQSEpluc7Fua+j1NolZHiEHEpaSEKdsH0tew=
|
||||
github.com/samber/lo v1.49.1/go.mod h1:dO6KHFzUKXgP8LDhU0oI8d2hekjXnGOu0DB8Jecxd6o=
|
||||
github.com/spf13/afero v1.2.2 h1:5jhuqJyZCZf2JRofRvN/nIFgIWNzPa3/Vz8mYylgbWc=
|
||||
github.com/spf13/afero v1.2.2/go.mod h1:9ZxEEn6pIJ8Rxe320qSDBk6AsU0r9pR7Q4OcevTdifk=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
|
||||
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||
github.com/tkrajina/go-reflector v0.5.8 h1:yPADHrwmUbMq4RGEyaOUpz2H90sRsETNVpjzo3DLVQQ=
|
||||
github.com/tkrajina/go-reflector v0.5.8/go.mod h1:ECbqLgccecY5kPmPmXg1MrHW585yMcDkVl6IvJe64T4=
|
||||
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
|
||||
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
|
||||
github.com/valyala/fasttemplate v1.2.2 h1:lxLXG0uE3Qnshl9QyaK6XJxMXlQZELvChBOCmQD0Loo=
|
||||
github.com/valyala/fasttemplate v1.2.2/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ=
|
||||
github.com/wailsapp/go-webview2 v1.0.22 h1:YT61F5lj+GGaat5OB96Aa3b4QA+mybD0Ggq6NZijQ58=
|
||||
github.com/wailsapp/go-webview2 v1.0.22/go.mod h1:qJmWAmAmaniuKGZPWwne+uor3AHMB5PFhqiK0Bbj8kc=
|
||||
github.com/wailsapp/mimetype v1.4.1 h1:pQN9ycO7uo4vsUUuPeHEYoUkLVkaRntMnHJxVwYhwHs=
|
||||
github.com/wailsapp/mimetype v1.4.1/go.mod h1:9aV5k31bBOv5z6u+QP8TltzvNGJPmNJD4XlAL3U+j3o=
|
||||
github.com/wailsapp/wails/v2 v2.12.0 h1:BHO/kLNWFHYjCzucxbzAYZWUjub1Tvb4cSguQozHn5c=
|
||||
github.com/wailsapp/wails/v2 v2.12.0/go.mod h1:mo1bzK1DEJrobt7YrBjgxvb5Sihb1mhAY09hppbibQg=
|
||||
golang.org/x/crypto v0.33.0 h1:IOBPskki6Lysi0lo9qQvbxiQ+FvsCC/YWOecCHAixus=
|
||||
golang.org/x/crypto v0.33.0/go.mod h1:bVdXmD7IV/4GdElGPozy6U7lWdRXA4qyRVGJV57uQ5M=
|
||||
golang.org/x/mod v0.36.0 h1:JJjpVx6myfUsUdAzZuOSTTmRE0PfZeNWzzvKrP7amb4=
|
||||
golang.org/x/mod v0.36.0/go.mod h1:moc6ELqsWcOw5Ef3xVprK5ul/MvtVvkIXLziUOICjUQ=
|
||||
golang.org/x/net v0.0.0-20210505024714-0287a6fb4125/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||
golang.org/x/net v0.35.0 h1:T5GQRQb2y08kTAByq9L4/bz8cipCdA8FbRTXewonqY8=
|
||||
golang.org/x/net v0.35.0/go.mod h1:EglIi67kWsHKlRzzVMUD93VMSWGFOMSZgxFjparz1Qk=
|
||||
golang.org/x/sync v0.20.0 h1:e0PTpb7pjO8GAtTs2dQ6jYa5BWYlMuX047Dco/pItO4=
|
||||
golang.org/x/sync v0.20.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0=
|
||||
golang.org/x/sys v0.0.0-20200810151505-1b9f1253b3ed/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.44.0 h1:ildZl3J4uzeKP07r2F++Op7E9B29JRUy+a27EibtBTQ=
|
||||
golang.org/x/sys v0.44.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.22.0 h1:bofq7m3/HAFvbF51jz3Q9wLg3jkvSPuiZu/pD1XwgtM=
|
||||
golang.org/x/text v0.22.0/go.mod h1:YRoo4H8PVmsu+E3Ou7cqLVH8oXWIHVoX0jqUWALQhfY=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.45.0 h1:18qN3FAooORvApf5XjCXgsuayZOEtXf6JK18I3+ONa8=
|
||||
golang.org/x/tools v0.45.0/go.mod h1:LuUGqqaXcXMEFEruIVJVm5mgDD8vww/z/SR1gQ4uE/0=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
modernc.org/cc/v4 v4.28.4 h1:Hd/4Es+MBj+/7hSdZaisNyu6bv3V0Dp2MdllyfqaH+c=
|
||||
modernc.org/cc/v4 v4.28.4/go.mod h1:OnovgIhbbMXMu1aISnJ0wvVD1KnW+cAUJkIrAWh+kVI=
|
||||
modernc.org/ccgo/v4 v4.34.4 h1:OVnSOWQjVKOYkFxoHYB+qQmSHK5gqMqARM+K9DpR/Ws=
|
||||
modernc.org/ccgo/v4 v4.34.4/go.mod h1:qdKqE8FNIYyysougB1RX9MxCzp5oJOcQXSobANJ4TuE=
|
||||
modernc.org/fileutil v1.4.0 h1:j6ZzNTftVS054gi281TyLjHPp6CPHr2KCxEXjEbD6SM=
|
||||
modernc.org/fileutil v1.4.0/go.mod h1:EqdKFDxiByqxLk8ozOxObDSfcVOv/54xDs/DUHdvCUU=
|
||||
modernc.org/gc/v2 v2.6.5 h1:nyqdV8q46KvTpZlsw66kWqwXRHdjIlJOhG6kxiV/9xI=
|
||||
modernc.org/gc/v2 v2.6.5/go.mod h1:YgIahr1ypgfe7chRuJi2gD7DBQiKSLMPgBQe9oIiito=
|
||||
modernc.org/gc/v3 v3.1.3 h1:6QAplYyVO+KdPW3pGnqmJDUxtkec8ooEWvks/hhU3lc=
|
||||
modernc.org/gc/v3 v3.1.3/go.mod h1:HFK/6AGESC7Ex+EZJhJ2Gni6cTaYpSMmU/cT9RmlfYY=
|
||||
modernc.org/goabi0 v0.2.0 h1:HvEowk7LxcPd0eq6mVOAEMai46V+i7Jrj13t4AzuNks=
|
||||
modernc.org/goabi0 v0.2.0/go.mod h1:CEFRnnJhKvWT1c1JTI3Avm+tgOWbkOu5oPA8eH8LnMI=
|
||||
modernc.org/libc v1.73.4 h1:+ra4Ui8ngyt8HDcO1FTDPWlkAh6yOdaO2yAoh8MddQA=
|
||||
modernc.org/libc v1.73.4/go.mod h1:DXZ3eO8qMCNn2SnmTNCiC71nJ9Rcq3PsnpU6Vc4rWK8=
|
||||
modernc.org/mathutil v1.7.1 h1:GCZVGXdaN8gTqB1Mf/usp1Y/hSqgI2vAGGP4jZMCxOU=
|
||||
modernc.org/mathutil v1.7.1/go.mod h1:4p5IwJITfppl0G4sUEDtCr4DthTaT47/N3aT6MhfgJg=
|
||||
modernc.org/memory v1.11.0 h1:o4QC8aMQzmcwCK3t3Ux/ZHmwFPzE6hf2Y5LbkRs+hbI=
|
||||
modernc.org/memory v1.11.0/go.mod h1:/JP4VbVC+K5sU2wZi9bHoq2MAkCnrt2r98UGeSK7Mjw=
|
||||
modernc.org/opt v0.2.0 h1:tGyef5ApycA7FSEOMraay9SaTk5zmbx7Tu+cJs4QKZg=
|
||||
modernc.org/opt v0.2.0/go.mod h1:03fq9lsNfvkYSfxrfUhZCWPk1lm4cq4N+Bh//bEtgns=
|
||||
modernc.org/sortutil v1.2.1 h1:+xyoGf15mM3NMlPDnFqrteY07klSFxLElE2PVuWIJ7w=
|
||||
modernc.org/sortutil v1.2.1/go.mod h1:7ZI3a3REbai7gzCLcotuw9AC4VZVpYMjDzETGsSMqJE=
|
||||
modernc.org/sqlite v1.53.0 h1:20WG8N9q4ji/dEqGk4uiI0c6OPjSeLTNYGFCc3+7c1M=
|
||||
modernc.org/sqlite v1.53.0/go.mod h1:xoEpOIpGrgT48H5iiyt/YXPCZPEzlfmfFwtk8Lklw8s=
|
||||
modernc.org/strutil v1.2.1 h1:UneZBkQA+DX2Rp35KcM69cSsNES9ly8mQWD71HKlOA0=
|
||||
modernc.org/strutil v1.2.1/go.mod h1:EHkiggD70koQxjVdSBM3JKM7k6L0FbGE5eymy9i3B9A=
|
||||
modernc.org/token v1.1.0 h1:Xl7Ap9dKaEs5kLoOQeQmPWevfnk/DM5qcLcYlA8ys6Y=
|
||||
modernc.org/token v1.1.0/go.mod h1:UGzOrNV1mAFSEB63lOFHIpNRUVMvYTc6yu1SMY/XTDM=
|
||||
39
main.go
Normal file
@@ -0,0 +1,39 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"embed"
|
||||
|
||||
"github.com/wailsapp/wails/v2"
|
||||
"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() {
|
||||
// Create an instance of the app structure
|
||||
app := NewApp()
|
||||
|
||||
// Create application with options
|
||||
err := wails.Run(&options.App{
|
||||
Title: "Code Count",
|
||||
Width: 1280,
|
||||
Height: 820,
|
||||
MinWidth: 960,
|
||||
MinHeight: 680,
|
||||
AssetServer: &assetserver.Options{
|
||||
Assets: assets,
|
||||
},
|
||||
BackgroundColour: &options.RGBA{R: 13, G: 18, B: 28, A: 1},
|
||||
OnStartup: app.startup,
|
||||
OnShutdown: app.shutdown,
|
||||
Bind: []interface{}{
|
||||
app,
|
||||
},
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
println("Error:", err.Error())
|
||||
}
|
||||
}
|
||||
205
model/models.go
Normal file
@@ -0,0 +1,205 @@
|
||||
// Package model 定义后端服务、SQLite 仓储和 Wails 前端之间共享的数据结构。
|
||||
// 该包只描述数据,不包含数据库或系统命令逻辑,因此可被各层安全复用。
|
||||
package model
|
||||
|
||||
type Project struct {
|
||||
ID int64 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Path string `json:"path"`
|
||||
Description string `json:"description"`
|
||||
GroupID int64 `json:"groupId"`
|
||||
GroupName string `json:"groupName"`
|
||||
CreatedAt string `json:"createdAt"`
|
||||
UpdatedAt string `json:"updatedAt"`
|
||||
Stats ProjectStats `json:"stats"`
|
||||
Languages []LanguageStat `json:"languages"`
|
||||
}
|
||||
type ProjectInput struct {
|
||||
Name string `json:"name"`
|
||||
Path string `json:"path"`
|
||||
Description string `json:"description"`
|
||||
GroupID int64 `json:"groupId"`
|
||||
}
|
||||
type ProjectGroup struct {
|
||||
ID int64 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
CreatedAt string `json:"createdAt"`
|
||||
UpdatedAt string `json:"updatedAt"`
|
||||
}
|
||||
type ProjectStats struct {
|
||||
TotalLines int64 `json:"totalLines"`
|
||||
CodeLines int64 `json:"codeLines"`
|
||||
CommentLines int64 `json:"commentLines"`
|
||||
BlankLines int64 `json:"blankLines"`
|
||||
FileCount int64 `json:"fileCount"`
|
||||
CommitCount int64 `json:"commitCount"`
|
||||
AddedLines int64 `json:"addedLines"`
|
||||
DeletedLines int64 `json:"deletedLines"`
|
||||
ContributorCount int64 `json:"contributorCount"`
|
||||
LastAnalyzed string `json:"lastAnalyzed"`
|
||||
}
|
||||
type LanguageStat struct {
|
||||
Name string `json:"name"`
|
||||
Files int64 `json:"files"`
|
||||
Code int64 `json:"code"`
|
||||
Comments int64 `json:"comments"`
|
||||
Blanks int64 `json:"blanks"`
|
||||
}
|
||||
type FileEntry struct {
|
||||
Path string `json:"path"`
|
||||
Name string `json:"name"`
|
||||
Extension string `json:"extension"`
|
||||
Size int64 `json:"size"`
|
||||
IsDir bool `json:"isDir"`
|
||||
Parent string `json:"parent"`
|
||||
}
|
||||
type StructureStats struct {
|
||||
Files []FileEntry `json:"files"`
|
||||
TotalFiles int64 `json:"totalFiles"`
|
||||
TotalDirs int64 `json:"totalDirs"`
|
||||
TotalSize int64 `json:"totalSize"`
|
||||
LargeFiles []FileEntry `json:"largeFiles"`
|
||||
Folders []FolderStat `json:"folders"`
|
||||
Extensions []ExtensionStat `json:"extensions"`
|
||||
}
|
||||
type FolderStat struct {
|
||||
Name string `json:"name"`
|
||||
Files int64 `json:"files"`
|
||||
Size int64 `json:"size"`
|
||||
}
|
||||
type ExtensionStat struct {
|
||||
Extension string `json:"extension"`
|
||||
Files int64 `json:"files"`
|
||||
Size int64 `json:"size"`
|
||||
}
|
||||
|
||||
type GitCommit struct {
|
||||
Hash string `json:"hash"`
|
||||
Author string `json:"author"`
|
||||
Email string `json:"email"`
|
||||
Message string `json:"message"`
|
||||
Date string `json:"date"`
|
||||
Added int64 `json:"added"`
|
||||
Deleted int64 `json:"deleted"`
|
||||
}
|
||||
type GitRef struct {
|
||||
Name string `json:"name"`
|
||||
Hash string `json:"hash"`
|
||||
Kind string `json:"kind"`
|
||||
Current bool `json:"current"`
|
||||
}
|
||||
type Contributor struct {
|
||||
Name string `json:"name"`
|
||||
Email string `json:"email"`
|
||||
Commits int64 `json:"commits"`
|
||||
Added int64 `json:"added"`
|
||||
Deleted int64 `json:"deleted"`
|
||||
}
|
||||
type HeatDay struct {
|
||||
Date string `json:"date"`
|
||||
Count int64 `json:"count"`
|
||||
}
|
||||
type GitStats struct {
|
||||
Available bool `json:"available"`
|
||||
Error string `json:"error,omitempty"`
|
||||
CurrentBranch string `json:"currentBranch"`
|
||||
WorkspaceBranch string `json:"workspaceBranch"`
|
||||
ViewRef string `json:"viewRef"`
|
||||
CommitCount int64 `json:"commitCount"`
|
||||
Added int64 `json:"added"`
|
||||
Deleted int64 `json:"deleted"`
|
||||
ContributorCount int64 `json:"contributorCount"`
|
||||
Commits []GitCommit `json:"commits"`
|
||||
Refs []GitRef `json:"refs"`
|
||||
Contributors []Contributor `json:"contributors"`
|
||||
Heatmap []HeatDay `json:"heatmap"`
|
||||
}
|
||||
type GitDiagnostics struct {
|
||||
Available bool `json:"available"`
|
||||
ErrorCode string `json:"errorCode,omitempty"`
|
||||
Detail string `json:"detail,omitempty"`
|
||||
IsWSL bool `json:"isWsl"`
|
||||
Distro string `json:"distro,omitempty"`
|
||||
LinuxPath string `json:"linuxPath,omitempty"`
|
||||
WorkspaceBranch string `json:"workspaceBranch,omitempty"`
|
||||
ViewRef string `json:"viewRef,omitempty"`
|
||||
RefCount int `json:"refCount"`
|
||||
}
|
||||
type ProjectInsights struct {
|
||||
ProjectID int64 `json:"projectId"`
|
||||
HealthScore int `json:"healthScore"`
|
||||
GeneratedAt string `json:"generatedAt"`
|
||||
Summary InsightSummary `json:"summary"`
|
||||
Issues []InsightIssue `json:"issues"`
|
||||
}
|
||||
type InsightSummary struct {
|
||||
High int `json:"high"`
|
||||
Medium int `json:"medium"`
|
||||
Low int `json:"low"`
|
||||
TodoCount int `json:"todoCount"`
|
||||
LongFiles int `json:"longFiles"`
|
||||
LargeFiles int `json:"largeFiles"`
|
||||
}
|
||||
type InsightIssue struct {
|
||||
Severity string `json:"severity"`
|
||||
Type string `json:"type"`
|
||||
Title string `json:"title"`
|
||||
Detail string `json:"detail"`
|
||||
Path string `json:"path,omitempty"`
|
||||
Line int `json:"line,omitempty"`
|
||||
Suggestion string `json:"suggestion"`
|
||||
Evidence string `json:"evidence,omitempty"`
|
||||
}
|
||||
type GitFileChange struct {
|
||||
Path string `json:"path"`
|
||||
Status string `json:"status"`
|
||||
Added int64 `json:"added"`
|
||||
Deleted int64 `json:"deleted"`
|
||||
}
|
||||
type GitCommitDetail struct {
|
||||
GitCommit
|
||||
Files []GitFileChange `json:"files"`
|
||||
}
|
||||
type CheckoutResult struct {
|
||||
Branch string `json:"branch"`
|
||||
Message string `json:"message"`
|
||||
}
|
||||
|
||||
type ExclusionRule struct {
|
||||
ID int64 `json:"id"`
|
||||
Pattern string `json:"pattern"`
|
||||
Category string `json:"category"`
|
||||
Builtin bool `json:"builtin"`
|
||||
}
|
||||
type LogEntry struct {
|
||||
ID int64 `json:"id"`
|
||||
Level string `json:"level"`
|
||||
Category string `json:"category"`
|
||||
Message string `json:"message"`
|
||||
Detail string `json:"detail"`
|
||||
CreatedAt string `json:"createdAt"`
|
||||
}
|
||||
type AppSettings struct {
|
||||
Theme string `json:"theme"`
|
||||
Locale string `json:"locale"`
|
||||
GitScope string `json:"gitScope"`
|
||||
DatabasePath string `json:"databasePath"`
|
||||
AutoRefresh bool `json:"autoRefresh"`
|
||||
GlassOpacity int `json:"glassOpacity"`
|
||||
LoadingStyle string `json:"loadingStyle"`
|
||||
}
|
||||
type Dashboard struct {
|
||||
Projects int64 `json:"projects"`
|
||||
TotalLines int64 `json:"totalLines"`
|
||||
Commits int64 `json:"commits"`
|
||||
}
|
||||
|
||||
// TaskEvent 只传递稳定消息键,具体中文或英文由前端根据当前语言即时翻译。
|
||||
type TaskEvent struct {
|
||||
TaskID string `json:"taskId"`
|
||||
ProjectID int64 `json:"projectId"`
|
||||
Stage string `json:"stage"`
|
||||
Progress int `json:"progress"`
|
||||
MessageKey string `json:"messageKey"`
|
||||
Params map[string]any `json:"params,omitempty"`
|
||||
}
|
||||
31
models.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package main
|
||||
|
||||
import "view/model"
|
||||
|
||||
// 根包保留别名仅用于维持 Wails 公开 API 和旧测试兼容;真实模型集中在 model 包。
|
||||
type Project = model.Project
|
||||
type ProjectInput = model.ProjectInput
|
||||
type ProjectGroup = model.ProjectGroup
|
||||
type ProjectStats = model.ProjectStats
|
||||
type LanguageStat = model.LanguageStat
|
||||
type FileEntry = model.FileEntry
|
||||
type StructureStats = model.StructureStats
|
||||
type FolderStat = model.FolderStat
|
||||
type ExtensionStat = model.ExtensionStat
|
||||
type GitCommit = model.GitCommit
|
||||
type GitRef = model.GitRef
|
||||
type Contributor = model.Contributor
|
||||
type HeatDay = model.HeatDay
|
||||
type GitStats = model.GitStats
|
||||
type GitDiagnostics = model.GitDiagnostics
|
||||
type ProjectInsights = model.ProjectInsights
|
||||
type InsightSummary = model.InsightSummary
|
||||
type InsightIssue = model.InsightIssue
|
||||
type GitFileChange = model.GitFileChange
|
||||
type GitCommitDetail = model.GitCommitDetail
|
||||
type CheckoutResult = model.CheckoutResult
|
||||
type ExclusionRule = model.ExclusionRule
|
||||
type LogEntry = model.LogEntry
|
||||
type AppSettings = model.AppSettings
|
||||
type Dashboard = model.Dashboard
|
||||
type TaskEvent = model.TaskEvent
|
||||
77
platform/command.go
Normal file
@@ -0,0 +1,77 @@
|
||||
package platform
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"errors"
|
||||
"os/exec"
|
||||
"strconv"
|
||||
"strings"
|
||||
"unicode/utf16"
|
||||
)
|
||||
|
||||
// CommandError 保存后台命令失败时的原始诊断信息。
|
||||
// 服务层会把这些输出映射成稳定错误码,界面再按当前语言展示友好提示。
|
||||
type CommandError struct {
|
||||
Command string
|
||||
Args []string
|
||||
ExitCode int
|
||||
Output string
|
||||
}
|
||||
|
||||
func (e *CommandError) Error() string {
|
||||
if strings.TrimSpace(e.Output) != "" {
|
||||
return strings.TrimSpace(e.Output)
|
||||
}
|
||||
if e.ExitCode != 0 {
|
||||
return e.Command + " exited with code " + strconv.Itoa(e.ExitCode)
|
||||
}
|
||||
return e.Command + " failed"
|
||||
}
|
||||
|
||||
// RunHidden 在后台执行命令并合并 stdout/stderr。
|
||||
// Windows 下由平台文件设置 HideWindow 和 CREATE_NO_WINDOW,避免 Git/WSL 查询弹出终端窗口。
|
||||
func RunHidden(ctx context.Context, name string, args ...string) (string, error) {
|
||||
cmd := exec.CommandContext(ctx, name, args...)
|
||||
configureHidden(cmd)
|
||||
var stdout, stderr bytes.Buffer
|
||||
cmd.Stdout = &stdout
|
||||
cmd.Stderr = &stderr
|
||||
e := cmd.Run()
|
||||
out := strings.TrimSpace(strings.ReplaceAll(decodeOutput(stdout.Bytes()), "\x00", ""))
|
||||
errOut := strings.TrimSpace(strings.ReplaceAll(decodeOutput(stderr.Bytes()), "\x00", ""))
|
||||
if e != nil {
|
||||
if out == "" {
|
||||
out = errOut
|
||||
} else if errOut != "" {
|
||||
out += "\n" + errOut
|
||||
}
|
||||
if out == "" {
|
||||
out = e.Error()
|
||||
}
|
||||
exitCode := -1
|
||||
var exit *exec.ExitError
|
||||
if errors.As(e, &exit) {
|
||||
exitCode = exit.ExitCode()
|
||||
}
|
||||
return "", &CommandError{Command: name, Args: args, ExitCode: exitCode, Output: out}
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// DecodeWSLList 兼容部分 Windows 版本返回的 UTF-16LE 发行版列表。
|
||||
func DecodeWSLList(b []byte) string { return decodeOutput(b) }
|
||||
|
||||
func decodeOutput(b []byte) string {
|
||||
if len(b) >= 2 && (b[1] == 0 || b[0] == 0xff && b[1] == 0xfe) {
|
||||
if len(b)%2 != 0 {
|
||||
b = b[:len(b)-1]
|
||||
}
|
||||
u := make([]uint16, 0, len(b)/2)
|
||||
for i := 0; i+1 < len(b); i += 2 {
|
||||
u = append(u, uint16(b[i])|uint16(b[i+1])<<8)
|
||||
}
|
||||
return strings.TrimPrefix(string(utf16.Decode(u)), "\ufeff")
|
||||
}
|
||||
return string(b)
|
||||
}
|
||||
45
platform/path.go
Normal file
@@ -0,0 +1,45 @@
|
||||
// Package platform 封装操作系统差异,包括隐藏子进程和 WSL 路径转换。
|
||||
package platform
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// PathDescriptor 是项目路径的标准描述。WindowsPath 用于 Go 文件扫描,LinuxPath 用于 WSL 内 Git。
|
||||
type PathDescriptor struct {
|
||||
Original string
|
||||
WindowsPath string
|
||||
Distro string
|
||||
LinuxPath string
|
||||
WSL bool
|
||||
}
|
||||
|
||||
// ResolvePath 识别两种 WSL UNC 前缀,并转换为 WSL 内部可识别的 Linux 绝对路径。
|
||||
func ResolvePath(raw string) (PathDescriptor, error) {
|
||||
p := filepath.Clean(strings.TrimSpace(raw))
|
||||
if p == "" {
|
||||
return PathDescriptor{}, errors.New("PATH_REQUIRED")
|
||||
}
|
||||
slash := strings.ReplaceAll(p, "/", "\\")
|
||||
lower := strings.ToLower(slash)
|
||||
prefix := ""
|
||||
switch {
|
||||
case strings.HasPrefix(lower, "\\\\wsl.localhost\\"):
|
||||
prefix = "\\\\wsl.localhost\\"
|
||||
case strings.HasPrefix(lower, "\\\\wsl$\\"):
|
||||
prefix = "\\\\wsl$\\"
|
||||
default:
|
||||
return PathDescriptor{Original: raw, WindowsPath: p}, nil
|
||||
}
|
||||
rest := strings.TrimPrefix(slash, prefix)
|
||||
parts := strings.Split(rest, "\\")
|
||||
if len(parts) < 2 || parts[0] == "" {
|
||||
return PathDescriptor{}, errors.New("WSL_PATH_INVALID")
|
||||
}
|
||||
distro := parts[0]
|
||||
linux := "/" + strings.Join(parts[1:], "/")
|
||||
canonical := "\\\\wsl.localhost\\" + distro + "\\" + strings.Join(parts[1:], "\\")
|
||||
return PathDescriptor{Original: raw, WindowsPath: canonical, Distro: distro, LinuxPath: linux, WSL: true}, nil
|
||||
}
|
||||
25
platform/path_test.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package platform
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestResolveWSLPaths(t *testing.T) {
|
||||
cases := []struct{ input, distro, linux string }{{`\\wsl.localhost\Ubuntu-24.04\home\lee\app`, "Ubuntu-24.04", "/home/lee/app"}, {`\\wsl$\Debian\opt\site`, "Debian", "/opt/site"}}
|
||||
for _, c := range cases {
|
||||
d, e := ResolvePath(c.input)
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
if !d.WSL || d.Distro != c.distro || d.LinuxPath != c.linux {
|
||||
t.Fatalf("%q => %#v", c.input, d)
|
||||
}
|
||||
}
|
||||
}
|
||||
func TestResolveWindowsPath(t *testing.T) {
|
||||
d, e := ResolvePath(`D:\code\app`)
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
if d.WSL {
|
||||
t.Fatal("windows path detected as WSL")
|
||||
}
|
||||
}
|
||||
7
platform/process_other.go
Normal file
@@ -0,0 +1,7 @@
|
||||
//go:build !windows
|
||||
|
||||
package platform
|
||||
|
||||
import "os/exec"
|
||||
|
||||
func configureHidden(_ *exec.Cmd) {}
|
||||
13
platform/process_windows.go
Normal file
@@ -0,0 +1,13 @@
|
||||
//go:build windows
|
||||
|
||||
package platform
|
||||
|
||||
import (
|
||||
"os/exec"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
// configureHidden 同时设置 HideWindow 和 CREATE_NO_WINDOW,避免 git/wsl 查询闪出终端窗口。
|
||||
func configureHidden(cmd *exec.Cmd) {
|
||||
cmd.SysProcAttr = &syscall.SysProcAttr{HideWindow: true, CreationFlags: 0x08000000}
|
||||
}
|
||||
16
platform/process_windows_test.go
Normal file
@@ -0,0 +1,16 @@
|
||||
//go:build windows
|
||||
|
||||
package platform
|
||||
|
||||
import (
|
||||
"os/exec"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestConfigureHidden(t *testing.T) {
|
||||
c := exec.Command("cmd.exe", "/c", "exit", "0")
|
||||
configureHidden(c)
|
||||
if c.SysProcAttr == nil || !c.SysProcAttr.HideWindow || c.SysProcAttr.CreationFlags&0x08000000 == 0 {
|
||||
t.Fatalf("hidden process flags missing: %#v", c.SysProcAttr)
|
||||
}
|
||||
}
|
||||
35
platform/wsl.go
Normal file
@@ -0,0 +1,35 @@
|
||||
package platform
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os/exec"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// ListWSLDistros 返回本机已安装的 WSL 发行版;未安装 WSL 时返回稳定错误码。
|
||||
func ListWSLDistros(ctx context.Context) ([]string, error) {
|
||||
if _, e := exec.LookPath("wsl.exe"); e != nil {
|
||||
return nil, &PlatformError{Code: "WSL_NOT_INSTALLED", Detail: e.Error()}
|
||||
}
|
||||
out, e := RunHidden(ctx, "wsl.exe", "--list", "--quiet")
|
||||
if e != nil {
|
||||
return nil, &PlatformError{Code: "WSL_LIST_FAILED", Detail: e.Error()}
|
||||
}
|
||||
items := []string{}
|
||||
for _, v := range strings.FieldsFunc(out, func(r rune) bool { return r == '\r' || r == '\n' || r == 0 }) {
|
||||
v = strings.TrimSpace(v)
|
||||
if v != "" {
|
||||
items = append(items, v)
|
||||
}
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
type PlatformError struct{ Code, Detail string }
|
||||
|
||||
func (e *PlatformError) Error() string {
|
||||
if e.Detail == "" {
|
||||
return e.Code
|
||||
}
|
||||
return e.Code + ": " + e.Detail
|
||||
}
|
||||
8
scanner.go
Normal file
@@ -0,0 +1,8 @@
|
||||
package main
|
||||
|
||||
import "view/service"
|
||||
|
||||
// Scanner 是 service.Scanner 的兼容别名,新业务实现位于 service 目录。
|
||||
type Scanner = service.Scanner
|
||||
|
||||
func wildcardMatch(pattern, rel string) bool { return service.MatchExcludedPattern(pattern, rel) }
|
||||
79
scanner_test.go
Normal file
@@ -0,0 +1,79 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestScannerCountsAndExcludes(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
if err := os.WriteFile(filepath.Join(root, "main.go"), []byte("package main\n\n// note\nfunc main() {}\n"), 0644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := os.Mkdir(filepath.Join(root, "node_modules"), 0755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := os.WriteFile(filepath.Join(root, "node_modules", "bad.js"), []byte("alert(1)\n"), 0644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
langs, files, err := (Scanner{}).Analyze(context.Background(), root, []ExclusionRule{{Pattern: "node_modules"}}, func(int, string) {})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(langs) != 1 || langs[0].Name != "Go" {
|
||||
t.Fatalf("unexpected languages: %#v", langs)
|
||||
}
|
||||
if langs[0].Code != 2 || langs[0].Comments != 1 || langs[0].Blanks != 1 {
|
||||
t.Fatalf("unexpected count: %#v", langs[0])
|
||||
}
|
||||
for _, f := range files {
|
||||
if f.Name == "bad.js" {
|
||||
t.Fatal("excluded file was scanned")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestWildcardMatch(t *testing.T) {
|
||||
cases := []struct {
|
||||
p, s string
|
||||
want bool
|
||||
}{{"*.log", "storage/app.log", true}, {"vendor", "vendor/a.php", true}, {"dist", "src/main.js", false}}
|
||||
for _, c := range cases {
|
||||
if got := wildcardMatch(c.p, c.s); got != c.want {
|
||||
t.Errorf("%s %s = %v", c.p, c.s, got)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestNestedGitignoreDoesNotExcludeSiblingSource(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
dependency := filepath.Join(root, "vendor", "package")
|
||||
if err := os.MkdirAll(dependency, 0755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// 依赖包中的局部规则只应作用于 vendor/package,不能过滤项目根目录。
|
||||
if err := os.WriteFile(filepath.Join(dependency, ".gitignore"), []byte("*\n"), 0644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := os.WriteFile(filepath.Join(dependency, "ignored.go"), []byte("package ignored\n"), 0644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := os.WriteFile(filepath.Join(root, "main.go"), []byte("package main\nfunc main() {}\n"), 0644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
langs, files, err := (Scanner{}).Analyze(context.Background(), root, nil, func(int, string) {})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(langs) != 1 || langs[0].Name != "Go" || langs[0].Files != 1 {
|
||||
t.Fatalf("嵌套 .gitignore 错误影响了同级源码: %#v", langs)
|
||||
}
|
||||
for _, file := range files {
|
||||
if file.Name == "ignored.go" {
|
||||
t.Fatal("嵌套 .gitignore 未排除自身目录中的文件")
|
||||
}
|
||||
}
|
||||
}
|
||||
321
service/git.go
Normal file
@@ -0,0 +1,321 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"os/exec"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
"view/model"
|
||||
"view/platform"
|
||||
)
|
||||
|
||||
// GitError 使用稳定错误码作为 Error() 返回值,同时保留命令输出细节。
|
||||
// 这样旧调用方仍能按错误码判断,诊断接口也能把真实原因展示给用户。
|
||||
type GitError struct {
|
||||
Code string
|
||||
Detail string
|
||||
}
|
||||
|
||||
func (e *GitError) Error() string { return e.Code }
|
||||
|
||||
// GitErrorDetail 提取 GitError 的详细原因,用于中文日志或诊断面板。
|
||||
func GitErrorDetail(err error) string {
|
||||
var ge *GitError
|
||||
if errors.As(err, &ge) {
|
||||
return ge.Detail
|
||||
}
|
||||
if err != nil {
|
||||
return err.Error()
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// GitService 根据项目路径自动选择 Windows Git 或 WSL 内 Git。
|
||||
// 所有命令都经过 platform.RunHidden,确保分析时不会弹出 CMD/PowerShell/WSL 窗口。
|
||||
type GitService struct{}
|
||||
|
||||
func (g GitService) run(ctx context.Context, dir string, args ...string) (string, error) {
|
||||
desc, e := platform.ResolvePath(dir)
|
||||
if e != nil {
|
||||
return "", e
|
||||
}
|
||||
if desc.WSL {
|
||||
// WSL 的裸 "-- git ..." 在部分环境会交给默认 shell 解析,
|
||||
// Git format 参数中的 "%(...)" 会被 bash 当成语法。--exec 可直接执行 git。
|
||||
base := []string{"-d", desc.Distro, "--exec", "git", "-C", desc.LinuxPath}
|
||||
out, e := platform.RunHidden(ctx, "wsl.exe", append(base, args...)...)
|
||||
if e != nil {
|
||||
return "", mapGitError(desc, e)
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
if _, e = exec.LookPath("git"); e != nil {
|
||||
return "", &GitError{Code: "GIT_NOT_INSTALLED", Detail: e.Error()}
|
||||
}
|
||||
out, e := platform.RunHidden(ctx, "git", append([]string{"-C", desc.WindowsPath}, args...)...)
|
||||
if e != nil {
|
||||
return "", mapGitError(desc, e)
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func mapGitError(desc platform.PathDescriptor, err error) error {
|
||||
detail := strings.TrimSpace(err.Error())
|
||||
lower := strings.ToLower(detail)
|
||||
code := "GIT_COMMAND_FAILED"
|
||||
switch {
|
||||
case strings.Contains(lower, "not a git repository"):
|
||||
code = "NOT_GIT_REPOSITORY"
|
||||
case strings.Contains(lower, "detected dubious ownership"):
|
||||
code = "GIT_SAFE_DIRECTORY"
|
||||
case strings.Contains(lower, "permission denied") || strings.Contains(lower, "could not open"):
|
||||
code = "GIT_PERMISSION_DENIED"
|
||||
case strings.Contains(lower, "executable file not found") || strings.Contains(lower, "not recognized"):
|
||||
if desc.WSL {
|
||||
code = "WSL_NOT_INSTALLED"
|
||||
} else {
|
||||
code = "GIT_NOT_INSTALLED"
|
||||
}
|
||||
case strings.Contains(lower, "git: not found") || strings.Contains(lower, "git: command not found"):
|
||||
code = "WSL_GIT_NOT_INSTALLED"
|
||||
case strings.Contains(lower, "there is no distribution") || strings.Contains(lower, "specified distribution") || strings.Contains(lower, "wsl_e_distro_not_found"):
|
||||
code = "WSL_DISTRO_NOT_FOUND"
|
||||
case strings.Contains(lower, "cannot access") && desc.WSL:
|
||||
code = "WSL_PATH_UNREADABLE"
|
||||
case strings.Contains(lower, "unknown revision") || strings.Contains(lower, "bad revision"):
|
||||
code = "GIT_REF_NOT_FOUND"
|
||||
}
|
||||
return &GitError{Code: code, Detail: detail}
|
||||
}
|
||||
|
||||
// Diagnostics 分步探测 Git 状态,供详情页解释“为什么 Git 统计是 0”。
|
||||
func (g GitService) Diagnostics(ctx context.Context, dir string, ref string) model.GitDiagnostics {
|
||||
desc, e := platform.ResolvePath(dir)
|
||||
d := model.GitDiagnostics{}
|
||||
if e != nil {
|
||||
d.ErrorCode = e.Error()
|
||||
d.Detail = e.Error()
|
||||
return d
|
||||
}
|
||||
d.IsWSL, d.Distro, d.LinuxPath = desc.WSL, desc.Distro, desc.LinuxPath
|
||||
if _, e = g.run(ctx, dir, "rev-parse", "--git-dir"); e != nil {
|
||||
d.ErrorCode = e.Error()
|
||||
d.Detail = GitErrorDetail(e)
|
||||
return d
|
||||
}
|
||||
branch, _ := g.run(ctx, dir, "branch", "--show-current")
|
||||
refs, e := g.run(ctx, dir, "for-each-ref", "--format=%(refname:short)%x1f%(objectname)%x1f%(refname)", "refs/heads", "refs/remotes")
|
||||
if e != nil {
|
||||
d.ErrorCode = e.Error()
|
||||
d.Detail = GitErrorDetail(e)
|
||||
return d
|
||||
}
|
||||
if ref == "" {
|
||||
ref = strings.TrimSpace(branch)
|
||||
}
|
||||
refCount := 0
|
||||
for _, line := range strings.Split(refs, "\n") {
|
||||
if strings.TrimSpace(line) != "" {
|
||||
refCount++
|
||||
}
|
||||
}
|
||||
d.Available = true
|
||||
d.WorkspaceBranch = strings.TrimSpace(branch)
|
||||
d.ViewRef = strings.TrimSpace(ref)
|
||||
d.RefCount = refCount
|
||||
return d
|
||||
}
|
||||
|
||||
// Analyze 分析工作区当前分支。
|
||||
func (g GitService) Analyze(ctx context.Context, dir string) (model.GitStats, error) {
|
||||
return g.AnalyzeRef(ctx, dir, "")
|
||||
}
|
||||
|
||||
// AnalyzeRef 只切换统计视图,不修改用户工作区。
|
||||
func (g GitService) AnalyzeRef(ctx context.Context, dir, ref string) (model.GitStats, error) {
|
||||
if _, e := g.run(ctx, dir, "rev-parse", "--git-dir"); e != nil {
|
||||
return model.GitStats{Available: false, Error: e.Error()}, e
|
||||
}
|
||||
branch, _ := g.run(ctx, dir, "branch", "--show-current")
|
||||
branch = strings.TrimSpace(branch)
|
||||
if ref == "" {
|
||||
ref = branch
|
||||
}
|
||||
out := model.GitStats{Available: true, CurrentBranch: branch, WorkspaceBranch: branch, ViewRef: ref, Commits: []model.GitCommit{}, Refs: []model.GitRef{}, Contributors: []model.Contributor{}, Heatmap: []model.HeatDay{}}
|
||||
refs, e := g.run(ctx, dir, "for-each-ref", "--format=%(refname:short)%x1f%(objectname)%x1f%(refname)", "refs/heads", "refs/remotes")
|
||||
if e != nil {
|
||||
out.Available = false
|
||||
out.Error = e.Error()
|
||||
return out, e
|
||||
}
|
||||
for _, line := range strings.Split(refs, "\n") {
|
||||
p := strings.Split(line, "\x1f")
|
||||
if len(p) != 3 {
|
||||
p = strings.Split(line, "%x1f")
|
||||
}
|
||||
if len(p) != 3 {
|
||||
continue
|
||||
}
|
||||
kind := "local"
|
||||
if strings.HasPrefix(p[2], "refs/remotes/") {
|
||||
kind = "remote"
|
||||
}
|
||||
out.Refs = append(out.Refs, model.GitRef{Name: p[0], Hash: ShortHash(p[1]), Kind: kind, Current: p[0] == branch})
|
||||
}
|
||||
args := []string{"log", "--use-mailmap", "--date=iso-strict", "--pretty=format:@@CC@@%H%x1f%aN%x1f%aE%x1f%aI%x1f%s", "--numstat"}
|
||||
if strings.TrimSpace(ref) != "" {
|
||||
args = append(args, ref)
|
||||
}
|
||||
log, e := g.run(ctx, dir, args...)
|
||||
if e != nil {
|
||||
out.Available = false
|
||||
out.Error = e.Error()
|
||||
return out, e
|
||||
}
|
||||
parseLog(log, &out)
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// CommitDetail 按需读取单次提交和逐文件增删行,避免 Git 首页一次传输过多数据。
|
||||
func (g GitService) CommitDetail(ctx context.Context, dir, hash string) (model.GitCommitDetail, error) {
|
||||
meta, e := g.run(ctx, dir, "show", "-s", "--use-mailmap", "--date=iso-strict", "--format=%H%x1f%aN%x1f%aE%x1f%aI%x1f%s", hash)
|
||||
if e != nil {
|
||||
return model.GitCommitDetail{}, e
|
||||
}
|
||||
p := strings.Split(meta, "\x1f")
|
||||
if len(p) != 5 {
|
||||
return model.GitCommitDetail{}, &GitError{Code: "GIT_COMMIT_PARSE_FAILED", Detail: meta}
|
||||
}
|
||||
d := model.GitCommitDetail{GitCommit: model.GitCommit{Hash: p[0], Author: p[1], Email: strings.ToLower(p[2]), Date: p[3], Message: p[4]}, Files: []model.GitFileChange{}}
|
||||
nums, e := g.run(ctx, dir, "show", "--format=", "--numstat", hash)
|
||||
if e != nil {
|
||||
return d, e
|
||||
}
|
||||
for _, line := range strings.Split(nums, "\n") {
|
||||
x := strings.Split(line, "\t")
|
||||
if len(x) < 3 {
|
||||
continue
|
||||
}
|
||||
a, ea := strconv.ParseInt(x[0], 10, 64)
|
||||
del, ed := strconv.ParseInt(x[1], 10, 64)
|
||||
if ea != nil {
|
||||
a = 0
|
||||
}
|
||||
if ed != nil {
|
||||
del = 0
|
||||
}
|
||||
status := "modified"
|
||||
if a > 0 && del == 0 {
|
||||
status = "added"
|
||||
}
|
||||
if del > 0 && a == 0 {
|
||||
status = "deleted"
|
||||
}
|
||||
d.Files = append(d.Files, model.GitFileChange{Path: x[2], Status: status, Added: a, Deleted: del})
|
||||
d.Added += a
|
||||
d.Deleted += del
|
||||
}
|
||||
return d, nil
|
||||
}
|
||||
|
||||
// CheckoutBranch 在修改工作区前先检查已跟踪和未跟踪变更;发现任何内容都拒绝切换。
|
||||
func (g GitService) CheckoutBranch(ctx context.Context, dir, ref string) (model.CheckoutResult, error) {
|
||||
dirty, e := g.run(ctx, dir, "status", "--porcelain")
|
||||
if e != nil {
|
||||
return model.CheckoutResult{}, e
|
||||
}
|
||||
if strings.TrimSpace(dirty) != "" {
|
||||
return model.CheckoutResult{}, &GitError{Code: "GIT_WORKTREE_DIRTY", Detail: dirty}
|
||||
}
|
||||
kind, _ := g.run(ctx, dir, "for-each-ref", "--format=%(refname)", "refs/remotes/"+ref)
|
||||
if strings.TrimSpace(kind) != "" {
|
||||
local := ref
|
||||
if i := strings.Index(ref, "/"); i >= 0 {
|
||||
local = ref[i+1:]
|
||||
}
|
||||
if _, x := g.run(ctx, dir, "show-ref", "--verify", "--quiet", "refs/heads/"+local); x == nil {
|
||||
_, e = g.run(ctx, dir, "switch", local)
|
||||
} else {
|
||||
_, e = g.run(ctx, dir, "switch", "--track", ref)
|
||||
}
|
||||
} else {
|
||||
_, e = g.run(ctx, dir, "switch", ref)
|
||||
}
|
||||
if e != nil {
|
||||
return model.CheckoutResult{}, e
|
||||
}
|
||||
branch, _ := g.run(ctx, dir, "branch", "--show-current")
|
||||
return model.CheckoutResult{Branch: strings.TrimSpace(branch), Message: "分支切换成功"}, nil
|
||||
}
|
||||
|
||||
func parseLog(log string, out *model.GitStats) {
|
||||
var cur *model.GitCommit
|
||||
for _, line := range strings.Split(log, "\n") {
|
||||
if strings.HasPrefix(line, "@@CC@@") {
|
||||
if cur != nil {
|
||||
out.Commits = append(out.Commits, *cur)
|
||||
}
|
||||
p := strings.Split(strings.TrimPrefix(line, "@@CC@@"), "\x1f")
|
||||
if len(p) == 5 {
|
||||
cur = &model.GitCommit{Hash: p[0], Author: p[1], Email: strings.ToLower(p[2]), Date: p[3], Message: p[4]}
|
||||
} else {
|
||||
cur = nil
|
||||
}
|
||||
continue
|
||||
}
|
||||
if cur != nil {
|
||||
p := strings.Split(line, "\t")
|
||||
if len(p) >= 2 {
|
||||
a, e1 := strconv.ParseInt(p[0], 10, 64)
|
||||
d, e2 := strconv.ParseInt(p[1], 10, 64)
|
||||
if e1 == nil {
|
||||
cur.Added += a
|
||||
}
|
||||
if e2 == nil {
|
||||
cur.Deleted += d
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if cur != nil {
|
||||
out.Commits = append(out.Commits, *cur)
|
||||
}
|
||||
cm := map[string]*model.Contributor{}
|
||||
hm := map[string]int64{}
|
||||
cut := time.Now().AddDate(-1, 0, 0)
|
||||
for _, c := range out.Commits {
|
||||
out.Added += c.Added
|
||||
out.Deleted += c.Deleted
|
||||
x := cm[c.Email]
|
||||
if x == nil {
|
||||
x = &model.Contributor{Name: c.Author, Email: c.Email}
|
||||
cm[c.Email] = x
|
||||
}
|
||||
x.Commits++
|
||||
x.Added += c.Added
|
||||
x.Deleted += c.Deleted
|
||||
if t, e := time.Parse(time.RFC3339, c.Date); e == nil && t.After(cut) {
|
||||
hm[t.Local().Format("2006-01-02")]++
|
||||
}
|
||||
}
|
||||
out.CommitCount = int64(len(out.Commits))
|
||||
for _, x := range cm {
|
||||
out.Contributors = append(out.Contributors, *x)
|
||||
}
|
||||
out.ContributorCount = int64(len(out.Contributors))
|
||||
sort.Slice(out.Contributors, func(i, j int) bool { return out.Contributors[i].Commits > out.Contributors[j].Commits })
|
||||
for d, c := range hm {
|
||||
out.Heatmap = append(out.Heatmap, model.HeatDay{Date: d, Count: c})
|
||||
}
|
||||
sort.Slice(out.Heatmap, func(i, j int) bool { return out.Heatmap[i].Date < out.Heatmap[j].Date })
|
||||
}
|
||||
|
||||
func ShortHash(s string) string {
|
||||
if len(s) > 7 {
|
||||
return s[:7]
|
||||
}
|
||||
return s
|
||||
}
|
||||
201
service/insights.go
Normal file
@@ -0,0 +1,201 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"context"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
"view/model"
|
||||
"view/platform"
|
||||
)
|
||||
|
||||
const (
|
||||
insightMaxFileSize = 1024 * 1024
|
||||
insightMaxTotalRead = 20 * 1024 * 1024
|
||||
)
|
||||
|
||||
// InsightService 基于既有统计快照做维护性检查。
|
||||
// 它不会重新遍历整个仓库,只读取已记录的小型源码文件,用于发现 TODO、长文件等轻量风险。
|
||||
type InsightService struct{}
|
||||
|
||||
func (InsightService) Analyze(ctx context.Context, project model.Project, structure model.StructureStats, git model.GitStats) (model.ProjectInsights, error) {
|
||||
desc, e := platform.ResolvePath(project.Path)
|
||||
if e != nil {
|
||||
return model.ProjectInsights{}, e
|
||||
}
|
||||
out := model.ProjectInsights{ProjectID: project.ID, GeneratedAt: time.Now().Format(time.RFC3339), Issues: []model.InsightIssue{}}
|
||||
add := func(issue model.InsightIssue) {
|
||||
out.Issues = append(out.Issues, issue)
|
||||
switch issue.Severity {
|
||||
case "high":
|
||||
out.Summary.High++
|
||||
case "medium":
|
||||
out.Summary.Medium++
|
||||
default:
|
||||
out.Summary.Low++
|
||||
}
|
||||
}
|
||||
|
||||
checkLanguageHealth(project.Languages, add)
|
||||
out.Summary.LargeFiles = len(structure.LargeFiles)
|
||||
checkStructureHealth(structure, add)
|
||||
checkGitHealth(git, add)
|
||||
if e = scanTextMarkers(ctx, desc.WindowsPath, structure.Files, add, &out.Summary); e != nil {
|
||||
add(model.InsightIssue{Severity: "medium", Type: "scan_error", Title: "源码检查未完全完成", Detail: e.Error(), Suggestion: "检查项目目录权限,或重新执行项目统计。"})
|
||||
}
|
||||
|
||||
sort.SliceStable(out.Issues, func(i, j int) bool {
|
||||
return severityRank(out.Issues[i].Severity) > severityRank(out.Issues[j].Severity)
|
||||
})
|
||||
out.HealthScore = healthScore(out.Summary)
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func checkLanguageHealth(langs []model.LanguageStat, add func(model.InsightIssue)) {
|
||||
for _, x := range langs {
|
||||
total := x.Code + x.Comments
|
||||
if x.Code < 500 || x.Files < 3 || total == 0 {
|
||||
continue
|
||||
}
|
||||
ratio := float64(x.Comments) / float64(total)
|
||||
if ratio < 0.03 {
|
||||
add(model.InsightIssue{Severity: "medium", Type: "low_comment_ratio", Title: "注释率偏低", Detail: x.Name + " 的注释占比低于 3%。", Suggestion: "为核心业务、复杂条件和公共接口补充解释性注释。"})
|
||||
} else if ratio < 0.06 {
|
||||
add(model.InsightIssue{Severity: "low", Type: "low_comment_ratio", Title: "注释率略低", Detail: x.Name + " 的注释占比低于 6%。", Suggestion: "优先补充复杂模块和团队协作频繁的文件。"})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func checkStructureHealth(s model.StructureStats, add func(model.InsightIssue)) {
|
||||
for _, f := range s.LargeFiles {
|
||||
severity := "medium"
|
||||
if f.Size >= 5*1024*1024 {
|
||||
severity = "high"
|
||||
}
|
||||
add(model.InsightIssue{Severity: severity, Type: "large_file", Title: "发现大文件", Detail: "文件体积可能影响仓库加载和代码审查。", Path: f.Path, Suggestion: "确认是否可以拆分、压缩或移动到对象存储。"})
|
||||
}
|
||||
if len(s.Folders) > 0 && s.TotalSize > 0 {
|
||||
top := s.Folders[0]
|
||||
if float64(top.Size)/float64(s.TotalSize) > 0.65 && top.Files > 20 {
|
||||
add(model.InsightIssue{Severity: "medium", Type: "folder_concentration", Title: "目录体量过于集中", Detail: top.Name + " 占据了项目大部分体积。", Path: top.Name, Suggestion: "检查该目录是否混入构建产物、缓存或可拆分模块。"})
|
||||
}
|
||||
}
|
||||
unknown := 0
|
||||
for _, x := range s.Extensions {
|
||||
if x.Extension == "" {
|
||||
unknown += int(x.Files)
|
||||
}
|
||||
}
|
||||
if unknown > 20 {
|
||||
add(model.InsightIssue{Severity: "low", Type: "unknown_files", Title: "无扩展名文件较多", Detail: "项目中存在较多无扩展名文件。", Suggestion: "确认这些文件是否都是必要脚本、配置或运行产物。"})
|
||||
}
|
||||
}
|
||||
|
||||
func checkGitHealth(g model.GitStats, add func(model.InsightIssue)) {
|
||||
if g.CommitCount == 0 || len(g.Contributors) == 0 {
|
||||
return
|
||||
}
|
||||
top := g.Contributors[0]
|
||||
if float64(top.Commits)/float64(g.CommitCount) > 0.75 && g.CommitCount > 20 {
|
||||
add(model.InsightIssue{Severity: "medium", Type: "contributor_concentration", Title: "提交集中度较高", Detail: top.Name + " 贡献了超过 75% 的提交。", Suggestion: "关注知识分散、代码评审和关键模块交接风险。"})
|
||||
}
|
||||
for _, c := range g.Commits[:min(30, len(g.Commits))] {
|
||||
if c.Added+c.Deleted > 3000 {
|
||||
add(model.InsightIssue{Severity: "low", Type: "large_commit", Title: "近期存在大提交", Detail: c.Message, Path: c.Hash, Suggestion: "大提交建议拆分审查,降低回滚和定位问题的成本。"})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func scanTextMarkers(ctx context.Context, root string, files []model.FileEntry, add func(model.InsightIssue), summary *model.InsightSummary) error {
|
||||
totalRead := int64(0)
|
||||
for _, f := range files {
|
||||
if f.IsDir || f.Size <= 0 || f.Size > insightMaxFileSize || !isInsightTextFile(f.Extension) {
|
||||
continue
|
||||
}
|
||||
if totalRead+f.Size > insightMaxTotalRead {
|
||||
return nil
|
||||
}
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return ctx.Err()
|
||||
default:
|
||||
}
|
||||
totalRead += f.Size
|
||||
path := filepath.Join(root, filepath.FromSlash(f.Path))
|
||||
lines, markers := inspectTextFile(path)
|
||||
if lines >= 1500 {
|
||||
summary.LongFiles++
|
||||
add(model.InsightIssue{Severity: "high", Type: "long_file", Title: "文件过长", Detail: "文件超过 1500 行,理解和评审成本较高。", Path: f.Path, Suggestion: "按职责拆分模块,提取复用函数或服务。"})
|
||||
} else if lines >= 800 {
|
||||
summary.LongFiles++
|
||||
add(model.InsightIssue{Severity: "medium", Type: "long_file", Title: "文件偏长", Detail: "文件超过 800 行。", Path: f.Path, Suggestion: "关注是否存在多个职责混在同一文件中。"})
|
||||
}
|
||||
for _, issue := range markers {
|
||||
summary.TodoCount++
|
||||
issue.Path = f.Path
|
||||
add(issue)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func inspectTextFile(path string) (int, []model.InsightIssue) {
|
||||
file, e := os.Open(path)
|
||||
if e != nil {
|
||||
return 0, nil
|
||||
}
|
||||
defer file.Close()
|
||||
scanner := bufio.NewScanner(file)
|
||||
scanner.Buffer(make([]byte, 0, 64*1024), 1024*1024)
|
||||
line := 0
|
||||
issues := []model.InsightIssue{}
|
||||
for scanner.Scan() {
|
||||
line++
|
||||
text := scanner.Text()
|
||||
upper := strings.ToUpper(text)
|
||||
kind, severity := "", "low"
|
||||
switch {
|
||||
case strings.Contains(upper, "FIXME"):
|
||||
kind, severity = "FIXME", "medium"
|
||||
case strings.Contains(upper, "HACK"):
|
||||
kind, severity = "HACK", "medium"
|
||||
case strings.Contains(upper, "TODO"):
|
||||
kind = "TODO"
|
||||
}
|
||||
if kind != "" {
|
||||
issues = append(issues, model.InsightIssue{Severity: severity, Type: "todo_marker", Title: "发现 " + kind + " 标记", Detail: "源码中存在待处理标记。", Line: line, Suggestion: "确认该标记是否仍有效,并补充负责人或处理计划。", Evidence: strings.TrimSpace(text)})
|
||||
}
|
||||
}
|
||||
return line, issues
|
||||
}
|
||||
|
||||
func isInsightTextFile(ext string) bool {
|
||||
switch strings.ToLower(ext) {
|
||||
case ".go", ".php", ".js", ".ts", ".vue", ".jsx", ".tsx", ".css", ".scss", ".sass", ".less", ".html", ".md", ".json", ".yaml", ".yml", ".xml", ".sql", ".py", ".java", ".cs", ".rb", ".rs", ".c", ".cpp", ".h":
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
func healthScore(s model.InsightSummary) int {
|
||||
score := 100 - s.High*12 - s.Medium*6 - s.Low*2
|
||||
if score < 0 {
|
||||
return 0
|
||||
}
|
||||
return score
|
||||
}
|
||||
|
||||
func severityRank(s string) int {
|
||||
switch s {
|
||||
case "high":
|
||||
return 3
|
||||
case "medium":
|
||||
return 2
|
||||
default:
|
||||
return 1
|
||||
}
|
||||
}
|
||||
198
service/scanner.go
Normal file
@@ -0,0 +1,198 @@
|
||||
// Package service 实现代码扫描、Git 分析和后台任务等业务能力。
|
||||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/hhatto/gocloc"
|
||||
gitignore "github.com/sabhiram/go-gitignore"
|
||||
"io/fs"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"strings"
|
||||
"view/model"
|
||||
"view/platform"
|
||||
)
|
||||
|
||||
// Scanner 负责遍历项目、应用排除规则并调用 gocloc 统计代码。它不依赖 Wails,可独立测试。
|
||||
type Scanner struct{}
|
||||
|
||||
// MatchExcludedPattern 对目录的每一级名称应用通配符,并对带斜杠的规则匹配完整相对路径。
|
||||
func MatchExcludedPattern(pattern, rel string) bool {
|
||||
pattern = filepath.ToSlash(strings.TrimSpace(pattern))
|
||||
rel = filepath.ToSlash(rel)
|
||||
if strings.Contains(pattern, "/") {
|
||||
ok, _ := filepath.Match(filepath.FromSlash(pattern), filepath.FromSlash(rel))
|
||||
return ok
|
||||
}
|
||||
for _, part := range strings.Split(rel, "/") {
|
||||
if ok, _ := filepath.Match(pattern, part); ok {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// Analyze 同时支持普通 Windows 路径与 WSL UNC 路径。WSL 文件通过 UNC 读取,Git 则由 GitService 在发行版内部执行。
|
||||
func (Scanner) Analyze(ctx context.Context, root string, rules []model.ExclusionRule, progress func(int, string)) ([]model.LanguageStat, []model.FileEntry, error) {
|
||||
desc, e := platform.ResolvePath(root)
|
||||
if e != nil {
|
||||
return nil, nil, e
|
||||
}
|
||||
root = desc.WindowsPath
|
||||
// WalkDir 对根目录回调错误若被忽略会得到“0 文件但成功”的假结果,因此分析前必须验证根目录。
|
||||
if info, statErr := os.Stat(root); statErr != nil {
|
||||
if desc.WSL {
|
||||
return nil, nil, &platform.PlatformError{Code: "WSL_PATH_UNAVAILABLE", Detail: statErr.Error()}
|
||||
}
|
||||
return nil, nil, statErr
|
||||
} else if !info.IsDir() {
|
||||
return nil, nil, errors.New("PROJECT_PATH_NOT_DIRECTORY")
|
||||
}
|
||||
// 每份 .gitignore 只控制其所在目录及后代。不能预先收集后再全局匹配,
|
||||
// 否则 vendor 等依赖目录中的局部通配符会错误排除项目根目录的源码。
|
||||
type scopedIgnore struct {
|
||||
base string
|
||||
matcher *gitignore.GitIgnore
|
||||
}
|
||||
ignores := []scopedIgnore{}
|
||||
addIgnore := func(dir, base string) {
|
||||
matcher, compileErr := gitignore.CompileIgnoreFile(filepath.Join(dir, ".gitignore"))
|
||||
if compileErr == nil {
|
||||
ignores = append(ignores, scopedIgnore{base: filepath.ToSlash(base), matcher: matcher})
|
||||
}
|
||||
}
|
||||
excluded := func(rel string) bool {
|
||||
slash := filepath.ToSlash(rel)
|
||||
for _, r := range rules {
|
||||
if MatchExcludedPattern(r.Pattern, slash) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
for _, scoped := range ignores {
|
||||
local := slash
|
||||
if scoped.base != "." && scoped.base != "" {
|
||||
prefix := strings.TrimSuffix(scoped.base, "/") + "/"
|
||||
if !strings.HasPrefix(slash, prefix) {
|
||||
continue
|
||||
}
|
||||
local = strings.TrimPrefix(slash, prefix)
|
||||
}
|
||||
if scoped.matcher.MatchesPath(local) || scoped.matcher.MatchesPath("/"+local) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
files := []model.FileEntry{}
|
||||
codeFiles := []string{}
|
||||
count := 0
|
||||
e = filepath.WalkDir(root, func(path string, d fs.DirEntry, err error) error {
|
||||
if err != nil {
|
||||
if path == root {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return ctx.Err()
|
||||
default:
|
||||
}
|
||||
if path == root {
|
||||
addIgnore(root, ".")
|
||||
return nil
|
||||
}
|
||||
rel, x := filepath.Rel(root, path)
|
||||
if x != nil {
|
||||
return nil
|
||||
}
|
||||
if d.Type()&os.ModeSymlink != 0 {
|
||||
if d.IsDir() {
|
||||
return filepath.SkipDir
|
||||
}
|
||||
return nil
|
||||
}
|
||||
if excluded(rel) {
|
||||
if d.IsDir() {
|
||||
return filepath.SkipDir
|
||||
}
|
||||
return nil
|
||||
}
|
||||
if d.IsDir() {
|
||||
addIgnore(path, rel)
|
||||
}
|
||||
info, x := d.Info()
|
||||
if x != nil {
|
||||
return nil
|
||||
}
|
||||
entry := model.FileEntry{Path: filepath.ToSlash(rel), Name: d.Name(), Extension: strings.ToLower(filepath.Ext(d.Name())), Size: info.Size(), IsDir: d.IsDir(), Parent: filepath.ToSlash(filepath.Dir(rel))}
|
||||
files = append(files, entry)
|
||||
if !d.IsDir() {
|
||||
count++
|
||||
ext := strings.TrimPrefix(entry.Extension, ".")
|
||||
if _, ok := gocloc.Exts[ext]; ok {
|
||||
codeFiles = append(codeFiles, path)
|
||||
}
|
||||
if count%250 == 0 {
|
||||
progress(min(65, 10+count/50), "task.scan")
|
||||
}
|
||||
}
|
||||
return nil
|
||||
})
|
||||
if e != nil {
|
||||
return nil, nil, e
|
||||
}
|
||||
progress(70, "task.count")
|
||||
defs := gocloc.NewDefinedLanguages()
|
||||
opts := gocloc.NewClocOptions()
|
||||
totals := map[string]*model.LanguageStat{}
|
||||
for i, path := range codeFiles {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return nil, nil, ctx.Err()
|
||||
default:
|
||||
}
|
||||
ext := strings.TrimPrefix(strings.ToLower(filepath.Ext(path)), ".")
|
||||
name := gocloc.Exts[ext]
|
||||
lang := defs.Langs[name]
|
||||
if lang == nil {
|
||||
continue
|
||||
}
|
||||
cf, parseErr := analyzeFileSafe(path, lang, opts)
|
||||
if parseErr != nil {
|
||||
continue
|
||||
}
|
||||
x := totals[name]
|
||||
if x == nil {
|
||||
x = &model.LanguageStat{Name: name}
|
||||
totals[name] = x
|
||||
}
|
||||
x.Files++
|
||||
x.Code += int64(cf.Code)
|
||||
x.Comments += int64(cf.Comments)
|
||||
x.Blanks += int64(cf.Blanks)
|
||||
if i%100 == 0 {
|
||||
progress(70+min(25, i*25/max(1, len(codeFiles))), "task.count")
|
||||
}
|
||||
}
|
||||
langs := make([]model.LanguageStat, 0, len(totals))
|
||||
for _, x := range totals {
|
||||
langs = append(langs, *x)
|
||||
}
|
||||
sort.Slice(langs, func(i, j int) bool { return langs[i].Code > langs[j].Code })
|
||||
progress(98, "task.save")
|
||||
return langs, files, nil
|
||||
}
|
||||
|
||||
// analyzeFileSafe 隔离第三方语言解析器的单文件异常。某个特殊源码不能影响整个桌面进程和其他文件统计。
|
||||
func analyzeFileSafe(path string, lang *gocloc.Language, opts *gocloc.ClocOptions) (result *gocloc.ClocFile, err error) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
err = fmt.Errorf("CODE_FILE_PARSE_PANIC: %s: %v", path, r)
|
||||
}
|
||||
}()
|
||||
return gocloc.AnalyzeFile(path, lang, opts), nil
|
||||
}
|
||||
13
wails.json
Normal file
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"$schema": "https://wails.io/schemas/config.v2.json",
|
||||
"name": "Code Count",
|
||||
"outputfilename": "code-count",
|
||||
"frontend:install": "npm install",
|
||||
"frontend:build": "npm run build",
|
||||
"frontend:dev:watcher": "npm run dev",
|
||||
"frontend:dev:serverUrl": "auto",
|
||||
"author": {
|
||||
"name": "李琦",
|
||||
"email": "liqiworkers@gmail.com"
|
||||
}
|
||||
}
|
||||
BIN
wsl-final.png
Normal file
|
After Width: | Height: | Size: 346 KiB |
BIN
wsl-refresh.png
Normal file
|
After Width: | Height: | Size: 418 KiB |