Skip to content

Commit

Permalink
Start up sequence callback (#1070)
Browse files Browse the repository at this point in the history
* expose callback to internal sdk.

* added callbacks.

* Added callback for ui.

* Implemented loading shimmer for VPN tap.

* Implemented internet checker.

* Disable VPN if internet connection not available.

* added logs and use dynamic vaules.

* Update GeneratedPluginRegistrant.swift

* Show init message on startup for desktop

* updated internal sdk to new flashlight

* 🚀 Add startup sequence callback for Android

* Remove InitCallback from app.go

* Remove network warning from android and use flutter one.

* Track timer while startup android.

* change method name.

* Change switch package.

* Fix other small UI issue.

* Fixed conflicts.

* PR review udpates.

* update go.opentelemetry.io/otel/sdk/metric

* update how new instance of bandit is created in ios code

* switch back to same flashlight version.

* Update flashlight again

* Update flashlight again

* Update flashlight again

---------

Co-authored-by: atavism <[email protected]>
  • Loading branch information
jigar-f and atavism authored Jun 10, 2024
1 parent d7582b2 commit b397e87
Show file tree
Hide file tree
Showing 34 changed files with 897 additions and 221 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ abstract class SessionManager(application: Application) : Session {
adsBlocked: Long,
hasSucceedingProxy: Boolean,
) {
Logger.debug("updateStats", "city $city, country $country, countryCode $countryCode")
Logger.debug("updateStats", "city $city, country $country, countryCode $countryCode hasSucceedingProxy $hasSucceedingProxy")
if (hasUpdatedStats.compareAndSet(false, true)) {
// The first time that we get the stats, hasSucceedingProxy is always false because we
// haven't hit any proxies yet. So, we just ignore the stats.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,12 @@ public DnsDetector(Context context, String fakeDnsIP) {
public void onAvailable(@NonNull Network network) {
Logger.debug(TAG, "Adding available network");
allNetworks.put(network, "");
EventBus.getDefault().postSticky(Event.NetworkAvailable);
}

@Override
public void onLost(@NonNull Network network) {
Logger.debug(TAG, "Removing lost network");
allNetworks.remove(network);
publishNetworkAvailability();
}
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,24 @@ class LanternSessionManager(application: Application) : SessionManager(applicati
return prefs.getString(PROVIDER, "")
}

override fun setHasConfigFetched(hasConfig: Boolean) {
db.mutate {
it.put(PATH_HAS_CONFIG, hasConfig)
}
}

override fun setHasProxyFetched(hasProxy: Boolean) {
db.mutate {
it.put(PATH_HAS_PROXY, hasProxy)
}
}

override fun setOnSuccess(hasConnection: Boolean) {
db.mutate {
it.put(PATH_HAS_ONSUCESS, hasConnection)
}
}

fun setReferral(referralCode: String?) {
referral = referralCode
}
Expand Down Expand Up @@ -436,6 +454,10 @@ class LanternSessionManager(application: Application) : SessionManager(applicati
private const val RENEWAL_LAST_SEEN = "renewalseen"
private const val PROVIDER = "provider"
private const val RESELLER_CODE = "resellercode"
private const val PATH_HAS_CONFIG = "hasConfigFetched"
private const val PATH_HAS_PROXY = "hasProxyFetched"
private const val PATH_HAS_ONSUCESS = "hasOnSuccess"


// other constants
private const val DEFAULT_ONE_YEAR_COST: Long = 3200
Expand Down
10 changes: 10 additions & 0 deletions assets/images/cloud_off.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions assets/locales/en-us.po
Original file line number Diff line number Diff line change
Expand Up @@ -1527,6 +1527,31 @@ msgstr "Sorry, we are unable to load that page at the moment, please tap ‘Refr
msgid "refresh"
msgstr "Refresh"

msgid "check_your_internet_connection"
msgstr "Check your internet connection"

msgid "please_try"
msgstr "Please try"

msgid "turning_off_airplane_mode"
msgstr "Turning off airplane mode"

msgid "turning_on_mobile_data_or_wifi"
msgstr "Turning on mobile data or wifi"

msgid "check_the_signal_in_your_area"
msgstr "Check the signal in your area"

msgid "got_it"
msgstr "Got it"

msgid "fetching_configuration"
msgstr "Fetching Configuration"

msgid "establish_connection_to_server"
msgstr "Establish connection to server"


msgid "file_size_limit_title"
msgstr "Limit Reached"

Expand Down
74 changes: 44 additions & 30 deletions desktop/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,15 @@ var (
func init() {
autoupdate.Version = common.ApplicationVersion
autoupdate.PublicKey = []byte(packagePublicKey)

}

// App is the core of the Lantern desktop application, in the form of a library.
type App struct {
hasExited int64
fetchedGlobalConfig int32
fetchedProxiesConfig int32
hasSucceedingProxy int32

Flags flashlight.Flags
configDir string
Expand Down Expand Up @@ -187,15 +189,6 @@ func (app *App) Run(isMain bool) {
}()
}

if app.Flags.Initialize {
app.statsTracker.AddListener(func(newStats stats.Stats) {
if newStats.HasSucceedingProxy {
log.Debug("Finished initialization")
app.Exit(nil)
}
})
}

cacheDir, err := os.UserCacheDir()
if err != nil {
cacheDir = os.TempDir()
Expand All @@ -214,14 +207,22 @@ func (app *App) Run(isMain bool) {
func() bool { return false }, // on desktop, we do not allow private hosts
app.settings.IsAutoReport,
app.Flags.AsMap(),
app.onConfigUpdate,
app.onProxiesUpdate,
app.settings,
app.statsTracker,
app.IsPro,
app.settings.GetLanguage,
func(addr string) (string, error) { return addr, nil }, // no dnsgrab reverse lookups on desktop
app.analyticsSession.EventWithLabel,
flashlight.WithOnConfig(app.onConfigUpdate),
flashlight.WithOnProxies(app.onProxiesUpdate),
flashlight.WithOnDialError(func(err error, hasSucceeding bool) {
if err != nil && !hasSucceeding {
app.onSucceedingProxy(hasSucceeding)
}
}),
flashlight.WithOnSucceedingProxy(func() {
app.onSucceedingProxy(true)
}),
)
if err != nil {
app.Exit(err)
Expand All @@ -240,6 +241,7 @@ func (app *App) Run(isMain bool) {
app.startFeaturesService(geolookup.OnRefresh(), chUserChanged, chProStatusChanged, app.chGlobalConfigChanged)

notifyConfigSaveErrorOnce := new(sync.Once)

app.flashlight.SetErrorHandler(func(t flashlight.HandledErrorType, err error) {
switch t {
case flashlight.ErrorTypeProxySaveFailure, flashlight.ErrorTypeConfigSaveFailure:
Expand Down Expand Up @@ -354,20 +356,6 @@ func (app *App) beforeStart(listenAddr string) {
app.AddExitFunc("stopping notifier", notifier.NotificationsLoop(app.analyticsSession))
}

// Connect turns on proxying
func (app *App) Connect() {
app.analyticsSession.Event("systray-menu", "connect")
ops.Begin("connect").End()
app.settings.SetDisconnected(false)
}

// Disconnect turns off proxying
func (app *App) Disconnect() {
app.analyticsSession.Event("systray-menu", "disconnect")
ops.Begin("disconnect").End()
app.settings.SetDisconnected(true)
}

// GetLanguage returns the user language
func (app *App) GetLanguage() string {
return app.settings.GetLanguage()
Expand Down Expand Up @@ -429,9 +417,8 @@ func (app *App) afterStart(cl *flashlightClient.Client) {
}

func (app *App) onConfigUpdate(cfg *config.Global, src config.Source) {
if src == config.Fetched {
atomic.StoreInt32(&app.fetchedGlobalConfig, 1)
}
log.Debugf("[Startup Desktop] Got config update from %v", src)
atomic.StoreInt32(&app.fetchedGlobalConfig, 1)
autoupdate.Configure(cfg.UpdateServerURL, cfg.AutoUpdateCA, func() string {
return "/img/lantern_logo.png"
})
Expand All @@ -447,9 +434,36 @@ func (app *App) onConfigUpdate(cfg *config.Global, src config.Source) {
}

func (app *App) onProxiesUpdate(proxies []bandit.Dialer, src config.Source) {
if src == config.Fetched {
atomic.StoreInt32(&app.fetchedProxiesConfig, 1)
log.Debugf("[Startup Desktop] Got proxies update from %v", src)
atomic.StoreInt32(&app.fetchedProxiesConfig, 1)
}

func (app *App) onSucceedingProxy(succeeding bool) {
hasSucceedingProxy := int32(0)
if succeeding {
hasSucceedingProxy = 1
}
atomic.StoreInt32(&app.hasSucceedingProxy, hasSucceedingProxy)
log.Debugf("[Startup Desktop] onSucceedingProxy %v", succeeding)
}

// HasSucceedingProxy returns whether or not the app is currently configured with any succeeding proxies
func (app *App) HasSucceedingProxy() bool {
return atomic.LoadInt32(&app.hasSucceedingProxy) == 1
}

func (app *App) GetHasConfigFetched() bool {

log.Debugf("Global config fetched: %v, Proxies config fetched: %v")
return atomic.LoadInt32(&app.fetchedGlobalConfig) == 1
}

func (app *App) GetHasProxyFetched() bool {
return atomic.LoadInt32(&app.fetchedProxiesConfig) == 1
}

func (app *App) GetOnSuccess() bool {
return app.HasSucceedingProxy()
}

// AddExitFunc adds a function to be called before the application exits.
Expand Down
31 changes: 29 additions & 2 deletions desktop/lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ func start() {
})

a = app.NewApp(flags, cdir, proClient, settings)

go func() {
err := fetchOrCreate()
if err != nil {
Expand Down Expand Up @@ -139,6 +138,30 @@ func start() {
}()
}

//export hasProxyFected
func hasProxyFected() *C.char {
if a.GetHasProxyFetched() {
return C.CString(string("true"))
}
return C.CString(string("false"))
}

//export hasConfigFected
func hasConfigFected() *C.char {
if a.GetHasConfigFetched() {
return C.CString(string("true"))
}
return C.CString(string("false"))
}

//export onSuccess
func onSuccess() *C.char {
if a.GetOnSuccess() {
return C.CString(string("true"))
}
return C.CString(string("false"))
}

func fetchOrCreate() error {
settings := a.Settings()
userID := settings.GetUserID()
Expand Down Expand Up @@ -485,7 +508,11 @@ func vpnStatus() *C.char {

//export hasSucceedingProxy
func hasSucceedingProxy() *C.char {
return C.CString("true")
hasSucceedingProxy := a.HasSucceedingProxy()
if hasSucceedingProxy {
return C.CString("true")
}
return C.CString("false")
}

//export onBoardingStatus
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module github.com/getlantern/lantern-client

go 1.22.0

// replace github.com/getlantern/flashlight/v7 => ../flashlight
//replace github.com/getlantern/flashlight/v7 => ../flashlight

// replace github.com/getlantern/fronted => ../fronted

Expand Down Expand Up @@ -42,7 +42,7 @@ require (
github.com/getlantern/eventual v1.0.0
github.com/getlantern/eventual/v2 v2.0.2
github.com/getlantern/filepersist v0.0.0-20210901195658-ed29a1cb0b7c
github.com/getlantern/flashlight/v7 v7.6.80
github.com/getlantern/flashlight/v7 v7.6.83
github.com/getlantern/fronted v0.0.0-20230601004823-7fec719639d8
github.com/getlantern/golog v0.0.0-20230503153817-8e72de7e0a65
github.com/getlantern/i18n v0.0.0-20181205222232-2afc4f49bb1c
Expand All @@ -69,6 +69,7 @@ require (
github.com/gorilla/mux v1.8.0
github.com/gorilla/websocket v1.5.0
github.com/jackpal/gateway v1.0.13
github.com/joho/godotenv v1.5.1
github.com/leekchan/accounting v1.0.0
github.com/shopspring/decimal v1.4.0
github.com/stretchr/testify v1.9.0
Expand Down Expand Up @@ -219,7 +220,6 @@ require (
github.com/hashicorp/golang-lru v1.0.2 // indirect
github.com/huandu/xstrings v1.4.0 // indirect
github.com/jaffee/commandeer v0.6.0 // indirect
github.com/joho/godotenv v1.5.1 // indirect
github.com/keighl/mandrill v0.0.0-20170605120353-1775dd4b3b41 // indirect
github.com/kennygrant/sanitize v1.2.4 // indirect
github.com/klauspost/compress v1.17.6 // indirect
Expand Down
16 changes: 10 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -280,10 +280,16 @@ github.com/getlantern/fdcount v0.0.0-20210503151800-5decd65b3731/go.mod h1:XZwE+
github.com/getlantern/filepersist v0.0.0-20160317154340-c5f0cd24e799/go.mod h1:8DGAx0LNUfXNnEH+fXI0s3OCBA/351kZCiz/8YSK3i8=
github.com/getlantern/filepersist v0.0.0-20210901195658-ed29a1cb0b7c h1:mcz27xtAkb1OuOLBct/uFfL1p3XxAIcFct82GbT+UZM=
github.com/getlantern/filepersist v0.0.0-20210901195658-ed29a1cb0b7c/go.mod h1:8DGAx0LNUfXNnEH+fXI0s3OCBA/351kZCiz/8YSK3i8=
github.com/getlantern/flashlight/v7 v7.6.79 h1:GAvX9yuCJ3S8qB680gFYM6D/zwmAEk9FcC+LE8hgEGQ=
github.com/getlantern/flashlight/v7 v7.6.79/go.mod h1:1zs3W2WkM5eqJ2fhEsMa8lo6hqmDW8EwokpT7TQ/MrI=
github.com/getlantern/flashlight/v7 v7.6.80 h1:RZBLtFMUDy1CpORFaz9xMTE04ZBTf3yHhTCP1XbLkyQ=
github.com/getlantern/flashlight/v7 v7.6.80/go.mod h1:1zs3W2WkM5eqJ2fhEsMa8lo6hqmDW8EwokpT7TQ/MrI=
github.com/getlantern/flashlight/v7 v7.6.80-0.20240530173801-eaa86a1afe9f h1:Bp5g6x9RHyXSv/N2K0AgLIWY5/ym5qsITsjFWcH6SPY=
github.com/getlantern/flashlight/v7 v7.6.80-0.20240530173801-eaa86a1afe9f/go.mod h1:1zs3W2WkM5eqJ2fhEsMa8lo6hqmDW8EwokpT7TQ/MrI=
github.com/getlantern/flashlight/v7 v7.6.82-0.20240606214531-37c147431d2b h1:17x0t1q6LzA+qYG2EH51r+f8oALh+0kQCfqpEveu9LY=
github.com/getlantern/flashlight/v7 v7.6.82-0.20240606214531-37c147431d2b/go.mod h1:1zs3W2WkM5eqJ2fhEsMa8lo6hqmDW8EwokpT7TQ/MrI=
github.com/getlantern/flashlight/v7 v7.6.82-0.20240606214720-ea08484f5c06 h1:6QUqgrCiYvKSyS9CMag5C7A+3odKaXZ4D1obMPg9jnE=
github.com/getlantern/flashlight/v7 v7.6.82-0.20240606214720-ea08484f5c06/go.mod h1:1zs3W2WkM5eqJ2fhEsMa8lo6hqmDW8EwokpT7TQ/MrI=
github.com/getlantern/flashlight/v7 v7.6.82 h1:D+sUCKvg/iA77j/Y1yQ9NqSAUWNe8GQ4Dm2LefanRII=
github.com/getlantern/flashlight/v7 v7.6.82/go.mod h1:1zs3W2WkM5eqJ2fhEsMa8lo6hqmDW8EwokpT7TQ/MrI=
github.com/getlantern/flashlight/v7 v7.6.83 h1:623tGo7fhdMOD3O2b0PTQnREdEtfC+GiDjkxIhDEiks=
github.com/getlantern/flashlight/v7 v7.6.83/go.mod h1:1zs3W2WkM5eqJ2fhEsMa8lo6hqmDW8EwokpT7TQ/MrI=
github.com/getlantern/framed v0.0.0-20190601192238-ceb6431eeede h1:yrU6Px3ZkvCsDLPryPGi6FN+2iqFPq+JeCb7EFoDBhw=
github.com/getlantern/framed v0.0.0-20190601192238-ceb6431eeede/go.mod h1:nhnoiS6DE6zfe+BaCMU4YI01UpsuiXnDqM5S8jxHuuI=
github.com/getlantern/fronted v0.0.0-20230601004823-7fec719639d8 h1:r/Z/SPPIfLXDI3QA7/tE6nOfPncrqeUPDjiFjnNGP50=
Expand Down Expand Up @@ -987,8 +993,6 @@ go.opentelemetry.io/otel/metric v1.27.0 h1:hvj3vdEKyeCi4YaYfNjv2NUje8FqKqUY8IlF0
go.opentelemetry.io/otel/metric v1.27.0/go.mod h1:mVFgmRlhljgBiuk/MP/oKylr4hs85GZAylncepAX/ak=
go.opentelemetry.io/otel/sdk v1.27.0 h1:mlk+/Y1gLPLn84U4tI8d3GNJmGT/eXe3ZuOXN9kTWmI=
go.opentelemetry.io/otel/sdk v1.27.0/go.mod h1:Ha9vbLwJE6W86YstIywK2xFfPjbWlCuwPtMkKdz/Y4A=
go.opentelemetry.io/otel/sdk/metric v1.19.0 h1:EJoTO5qysMsYCa+w4UghwFV/ptQgqSL/8Ni+hx+8i1k=
go.opentelemetry.io/otel/sdk/metric v1.19.0/go.mod h1:XjG0jQyFJrv2PbMvwND7LwCEhsJzCzV5210euduKcKY=
go.opentelemetry.io/otel/sdk/metric v1.27.0 h1:5uGNOlpXi+Hbo/DRoI31BSb1v+OGcpv2NemcCrOL8gI=
go.opentelemetry.io/otel/sdk/metric v1.27.0/go.mod h1:we7jJVrYN2kh3mVBlswtPU22K0SA+769l93J6bsyvqw=
go.opentelemetry.io/otel/trace v1.27.0 h1:IqYb813p7cmbHk0a5y6pD5JPakbVfftRXABGt5/Rscw=
Expand Down
Loading

0 comments on commit b397e87

Please sign in to comment.