mirror of
https://github.com/black-ant/Ant-Browser.git
synced 2026-07-14 18:48:55 +08:00
channel: master version: 1.0.0 source-ref: master published-at-utc: 2026-03-13T15:19:28Z
84 lines
2.5 KiB
Go
84 lines
2.5 KiB
Go
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 获取实例的 LaunchCode(Wails 绑定)
|
||
func (a *App) BrowserProfileGetCode(profileId string) (string, error) {
|
||
if a.launchCodeSvc == nil {
|
||
return "", nil
|
||
}
|
||
return a.launchCodeSvc.EnsureCode(profileId)
|
||
}
|
||
|
||
// BrowserProfileRegenerateCode 重新生成实例的 LaunchCode(Wails 绑定)
|
||
func (a *App) BrowserProfileRegenerateCode(profileId string) (string, error) {
|
||
if a.launchCodeSvc == nil {
|
||
return "", nil
|
||
}
|
||
return a.launchCodeSvc.RegenerateCode(profileId)
|
||
}
|
||
|
||
// BrowserProfileSetCode 自定义设置实例 LaunchCode(Wails 绑定)
|
||
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)
|