Skip to content

Commit

Permalink
This fixes leftover android-lantern naming along with minor other fix…
Browse files Browse the repository at this point in the history
…es (#955)

* Lots of changes to use new lantern-client naming and small cleanups

* make tests compile
  • Loading branch information
myleshorton authored Nov 28, 2023
1 parent 8d5233c commit 0f41272
Show file tree
Hide file tree
Showing 22 changed files with 105 additions and 122 deletions.
18 changes: 7 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ STAGING = false
UPDATE_SERVER_URL ?=
VERSION ?= 9999.99.99
# Note - we don't bother stripping symbols or DWARF table as Android's packaging seems to take care of that for us
LDFLAGS := -X github.com/getlantern/android-lantern/internalsdk.RevisionDate=$(REVISION_DATE) -X github.com/getlantern/android-lantern/internalsdk.ApplicationVersion=$(VERSION) -X github.com/getlantern/flashlight/v7/common.StagingMode=$(STAGING)
LDFLAGS := -X github.com/getlantern/lantern-client/internalsdk.RevisionDate=$(REVISION_DATE) -X github.com/getlantern/lantern-client/internalsdk.ApplicationVersion=$(VERSION) -X github.com/getlantern/flashlight/v7/common.StagingMode=$(STAGING)

# Ref https://pkg.go.dev/cmd/link
# -w omits the DWARF table
Expand Down Expand Up @@ -287,7 +287,7 @@ $(ANDROID_LIB):
-androidapi=23 \
-ldflags="$(LDFLAGS)" \
$(GOMOBILE_EXTRA_BUILD_FLAGS) \
github.com/getlantern/android-lantern/internalsdk github.com/getlantern/pathdb/testsupport github.com/getlantern/pathdb/minisql
github.com/getlantern/lantern-client/internalsdk github.com/getlantern/pathdb/testsupport github.com/getlantern/pathdb/minisql

$(MOBILE_ANDROID_LIB): $(ANDROID_LIB)
mkdir -p $(MOBILE_LIBS) && \
Expand Down Expand Up @@ -425,10 +425,10 @@ changelog: require-version require-changelog require-app
# Creates a dump of the source code lantern-android-sources-<version>.tar.gz
sourcedump: require-version
here=`pwd` && \
rm -Rf /tmp/android-lantern ; \
mkdir -p /tmp/android-lantern && \
cp -R LICENSE LICENSING.md android internalsdk lib protos* go.mod go.sum /tmp/android-lantern && \
cd /tmp/android-lantern && \
rm -Rf /tmp/lantern-client ; \
mkdir -p /tmp/lantern-client && \
cp -R LICENSE LICENSING.md android internalsdk lib protos* go.mod go.sum /tmp/lantern-client && \
cd /tmp/lantern-client && \
find . -name "*_test.go" -exec rm {} \; && \
find . -name "*.jks" -exec rm {} \; && \
rm -Rf android/.idea android/sentry.properties android/.settings android/local.properties android/app/.classpath android/app/.project android/app/.settings android/app/src/androidTest android/app/src/test android/app/src/main/res android/app/libs android/.gradle android/alipaySdk-15.6.5-20190718211148/ android/app/bin android/app/.cxx android/app/google-services.json && \
Expand All @@ -450,7 +450,7 @@ build-framework: assert-go-version install-gomobile
-tags='headless lantern ios' \
-ldflags="$(LDFLAGS)" \
$(GOMOBILE_EXTRA_BUILD_FLAGS) \
github.com/getlantern/android-lantern/internalsdk github.com/getlantern/pathdb/testsupport github.com/getlantern/pathdb/minisql github.com/getlantern/flashlight/v7/ios
github.com/getlantern/lantern-client/internalsdk github.com/getlantern/pathdb/testsupport github.com/getlantern/pathdb/minisql github.com/getlantern/flashlight/v7/ios
@echo "moving framework"
mkdir -p $(INTERNALSDK_FRAMEWORK_DIR)
mv ./$(INTERNALSDK_FRAMEWORK_NAME) $(INTERNALSDK_FRAMEWORK_DIR)/$(INTERNALSDK_FRAMEWORK_NAME)
Expand All @@ -476,7 +476,3 @@ clean:
rm -f `which gomobile` && \
rm -f `which gobind`
rm -Rf "$(FLASHLIGHT_FRAMEWORK_PATH)" "$(INTERMEDIATE_FLASHLIGHT_FRAMEWORK_PATH)"




77 changes: 37 additions & 40 deletions desktop/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,12 @@ import (
"sync/atomic"
"time"

"github.com/getsentry/sentry-go"
. "github.com/anacrolix/generics"
"github.com/getsentry/sentry-go"

"github.com/getlantern/dhtup"
"github.com/getlantern/errors"
"github.com/getlantern/golog"
"github.com/getlantern/eventual"
"github.com/getlantern/i18n"
"github.com/getlantern/memhelper"
notify "github.com/getlantern/notifier"
"github.com/getlantern/profiling"
"github.com/getlantern/flashlight/v7"
"github.com/getlantern/flashlight/v7/balancer"
"github.com/getlantern/flashlight/v7/browsers/simbrowser"
Expand All @@ -33,44 +28,48 @@ import (
"github.com/getlantern/flashlight/v7/ops"
"github.com/getlantern/flashlight/v7/pro"
"github.com/getlantern/flashlight/v7/stats"
"github.com/getlantern/golog"
"github.com/getlantern/i18n"
"github.com/getlantern/memhelper"
notify "github.com/getlantern/notifier"
"github.com/getlantern/profiling"
"github.com/getlantern/trafficlog-flashlight/tlproc"

"github.com/getlantern/android-lantern/desktop/analytics"
"github.com/getlantern/android-lantern/desktop/features"
"github.com/getlantern/android-lantern/desktop/notifier"
"github.com/getlantern/android-lantern/desktop/server"
"github.com/getlantern/android-lantern/desktop/ws"
uicommon "github.com/getlantern/android-lantern/desktop/common"
"github.com/getlantern/lantern-client/desktop/analytics"
uicommon "github.com/getlantern/lantern-client/desktop/common"
"github.com/getlantern/lantern-client/desktop/features"
"github.com/getlantern/lantern-client/desktop/notifier"
"github.com/getlantern/lantern-client/desktop/server"
"github.com/getlantern/lantern-client/desktop/ws"
)

var (
log = golog.LoggerFor("lantern-desktop.app")
startTime = time.Now()
log = golog.LoggerFor("lantern-desktop.app")
startTime = time.Now()
translationAppName = strings.ToUpper(common.DefaultAppName)
)

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

Flags flashlight.Flags
configDir string
exited eventual.Value
Flags flashlight.Flags
configDir string
exited eventual.Value
analyticsSession analytics.Session
settings *Settings
statsTracker *statsTracker


muExitFuncs sync.RWMutex
exitFuncs []func()

chGlobalConfigChanged chan bool

ws ws.UIChannel
flashlight *flashlight.Flashlight
dhtupContext Option[dhtup.Context]
ws ws.UIChannel
flashlight *flashlight.Flashlight
dhtupContext Option[dhtup.Context]

// If both the trafficLogLock and proxiesLock are needed, the trafficLogLock should be obtained
// first. Keeping the order consistent avoids deadlocking.
Expand All @@ -89,21 +88,21 @@ type App struct {
proxies []balancer.Dialer
proxiesLock sync.RWMutex

selectedTab Tab
selectedTab Tab
selectedTabMu sync.Mutex
}

// NewApp creates a new desktop app that initializes the app and acts as a moderator between all desktop components.
func NewApp(flags flashlight.Flags, configDir string, settings *Settings) *App {
analyticsSession := newAnalyticsSession(settings)
app := &App{
configDir: configDir,
exited: eventual.NewValue(),
settings: settings,
analyticsSession: analyticsSession,
selectedTab: AccountTab,
statsTracker: NewStatsTracker(),
ws: ws.NewUIChannel(),
configDir: configDir,
exited: eventual.NewValue(),
settings: settings,
analyticsSession: analyticsSession,
selectedTab: AccountTab,
statsTracker: NewStatsTracker(),
ws: ws.NewUIChannel(),
}

return app
Expand Down Expand Up @@ -516,14 +515,14 @@ func (app *App) doExit(err error) {
if err != nil {
log.Errorf("Exiting app %d(%d) because of %v", os.Getpid(), os.Getppid(), err)
if ShouldReportToSentry() {
sentry.ConfigureScope(func(scope *sentry.Scope) {
scope.SetLevel(sentry.LevelFatal)
})

sentry.CaptureException(err)
if result := sentry.Flush(common.SentryTimeout); !result {
log.Error("Flushing to Sentry timed out")
}
sentry.ConfigureScope(func(scope *sentry.Scope) {
scope.SetLevel(sentry.LevelFatal)
})

sentry.CaptureException(err)
if result := sentry.Flush(common.SentryTimeout); !result {
log.Error("Flushing to Sentry timed out")
}
}
} else {
log.Debugf("Exiting app %d(%d)", os.Getpid(), os.Getppid())
Expand Down Expand Up @@ -622,5 +621,3 @@ func (app *App) AdTrackURL() string {
func (app *App) AddToken(path string) string {
return path
}


4 changes: 2 additions & 2 deletions desktop/app/pro.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"github.com/getlantern/flashlight/v7/pro/client"
"github.com/getlantern/golog"

"github.com/getlantern/android-lantern/desktop/deviceid"
"github.com/getlantern/android-lantern/desktop/ws"
"github.com/getlantern/lantern-client/desktop/deviceid"
"github.com/getlantern/lantern-client/desktop/ws"
)

// isProUser blocks itself to check if current user is Pro, or !ok if error
Expand Down
4 changes: 2 additions & 2 deletions desktop/app/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import (
"github.com/getlantern/timezone"
"github.com/getlantern/yaml"

"github.com/getlantern/android-lantern/desktop/deviceid"
"github.com/getlantern/android-lantern/desktop/ws"
"github.com/getlantern/lantern-client/desktop/deviceid"
"github.com/getlantern/lantern-client/desktop/ws"
)

// SettingName is the name of a setting.
Expand Down
2 changes: 1 addition & 1 deletion desktop/app/stats_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package app
import (
"github.com/getlantern/flashlight/v7/stats"

"github.com/getlantern/android-lantern/desktop/ws"
"github.com/getlantern/lantern-client/desktop/ws"
)

type statsTracker struct {
Expand Down
2 changes: 1 addition & 1 deletion desktop/app/sysproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/getlantern/flashlight/v7/ops"
"github.com/getlantern/sysproxy"

"github.com/getlantern/android-lantern/desktop/icons"
"github.com/getlantern/lantern-client/desktop/icons"
)

var (
Expand Down
4 changes: 2 additions & 2 deletions desktop/app/trafficlog.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import (
"github.com/getlantern/trafficlog-flashlight/tlproc"
"github.com/getlantern/yaml"

"github.com/getlantern/android-lantern/desktop/features"
"github.com/getlantern/android-lantern/desktop/icons"
"github.com/getlantern/lantern-client/desktop/features"
"github.com/getlantern/lantern-client/desktop/icons"
)

const (
Expand Down
23 changes: 19 additions & 4 deletions desktop/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@ package main
import (
"os"
"os/signal"
"syscall"
"path/filepath"
"runtime"
"runtime/debug"
"syscall"

"github.com/getlantern/appdir"
"github.com/getlantern/android-lantern/desktop/app"
"github.com/getlantern/flashlight/v7"
"github.com/getlantern/flashlight/v7/common"
"github.com/getlantern/golog"
"github.com/getlantern/lantern-client/desktop/app"
)

var (
Expand All @@ -28,7 +29,8 @@ func main() {
flags := flashlight.ParseFlags()

cdir := configDir(&flags)
a := app.NewApp(flags, cdir)
settings := loadSettings(cdir)
a := app.NewApp(flags, cdir, settings)
log.Debug("Running headless")
runApp(a)
err := a.WaitForExit()
Expand All @@ -40,6 +42,19 @@ func main() {
os.Exit(0)
}

// loadSettings loads the initial settings at startup, either from disk or using defaults.
func loadSettings(configDir string) *app.Settings {
path := filepath.Join(configDir, "settings.yaml")
if common.Staging {
path = filepath.Join(configDir, "settings-staging.yaml")
}
settings := app.LoadSettingsFrom(app.ApplicationVersion, app.RevisionDate, app.BuildDate, path)
if common.Staging {
settings.SetUserIDAndToken(9007199254740992, "OyzvkVvXk7OgOQcx-aZpK5uXx6gQl5i8BnOuUkc0fKpEZW6tc8uUvA")
}
return settings
}

func configDir(flags *flashlight.Flags) string {
cdir := flags.ConfigDir
if cdir == "" {
Expand Down Expand Up @@ -77,4 +92,4 @@ func handleSignals(a *app.App) {
os.Exit(1)
//desktop.QuitSystray(a)
}()
}
}
4 changes: 2 additions & 2 deletions desktop/go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/getlantern/android-lantern/desktop
module github.com/getlantern/lantern-client/desktop

go 1.21

Expand Down Expand Up @@ -40,6 +40,7 @@ require (
github.com/gorilla/websocket v1.5.0
github.com/stretchr/testify v1.8.4
golang.org/x/sys v0.14.0
google.golang.org/protobuf v1.31.0
)

require (
Expand Down Expand Up @@ -258,7 +259,6 @@ require (
google.golang.org/genproto/googleapis/api v0.0.0-20231106174013-bbf56f31fb17 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20231106174013-bbf56f31fb17 // indirect
google.golang.org/grpc v1.59.0 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
howett.net/plist v1.0.0 // indirect
modernc.org/libc v1.22.3 // indirect
Expand Down
18 changes: 9 additions & 9 deletions desktop/lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,27 @@ import (
"os"
"os/signal"
"path/filepath"
"syscall"
"runtime"
"runtime/debug"
"strconv"
"syscall"

"github.com/getlantern/appdir"
"github.com/getlantern/android-lantern/desktop/app"
"github.com/getlantern/android-lantern/desktop/pro"
"github.com/getlantern/flashlight/v7"
"github.com/getlantern/flashlight/v7/common"
"github.com/getlantern/golog"
"github.com/getlantern/lantern-client/desktop/app"
"github.com/getlantern/lantern-client/desktop/pro"
)

import "C"

var (
log = golog.LoggerFor("lantern-desktop.main")
a *app.App
a *app.App

proClient *pro.ProClient
settings *app.Settings
settings *app.Settings
)

//export Start
Expand All @@ -44,7 +44,7 @@ func Start() *C.char {
proClient = pro.New()
a = app.NewApp(flags, cdir, settings)
log.Debug("Running headless")
go func() {
go func() {
runApp(a)
err := a.WaitForExit()
if err != nil {
Expand All @@ -54,19 +54,19 @@ func Start() *C.char {
log.Debug("Lantern stopped")
os.Exit(0)
}()
return C.CString("")
return C.CString("")
}

//export SysProxyOn
func SysProxyOn() *C.char {
app.SysproxyOn()
return C.CString("on")
return C.CString("on")
}

//export SysProxyOff
func SysProxyOff() *C.char {
app.SysProxyOff()
return C.CString("off")
return C.CString("off")
}

func userHeaders() (string, string, string) {
Expand Down
2 changes: 1 addition & 1 deletion desktop/notifier/notifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
notify "github.com/getlantern/notifier"
"github.com/getsentry/sentry-go"

"github.com/getlantern/android-lantern/desktop/analytics"
"github.com/getlantern/lantern-client/desktop/analytics"
)

const (
Expand Down
Loading

0 comments on commit 0f41272

Please sign in to comment.