Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Start up sequence callback #1070

Merged
merged 33 commits into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
f50101f
expose callback to internal sdk.
jigar-f Apr 29, 2024
d09d012
added callbacks.
jigar-f May 1, 2024
811894b
Merge branch 'main' into jigar/init-callback
jigar-f May 6, 2024
1a82709
Added callback for ui.
jigar-f May 7, 2024
a125a3f
Implemented loading shimmer for VPN tap.
jigar-f May 8, 2024
091bb7e
Implemented internet checker.
jigar-f May 8, 2024
91f1c6f
Disable VPN if internet connection not available.
jigar-f May 8, 2024
595aeb5
added logs and use dynamic vaules.
jigar-f May 8, 2024
dfea544
Update GeneratedPluginRegistrant.swift
jigar-f May 8, 2024
062ba3c
Show init message on startup for desktop
jigar-f May 9, 2024
e3598e3
updated internal sdk to new flashlight
jigar-f May 10, 2024
d381ed9
🚀 Add startup sequence callback for Android
jigar-f May 10, 2024
8c886b6
Remove InitCallback from app.go
jigar-f May 13, 2024
6cdb9ba
Remove network warning from android and use flutter one.
jigar-f May 13, 2024
f3616f9
Track timer while startup android.
jigar-f May 13, 2024
550ff9c
change method name.
jigar-f May 13, 2024
158bb46
Change switch package.
jigar-f May 16, 2024
eb0531a
Fix other small UI issue.
jigar-f May 16, 2024
99f6ae1
Merge branch 'main' into jigar/init-callback
jigar-f May 22, 2024
f5a6944
Fixed conflicts.
jigar-f May 22, 2024
50e3bc2
merge latest, update flashlight
atavism May 24, 2024
96c8500
PR review udpates.
jigar-f May 28, 2024
93d468a
Merge branch 'main' into jigar/init-callback
jigar-f May 28, 2024
a3ae639
Update flashlight, merge latest
atavism Jun 3, 2024
cda3ae9
update go.opentelemetry.io/otel/sdk/metric
atavism Jun 3, 2024
2dcb755
update how new instance of bandit is created in ios code
atavism Jun 3, 2024
b4624f8
Merge branch 'main' into jigar/init-callback
jigar-f Jun 6, 2024
3266fd9
switch back to same flashlight version.
jigar-f Jun 6, 2024
6799410
Update flashlight again
atavism Jun 7, 2024
538d433
Update flashlight again
atavism Jun 7, 2024
e5182ff
Merge branch 'jigar/init-callback' of github.com:getlantern/lantern-c…
atavism Jun 7, 2024
5fedaf5
Update flashlight again
atavism Jun 7, 2024
03b3ce3
Merge remote-tracking branch 'origin/main' into jigar/init-callback
atavism Jun 7, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
atavism marked this conversation as resolved.
Show resolved Hide resolved
}

@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.
28 changes: 28 additions & 0 deletions assets/locales/en.po
Original file line number Diff line number Diff line change
Expand Up @@ -1526,3 +1526,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"




89 changes: 57 additions & 32 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 @@ -186,14 +188,9 @@ 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)
}
})
}
app.statsTracker.AddListener(func(newStats stats.Stats) {
app.onSucceedingProxy(newStats.HasSucceedingProxy)
})

cacheDir, err := os.UserCacheDir()
if err != nil {
Expand All @@ -209,18 +206,19 @@ func (app *App) Run(isMain bool) {
app.configDir,
app.Flags.VPN,
func() bool { return app.settings.GetDisconnected() }, // check whether we're disconnected
app.settings.GetProxyAll,
func() bool { return false }, // on desktop, we do not allow private hosts
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,
flashlightClient.WithOnConfig(app.onConfigUpdate),
flashlightClient.WithProxies(app.onProxiesUpdate),
flashlightClient.WithIsPro(app.IsPro),
flashlightClient.WithSucceedingProxy(app.onSucceedingProxy),
)
if err != nil {
app.Exit(err)
Expand All @@ -239,9 +237,10 @@ 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) {

app.flashlight.Client().SetErrorHandler(func(t flashlightClient.HandledErrorType, err error) {
switch t {
case flashlight.ErrorTypeProxySaveFailure, flashlight.ErrorTypeConfigSaveFailure:
case flashlightClient.ErrorTypeProxySaveFailure, flashlightClient.ErrorTypeConfigSaveFailure:
log.Errorf("failed to save config (%v): %v", t, err)

notifyConfigSaveErrorOnce.Do(func() {
Expand Down Expand Up @@ -282,7 +281,7 @@ func (app *App) setFeatures(enabledFeatures map[string]bool, values map[features
// (based on the env vars at build time or the user's settings/geolocation)
// and starts appropriate services
func (app *App) checkEnabledFeatures() {
enabledFeatures := app.flashlight.EnabledFeatures()
enabledFeatures := app.flashlight.Client().EnabledFeatures()

app.setFeatures(enabledFeatures, features.EnabledFeatures)

Expand Down Expand Up @@ -354,18 +353,18 @@ func (app *App) beforeStart(listenAddr string) {
}

// 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)
}
// 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 {
Expand Down Expand Up @@ -427,9 +426,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 @@ -445,9 +443,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 @@ -83,7 +83,6 @@ func start() {
})

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

go func() {
err := fetchOrCreate()
if err != nil {
Expand Down Expand Up @@ -132,6 +131,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 @@ -477,7 +500,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
2 changes: 1 addition & 1 deletion 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
atavism marked this conversation as resolved.
Show resolved Hide resolved

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

Expand Down
4 changes: 0 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,6 @@ 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.75 h1:wIGWerqUtifHwtmuMAW0nrViTUUCMMrdR7y/mZ/wsFk=
github.com/getlantern/flashlight/v7 v7.6.75/go.mod h1:GQtpdfigs9k+aoqSdxh2qTdRtAbktJSE5u1Sx3IsgW0=
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 @@ -962,8 +960,6 @@ go.etcd.io/bbolt v1.3.7/go.mod h1:N9Mkw9X8x5fupy0IKsmuqVtoGDyxsaDlbk4Rd05IAQw=
go.opencensus.io v0.20.1/go.mod h1:6WKK9ahsWS3RSO+PY9ZHZUfv2irvY6gN279GOPZjmmk=
go.opencensus.io v0.20.2/go.mod h1:6WKK9ahsWS3RSO+PY9ZHZUfv2irvY6gN279GOPZjmmk=
go.opencensus.io v0.22.3/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.42.0 h1:pginetY7+onl4qN1vl0xW/V/v6OBZ0vVdH+esuJgvmM=
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.42.0/go.mod h1:XiYsayHc36K3EByOO6nbAXnAWbrUxdjUROCEeeROOH8=
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.44.0 h1:KfYpVmrjI7JuToy5k8XV3nkapjWx48k4E4JOtVstzQI=
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.44.0/go.mod h1:SeQhzAEccGVZVEy7aH87Nh0km+utSpo1pTv6eMMop48=
go.opentelemetry.io/otel v1.22.0 h1:xS7Ku+7yTFvDfDraDIJVpw7XPyuHlB9MCiqqX5mcJ6Y=
Expand Down
Loading
Loading