Implement new deprecated warnings

This commit is contained in:
世界
2024-11-07 12:02:36 +08:00
parent 74b16ff814
commit a21eaa7de5
10 changed files with 74 additions and 23 deletions

View File

@@ -78,9 +78,36 @@ var OptionTUNAddressX = Note{
MigrationLink: "https://sing-box.sagernet.org/migration/#tun-address-fields-are-merged",
}
var OptionSpecialOutbounds = Note{
Name: "special-outbounds",
Description: "legacy special outbounds",
DeprecatedVersion: "1.11.0",
ScheduledVersion: "1.13.0",
MigrationLink: "https://sing-box.sagernet.org/migration/#migrate-legacy-special-outbounds-to-rule-actions",
}
var OptionInboundOptions = Note{
Name: "inbound-options",
Description: "legacy inbound fields",
DeprecatedVersion: "1.11.0",
ScheduledVersion: "1.13.0",
MigrationLink: "https://sing-box.sagernet.org/migration/#migrate-legacy-special-outbounds-to-rule-actions",
}
var OptionLegacyDNSRouteOptions = Note{
Name: "legacy-dns-route-options",
Description: "legacy dns route options",
DeprecatedVersion: "1.11.0",
ScheduledVersion: "1.12.0",
MigrationLink: "https://sing-box.sagernet.org/migration/#migrate-legacy-dns-route-options-to-rule-actions",
}
var Options = []Note{
OptionBadMatchSource,
OptionGEOIP,
OptionGEOSITE,
OptionTUNAddressX,
OptionSpecialOutbounds,
OptionInboundOptions,
OptionLegacyDNSRouteOptions,
}

View File

@@ -2,6 +2,7 @@ package deprecated
import (
"context"
"runtime/debug"
"github.com/sagernet/sing/service"
)
@@ -13,6 +14,7 @@ type Manager interface {
func Report(ctx context.Context, feature Note) {
manager := service.FromContext[Manager](ctx)
if manager == nil {
debug.PrintStack()
return
}
manager.ReportDeprecated(feature)

View File

@@ -7,15 +7,23 @@ import (
"github.com/sagernet/sing/common/logger"
)
type envManager struct {
logger logger.Logger
type stderrManager struct {
logger logger.Logger
reported map[string]bool
}
func NewEnvManager(logger logger.Logger) Manager {
return &envManager{logger: logger}
func NewStderrManager(logger logger.Logger) Manager {
return &stderrManager{
logger: logger,
reported: make(map[string]bool),
}
}
func (f *envManager) ReportDeprecated(feature Note) {
func (f *stderrManager) ReportDeprecated(feature Note) {
if f.reported[feature.Name] {
return
}
f.reported[feature.Name] = true
if !feature.Impending() {
f.logger.Warn(feature.MessageWithLink())
return