Skip to content

Commit 10b55ec

Browse files
committed
feat: 修复oadin-app启动问题
1 parent 8693aad commit 10b55ec

1 file changed

Lines changed: 4 additions & 49 deletions

File tree

tray/systray.go

Lines changed: 4 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ import (
55
"github.com/gofrs/flock"
66
"log"
77
"net"
8-
"oadin/internal/constants"
9-
"oadin/internal/logger"
108
"os"
119
"os/exec"
1210
"path/filepath"
@@ -17,10 +15,10 @@ import (
1715
"github.com/getlantern/systray/example/icon"
1816
"github.com/pkg/browser"
1917
"github.com/sqweek/dialog"
20-
"oadin/internal/utils"
2118
serverUtils "oadin/internal/utils/server"
2219
trayTemplate "oadin/tray/icon"
2320
tray "oadin/tray/utils"
21+
"oadin/internal/logger"
2422
)
2523

2624
// Manager handles the system tray functionality
@@ -71,7 +69,7 @@ func (m *Manager) Start() {
7169
if !m.serverRunning {
7270
logger.LogicLogger.Error("=== Server not running, attempting to start...===")
7371
fmt.Println("Server not running, attempting to start...")
74-
err := StartOADINServerTray(m.logPath, m.pidPath)
72+
err := serverUtils.StartOadinServer(m.logPath, m.pidPath)
7573
if err == nil {
7674
m.serverRunning = true
7775
logger.LogicLogger.Info("Server started successfully")
@@ -283,7 +281,7 @@ func (m *Manager) handleStartStop() {
283281
}
284282
} else {
285283
// 启动服务器
286-
err := StartOADINServerTray(m.logPath, m.pidPath)
284+
err := serverUtils.StartOadinServer(m.logPath, m.pidPath)
287285
if err == nil {
288286
m.serverRunning = true
289287
// 启动成功后打开浏览器
@@ -300,7 +298,7 @@ func (m *Manager) handleOpenConsole() {
300298
if !serverUtils.IsServerRunning() {
301299
// 如果服务器没运行,询问是否启动
302300
if confirmed := dialog.Message("Oadin 服务器未运行,是否立即启动?").Title("启动服务器").YesNo(); confirmed {
303-
err := StartOADINServerTray(m.logPath, m.pidPath)
301+
err := serverUtils.StartOadinServer(m.logPath, m.pidPath)
304302
if err != nil {
305303
dialog.Message("启动服务器失败: %v", err).Title("错误").Error()
306304
return
@@ -439,46 +437,3 @@ func isMacDarkMode() bool {
439437
}
440438
return string(out) == "Dark\n"
441439
}
442-
443-
func StartOADINServerTray(logPath string, pidFilePath string) error {
444-
logFile, err := os.OpenFile(logPath, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0o600)
445-
if err != nil {
446-
return fmt.Errorf("failed to open log file: %v", err)
447-
}
448-
defer logFile.Close()
449-
//appExe, err := os.Executable()
450-
//if err != nil {
451-
// return fmt.Errorf("failed to get executable path: %v", err)
452-
//}
453-
454-
oadinExe := "oadin"
455-
if runtime.GOOS == "windows" {
456-
oadinExe = "oadin.exe"
457-
}
458-
if runtime.GOOS == "darwin" {
459-
oadinExe = filepath.Join(constants.MacOadinExecPath, "oadin")
460-
if _, err = os.Stat(oadinExe); err != nil {
461-
return fmt.Errorf("failed to find oadin executable: %v", err)
462-
}
463-
}
464-
//execFile := filepath.Join(filepath.Dir(appExe), oadinExe)
465-
//fmt.Println("Starting oadin server: ", execFile)
466-
cmd := exec.Command(oadinExe, "server", "start")
467-
cmd.Stdout = logFile
468-
cmd.Stderr = logFile
469-
utils.SetCmdSysProcAttr(cmd)
470-
471-
if err := cmd.Start(); err != nil {
472-
return fmt.Errorf("failed to start oadin server: %v", err)
473-
}
474-
475-
// Save PID to file.
476-
pid := cmd.Process.Pid
477-
pidFile := filepath.Join(pidFilePath, "oadin.pid")
478-
if err := os.WriteFile(pidFile, []byte(fmt.Sprintf("%d", pid)), 0o644); err != nil {
479-
return fmt.Errorf("failed to save PID to file: %v", err)
480-
}
481-
482-
fmt.Printf("\roadin server started with PID: %d\n", cmd.Process.Pid)
483-
return nil
484-
}

0 commit comments

Comments
 (0)