Skip to content

Commit d431727

Browse files
committed
fix: window 路径错误
1 parent a046f88 commit d431727

File tree

4 files changed

+41
-14
lines changed

4 files changed

+41
-14
lines changed

apps/datas/paths.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,18 @@ import (
88
"strings"
99
)
1010

11+
func ToPath(savePath string) string {
12+
if runtime.GOOS != "windows" {
13+
return savePath
14+
}
15+
savePath = strings.ReplaceAll(savePath, "\\", "/")
16+
savePath = savePath[:3] + strings.ReplaceAll(savePath[3:], ":", "/")
17+
savePath = strings.ReplaceAll(savePath, "//", "/")
18+
savePath = strings.ReplaceAll(savePath, "-", "_")
19+
20+
return savePath
21+
}
22+
1123
func GetDataDir(appName string) (string, error) {
1224
var dataDir string
1325

apps/mysql/sqlite.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,16 @@ func getSqliteDBName(binlogFilePath string) (dbPath, table string) {
2525
table = arr[1]
2626
}
2727

28-
return datas.GetSqlitePath(dbPath), "binlog_" + table
28+
gotPath := datas.GetSqlitePath(dbPath)
29+
gotPath = datas.ToPath(gotPath)
30+
31+
return gotPath, "binlog_" + table
2932
}
3033

3134
// GetDB 链接指定 db 必须手动关闭
3235
func GetDB(dbPath, table string) (*gorm.DB, error) {
3336
savePath := path.Dir(dbPath)
37+
savePath = datas.ToPath(savePath)
3438
if err := os.MkdirAll(savePath, 0755); err != nil {
3539
return nil, err
3640
}
@@ -41,6 +45,7 @@ func GetDB(dbPath, table string) (*gorm.DB, error) {
4145
LogLevel: logger.Warn, // 日志级别,你可以设置为logger.Silent以禁用日志
4246
},
4347
)
48+
dbPath = datas.ToPath(dbPath)
4449
db, err := gorm.Open(sqlite.Open(dbPath+".db"), &gorm.Config{
4550
Logger: newLogger,
4651
})

apps/orm/sqlite.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,11 @@ func GetDB() *gorm.DB {
2525
// NewDB 每次都是新的
2626
func NewDB(dbPath string) *gorm.DB {
2727
savePath := path.Dir(dbPath)
28+
savePath = datas.ToPath(savePath)
2829
if err := os.MkdirAll(savePath, 0755); err != nil {
2930
return nil
3031
}
31-
32+
dbPath = datas.ToPath(dbPath)
3233
db, err := gorm.Open(sqlite.Open(dbPath), &gorm.Config{
3334
Logger: NewSqlLog(logger.Config{
3435
SlowThreshold: 0,

main.go

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ package main
33
import (
44
"changeme/apps"
55
"embed"
6-
"log"
7-
"runtime"
8-
96
"github.com/wailsapp/wails/v2"
107
"github.com/wailsapp/wails/v2/pkg/logger"
8+
"github.com/wailsapp/wails/v2/pkg/menu"
119
"github.com/wailsapp/wails/v2/pkg/options"
1210
"github.com/wailsapp/wails/v2/pkg/options/assetserver"
1311
"github.com/wailsapp/wails/v2/pkg/options/mac"
1412
"github.com/wailsapp/wails/v2/pkg/options/windows"
13+
"log"
14+
"runtime"
1515
)
1616

1717
//go:embed all:frontend/dist
@@ -24,6 +24,14 @@ func main() {
2424
// Create an instance of the app structure
2525
app := apps.NewApp()
2626

27+
// menu
28+
appMenu := menu.NewMenu()
29+
if runtime.GOOS == "darwin" {
30+
appMenu.Append(menu.AppMenu())
31+
appMenu.Append(menu.EditMenu())
32+
appMenu.Append(menu.WindowMenu())
33+
}
34+
2735
// Create application with options
2836
err := wails.Run(&options.App{
2937
Title: "mysql-binlog",
@@ -40,15 +48,16 @@ func main() {
4048
AssetServer: &assetserver.Options{
4149
Assets: assets,
4250
},
43-
Menu: nil,
44-
Logger: nil,
45-
LogLevel: logger.DEBUG,
46-
OnStartup: app.StartUp,
47-
OnDomReady: app.DomReady,
48-
OnBeforeClose: app.BeforeClose,
49-
OnShutdown: app.Shutdown,
50-
WindowStartState: options.Normal,
51-
Bind: app.GetBind(),
51+
Menu: appMenu,
52+
EnableDefaultContextMenu: true,
53+
Logger: nil,
54+
LogLevel: logger.DEBUG,
55+
OnStartup: app.StartUp,
56+
OnDomReady: app.DomReady,
57+
OnBeforeClose: app.BeforeClose,
58+
OnShutdown: app.Shutdown,
59+
WindowStartState: options.Normal,
60+
Bind: app.GetBind(),
5261
// Windows platform specific options
5362
Windows: &windows.Options{
5463
WebviewIsTransparent: true,

0 commit comments

Comments
 (0)