Private
Public Access
1
0
Files
u-desk/main.go

106 lines
2.6 KiB
Go
Raw Permalink 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"
"net/http"
"os"
"github.com/wailsapp/wails/v3/pkg/application"
"u-desk/internal/hotkey"
)
//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() {
app := NewApp()
wailsApp := application.New(application.Options{
Name: "U-Desk",
Description: "桌面文件管理器",
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
}
}
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,
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)
if err := wailsApp.Run(); err != nil {
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
}
}