Merge pull request #92 from GiCo001/dev-darwin

feat(app): 调整darwin版本的窗口,显示toolbar
This commit is contained in:
SparkMemory 2025-07-11 16:18:00 +08:00 committed by GitHub
commit 789e7427ce
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 59 additions and 17 deletions

9
app.go
View File

@ -998,15 +998,6 @@ func (a *App) ExportConfig() string {
}
return "导出成功:" + file
}
func getScreenResolution() (int, int, error) {
//user32 := syscall.NewLazyDLL("user32.dll")
//getSystemMetrics := user32.NewProc("GetSystemMetrics")
//
//width, _, _ := getSystemMetrics.Call(0)
//height, _, _ := getSystemMetrics.Call(1)
return int(1366), int(768), nil
}
func (a *App) ShareAnalysis(stockCode, stockName string) string {
//http://go-stock.sparkmemory.top:16688/upload

View File

@ -67,9 +67,31 @@ func (a *App) startup(ctx context.Context) {
log.Fatalf("系统通知失败: %v", err)
}
}()
go setUpScreen(a)
logger.SugaredLogger.Infof(" application startup Version:%s", Version)
}
func setUpScreen(a *App) {
screens, _ := runtime.ScreenGetAll(a.ctx)
if len(screens) == 0 {
return
}
screen := screens[0]
sw, sh := screen.Width, screen.Height
// macOS 菜单栏 + Dock 留出空间
topBarHeight := 22
dockHeight := 56
verticalMargin := topBarHeight + dockHeight
// 设置窗口为屏幕 80% 宽 × 可用高度 90%
w := int(float64(sw) * 0.8)
h := int(float64(sh-verticalMargin) * 0.9)
runtime.WindowSetSize(a.ctx, w, h)
runtime.WindowCenter(a.ctx)
}
// OnSecondInstanceLaunch 处理第二实例启动时的通知
func OnSecondInstanceLaunch(secondInstanceData options.SecondInstanceData) {
err := beeep.Notify("go-stock", "程序已经在运行了", "")
@ -166,3 +188,17 @@ func (a *App) beforeClose(ctx context.Context) (prevent bool) {
return false // 如果选择了确定,继续关闭应用
}
}
func getFrameless() bool {
return false
}
func getScreenResolution() (int, int, int, int, error) {
//user32 := syscall.NewLazyDLL("user32.dll")
//getSystemMetrics := user32.NewProc("GetSystemMetrics")
//
//width, _, _ := getSystemMetrics.Call(0)
//height, _, _ := getSystemMetrics.Call(1)
return int(1200), int(800), 0, 0, nil
}

View File

@ -199,3 +199,17 @@ func (a *App) beforeClose(ctx context.Context) (prevent bool) {
return false
}
}
func getFrameless() bool {
return true
}
func getScreenResolution() (int, int, int, int, error) {
//user32 := syscall.NewLazyDLL("user32.dll")
//getSystemMetrics := user32.NewProc("GetSystemMetrics")
//
//width, _, _ := getSystemMetrics.Call(0)
//height, _, _ := getSystemMetrics.Call(1)
return int(1366), int(768), 1456, 768, nil
}

View File

@ -1 +1 @@
2d63c3a999d797889c01d6c96451b197
8d3264f90073dfceb29c3619775d830d

15
main.go
View File

@ -109,7 +109,7 @@ func main() {
//var width, height int
//var err error
//
width, _, err := getScreenResolution()
width, _, minWidth, minHeight, err := getScreenResolution()
if err != nil {
log.SugaredLogger.Error("get screen resolution error")
width = 1456
@ -122,18 +122,20 @@ func main() {
backgroundColour = &options.RGBA{R: 27, G: 38, B: 54, A: 1}
}
frameless := getFrameless()
// Create application with options
err = wails.Run(&options.App{
Title: "go-stock",
Width: width * 4 / 5,
Height: 900,
MinWidth: 1456,
MinHeight: 768,
MinWidth: minWidth,
MinHeight: minHeight,
//MaxWidth: width,
//MaxHeight: height,
DisableResize: false,
Fullscreen: false,
Frameless: true,
Frameless: frameless,
StartHidden: false,
HideWindowOnClose: false,
EnableDefaultContextMenu: true,
@ -166,12 +168,11 @@ func main() {
// Mac platform specific options
Mac: &mac.Options{
TitleBar: &mac.TitleBar{
TitlebarAppearsTransparent: true,
TitlebarAppearsTransparent: false,
HideTitle: false,
HideTitleBar: false,
FullSizeContent: false,
UseToolbar: false,
HideToolbarSeparator: true,
UseToolbar: true,
},
Appearance: mac.NSAppearanceNameDarkAqua,
WebviewIsTransparent: true,