-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.go
More file actions
134 lines (116 loc) · 2.63 KB
/
utils.go
File metadata and controls
134 lines (116 loc) · 2.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
package main
import (
"changeme/common"
"context"
"errors"
"github.com/labstack/gommon/log"
"github.com/wailsapp/wails/v2/pkg/runtime"
"golang.org/x/exp/slog"
"gopkg.in/yaml.v3"
"os"
"os/exec"
"path/filepath"
"time"
)
type GOContext struct {
ctx context.Context
}
var (
Version string
BuildTime string
Commit string
)
func (c GOContext) Start(config common.Config) error {
cmd := &common.Exec{}
log.Info("执行命令:", config)
err := cmd.CmdExec(config.Env, config.Command, config.Dir)
if err != nil {
return err
}
return nil
}
func (c GOContext) TestCmdExec(config common.Config) error {
cmd := &common.Exec{}
log.Info("测试命令:", config.Command)
err := cmd.TestCmdExec(config.Env, config.Command, config.Dir)
if err != nil {
return err
}
return nil
}
func (c GOContext) GetConfigs() ([]common.TypeConfig, error) {
return common.Configs, nil
}
func (c GOContext) GetENVConfigs() (common.YamlInfo, error) {
return common.Paths, nil
}
func (c GOContext) SaveENVConfigs(env common.YamlInfo) error {
envs, err := yaml.Marshal(env)
if err != nil {
return err
}
//改变目录
common.CdExePath()
//保存配置文件
os.WriteFile("config/base.yml", envs, os.ModePerm)
return nil
}
func (c GOContext) GetStartTime() time.Time {
return startTime
}
func (c GOContext) GetRefreshTime() time.Time {
return refreshTime
}
func (c GOContext) InitEnv() error {
return common.InitEnv()
}
func (c GOContext) InitConfig() error {
refreshTime = time.Now()
if err := common.InitEnv(); err != nil {
// 配置文件不存在,跳转到初始化页面
//if errors.Is(err, os.ErrNotExist) {
// runtime.EventsEmit(*wailsContext, "navigate", "/init")
//} else {
return err
//}
}
return common.InitConfig()
}
func (c GOContext) GenerateConfig() error {
err := common.GenerateConfig()
if err != nil {
return err
}
// 根据配置文件更改应用标题
if common.Paths.Title != "" {
runtime.WindowSetTitle(*wailsContext, common.Paths.Title)
}
return nil
}
func (c GOContext) OpenFolderInExplorer(path string) error {
folderPath, err := filepath.Abs(path)
if err != nil {
return err
}
// 检查文件夹路径是否存在
if _, err := os.Stat(folderPath); os.IsNotExist(err) {
slog.Error("文件夹路径不存在")
return errors.New("路径不存在: " + path)
}
// 在资源管理器中打开文件夹
cmd := exec.Command("explorer", folderPath)
cmd.Run()
return nil
}
func (c GOContext) Exit() {
os.Exit(0)
}
func (c GOContext) GetVersion() string {
return Version
}
func (c GOContext) GetBuildTime() string {
return BuildTime
}
func (c GOContext) GetGitCommit() string {
return Commit
}