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

Desktop updates: websocket service and pro account management #1026

Merged
merged 53 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
6b001ea
do not pass initialize flag when running Lantern
atavism Mar 18, 2024
39a1e39
do not pass initialize flag when running Lantern
atavism Mar 18, 2024
99ee35a
remove tray manager references in vpn switch widget
atavism Mar 18, 2024
1d0b91b
remove tray manager references in vpn switch widget
atavism Mar 18, 2024
e07e011
use windows webview
atavism Mar 18, 2024
c775cc9
update windows webview
atavism Mar 18, 2024
d808196
update windows webview
atavism Mar 18, 2024
289604c
windows webview updates
atavism Mar 18, 2024
368cc36
windows webview updates
atavism Mar 18, 2024
312c0cf
windows webview updates
atavism Mar 18, 2024
ca8e7b7
updates to use flutter_windows_webview
atavism Mar 18, 2024
1ba4262
update CI branch
atavism Mar 18, 2024
fbb4d98
merge latest
atavism Mar 19, 2024
a2335d1
use wgh136/flutter_windows_webview
atavism Mar 19, 2024
482b153
use subosito/flutter-action v2.12.0
atavism Mar 19, 2024
d6943f4
use subosito/flutter-action v2.12.0
atavism Mar 19, 2024
219991a
use subosito/flutter-action v2.12.0
atavism Mar 19, 2024
79a6b19
merge latest
atavism Mar 19, 2024
50f269d
Add expectedMonthlyPrice to plan json
atavism Mar 19, 2024
4d10af0
update branch name
atavism Mar 19, 2024
a56f3ed
update planfromJson
atavism Mar 19, 2024
7c6f2da
use cannot_sign_in instead of cannot_login
atavism Mar 19, 2024
6123581
fix issue with blank pro account screen
atavism Mar 19, 2024
084871d
Add devices and expiryDate
atavism Mar 19, 2024
117001e
update branch name
atavism Mar 19, 2024
8558285
Add report_description
atavism Mar 19, 2024
a1dba70
Add report_description
atavism Mar 19, 2024
2620791
save email address and pass currency to paymentRedirect
atavism Mar 20, 2024
322da45
dart format
atavism Mar 20, 2024
7babd06
merge latest
atavism Mar 20, 2024
ef82f53
use switch statement for desktop os opening webview
atavism Mar 20, 2024
82909d8
update user is pro check
atavism Mar 21, 2024
961b1ed
add websocket service
atavism Mar 21, 2024
d5d72fc
add websocket service
atavism Mar 21, 2024
c00ced4
clean-ups, add comments
atavism Mar 21, 2024
7d43b8f
apply formatting
atavism Mar 21, 2024
c901d47
Added socket to account menu and
jigar-f Mar 22, 2024
5f34ebc
updates to use didChangeAppLifecycleState
atavism Mar 24, 2024
81b5066
updates to init websocket when app starts
atavism Mar 24, 2024
39d67a9
clean-ups, add comments
atavism Mar 24, 2024
8fcdc92
updates to websocket service
atavism Mar 24, 2024
908f9d6
merge latest
atavism Mar 24, 2024
f0d03de
remove websocket changes to account menu
atavism Mar 24, 2024
a8d3a1a
apply formatting
atavism Mar 24, 2024
3cd60c5
refresh user data when home page is loaded
atavism Mar 24, 2024
3f10436
remove redundant methods
atavism Mar 25, 2024
3f012fa
update onTrayMenuItemClick
atavism Mar 25, 2024
b9b7b67
clean-ups, do not fetch user data when checking email address
atavism Mar 25, 2024
65a62fb
set Localization.locale in setLanguage
atavism Mar 25, 2024
e9af14d
use Localization.locale when parsing plan json
atavism Mar 25, 2024
ea7e495
fix system menu show button
atavism Mar 25, 2024
5a59708
support redeeming reseller codes on desktop
atavism Mar 25, 2024
05cece0
Desktop Error handling and other hot fix (#1027)
jigar-f Mar 26, 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
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Publish releases

on:
push:
branches: [ main ]
branches: [ atavism/pro-account-screen ]
tags:
- '*'

Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ android/app/libs/liblantern-all.aar
lantern-installer.dmg
liblantern.h
liblantern.dylib
liblantern_arm64.dylib
liblantern_amd64.dylib
lib/generated_bindings.dart

*.env
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,7 @@ darwin: darwin-arm64
${DESKTOP_LIB_NAME}_amd64.dylib \
-output ${DARWIN_LIB_NAME}
install_name_tool -id "@rpath/${DARWIN_LIB_NAME}" ${DARWIN_LIB_NAME}
rm ${DESKTOP_LIB_NAME}_arm64.h && mv ${DESKTOP_LIB_NAME}_amd64.h ${DESKTOP_LIB_NAME}.h

$(INSTALLER_NAME).dmg: require-version require-appdmg require-retry require-magick
@echo "Generating distribution package for darwin/amd64..." && \
Expand Down
28 changes: 24 additions & 4 deletions assets/locales/en.po
Original file line number Diff line number Diff line change
Expand Up @@ -162,20 +162,27 @@ msgstr "Cannot access blocked sites"
msgid "cannot_complete_purchase"
msgstr "Cannot complete purchase"


msgid "discover_not_working"
msgstr "Discover not working "




msgid "cannot_sign_in"
msgstr "Cannot sign in"

msgid "loading_spinner_spins_endlessly"
msgstr "Loading spinner spins endlessly"
msgid "spinner_loads_endlessly"
msgstr "Spinner loads endlessly"

msgid "slow"
msgstr "Slow"

msgid "cannot_link_devices"
msgstr "Cannot link devices"

msgid "lantern_crashes"
msgstr "Lantern crashes"
msgid "application_crashes"
msgstr "Application crashes"

msgid "other"
msgstr "Other"
Expand Down Expand Up @@ -248,6 +255,9 @@ msgstr "Lantern Pro Email"
msgid "lantern_desktop"
msgstr "Lantern Desktop"

msgid "report_description"
msgstr "Issue Description"

msgid "report_issue"
msgstr "Report Issue"

Expand Down Expand Up @@ -1469,4 +1479,14 @@ msgstr "Your device has been successfully added. If you do not see the device co
msgid "search_apps"
msgstr "Search Apps"

msgid "wrong_seller_code"
msgstr "Incorrect reseller code. Please verify and try again."

msgid "report_issue_error"
msgstr "We're experiencing technical difficulties. Try again later."

msgid "we_are_experiencing_technical_difficulties"
msgstr "We're experiencing technical difficulties. Try again later."



12 changes: 12 additions & 0 deletions desktop/app/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const (
SNLocalHTTPToken SettingName = "localHTTPToken"

SNDeviceID SettingName = "deviceID"
SNEmailAddress SettingName = "emailAddress"
SNUserID SettingName = "userID"
SNUserToken SettingName = "userToken"
SNMigratedDeviceIDForUserID SettingName = "migratedDeviceIDForUserID"
Expand Down Expand Up @@ -80,6 +81,7 @@ var settingMeta = map[SettingName]struct {
SNLocalHTTPToken: {stString, true, true},

// SNDeviceID: intentionally omit, to avoid setting it from UI
SNEmailAddress: {stString, true, true},
SNUserID: {stNumber, true, true},
SNUserToken: {stString, true, true},
SNMigratedDeviceIDForUserID: {stNumber, true, true},
Expand Down Expand Up @@ -485,6 +487,16 @@ func (s *Settings) GetAddr() string {
return s.getString(SNAddr)
}

// GetEmailAddress gets the email address of pro users.
func (s *Settings) GetEmailAddress() string {
return s.getString(SNEmailAddress)
}

// SetEmailAddress locally stores the email address of a pro user
func (s *Settings) SetEmailAddress(email string) {
s.setVal(SNEmailAddress, email)
}

// GetUIAddr returns the address of the UI, stored across runs to avoid a
// different port on each run, which breaks things like local storage in the UI.
func (s *Settings) GetUIAddr() string {
Expand Down
139 changes: 103 additions & 36 deletions desktop/lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"runtime"
"runtime/debug"
"strconv"
"strings"
"syscall"
"time"

Expand All @@ -24,6 +25,7 @@ import (
"github.com/getlantern/flashlight/v7/pro/client"
"github.com/getlantern/golog"
"github.com/getlantern/i18n"
"github.com/getlantern/jibber_jabber"
"github.com/getlantern/lantern-client/desktop/app"
"github.com/getlantern/lantern-client/desktop/autoupdate"
"github.com/getlantern/lantern-client/internalsdk/protos"
Expand All @@ -35,12 +37,29 @@ import (

import "C"

const (
defaultLocale = "en-US"
)

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

var issueMap = map[string]string{
"Cannot access blocked sites": "3",
"Cannot complete purchase": "0",
"Cannot sign in": "1",
"Spinner loads endlessly": "2",
"Slow": "4",
"Chat not working": "7",
"Discover not working": "8",
"Cannot link device": "5",
"Application crashes": "6",
"Other": "9",
}

//export start
func start() {
runtime.LockOSThread()
Expand Down Expand Up @@ -122,11 +141,7 @@ func sendError(err error) *C.char {
if err == nil {
return C.CString("")
}
errors := map[string]interface{}{
"error": err.Error(),
}
b, _ := json.Marshal(errors)
return C.CString(string(b))
return C.CString(err.Error())
}

//export selectedTab
Expand Down Expand Up @@ -169,13 +184,46 @@ func paymentMethods() *C.char {
return C.CString(string(b))
}

func getUserData() (*client.User, error) {
resp, err := proClient.UserData(userConfig())
if err != nil {
return nil, err
}
user := resp.User
if user.Email != "" {
a.Settings().SetEmailAddress(user.Email)
}
return &user, nil
}

//export devices
func devices() *C.char {
user, err := getUserData()
if err != nil {
return sendError(err)
}
b, _ := json.Marshal(user.Devices)
return C.CString(string(b))
}

//export expiryDate
func expiryDate() *C.char {
user, err := getUserData()
if err != nil {
return sendError(err)
}
tm := time.Unix(user.Expiration, 0)
exp := tm.Format("01/02/2006")
return C.CString(string(exp))
}

//export userData
func userData() *C.char {
resp, err := proClient.UserData(userConfig())
user, err := getUserData()
if err != nil {
return sendError(err)
}
b, _ := json.Marshal(resp.User)
b, _ := json.Marshal(user)
return C.CString(string(b))
}

Expand All @@ -196,7 +244,7 @@ func serverInfo() *C.char {

//export emailAddress
func emailAddress() *C.char {
return C.CString("")
return C.CString(a.Settings().GetEmailAddress())
}

//export emailExists
Expand All @@ -209,6 +257,23 @@ func emailExists(email *C.char) *C.char {
return C.CString("false")
}

// The function returns two C strings: the first represents success, and the second represents an error.
// If the redemption is successful, the first string contains "true", and the second string is nil.
// If an error occurs during redemption, the first string is nil, and the second string contains the error message.
//
//export redeemResellerCode
func redeemResellerCode(email, currency, deviceName, resellerCode *C.char) (*C.char, *C.char) {
_, err := proClient.RedeemResellerCode(userConfig(), C.GoString(email), C.GoString(resellerCode),
C.GoString(deviceName), C.GoString(currency))
if err != nil {
log.Debugf("DEBUG: error while redeeming reseller code: %v", err)
return nil, C.CString(err.Error())
// return sendError(err)
}
log.Debugf("DEBUG: redeeming reseller code success: %v", err)
return C.CString("true"), nil
}

//export referral
func referral() *C.char {
referralCode, err := a.ReferralCode(userConfig())
Expand Down Expand Up @@ -238,7 +303,7 @@ func lang() *C.char {
lang := a.Settings().GetLanguage()
if lang == "" {
// Default language is English
lang = "en-US"
lang = defaultLocale
}
return C.CString(lang)
}
Expand Down Expand Up @@ -284,6 +349,8 @@ func acceptedTermsVersion() *C.char {

//export proUser
func proUser() *C.char {
// refresh user data when home page is loaded on desktop
go pro.FetchUserData(a.Settings())
if isProUser, ok := a.IsProUser(); isProUser && ok {
return C.CString("true")
}
Expand All @@ -301,20 +368,20 @@ func deviceLinkingCode() *C.char {
}

//export paymentRedirect
func paymentRedirect(planID, provider, email, deviceName *C.char) *C.char {
func paymentRedirect(planID, currency, provider, email, deviceName *C.char) (*C.char, *C.char) {
country := a.Settings().GetCountry()
resp, err := proClient.PaymentRedirect(userConfig(), &client.PaymentRedirectRequest{
Plan: C.GoString(planID),
Provider: C.GoString(provider),
Currency: "USD",
Currency: strings.ToUpper(C.GoString(currency)),
Email: C.GoString(email),
DeviceName: C.GoString(deviceName),
CountryCode: country,
})
if err != nil {
return sendError(err)
return nil, sendError(err)
}
return C.CString(resp.Redirect)
return C.CString(resp.Redirect), nil
}

//export developmentMode
Expand All @@ -337,19 +404,6 @@ func replicaAddr() *C.char {
return C.CString("")
}

var issueMap = map[string]string{
"Cannot access blocked sites": "3",
"Cannot complete purchase": "0",
"Cannot sign in": "1",
"Spinner loads endlessly": "2",
"Slow": "4",
"Chat not working": "7",
"Discover not working": "8",
"Cannot link device": "5",
"Application crashes": "6",
"Other": "9",
}

func userConfig() *common.UserConfigData {
settings := a.Settings()
userID, deviceID, token := settings.GetUserID(), settings.GetDeviceID(), settings.GetToken()
Expand All @@ -364,17 +418,17 @@ func userConfig() *common.UserConfigData {
}

//export reportIssue
func reportIssue(email, issueType, description *C.char) *C.char {
func reportIssue(email, issueType, description *C.char) (*C.char, *C.char) {
deviceID := a.Settings().GetDeviceID()
issueTypeInt, err := strconv.Atoi(C.GoString(issueType))
issueIndex := issueMap[C.GoString(issueType)]
issueTypeInt, err := strconv.Atoi(issueIndex)
if err != nil {
return sendError(err)
return nil, sendError(err)
}

uc := userConfig()

subscriptionLevel := "free"
if a.IsPro() {
if isProUser, ok := a.IsProUser(); ok && isProUser {
subscriptionLevel = "pro"
}

Expand All @@ -397,10 +451,10 @@ func reportIssue(email, issueType, description *C.char) *C.char {
nil,
)
if err != nil {
return sendError(err)
return nil, sendError(err)
}
log.Debug("Successfully reported issue")
return C.CString("true")
return C.CString("true"), nil
}

//export checkUpdates
Expand Down Expand Up @@ -476,6 +530,18 @@ func runApp(a *app.App) {
a.Run(true)
}

// useOSLocale detect OS locale for current user and let i18n to use it
func useOSLocale() (string, error) {
userLocale, err := jibber_jabber.DetectIETF()
if err != nil || userLocale == "C" {
log.Debugf("Ignoring OS locale and using default")
userLocale = defaultLocale
}
log.Debugf("Using OS locale of current user: %v", userLocale)
a.SetLanguage(userLocale)
return userLocale, nil
}

func i18nInit(a *app.App) {
i18n.SetMessagesFunc(func(filename string) ([]byte, error) {
return a.GetTranslations(filename)
Expand All @@ -485,10 +551,11 @@ func i18nInit(a *app.App) {
if _, err := i18n.SetLocale(locale); err != nil {
log.Debugf("i18n.SetLocale(%s) failed, fallback to OS default: %q", locale, err)

// On startup GetLanguage will return '', as the browser has not set the language yet.
// We use the OS locale instead and make sure the language is populated.
if locale, err := i18n.UseOSLocale(); err != nil {
// On startup GetLanguage will return '' We use the OS locale instead and make sure the language is
// populated.
if locale, err := useOSLocale(); err != nil {
log.Debugf("i18n.UseOSLocale: %q", err)
a.SetLanguage(defaultLocale)
} else {
a.SetLanguage(locale)
}
Expand Down
Loading
Loading