Standardize gomobile usages
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
|||||||
"github.com/sagernet/sing-box/common/urltest"
|
"github.com/sagernet/sing-box/common/urltest"
|
||||||
"github.com/sagernet/sing-box/experimental/deprecated"
|
"github.com/sagernet/sing-box/experimental/deprecated"
|
||||||
"github.com/sagernet/sing-box/include"
|
"github.com/sagernet/sing-box/include"
|
||||||
|
"github.com/sagernet/sing-box/log"
|
||||||
"github.com/sagernet/sing-box/option"
|
"github.com/sagernet/sing-box/option"
|
||||||
E "github.com/sagernet/sing/common/exceptions"
|
E "github.com/sagernet/sing/common/exceptions"
|
||||||
"github.com/sagernet/sing/common/json"
|
"github.com/sagernet/sing/common/json"
|
||||||
@@ -103,6 +104,7 @@ func (s *StartedService) newInstance(profileContent string, overrideOptions *Ove
|
|||||||
i.clashServer = service.FromContext[adapter.ClashServer](ctx)
|
i.clashServer = service.FromContext[adapter.ClashServer](ctx)
|
||||||
i.pauseManager = service.FromContext[pause.Manager](ctx)
|
i.pauseManager = service.FromContext[pause.Manager](ctx)
|
||||||
i.cacheFile = service.FromContext[adapter.CacheFile](ctx)
|
i.cacheFile = service.FromContext[adapter.CacheFile](ctx)
|
||||||
|
log.SetStdLogger(boxInstance.LogFactory().Logger())
|
||||||
return i, nil
|
return i, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -362,7 +362,7 @@ func (c *CommandClient) handleStatusStream() {
|
|||||||
c.handler.Disconnected(err.Error())
|
c.handler.Disconnected(err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
c.handler.WriteStatus(StatusMessageFromGRPC(status))
|
c.handler.WriteStatus(statusMessageFromGRPC(status))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -381,7 +381,7 @@ func (c *CommandClient) handleGroupStream() {
|
|||||||
c.handler.Disconnected(err.Error())
|
c.handler.Disconnected(err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
c.handler.WriteGroups(OutboundGroupIteratorFromGRPC(groups))
|
c.handler.WriteGroups(outboundGroupIteratorFromGRPC(groups))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -447,7 +447,7 @@ func (c *CommandClient) handleConnectionsStream() {
|
|||||||
c.handler.Disconnected(err.Error())
|
c.handler.Disconnected(err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
libboxEvents := ConnectionEventsFromGRPC(events)
|
libboxEvents := connectionEventsFromGRPC(events)
|
||||||
c.handler.WriteConnectionEvents(libboxEvents)
|
c.handler.WriteConnectionEvents(libboxEvents)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -523,7 +523,7 @@ func (c *CommandClient) GetSystemProxyStatus() (*SystemProxyStatus, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return SystemProxyStatusFromGRPC(status), nil
|
return systemProxyStatusFromGRPC(status), nil
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ type CommandServerHandler interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewCommandServer(handler CommandServerHandler, platformInterface PlatformInterface) (*CommandServer, error) {
|
func NewCommandServer(handler CommandServerHandler, platformInterface PlatformInterface) (*CommandServer, error) {
|
||||||
ctx := BaseContext(platformInterface)
|
ctx := baseContext(platformInterface)
|
||||||
platformWrapper := &platformInterfaceWrapper{
|
platformWrapper := &platformInterfaceWrapper{
|
||||||
iif: platformInterface,
|
iif: platformInterface,
|
||||||
useProcFS: platformInterface.UseProcFS(),
|
useProcFS: platformInterface.UseProcFS(),
|
||||||
|
|||||||
@@ -32,11 +32,11 @@ type OutboundGroup struct {
|
|||||||
Selectable bool
|
Selectable bool
|
||||||
Selected string
|
Selected string
|
||||||
IsExpand bool
|
IsExpand bool
|
||||||
ItemList []*OutboundGroupItem
|
itemList []*OutboundGroupItem
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *OutboundGroup) GetItems() OutboundGroupItemIterator {
|
func (g *OutboundGroup) GetItems() OutboundGroupItemIterator {
|
||||||
return newIterator(g.ItemList)
|
return newIterator(g.itemList)
|
||||||
}
|
}
|
||||||
|
|
||||||
type OutboundGroupIterator interface {
|
type OutboundGroupIterator interface {
|
||||||
@@ -267,12 +267,12 @@ type Connection struct {
|
|||||||
Rule string
|
Rule string
|
||||||
Outbound string
|
Outbound string
|
||||||
OutboundType string
|
OutboundType string
|
||||||
ChainList []string
|
chainList []string
|
||||||
ProcessInfo *ProcessInfo
|
ProcessInfo *ProcessInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Connection) Chain() StringIterator {
|
func (c *Connection) Chain() StringIterator {
|
||||||
return newIterator(c.ChainList)
|
return newIterator(c.chainList)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Connection) DisplayDestination() string {
|
func (c *Connection) DisplayDestination() string {
|
||||||
@@ -292,7 +292,7 @@ type ConnectionIterator interface {
|
|||||||
HasNext() bool
|
HasNext() bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func StatusMessageFromGRPC(status *daemon.Status) *StatusMessage {
|
func statusMessageFromGRPC(status *daemon.Status) *StatusMessage {
|
||||||
if status == nil {
|
if status == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -309,7 +309,7 @@ func StatusMessageFromGRPC(status *daemon.Status) *StatusMessage {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func OutboundGroupIteratorFromGRPC(groups *daemon.Groups) OutboundGroupIterator {
|
func outboundGroupIteratorFromGRPC(groups *daemon.Groups) OutboundGroupIterator {
|
||||||
if groups == nil || len(groups.Group) == 0 {
|
if groups == nil || len(groups.Group) == 0 {
|
||||||
return newIterator([]*OutboundGroup{})
|
return newIterator([]*OutboundGroup{})
|
||||||
}
|
}
|
||||||
@@ -323,7 +323,7 @@ func OutboundGroupIteratorFromGRPC(groups *daemon.Groups) OutboundGroupIterator
|
|||||||
IsExpand: g.IsExpand,
|
IsExpand: g.IsExpand,
|
||||||
}
|
}
|
||||||
for _, item := range g.Items {
|
for _, item := range g.Items {
|
||||||
libboxGroup.ItemList = append(libboxGroup.ItemList, &OutboundGroupItem{
|
libboxGroup.itemList = append(libboxGroup.itemList, &OutboundGroupItem{
|
||||||
Tag: item.Tag,
|
Tag: item.Tag,
|
||||||
Type: item.Type,
|
Type: item.Type,
|
||||||
URLTestTime: item.UrlTestTime,
|
URLTestTime: item.UrlTestTime,
|
||||||
@@ -335,7 +335,7 @@ func OutboundGroupIteratorFromGRPC(groups *daemon.Groups) OutboundGroupIterator
|
|||||||
return newIterator(libboxGroups)
|
return newIterator(libboxGroups)
|
||||||
}
|
}
|
||||||
|
|
||||||
func ConnectionFromGRPC(conn *daemon.Connection) Connection {
|
func connectionFromGRPC(conn *daemon.Connection) Connection {
|
||||||
var processInfo *ProcessInfo
|
var processInfo *ProcessInfo
|
||||||
if conn.ProcessInfo != nil {
|
if conn.ProcessInfo != nil {
|
||||||
processInfo = &ProcessInfo{
|
processInfo = &ProcessInfo{
|
||||||
@@ -367,12 +367,12 @@ func ConnectionFromGRPC(conn *daemon.Connection) Connection {
|
|||||||
Rule: conn.Rule,
|
Rule: conn.Rule,
|
||||||
Outbound: conn.Outbound,
|
Outbound: conn.Outbound,
|
||||||
OutboundType: conn.OutboundType,
|
OutboundType: conn.OutboundType,
|
||||||
ChainList: conn.ChainList,
|
chainList: conn.ChainList,
|
||||||
ProcessInfo: processInfo,
|
ProcessInfo: processInfo,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func ConnectionEventFromGRPC(event *daemon.ConnectionEvent) *ConnectionEvent {
|
func connectionEventFromGRPC(event *daemon.ConnectionEvent) *ConnectionEvent {
|
||||||
if event == nil {
|
if event == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -384,13 +384,13 @@ func ConnectionEventFromGRPC(event *daemon.ConnectionEvent) *ConnectionEvent {
|
|||||||
ClosedAt: event.ClosedAt,
|
ClosedAt: event.ClosedAt,
|
||||||
}
|
}
|
||||||
if event.Connection != nil {
|
if event.Connection != nil {
|
||||||
conn := ConnectionFromGRPC(event.Connection)
|
conn := connectionFromGRPC(event.Connection)
|
||||||
libboxEvent.Connection = &conn
|
libboxEvent.Connection = &conn
|
||||||
}
|
}
|
||||||
return libboxEvent
|
return libboxEvent
|
||||||
}
|
}
|
||||||
|
|
||||||
func ConnectionEventsFromGRPC(events *daemon.ConnectionEvents) *ConnectionEvents {
|
func connectionEventsFromGRPC(events *daemon.ConnectionEvents) *ConnectionEvents {
|
||||||
if events == nil {
|
if events == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -398,14 +398,14 @@ func ConnectionEventsFromGRPC(events *daemon.ConnectionEvents) *ConnectionEvents
|
|||||||
Reset: events.Reset_,
|
Reset: events.Reset_,
|
||||||
}
|
}
|
||||||
for _, event := range events.Events {
|
for _, event := range events.Events {
|
||||||
if libboxEvent := ConnectionEventFromGRPC(event); libboxEvent != nil {
|
if libboxEvent := connectionEventFromGRPC(event); libboxEvent != nil {
|
||||||
libboxEvents.events = append(libboxEvents.events, libboxEvent)
|
libboxEvents.events = append(libboxEvents.events, libboxEvent)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return libboxEvents
|
return libboxEvents
|
||||||
}
|
}
|
||||||
|
|
||||||
func SystemProxyStatusFromGRPC(status *daemon.SystemProxyStatus) *SystemProxyStatus {
|
func systemProxyStatusFromGRPC(status *daemon.SystemProxyStatus) *SystemProxyStatus {
|
||||||
if status == nil {
|
if status == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -415,7 +415,7 @@ func SystemProxyStatusFromGRPC(status *daemon.SystemProxyStatus) *SystemProxySta
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func SystemProxyStatusToGRPC(status *SystemProxyStatus) *daemon.SystemProxyStatus {
|
func systemProxyStatusToGRPC(status *SystemProxyStatus) *daemon.SystemProxyStatus {
|
||||||
if status == nil {
|
if status == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ import (
|
|||||||
"github.com/sagernet/sing/service/filemanager"
|
"github.com/sagernet/sing/service/filemanager"
|
||||||
)
|
)
|
||||||
|
|
||||||
func BaseContext(platformInterface PlatformInterface) context.Context {
|
func baseContext(platformInterface PlatformInterface) context.Context {
|
||||||
dnsRegistry := include.DNSTransportRegistry()
|
dnsRegistry := include.DNSTransportRegistry()
|
||||||
if platformInterface != nil {
|
if platformInterface != nil {
|
||||||
if localTransport := platformInterface.LocalDNSTransport(); localTransport != nil {
|
if localTransport := platformInterface.LocalDNSTransport(); localTransport != nil {
|
||||||
@@ -45,7 +45,7 @@ func parseConfig(ctx context.Context, configContent string) (option.Options, err
|
|||||||
}
|
}
|
||||||
|
|
||||||
func CheckConfig(configContent string) error {
|
func CheckConfig(configContent string) error {
|
||||||
ctx := BaseContext(nil)
|
ctx := baseContext(nil)
|
||||||
options, err := parseConfig(ctx, configContent)
|
options, err := parseConfig(ctx, configContent)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -189,7 +189,7 @@ func (s *interfaceMonitorStub) MyInterface() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func FormatConfig(configContent string) (*StringBox, error) {
|
func FormatConfig(configContent string) (*StringBox, error) {
|
||||||
options, err := parseConfig(BaseContext(nil), configContent)
|
options, err := parseConfig(baseContext(nil), configContent)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user