Files
u-desk/main.go
T
lxy 75a42c0b6a 修复: 粘贴图失效与SFTP串台回退等一批问题
粘贴图根修(Ctrl+V直读系统剪贴板,不再依赖不可靠的paste事件)/SFTP串台双刀(拨号期禁回退本机+盘符路径自动回根)/PDF导出目录设置与文案带落盘路径/性能批(连接保存下载防重/md渲染防抖+预热/hljs按需加载/审计锁外置/快捷方式解析超时/webview-watch可停)/前端62类型错清零(含keyPath蛇形字段炸弹)/目录图标字段错位修复
2026-10-24 13:48:54 +08:00

142 lines
4.0 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package main
import (
"embed"
"fmt"
"log/slog"
"net/http"
"os"
"github.com/wailsapp/wails/v3/pkg/application"
"github.com/wailsapp/wails/v3/pkg/events"
"u-desk/internal/common"
"u-desk/internal/hotkey"
"u-desk/internal/service"
)
//go:embed all:frontend/dist
var assets embed.FS
// 标题栏颜色(0x00BBGGRR)
var (
titleBarLight = uint32(0xF0F0F0) // #F0F0F0 近白
titleBarDark = uint32(0x2D2D2D) // #2D2D2D 深灰
noBorder = uint32(0xFFFFFFFE) // DWMWA_COLOR_NONE - Win11 抑制边框绘制
)
func main() {
// 崩溃取证基建先于一切:slog 落盘 + 主 goroutine panic 落盘
common.SetupFileLogging()
defer func() {
if r := recover(); r != nil {
common.AppendPanicLog("main", r)
os.Exit(2)
}
}()
// 启动时完成上次更新遗留的 exe 替换
service.ReplacePendingFile()
app := NewApp()
wailsApp := application.New(application.Options{
Name: "U-Desk",
Description: "桌面文件管理器",
// wails 系统日志(webview 生命周期、AssetFileServerFS 的 INFO 刷屏等)降到 Warn 落盘,
// 业务日志仍走 slog.Default() 的 INFO 全量——两路共用同一文件 writer,只是过滤级别不同
Logger: slog.New(slog.NewTextHandler(common.FileLogOut, &slog.HandlerOptions{Level: slog.LevelWarn})),
SingleInstance: &application.SingleInstanceOptions{
UniqueID: "top.1216.udesk",
},
Services: []application.Service{
application.NewService(app),
},
Assets: application.AssetOptions{
Handler: application.AssetFileServerFS(assets),
Middleware: func(next http.Handler) http.Handler {
return http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
if req.URL.Path == "/wails/custom.js" {
rw.Header().Set("Content-Type", "application/javascript")
rw.WriteHeader(200)
return
}
next.ServeHTTP(rw, req)
})
},
},
Mac: application.MacOptions{
ApplicationShouldTerminateAfterLastWindowClosed: true,
},
Windows: application.WindowsOptions{
WndProcInterceptor: func(hwnd uintptr, msg uint32, wParam, lParam uintptr) (uintptr, bool) {
switch msg {
case hotkey.WM_APP_HOTKEY:
app.RegisterGlobalHotkey()
return 0, true
case hotkey.WM_HOTKEY:
if wParam == 1 {
app.HandleHotkey()
return 0, true
}
case wmSizeMsg:
// webview 尺寸失同步兜底(app_window_fix.go):
// 只置脏标记,单 worker goroutine 统一消费,WM_SIZE 风暴不再批量 spawn goroutine
fixWebviewFill(hwnd)
}
return 0, false
},
},
})
window := application.Get().Window.NewWithOptions(application.WebviewWindowOptions{
Title: "U-Desk",
Width: 1400,
Height: 900,
MinWidth: 1000,
MinHeight: 600,
BackgroundColour: application.NewRGB(45, 45, 45),
URL: "/",
Frameless: true,
EnableFileDrop: true,
Windows: application.WindowsWindow{
Theme: application.SystemDefault,
CustomTheme: application.ThemeSettings{
LightModeActive: &application.WindowTheme{
TitleBarColour: &titleBarLight,
BorderColour: &noBorder,
},
LightModeInactive: &application.WindowTheme{
TitleBarColour: &titleBarLight,
BorderColour: &noBorder,
},
DarkModeActive: &application.WindowTheme{
TitleBarColour: &titleBarDark,
BorderColour: &noBorder,
},
DarkModeInactive: &application.WindowTheme{
TitleBarColour: &titleBarDark,
BorderColour: &noBorder,
},
},
},
})
app.SetMainWindow(window)
// webview 与窗口尺寸失同步的周期兜底(app_window_fix.go)
StartWebviewFillWatch()
// 外部文件拖入窗口(OS 资源管理器拖放):把本地路径转发给前端处理
// (本机面板=复制进当前目录,SFTP 面板=上传)
window.OnWindowEvent(events.Common.WindowFilesDropped, func(event *application.WindowEvent) {
files := event.Context().DroppedFiles()
if len(files) > 0 {
app.emitEvent("external-file-drop", files)
}
})
if err := wailsApp.Run(); err != nil {
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
}
}