Files
Ant-Browser/backend/app_launchcode.go
T
Ant Browser Release Bot 6f58a6c19a publish: 1.0.0 snapshot (bad2ec1)
channel: master
version: 1.0.0
source-ref: master
published-at-utc: 2026-03-13T15:19:28Z
2026-03-13 23:19:29 +08:00

84 lines
2.5 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package backend
import (
"ant-chrome/backend/internal/browser"
"ant-chrome/backend/internal/launchcode"
"fmt"
)
// StartInstance 实现 launchcode.BrowserStarter 接口
func (a *App) StartInstance(profileId string) (*browser.Profile, error) {
return a.BrowserInstanceStart(profileId)
}
// StartInstanceWithParams 实现 launchcode.BrowserStarterWithParams 接口
func (a *App) StartInstanceWithParams(profileId string, params launchcode.LaunchRequestParams) (*browser.Profile, error) {
return a.BrowserInstanceStartWithParams(profileId, params.LaunchArgs, params.StartURLs, params.SkipDefaultStartURLs)
}
// BrowserProfileGetCode 获取实例的 LaunchCodeWails 绑定)
func (a *App) BrowserProfileGetCode(profileId string) (string, error) {
if a.launchCodeSvc == nil {
return "", nil
}
return a.launchCodeSvc.EnsureCode(profileId)
}
// BrowserProfileRegenerateCode 重新生成实例的 LaunchCodeWails 绑定)
func (a *App) BrowserProfileRegenerateCode(profileId string) (string, error) {
if a.launchCodeSvc == nil {
return "", nil
}
return a.launchCodeSvc.RegenerateCode(profileId)
}
// BrowserProfileSetCode 自定义设置实例 LaunchCodeWails 绑定)
func (a *App) BrowserProfileSetCode(profileId string, code string) (string, error) {
if a.launchCodeSvc == nil {
return "", nil
}
return a.launchCodeSvc.SetCode(profileId, code)
}
// BrowserInstanceStartByCode 通过 LaunchCode 启动实例(Wails 绑定)
func (a *App) BrowserInstanceStartByCode(code string) (*browser.Profile, error) {
if a.launchCodeSvc == nil {
return nil, fmt.Errorf("launch code service not initialized")
}
profileId, err := a.launchCodeSvc.Resolve(code)
if err != nil {
return nil, err
}
return a.BrowserInstanceStart(profileId)
}
// GetLaunchServerInfo 返回 LaunchServer 的当前监听信息(Wails 绑定)
func (a *App) GetLaunchServerInfo() map[string]interface{} {
preferredPort := 0
if a.config != nil {
preferredPort = a.config.LaunchServer.Port
}
actualPort := 0
if a.launchServer != nil {
actualPort = a.launchServer.Port()
}
info := map[string]interface{}{
"host": "127.0.0.1",
"preferredPort": preferredPort,
"port": actualPort,
"ready": actualPort > 0,
}
if actualPort > 0 {
info["baseUrl"] = fmt.Sprintf("http://127.0.0.1:%d", actualPort)
} else {
info["baseUrl"] = ""
}
return info
}
// 确保编译器检查 App 实现了 BrowserStarter 接口
var _ launchcode.BrowserStarter = (*App)(nil)
var _ launchcode.BrowserStarterWithParams = (*App)(nil)