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 config service sooner and don't copy mutex #1250

Merged
merged 8 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
35 changes: 14 additions & 21 deletions desktop/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"net"
"net/http"
"os"
"strings"
"sync"
"sync/atomic"
"time"
Expand Down Expand Up @@ -46,9 +45,8 @@ import (
)

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

func init() {
Expand Down Expand Up @@ -78,18 +76,16 @@ type App struct {

flashlight *flashlight.Flashlight

issueReporter *issueReporter
authClient auth.AuthClient
proClient proclient.ProClient
authClient auth.AuthClient
proClient proclient.ProClient

selectedTab Tab

connectionStatusCallbacks []func(isConnected bool)

// Websocket-related settings
websocketAddr string
websocketServer *http.Server
ws ws.UIChannel
websocketAddr string
ws ws.UIChannel

cachedUserData sync.Map
plansCache sync.Map
Expand Down Expand Up @@ -145,9 +141,12 @@ func NewAppWithFlags(flags flashlight.Flags, configDir string) *App {

log.Debugf("Using configdir: %v", configDir)

app.issueReporter = newIssueReporter(app)
app.translations.Set(os.DirFS("locale/translation"))

if e := app.configService.StartService(app.ws); e != nil {
app.Exit(fmt.Errorf("unable to register config service: %q", e))
}

return app
}

Expand All @@ -169,7 +168,6 @@ func (app *App) Run(ctx context.Context) {
}
proClient := proclient.NewClient(fmt.Sprintf("https://%s", common.ProAPIHost), &webclient.Opts{
UserConfig: userConfig,

})
authClient := auth.NewClient(fmt.Sprintf("https://%s", common.DFBaseUrl), userConfig)

Expand Down Expand Up @@ -230,6 +228,7 @@ func (app *App) Run(ctx context.Context) {
func(category, action, label string) {},
flashlight.WithOnConfig(app.onConfigUpdate),
flashlight.WithOnProxies(app.onProxiesUpdate),
flashlight.WithOnSucceedingProxy(app.onSucceedingProxy),
)
if err != nil {
app.Exit(err)
Expand Down Expand Up @@ -285,11 +284,6 @@ func (app *App) beforeStart(ctx context.Context, listenAddr string) {
os.Exit(0)
}

if e := app.configService.StartService(app.ws); e != nil {
app.Exit(fmt.Errorf("unable to register config service: %q", e))
return
}

if e := app.settings.StartService(app.ws); e != nil {
app.Exit(fmt.Errorf("unable to register settings service: %q", e))
return
Expand Down Expand Up @@ -443,13 +437,12 @@ func (app *App) onConfigUpdate(cfg *config.Global, src config.Source) {
func (app *App) onProxiesUpdate(proxies []dialer.ProxyDialer, src config.Source) {
log.Debugf("[Startup Desktop] Got proxies update from %v", src)
app.fetchedProxiesConfig.Store(true)
app.hasSucceedingProxy.Store(true)
app.sendConfigOptions()
}

func (app *App) onSucceedingProxy(succeeding bool) {
app.hasSucceedingProxy.Store(succeeding)
log.Debugf("[Startup Desktop] onSucceedingProxy %v", succeeding)
func (app *App) onSucceedingProxy() {
app.hasSucceedingProxy.Store(true)
log.Debugf("[Startup Desktop] onSucceedingProxy")
}

// HasSucceedingProxy returns whether or not the app is currently configured with any succeeding proxies
Expand Down
4 changes: 2 additions & 2 deletions desktop/app/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (s *configService) StartService(channel ws.UIChannel) (err error) {
return err
}

func (s *configService) sendConfigOptions(cfg ConfigOptions) {
func (s *configService) sendConfigOptions(cfg *ConfigOptions) {
b, _ := json.Marshal(&cfg)
log.Debugf("Sending config options to client %s", string(b))
s.service.Out <- cfg
Expand Down Expand Up @@ -90,7 +90,7 @@ func (app *App) sendConfigOptions() {
log.Debugf("DEBUG: Devices: %s", string(devices))
log.Debugf("Expiration date: %s", app.settings.GetExpirationDate())

app.configService.sendConfigOptions(ConfigOptions{
app.configService.sendConfigOptions(&ConfigOptions{
DevelopmentMode: common.IsDevEnvironment(),
AppVersion: common.ApplicationVersion,
ReplicaAddr: "",
Expand Down
121 changes: 0 additions & 121 deletions desktop/app/issue.go

This file was deleted.

2 changes: 1 addition & 1 deletion desktop/app/sysproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (app *App) SysProxyOff() error {
log.Debug("Force clearing system proxy directly, just in case")
addr, found := getProxyAddr()
if !found {
err := fmt.Errorf("Unable to find proxy address, can't force clear system proxy")
err := fmt.Errorf("unable to find proxy address, can't force clear system proxy")
op.FailIf(log.Error(err))
return err
}
Expand Down
6 changes: 0 additions & 6 deletions desktop/app/ws.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,3 @@ func (app *App) WebsocketAddr() string {
}
return app.websocketAddr
}

func (app *App) setWebsocketServer(server *http.Server) {
app.mu.Lock()
defer app.mu.Unlock()
app.websocketServer = server
}
Loading