Skip to content

Commit

Permalink
Temporary workaround for Windows layout distortion and some other upd…
Browse files Browse the repository at this point in the history
…ates (#1204)

* updates to immediately exit app after clean-up

* updates to immediately exit app after clean-up

* clean-ups

* Add SafeArea around home component

* await waitUntilReadyToShow

* move intiialization to start

* move intiialization to start

* testing initialization updates

* Additional clean-ups, delay pro client init until running the app

* revert changes to temporarily silence notifications

* move call to super.initState in Home widget

* move call to super.initState in Home widget

* don't call _initWindowManager in addPostFrameCallback

* fix integration test

* update order we destroy resources when exiting the app

* fix integration test

* Update ordering of exit functions

* move LanternFFI.exit to end

* clean-ups, move window initialization back to main to avoid window repositioning

* clean-ups, move window initialization back to main to avoid window repositioning

* Add comments

* Add comment and temporary fix for broken UI on windows

* update comment

* update _initWindowManager

* update _initWindowManager

* immediately exit after cleanup

* clean-ups

* call setState to trigger refresh on windows

* remove call to setResizable

* add call to setState

* try downgrading window_manager

* updates that work on windows

* set window resizable to false on other platforms

* rename _initWindowManager
  • Loading branch information
atavism authored Oct 4, 2024
1 parent f7bd8ca commit cfff37e
Show file tree
Hide file tree
Showing 7 changed files with 123 additions and 99 deletions.
58 changes: 45 additions & 13 deletions desktop/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,12 @@ import (
"github.com/getlantern/lantern-client/desktop/datacap"
"github.com/getlantern/lantern-client/desktop/settings"
"github.com/getlantern/lantern-client/desktop/ws"
"github.com/getlantern/lantern-client/internalsdk/auth"
"github.com/getlantern/lantern-client/internalsdk/common"
"github.com/getlantern/lantern-client/internalsdk/pro"
proclient "github.com/getlantern/lantern-client/internalsdk/pro"
"github.com/getlantern/lantern-client/internalsdk/protos"
"github.com/getlantern/lantern-client/internalsdk/webclient"
)

var (
Expand Down Expand Up @@ -78,6 +81,7 @@ type App struct {
flashlight *flashlight.Flashlight

issueReporter *issueReporter
authClient auth.AuthClient
proClient proclient.ProClient

selectedTab Tab
Expand All @@ -94,18 +98,18 @@ type App struct {

onUserData []func(current *protos.User, new *protos.User)

mu sync.Mutex
mu sync.RWMutex
}

// 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, proClient proclient.ProClient, ss *settings.Settings) *App {
func NewApp(flags flashlight.Flags, configDir string) *App {
ss := settings.LoadSettings(configDir)
analyticsSession := newAnalyticsSession(ss)
statsTracker := NewStatsTracker()
app := &App{
Flags: flags,
configDir: configDir,
exited: eventual.NewValue(),
proClient: proClient,
settings: ss,
analyticsSession: analyticsSession,
connectionStatusCallbacks: make([]func(isConnected bool), 0),
Expand Down Expand Up @@ -153,33 +157,47 @@ func newAnalyticsSession(settings *settings.Settings) analytics.Session {
// Run starts the app.
func (app *App) Run(ctx context.Context) {
golog.OnFatal(app.exitOnFatal)

go func() {
for <-geolookup.OnRefresh() {
app.settings.SetCountry(geolookup.GetCountry(0))
app.Settings().SetCountry(geolookup.GetCountry(0))
}
}()

// Run below in separate goroutine as config.Init() can potentially block when Lantern runs
// for the first time. User can still quit Lantern through systray menu when it happens.
go func() {
log.Debug(app.Flags)
userConfig := func() common.UserConfig {
return settings.UserConfig(app.Settings())
}
proClient := proclient.NewClient(fmt.Sprintf("https://%s", common.ProAPIHost), &webclient.Opts{
UserConfig: userConfig,
})
authClient := auth.NewClient(fmt.Sprintf("https://%s", common.DFBaseUrl), userConfig)

app.mu.Lock()
app.proClient = proClient
app.authClient = authClient
app.mu.Unlock()

settings := app.Settings()

if app.Flags.ProxyAll {
// If proxyall flag was supplied, force proxying of all
app.settings.SetProxyAll(true)
settings.SetProxyAll(true)
}

listenAddr := app.Flags.Addr
if listenAddr == "" {
listenAddr = app.settings.GetAddr()
listenAddr = settings.GetAddr()
}
if listenAddr == "" {
listenAddr = defaultHTTPProxyAddress
}

socksAddr := app.Flags.SocksAddr
if socksAddr == "" {
socksAddr = app.settings.GetSOCKSAddr()
socksAddr = settings.GetSOCKSAddr()
}
if socksAddr == "" {
socksAddr = defaultSOCKSProxyAddress
Expand All @@ -200,15 +218,15 @@ func (app *App) Run(ctx context.Context) {
common.RevisionDate,
app.configDir,
app.Flags.VPN,
func() bool { return app.settings.GetDisconnected() }, // check whether we're disconnected
app.settings.GetProxyAll,
func() bool { return settings.GetDisconnected() }, // check whether we're disconnected
settings.GetProxyAll,
func() bool { return false }, // on desktop, we do not allow private hosts
app.settings.IsAutoReport,
settings.IsAutoReport,
app.Flags.AsMap(),
app.settings,
settings,
app.statsTracker,
app.IsPro,
app.settings.GetLanguage,
settings.GetLanguage,
func(addr string) (string, error) { return addr, nil }, // no dnsgrab reverse lookups on desktop
app.analyticsSession.EventWithLabel,
flashlight.WithOnConfig(app.onConfigUpdate),
Expand Down Expand Up @@ -786,5 +804,19 @@ func (app *App) GetTranslations(filename string) ([]byte, error) {
}

func (app *App) Settings() *settings.Settings {
app.mu.RLock()
defer app.mu.RUnlock()
return app.settings
}

func (app *App) AuthClient() auth.AuthClient {
app.mu.RLock()
defer app.mu.RUnlock()
return app.authClient
}

func (app *App) ProClient() pro.ProClient {
app.mu.RLock()
defer app.mu.RUnlock()
return app.proClient
}
14 changes: 1 addition & 13 deletions desktop/app/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package app
import (
"context"
"crypto/tls"
"fmt"
"io/ioutil"
"net/http"
"net/url"
Expand All @@ -29,9 +28,6 @@ import (
"github.com/getlantern/flashlight/v7/logging"
"github.com/getlantern/lantern-client/desktop/doh"
"github.com/getlantern/lantern-client/desktop/settings"
uicommon "github.com/getlantern/lantern-client/internalsdk/common"
"github.com/getlantern/lantern-client/internalsdk/pro"
"github.com/getlantern/lantern-client/internalsdk/webclient"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -193,16 +189,8 @@ func startApp(t *testing.T, helper *integrationtest.Helper) (*App, error) {
UIAddr: "127.0.0.1:16823",
Timeout: time.Duration(0),
}

ss := settings.EmptySettings()
webclientOpts := &webclient.Opts{
UserConfig: func() uicommon.UserConfig {
return settings.UserConfig(ss)
},
}
proClient := pro.NewClient(fmt.Sprintf("https://%s", common.ProAPIHost), webclientOpts)

a := NewApp(flags, helper.ConfigDir, proClient, ss)
a := NewApp(flags, helper.ConfigDir)
id := ss.GetUserID()
if id == 0 {
ss.SetUserIDAndToken(1, "token")
Expand Down
18 changes: 9 additions & 9 deletions desktop/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func getUserSalt(email string) ([]byte, error) {
return salt, nil
}
log.Debugf("Salt not found calling api for %s", email)
saltResponse, err := authClient.GetSalt(context.Background(), lowerCaseEmail)
saltResponse, err := a.AuthClient().GetSalt(context.Background(), lowerCaseEmail)
if err != nil {
return nil, err
}
Expand All @@ -61,7 +61,7 @@ func getUserSalt(email string) ([]byte, error) {
func signup(email *C.char, password *C.char) *C.char {
lowerCaseEmail := strings.ToLower(C.GoString(email))

salt, err := authClient.SignUp(lowerCaseEmail, C.GoString(password))
salt, err := a.AuthClient().SignUp(lowerCaseEmail, C.GoString(password))
if err != nil {
return sendError(err)
}
Expand All @@ -77,7 +77,7 @@ func signup(email *C.char, password *C.char) *C.char {
//export login
func login(email *C.char, password *C.char) *C.char {
lowerCaseEmail := strings.ToLower(C.GoString(email))
user, salt, err := authClient.Login(lowerCaseEmail, C.GoString(password), getDeviceID())
user, salt, err := a.AuthClient().Login(lowerCaseEmail, C.GoString(password), getDeviceID())
if err != nil {
return sendError(err)
}
Expand Down Expand Up @@ -119,7 +119,7 @@ func logout() *C.char {
LegacyUserID: userId,
}
log.Debugf("Sign out request %+v", signoutData)
loggedOut, logoutErr := authClient.SignOut(ctx, signoutData)
loggedOut, logoutErr := a.AuthClient().SignOut(ctx, signoutData)
if logoutErr != nil {
return sendError(log.Errorf("Error while signing out %v", logoutErr))
}
Expand Down Expand Up @@ -167,7 +167,7 @@ func startRecoveryByEmail(email *C.char) *C.char {
prepareRequestBody := &protos.StartRecoveryByEmailRequest{
Email: lowerCaseEmail,
}
recovery, err := authClient.StartRecoveryByEmail(context.Background(), prepareRequestBody)
recovery, err := a.AuthClient().StartRecoveryByEmail(context.Background(), prepareRequestBody)
if err != nil {
return sendError(err)
}
Expand Down Expand Up @@ -199,7 +199,7 @@ func completeRecoveryByEmail(email *C.char, code *C.char, password *C.char) *C.c
}

log.Debugf("new Verifier %v and salt %v", verifierKey.Bytes(), newsalt)
recovery, err := authClient.CompleteRecoveryByEmail(context.Background(), prepareRequestBody)
recovery, err := a.AuthClient().CompleteRecoveryByEmail(context.Background(), prepareRequestBody)
if err != nil {
return sendError(err)
}
Expand All @@ -219,7 +219,7 @@ func validateRecoveryByEmail(email *C.char, code *C.char) *C.char {
Email: lowerCaseEmail,
Code: C.GoString(code),
}
recovery, err := authClient.ValidateEmailRecoveryCode(context.Background(), prepareRequestBody)
recovery, err := a.AuthClient().ValidateEmailRecoveryCode(context.Background(), prepareRequestBody)
if err != nil {
return sendError(err)
}
Expand Down Expand Up @@ -253,7 +253,7 @@ func deleteAccount(password *C.char) *C.char {
A: A.Bytes(),
}
log.Debugf("Delete Account request email %v A %v", lowerCaseEmail, A.Bytes())
srpB, err := authClient.LoginPrepare(context.Background(), prepareRequestBody)
srpB, err := a.AuthClient().LoginPrepare(context.Background(), prepareRequestBody)
if err != nil {
return sendError(err)
}
Expand Down Expand Up @@ -295,7 +295,7 @@ func deleteAccount(password *C.char) *C.char {
}

log.Debugf("Delete Account request email %v prooof %v deviceId %v", lowerCaseEmail, clientProof, deviceId)
isAccountDeleted, err := authClient.DeleteAccount(context.Background(), changeEmailRequestBody)
isAccountDeleted, err := a.AuthClient().DeleteAccount(context.Background(), changeEmailRequestBody)
if err != nil {
return sendError(err)
}
Expand Down
Loading

0 comments on commit cfff37e

Please sign in to comment.