@@ -33,8 +33,6 @@ const (
3333 EventTypeConfig EventType = "config"
3434 EventTypeServerLocation EventType = "server-location"
3535 DefaultLogLevel = "trace"
36- defaultAdBlockURL = "https://raw.githubusercontent.com/REIJI007/AdBlock_Rule_For_Sing-box/main/adblock_reject.json"
37- adBlockSettingsFile = "adblock.json"
3836)
3937
4038// LanternCore is the main structure accessing the Lantern backend.
@@ -45,7 +43,6 @@ type LanternCore struct {
4543 apiClient * api.APIClient
4644 initOnce sync.Once
4745 eventEmitter utils.FlutterEventEmitter
48- adBlocker * adBlockerStub
4946}
5047
5148var (
@@ -130,13 +127,19 @@ type Ads interface {
130127 IsBlockAdsEnabled () bool
131128}
132129
130+ type SmartRouting interface {
131+ SetSmartRoutingEnabled (bool ) error
132+ IsSmartRoutingEnabled () bool
133+ }
134+
133135type Core interface {
134136 App
135137 User
136138 Payment
137139 PrivateServer
138140 SplitTunnel
139141 Ads
142+ SmartRouting
140143}
141144
142145// Make sure LanternCore implements the Core interface
@@ -189,7 +192,6 @@ func (lc *LanternCore) initialize(opts *utils.Opts, eventEmitter utils.FlutterEv
189192 lc .serverManager = lc .rad .ServerManager ()
190193 lc .apiClient = lc .rad .APIHandler ()
191194 lc .eventEmitter = eventEmitter
192- lc .adBlocker = newAdBlockerStub (settings .GetString (settings .DataPathKey ), defaultAdBlockURL )
193195
194196 // Listen for config updates and notify Flutter
195197 events .Subscribe (func (evt config.NewConfigEvent ) {
@@ -737,88 +739,24 @@ func (lc *LanternCore) RevokeServerManagerInvite(ip, port, accessToken, inviteNa
737739}
738740
739741func (lc * LanternCore ) SetBlockAdsEnabled (enabled bool ) error {
740- if lc .adBlocker == nil {
741- lc .adBlocker = newAdBlockerStub (settings .GetString (settings .DataPathKey ), defaultAdBlockURL )
742- }
743- if err := lc .adBlocker .SetEnabled (enabled ); err != nil {
744- return err
745- }
746- return nil
742+ return vpn .SetAdBlock (enabled )
747743}
748744
749745func (lc * LanternCore ) IsBlockAdsEnabled () bool {
750- if lc .adBlocker == nil {
751- return false
752- }
753- return lc .adBlocker .IsEnabled ()
754- }
755-
756- func (lc * LanternCore ) AddServerBasedOnURLs (urls string , skipCertVerification bool ) error {
757- slog .Debug ("Adding server based on URLs" , "urls" , urls , "skipCertVerification" , skipCertVerification )
758- return lc .serverManager .AddServerBasedOnURLs (context .Background (), urls , skipCertVerification )
759- }
760-
761- type adBlockerStub struct {
762- mu sync.RWMutex
763- path string
764- enabled bool
765- url string
766- }
767-
768- type adBlockSettings struct {
769- Enabled bool `json:"enabled"`
770- URL string `json:"url,omitempty"`
746+ return vpn .AdBlockEnabled ()
771747}
772748
773- func newAdBlockerStub (basePath , defaultURL string ) * adBlockerStub {
774- ab := & adBlockerStub {
775- path : filepath .Join (basePath , adBlockSettingsFile ),
776- url : defaultURL ,
777- }
778- ab .load ()
779- return ab
749+ func (lc * LanternCore ) SetSmartRoutingEnabled (enabled bool ) error {
750+ return vpn .SetSmartRouting (enabled )
780751}
781752
782- func (a * adBlockerStub ) load () {
783- a .mu .Lock ()
784- defer a .mu .Unlock ()
785- data , err := os .ReadFile (a .path )
786- if err != nil || len (data ) == 0 {
787- return
788- }
789- var s adBlockSettings
790- if err := json .Unmarshal (data , & s ); err == nil {
791- a .enabled = s .Enabled
792- if s .URL != "" {
793- a .url = s .URL
794- }
795- }
753+ func (lc * LanternCore ) IsSmartRoutingEnabled () bool {
754+ return vpn .SmartRoutingEnabled ()
796755}
797756
798- func (a * adBlockerStub ) save () error {
799- a .mu .RLock ()
800- defer a .mu .RUnlock ()
801- b , err := json .Marshal (adBlockSettings {
802- Enabled : a .enabled ,
803- URL : a .url ,
804- })
805- if err != nil {
806- return err
807- }
808- return os .WriteFile (a .path , b , 0644 )
809- }
810-
811- func (a * adBlockerStub ) SetEnabled (v bool ) error {
812- a .mu .Lock ()
813- a .enabled = v
814- a .mu .Unlock ()
815- return a .save ()
816- }
817-
818- func (a * adBlockerStub ) IsEnabled () bool {
819- a .mu .RLock ()
820- defer a .mu .RUnlock ()
821- return a .enabled
757+ func (lc * LanternCore ) AddServerBasedOnURLs (urls string , skipCertVerification bool ) error {
758+ slog .Debug ("Adding server based on URLs" , "urls" , urls , "skipCertVerification" , skipCertVerification )
759+ return lc .serverManager .AddServerBasedOnURLs (context .Background (), urls , skipCertVerification )
822760}
823761
824762// splitCSVClean splits a comma-separated string into a stable list
0 commit comments