Skip to content

Commit

Permalink
Lantern Desktop Beta 8.0.0 collected testing issues (#1057)
Browse files Browse the repository at this point in the history
* set default content padding on desktop text fields

* make label no longer a requirement of text field

* set padding on text area

* Format code.

* Use focus instead of show.

* update padding

* Add tryCacheUserData

* Add ffi method for exiting app and use it instead of SystemNavigator.pop

* Use SystemNavigator.pop for flutter exit.

---------

Co-authored-by: Jigar-f <[email protected]>
  • Loading branch information
atavism and jigar-f authored Apr 29, 2024
1 parent f120116 commit 09557a4
Show file tree
Hide file tree
Showing 8 changed files with 144 additions and 107 deletions.
42 changes: 28 additions & 14 deletions desktop/lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,12 @@ func start() {
}()

golog.SetPrepender(logging.Timestamped)
handleSignals(a)

go func() {
defer logging.Close()
i18nInit(a)
runApp(a)
a.Run(true)

err := a.WaitForExit()
if err != nil {
Expand Down Expand Up @@ -171,12 +172,12 @@ func fetchPayentMethodV4() error {

//export sysProxyOn
func sysProxyOn() {
a.SysproxyOn()
go a.SysproxyOn()
}

//export sysProxyOff
func sysProxyOff() {
a.SysProxyOff()
go a.SysProxyOff()
}

//export selectedTab
Expand Down Expand Up @@ -241,6 +242,11 @@ func paymentMethodsV4() *C.char {
return C.CString(string(b))
}

func cachedUserData() (*protos.User, bool) {
uc := userConfig(a.Settings())
return app.GetUserDataFast(context.Background(), uc.GetUserID())
}

func getUserData() (*protos.User, error) {
resp, err := proClient.UserData(context.Background())
if err != nil {
Expand All @@ -253,21 +259,29 @@ func getUserData() (*protos.User, error) {
return user, nil
}

// tryCacheUserData retrieves the latest user data for the given user.
// It first checks the cache and if present returns the user data stored there
func tryCacheUserData() (*protos.User, error) {
if cacheUserData, isOldFound := cachedUserData(); isOldFound {
return cacheUserData, nil
}
return getUserData()
}

// this method is reposible for checking if the user has updated plan or bought plans
//
//export hasPlanUpdatedOrBuy
func hasPlanUpdatedOrBuy() *C.char {
//Get the cached user data
log.Debugf("DEBUG: Checking if user has updated plan or bought new plan")
uc := userConfig(a.Settings())
cahcheUserData, isOldFound := app.GetUserDataFast(context.Background(), uc.GetUserID())
cacheUserData, isOldFound := cachedUserData()
//Get latest user data
resp, err := proClient.UserData(context.Background())
if err != nil {
return sendError(err)
}
if isOldFound {
if cahcheUserData.Expiration < resp.User.Expiration {
if cacheUserData.Expiration < resp.User.Expiration {
// New data has a later expiration
return C.CString(string("true"))
}
Expand All @@ -277,7 +291,7 @@ func hasPlanUpdatedOrBuy() *C.char {

//export devices
func devices() *C.char {
user, err := getUserData()
user, err := tryCacheUserData()
if err != nil {
return sendError(err)
}
Expand Down Expand Up @@ -320,7 +334,7 @@ func removeDevice(deviceId *C.char) *C.char {

//export expiryDate
func expiryDate() *C.char {
user, err := getUserData()
user, err := tryCacheUserData()
if err != nil {
return sendError(err)
}
Expand Down Expand Up @@ -518,6 +532,11 @@ func paymentRedirect(planID, currency, provider, email, deviceName *C.char) *C.c
return sendJson(resp)
}

//export exitApp
func exitApp() {
a.Exit(nil)
}

//export developmentMode
func developmentMode() *C.char {
return C.CString("false")
Expand Down Expand Up @@ -641,12 +660,6 @@ func configDir(flags *flashlight.Flags) string {
return cdir
}

func runApp(a *app.App) {
// Schedule cleanup actions
handleSignals(a)
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()
Expand Down Expand Up @@ -690,6 +703,7 @@ func handleSignals(a *app.App) {
go func() {
s := <-c
log.Debugf("Got signal \"%s\", exiting...", s)
a.Exit(nil)
}()
}

Expand Down
4 changes: 0 additions & 4 deletions lib/account/device_linking/authorize_device_via_email.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@ class AuthorizeDeviceViaEmail extends StatelessWidget {
controller: emailController,
autovalidateMode: AutovalidateMode.disabled,
//TODO: this throws an error when we set it to AutovalidateMode.onUserInteraction
contentPadding: const EdgeInsetsDirectional.only(
top: 8.0,
bottom: 8.0,
),
label: 'Email'.i18n,
helperText: 'auth_email_helper_text'.i18n,
keyboardType: TextInputType.emailAddress,
Expand Down
16 changes: 9 additions & 7 deletions lib/account/report_issue.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// ignore_for_file: use_build_context_synchronously

import 'package:email_validator/email_validator.dart';
import 'package:lantern/common/common.dart';
import 'package:lantern/common/ui/app_loading_dialog.dart';
Expand Down Expand Up @@ -88,10 +87,6 @@ class _ReportIssueState extends State<ReportIssue> {
initialValue: emailAddress,
controller: emailController,
autovalidateMode: AutovalidateMode.disabled,
contentPadding: const EdgeInsetsDirectional.only(
top: 8.0,
bottom: 8.0,
),
label: 'email'.i18n,
onChanged: (value) {
setState(() {});
Expand Down Expand Up @@ -138,6 +133,12 @@ class _ReportIssueState extends State<ReportIssue> {
issueController.text = newValue!;
});
},
padding: isDesktop()
? const EdgeInsetsDirectional.only(
top: 8,
bottom: 8,
)
: const EdgeInsetsDirectional.all(0),
items: <String>[
'cannot_access_blocked_sites'.i18n,
'cannot_complete_purchase'.i18n,
Expand All @@ -161,8 +162,9 @@ class _ReportIssueState extends State<ReportIssue> {
child: CTextField(
tooltipMessage: 'report_description'.i18n,
controller: descController,
contentPadding: const EdgeInsetsDirectional.all(8.0),
label: '',
contentPadding: isDesktop()
? const EdgeInsetsDirectional.all(16.0)
: const EdgeInsetsDirectional.all(8.0),
hintText: 'issue_description'.i18n,
autovalidateMode: AutovalidateMode.disabled,
maxLines: 8,
Expand Down
3 changes: 2 additions & 1 deletion lib/common/common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ export 'ui/text_highlighter.dart';
export 'ui/text_styles.dart';
export 'ui/transitions.dart';
export 'app_secret.dart';

final appLogger = Logger(
printer: PrettyPrinter(
methodCount: 0,
Expand All @@ -110,4 +111,4 @@ bool isMobile() {

bool isDesktop() {
return Platform.isMacOS || Platform.isLinux || Platform.isWindows;
}
}
59 changes: 34 additions & 25 deletions lib/common/ui/custom/text_field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import 'package:lantern/common/common.dart';
class CTextField extends StatefulWidget {
late final CustomTextEditingController controller;
late final String? initialValue;
late final dynamic label;
late final dynamic? label;
late final String? helperText;
late final String? hintText;
late final Widget? prefixIcon;
Expand Down Expand Up @@ -36,7 +36,7 @@ class CTextField extends StatefulWidget {
CTextField({
required this.controller,
this.initialValue,
required this.label,
this.label,
this.helperText,
this.hintText,
this.prefixIcon,
Expand Down Expand Up @@ -154,7 +154,15 @@ class _CTextFieldState extends State<CTextField> {
widget.textCapitalization ?? TextCapitalization.none,
decoration: InputDecoration(
contentPadding: widget.contentPadding ??
const EdgeInsetsDirectional.all(0),
(isDesktop()
? const EdgeInsetsDirectional.only(
top: 24,
bottom: 24,
)
: const EdgeInsetsDirectional.only(
top: 8,
bottom: 8,
)),
isDense: true,
floatingLabelBehavior: FloatingLabelBehavior.never,
// we handle floating labels using our custom method below
Expand Down Expand Up @@ -204,29 +212,30 @@ class _CTextFieldState extends State<CTextField> {
),
),
// * Label
(widget.label is String)
? Container(
margin: const EdgeInsetsDirectional.only(start: 11),
padding: EdgeInsetsDirectional.only(
start: hasFocus ? 2 : 0,
end: hasFocus ? 2 : 0,
),
color: white,
child: !hasFocus && widget.controller.value.text.isEmpty
? Container()
: CText(
widget.label,
style: CTextStyle(
fontSize: 12,
lineHeight: 12,
color: fieldKey.currentState?.mounted == true &&
fieldKey.currentState?.hasError == true
? indicatorRed
: blue4,
if (widget.label != null)
(widget.label is String)
? Container(
margin: const EdgeInsetsDirectional.only(start: 11),
padding: EdgeInsetsDirectional.only(
start: hasFocus ? 2 : 0,
end: hasFocus ? 2 : 0,
),
color: white,
child: !hasFocus && widget.controller.value.text.isEmpty
? Container()
: CText(
widget.label,
style: CTextStyle(
fontSize: 12,
lineHeight: 12,
color: fieldKey.currentState?.mounted == true &&
fieldKey.currentState?.hasError == true
? indicatorRed
: blue4,
),
),
),
)
: widget.label,
)
: widget.label,
],
);
}
Expand Down
5 changes: 5 additions & 0 deletions lib/ffi.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ void setLang(lang) => _bindings.setSelectLang(lang);

String websocketAddr() => _bindings.websocketAddr().cast<Utf8>().toDartString();

void ffiExit() {
_bindings.exitApp();
SystemChannels.platform.invokeMethod('SystemNavigator.pop');
}

Pointer<Utf8> ffiVpnStatus() => _bindings.vpnStatus().cast<Utf8>();

Pointer<Utf8> ffiSelectedTab() => _bindings.selectedTab().cast<Utf8>();
Expand Down
Loading

0 comments on commit 09557a4

Please sign in to comment.