更新若干功能

This commit is contained in:
李琦
2026-08-15 17:18:00 +08:00
parent 4954295961
commit 6a81e479ef
77 changed files with 8165 additions and 2372 deletions

View File

@@ -4,9 +4,14 @@ import (
_ "embed"
"errors"
"fmt"
"os"
"os/exec"
"path/filepath"
"runtime"
"strings"
"sync/atomic"
"time"
"view/platform"
"view/service"
"github.com/wailsapp/wails/v3/pkg/application"
@@ -24,7 +29,8 @@ type shellText struct {
file, newProject, batchAnalyze, database, quit string
view, theme, themeDark, themeLight, themeSystem, language string
tools, analyzeNow, settings, logsPage, help, about string
trayShow, trayBatch, trayQuit, aiHub string
trayShow, trayBatch, trayQuit, trayRestart, aiHub string
trayLaunchpad string
account, accountLogin, traySync, profile, logout string
trayProjects, trayAllProjects string
trayTodos, trayTickets, trayMessages, trayAutostart string
@@ -39,7 +45,7 @@ func shellTexts(locale string) shellText {
file: "File", newProject: "New Project", batchAnalyze: "Analyze All", database: "Data Management", quit: "Quit",
view: "View", theme: "Theme", themeDark: "Dark", themeLight: "Light", themeSystem: "System", language: "Language",
tools: "Tools", analyzeNow: "Analyze All Now", settings: "Settings", logsPage: "Activity Log", help: "Help", about: "About",
trayShow: "Show Main Window", trayBatch: "Analyze All Projects", trayQuit: "Quit", aiHub: "AI Analysis",
trayShow: "Show Main Window", trayLaunchpad: "Open Launchpad", trayBatch: "Analyze All Projects", trayRestart: "Restart", trayQuit: "Quit", aiHub: "AI Analysis",
account: "Account", accountLogin: "Sign In / Register", traySync: "Sync Now", profile: "Profile", logout: "Sign Out",
trayProjects: "Open Project", trayAllProjects: "All Projects…",
trayTodos: "Todos", trayTickets: "Tickets", trayMessages: "Messages", trayAutostart: "Start at Login",
@@ -53,7 +59,7 @@ func shellTexts(locale string) shellText {
file: "文件", newProject: "新建项目", batchAnalyze: "批量统计", database: "数据管理", quit: "退出",
view: "视图", theme: "主题", themeDark: "暗色", themeLight: "浅色", themeSystem: "跟随系统", language: "语言",
tools: "工具", analyzeNow: "立即分析全部", settings: "设置", logsPage: "运行日志", help: "帮助", about: "关于",
trayShow: "显示主窗口", trayBatch: "批量统计全部项目", trayQuit: "退出", aiHub: "AI 分析",
trayShow: "显示主窗口", trayLaunchpad: "打开启动台", trayBatch: "批量统计全部项目", trayRestart: "重新启动", trayQuit: "退出", aiHub: "AI 分析",
account: "账号", accountLogin: "登录 / 注册", traySync: "立即同步", profile: "个人中心", logout: "退出登录",
trayProjects: "打开项目", trayAllProjects: "全部项目…",
trayTodos: "待办事项", trayTickets: "需求工单", trayMessages: "消息中心", trayAutostart: "开机启动",
@@ -84,6 +90,21 @@ func (a *App) SetupShell(wapp *application.App, win *application.WebviewWindow)
e.Cancel()
}
})
// 原生拖放:仅落在 data-file-drop-target 的区域会触发;把绝对路径转给前端。
win.OnWindowEvent(events.Common.WindowFilesDropped, func(event *application.WindowEvent) {
files := event.Context().DroppedFiles()
if len(files) == 0 {
return
}
target := ""
if d := event.Context().DropTargetDetails(); d != nil {
target = d.ElementID
}
a.emit("files-dropped", map[string]any{
"files": files,
"target": target,
})
})
a.shell.tray = wapp.SystemTray.New()
a.shell.tray.SetIcon(appIcon)
a.shell.tray.OnClick(a.showMainWindow)
@@ -274,6 +295,7 @@ const trayProjectLimit = 8
func (a *App) buildTrayMenu(t shellText, st trayStatus) *application.Menu {
menu := a.shell.wapp.Menu.New()
menu.Add(t.trayShow).OnClick(func(*application.Context) { a.showMainWindow() })
menu.Add(t.trayLaunchpad).OnClick(func(*application.Context) { a.navigateTo("/launchpad") })
menu.AddSeparator()
// 状态区:点击状态行触发同步(或登录)。
@@ -320,6 +342,7 @@ func (a *App) buildTrayMenu(t shellText, st trayStatus) *application.Menu {
a.RefreshShell()
})
menu.AddSeparator()
menu.Add(t.trayRestart).OnClick(func(*application.Context) { a.RestartApp() })
menu.Add(t.trayQuit).OnClick(func(*application.Context) { a.QuitApp() })
return menu
}
@@ -381,6 +404,46 @@ func (a *App) QuitApp() {
}
}
// RestartApp 延迟拉起当前可执行文件后退出(避开单实例抢占)。
func (a *App) RestartApp() {
exe, err := os.Executable()
if err != nil || strings.TrimSpace(exe) == "" {
a.QuitApp()
return
}
if resolved, e := filepath.EvalSymlinks(exe); e == nil && resolved != "" {
exe = resolved
}
// 去掉 Windows 扩展路径前缀,否则 start/cmd 会解析成「\\」之类的无效目标。
exe = strings.TrimPrefix(exe, `\\?\`)
exe = filepath.Clean(exe)
if runtime.GOOS == "windows" {
bat := filepath.Join(os.TempDir(), fmt.Sprintf("cc-restart-%d.bat", os.Getpid()))
body := "@echo off\r\n" +
"ping -n 2 127.0.0.1 >nul\r\n" +
"start \"\" \"" + exe + "\"\r\n" +
"del \"%~f0\"\r\n"
if e := os.WriteFile(bat, []byte(body), 0644); e != nil {
if a.store != nil {
a.store.Log("error", "系统", "写入重启脚本失败", e.Error())
}
a.QuitApp()
return
}
cmd := exec.Command("cmd", "/C", bat)
platform.ConfigureHidden(cmd)
_ = cmd.Start()
} else {
cmd := exec.Command("sh", "-c", `sleep 1; exec "$1"`, "_", exe)
_ = cmd.Start()
}
if a.store != nil {
a.store.Log("info", "系统", "应用即将重新启动", exe)
}
a.QuitApp()
}
func (a *App) GetAppVersion() string { return appVersion }
// GetAutostart 查询开机自启是否已注册。