Skip to content

Commit

Permalink
Fix issues with report an issue page (#1064)
Browse files Browse the repository at this point in the history
* Fix issues with report an issue page

* check nil user and add set proxy all call

* check nil user and add set proxy all call

* Start settings service

* simplify websocket code for receiving messages

* update comments, clean-ups

* do not dispose controller.

* remove mobile call for setProxyAll

---------

Co-authored-by: Jigar-f <[email protected]>
  • Loading branch information
atavism and jigar-f authored May 3, 2024
1 parent bf1409a commit 17efb18
Show file tree
Hide file tree
Showing 8 changed files with 135 additions and 57 deletions.
2 changes: 1 addition & 1 deletion assets/locales/en.po
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ msgid "other"
msgstr "Other"

msgid "issue_description"
msgstr "Issue Description"
msgstr "Describe your issue"

msgid "check_for_updates"
msgstr "Check for Updates"
Expand Down
6 changes: 6 additions & 0 deletions desktop/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,12 @@ func (app *App) beforeStart(listenAddr string) {
app.Exit(nil)
os.Exit(0)
}

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

app.AddExitFunc("stopping loconf scanner", LoconfScanner(app.settings, app.configDir, 4*time.Hour,
func() (bool, bool) { return app.IsProUser(context.Background()) }, func() string {
return "/img/lantern_logo.png"
Expand Down
17 changes: 16 additions & 1 deletion desktop/lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,12 +238,27 @@ func getUserData() (*protos.User, error) {
return nil, err
}
user := resp.User
if user.Email != "" {
if user != nil && user.Email != "" {
a.Settings().SetEmailAddress(user.Email)
}
return user, nil
}

//export proxyAll
func proxyAll() *C.char {
proxyAll := a.Settings().GetProxyAll()
if proxyAll {
return C.CString("true")
}
return C.CString("false")
}

//export setProxyAll
func setProxyAll(value *C.char) {
proxyAll, _ := strconv.ParseBool(C.GoString(value))
go a.Settings().SetProxyAll(proxyAll)
}

// 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) {
Expand Down
14 changes: 3 additions & 11 deletions lib/account/report_issue.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,7 @@ class _ReportIssueState extends State<ReportIssue> {
return null;
});

@override
void dispose() {
emailController.dispose();
issueController.dispose();
descController.dispose();
super.dispose();
}


@override
Widget build(BuildContext context) {
Expand Down Expand Up @@ -166,6 +160,7 @@ class _ReportIssueState extends State<ReportIssue> {
? const EdgeInsetsDirectional.all(16.0)
: const EdgeInsetsDirectional.all(8.0),
hintText: 'issue_description'.i18n,
floatingLabelBehavior: FloatingLabelBehavior.always,
autovalidateMode: AutovalidateMode.disabled,
maxLines: 8,
keyboardType: TextInputType.multiline,
Expand All @@ -176,7 +171,7 @@ class _ReportIssueState extends State<ReportIssue> {
),
const Spacer(),
Tooltip(
message: AppKeys.sendReport,
message: isDesktop() ? '' : AppKeys.sendReport,
child: Button(
width: 200,
disabled: isButtonDisabled(),
Expand All @@ -202,9 +197,6 @@ class _ReportIssueState extends State<ReportIssue> {
if (issueController.text.isEmpty) {
return true;
}
if (descController.text.isEmpty) {
return true;
}
return false;
}

Expand Down
59 changes: 59 additions & 0 deletions lib/account/settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ class Settings extends StatelessWidget {

final packageInfo = PackageInfo.fromPlatform();

void openInfoProxyAll(BuildContext context) {
CDialog.showInfo(
context,
title: 'proxy_all'.i18n,
description: 'description_proxy_all_dialog'.i18n,
iconPath: ImagePaths.key,
);
}

void changeLanguage(BuildContext context) async =>
await context.pushRoute(Language());

Expand Down Expand Up @@ -142,6 +151,56 @@ class Settings extends StatelessWidget {
],
),
),
//* Proxy all
if (isDesktop())
sessionModel.proxyAll(
(BuildContext context, bool proxyAll, Widget? child) =>
ListItemFactory.settingsItem(
header: 'VPN'.i18n,
icon: ImagePaths.key,
content: CInkWell(
onTap: () => openInfoProxyAll(context),
child: Row(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Flexible(
child: CText(
'proxy_everything_is'
.i18n
.fill([proxyAll ? 'ON'.i18n : 'OFF'.i18n]),
softWrap: false,
style: tsSubtitle1.short,
),
),
const Padding(
padding: EdgeInsetsDirectional.only(start: 4.0),
child: CAssetImage(
key: ValueKey('proxy_all_icon'),
path: ImagePaths.info,
size: 12,
),
),
],
),
),
trailingArray: [
FlutterSwitch(
width: 44.0,
height: 24.0,
valueFontSize: 12.0,
padding: 2,
toggleSize: 18.0,
value: proxyAll,
activeColor: indicatorGreen,
inactiveColor: offSwitchColor,
onToggle: (bool newValue) {
sessionModel.setProxyAll(newValue);
},
),
],
),
),
ListItemFactory.settingsItem(
header: 'about'.i18n,
content: 'privacy_policy'.i18n,
Expand Down
84 changes: 42 additions & 42 deletions lib/common/session_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ class SessionModel extends Model {
'hasSucceedingProxy',
false,
);

}

if (Platform.isAndroid) {
Expand All @@ -82,11 +81,17 @@ class SessionModel extends Model {
late ValueNotifier<bool?> proxyAvailable;
late ValueNotifier<String?> country;

// wsMessageProp parses the given json, checks if it represents a pro user message and
// returns the value (if any) in the map for the given property.
String? wsMessageProp(Map<String, dynamic> json, String field) {
if (json["type"] != "pro") return null;
return json["message"][field];
// listenWebsocket listens for websocket messages from the server. If a message matches the given message type,
// the onMessage callback is triggered with the given property value
void listenWebsocket<T>(WebsocketImpl? websocket, String messageType,
property, void Function(T?) onMessage) {
if (websocket == null) return;
websocket.messageStream.listen(
(json) {
if (json["type"] == messageType) onMessage(json["message"][property]);
},
onError: (error) => appLogger.i("websocket error: ${error.description}"),
);
}

Widget proUser(ValueWidgetBuilder<bool> builder) {
Expand All @@ -97,18 +102,10 @@ class SessionModel extends Model {
return ffiValueBuilder<bool>(
'prouser',
defaultValue: false,
onChanges: (setValue) {
if (websocket == null) return;
websocket.messageStream.listen(
(json) {
final userStatus = wsMessageProp(json, "userStatus");
if (userStatus != null && userStatus.toString() == "active")
setValue(true);
},
onError: (error) =>
appLogger.i("websocket error: ${error.description}"),
);
},
onChanges: (setValue) =>
listenWebsocket(websocket, "pro", "userStatus", (value) {
if (value != null && value.toString() == "active") setValue(true);
}),
ffiProUser,
builder: builder,
);
Expand Down Expand Up @@ -199,17 +196,10 @@ class SessionModel extends Model {
return ffiValueBuilder<String>(
'lang',
defaultValue: 'en',
onChanges: (setValue) {
if (websocket == null) return;
websocket.messageStream.listen(
(json) {
final language = wsMessageProp(json, "language");
if (language != null && language != "") setValue(language);
},
onError: (error) =>
appLogger.i("websocket error: ${error.description}"),
);
},
onChanges: (setValue) =>
listenWebsocket(websocket, "pro", "language", (value) {
if (value != null && value.toString() != "") setValue(value.toString());
}),
ffiLang,
builder: builder,
);
Expand Down Expand Up @@ -305,12 +295,11 @@ class SessionModel extends Model {
);
}

Future<void> setProxyAll<T>(bool on) async {
unawaited(
methodChannel.invokeMethod('setProxyAll', <String, dynamic>{
'on': on,
}),
);
Future<void> setProxyAll<T>(bool isOn) async {
if (isDesktop()) {
return await compute(ffiSetProxyAll, isOn ? 'true' : 'false');
}
throw Exception("Not supported on mobile");
}

Future<String> getCountryCode() async {
Expand Down Expand Up @@ -366,9 +355,9 @@ class SessionModel extends Model {
.invokeMethod('resendRecoveryCode', <String, dynamic>{});
}

void setSelectedTab(BuildContext context,String tab) {
Provider.of<BottomBarChangeNotifier>(context, listen: false).setCurrentIndex(tab);

void setSelectedTab(BuildContext context, String tab) {
Provider.of<BottomBarChangeNotifier>(context, listen: false)
.setCurrentIndex(tab);
}

Widget shouldShowGoogleAds(ValueWidgetBuilder<bool> builder) {
Expand All @@ -378,7 +367,6 @@ class SessionModel extends Model {
);
}


Widget replicaAddr(ValueWidgetBuilder<String> builder) {
if (isMobile()) {
return subscribedSingleValueBuilder<String>(
Expand Down Expand Up @@ -472,10 +460,9 @@ class SessionModel extends Model {
}

Future<bool> hasUpdatePlansOrBuy() async {
return compute(ffiHasPlanUpdateOrBuy,'');
return compute(ffiHasPlanUpdateOrBuy, '');
}


Plan planFromJson(Map<String, dynamic> item) {
print("called plans $item");
final locale = Localization.locale;
Expand Down Expand Up @@ -794,6 +781,20 @@ class SessionModel extends Model {
);
}

Widget proxyAll(ValueWidgetBuilder<bool> builder) {
final websocket = WebsocketImpl.instance();
return ffiValueBuilder<bool>(
'proxyAll',
defaultValue: false,
onChanges: (setValue) =>
listenWebsocket(websocket, "settings", "proxyAll", (value) {
if (value != null) setValue(value as bool);
}),
ffiProxyAll,
builder: builder,
);
}

Future<void> setSplitTunneling<T>(bool on) async {
unawaited(
methodChannel.invokeMethod('setSplitTunneling', <String, dynamic>{
Expand Down Expand Up @@ -833,5 +834,4 @@ class SessionModel extends Model {
Future<void> disableScreenShot() {
return methodChannel.invokeMethod('disableScreenshot', <String, dynamic>{});
}

}
6 changes: 4 additions & 2 deletions lib/common/ui/custom/text_field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class CTextField extends StatefulWidget {
late final TextInputAction? textInputAction;
late final void Function(String value)? onFieldSubmitted;
late final String? actionIconPath;
late final FloatingLabelBehavior? floatingLabelBehavior;
late final int? maxLength;
late final InputCounterWidgetBuilder? buildCounter;
late final TextCapitalization? textCapitalization;
Expand Down Expand Up @@ -50,6 +51,7 @@ class CTextField extends StatefulWidget {
this.textInputAction,
this.onFieldSubmitted,
this.actionIconPath,
this.floatingLabelBehavior,
this.maxLength,
this.buildCounter,
this.textCapitalization,
Expand Down Expand Up @@ -118,7 +120,7 @@ class _CTextFieldState extends State<CTextField> {
// thumbVisibility: true,
trackVisibility: true,
child: Tooltip(
message: widget.tooltipMessage ?? '',
message: isDesktop() ? '' : (widget.tooltipMessage ?? ''),
child: TextFormField(
key: fieldKey,
autofocus: widget.autofocus!,
Expand Down Expand Up @@ -164,7 +166,7 @@ class _CTextFieldState extends State<CTextField> {
bottom: 8,
)),
isDense: true,
floatingLabelBehavior: FloatingLabelBehavior.never,
floatingLabelBehavior: widget.floatingLabelBehavior ?? FloatingLabelBehavior.never,
// we handle floating labels using our custom method below
labelText: (widget.label is String) ? widget.label : '',
helperText: widget.helperText,
Expand Down
4 changes: 4 additions & 0 deletions lib/ffi.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ void sysProxyOff() => _bindings.sysProxyOff();

void setLang(lang) => _bindings.setSelectLang(lang);

void ffiSetProxyAll(String isOn) => _bindings.setProxyAll(isOn.toPointerChar());

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

void ffiExit() {
Expand All @@ -30,6 +32,8 @@ Pointer<Utf8> ffiLang() => _bindings.lang().cast<Utf8>();

Pointer<Utf8> ffiPlayVersion() => _bindings.playVersion().cast<Utf8>();

Pointer<Utf8> ffiProxyAll() => _bindings.proxyAll().cast<Utf8>();

Pointer<Utf8> ffiStoreVersion() => _bindings.storeVersion().cast<Utf8>();

Pointer<Utf8> ffiHasSucceedingProxy() =>
Expand Down

0 comments on commit 17efb18

Please sign in to comment.