mirror of
https://wget.la/https://github.com/leookun/cursor-byok
synced 2026-08-19 04:27:02 +08:00
v0.3.8
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
package bridge
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"strings"
|
||||
|
||||
"cursor/internal/ads"
|
||||
|
||||
"github.com/pkg/browser"
|
||||
)
|
||||
|
||||
type AdRuntime = ads.Runtime
|
||||
type AdWindowConfig = ads.WindowConfig
|
||||
|
||||
type AdService struct {
|
||||
core *ads.Service
|
||||
}
|
||||
|
||||
func NewAdService(core *ads.Service) *AdService {
|
||||
return &AdService{core: core}
|
||||
}
|
||||
|
||||
func (service *AdService) GetAdRuntime() (AdRuntime, error) {
|
||||
if service == nil || service.core == nil {
|
||||
return AdRuntime{}, fmt.Errorf("广告服务未初始化")
|
||||
}
|
||||
return service.core.GetRuntime(context.Background())
|
||||
}
|
||||
|
||||
func (service *AdService) OpenExternalURL(rawURL string) error {
|
||||
parsed, err := url.Parse(strings.TrimSpace(rawURL))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
scheme := strings.ToLower(strings.TrimSpace(parsed.Scheme))
|
||||
if scheme != "http" && scheme != "https" {
|
||||
return fmt.Errorf("仅支持打开 http/https 地址")
|
||||
}
|
||||
if strings.TrimSpace(parsed.Host) == "" {
|
||||
return fmt.Errorf("地址缺少主机名")
|
||||
}
|
||||
return browser.OpenURL(parsed.String())
|
||||
}
|
||||
Reference in New Issue
Block a user