Skip to content

Commit

Permalink
fix: 修复macos配置文件找不到问题
Browse files Browse the repository at this point in the history
  • Loading branch information
lpdswing committed Apr 13, 2023
1 parent 439c3ff commit 3d35fca
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
27 changes: 21 additions & 6 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
wruntime "github.com/wailsapp/wails/v2/pkg/runtime"
"os"
"runtime"
"path"
"os/user"
)

// App struct
Expand All @@ -33,7 +35,7 @@ type PlatForm struct {
}

func (app *App) ReadMenu() []PlatForm {
filePath := "menu.json"
filePath := configPath("menu.json")

platforms := []PlatForm{}

Expand Down Expand Up @@ -75,7 +77,7 @@ func (app *App) ReadMenu() []PlatForm {
}

func (app *App) EditMenu(platorms []PlatForm) {
filePath := "menu.json"
filePath := configPath("menu.json")
content, err := json.Marshal(platorms)
if err != nil {
fmt.Println("Error marshalling json", err)
Expand All @@ -89,7 +91,7 @@ func (app *App) EditMenu(platorms []PlatForm) {
}

func (app *App) WriteHome(url string) {
filePath := "home.txt"
filePath := configPath("home.txt")
data := []byte(url)
err := os.WriteFile(filePath, data, 0644)
if err != nil {
Expand All @@ -105,8 +107,7 @@ func (app *App) updateCustomMenu() {
}

func (app *App) initMenu() *menu.Menu {
var trayMenu *menu.Menu
trayMenu = menu.NewMenu()
trayMenu := menu.NewMenu()
if runtime.GOOS == "darwin" {
trayMenu.Append(menu.AppMenu())
trayMenu.Append(menu.EditMenu())
Expand Down Expand Up @@ -163,7 +164,8 @@ func (app *App) initMenu() *menu.Menu {
// 工具
platformEdit := trayMenu.AddSubmenu("设置")
platformEdit.AddText("平台管理", nil, func(cd *menu.CallbackData) {
url, err := os.ReadFile("home.txt")
home := configPath("home.txt")
url, err := os.ReadFile(home)
if err != nil {
fmt.Println("Error reading file", err)
}
Expand All @@ -179,3 +181,16 @@ func (app *App) initMenu() *menu.Menu {
})
return trayMenu
}

func configPath(file string) string {
user, _ := user.Current()
homeDir := user.HomeDir
configDir := path.Join(homeDir, ".config", "gptfusion")
err := os.MkdirAll(configDir, 0755)
if err != nil {
fmt.Println("Error creating config dir", err)
}
filePath := path.Join(configDir, file)
fmt.Println(filePath)
return filePath
}
2 changes: 1 addition & 1 deletion frontend/package.json.md5
Original file line number Diff line number Diff line change
@@ -1 +1 @@
e0257f1129f5f4c17786c5b81d5270da
86445c287cf86d37ea9da2d5b3783f69

0 comments on commit 3d35fca

Please sign in to comment.