From f4f885fcea156739b3c7be424b985e2b8649c172 Mon Sep 17 00:00:00 2001 From: Sarah Jamie Lewis Date: Fri, 4 Jun 2021 11:13:52 -0700 Subject: [PATCH] New experiment checking method. --- lib/config.dart | 2 +- lib/cwtch_icons_icons.dart | 2 +- lib/model.dart | 6 +++--- lib/settings.dart | 15 ++++++++++++++- lib/views/addcontactview.dart | 4 ++-- lib/views/globalsettingsview.dart | 2 +- lib/views/messageview.dart | 5 ++++- lib/views/profilemgrview.dart | 11 +++++++---- lib/widgets/malformedbubble.dart | 3 +-- lib/widgets/messagerow.dart | 6 ++---- lib/widgets/textfield.dart | 2 +- lib/widgets/tor_icon.dart | 5 +++-- 12 files changed, 40 insertions(+), 23 deletions(-) diff --git a/lib/config.dart b/lib/config.dart index 281f4c0..7d0c4b8 100644 --- a/lib/config.dart +++ b/lib/config.dart @@ -3,4 +3,4 @@ const dev_version = "development"; class EnvironmentConfig { static const BUILD_VER = String.fromEnvironment('BUILD_VER', defaultValue: dev_version); static const BUILD_DATE = String.fromEnvironment('BUILD_DATE', defaultValue: "now"); -} \ No newline at end of file +} diff --git a/lib/cwtch_icons_icons.dart b/lib/cwtch_icons_icons.dart index 127cfcf..c9f51b0 100644 --- a/lib/cwtch_icons_icons.dart +++ b/lib/cwtch_icons_icons.dart @@ -11,7 +11,7 @@ /// fonts: /// - asset: assets/fonts/CwtchIcons.ttf /// -/// +/// /// import 'package:flutter/widgets.dart'; diff --git a/lib/model.dart b/lib/model.dart index 71ce029..a07fb07 100644 --- a/lib/model.dart +++ b/lib/model.dart @@ -480,9 +480,9 @@ class MessageState extends ChangeNotifier { this.error = true; } } catch (e) { - this._overlay = -1; - this.loaded = true; - this.malformed = true; + this._overlay = -1; + this.loaded = true; + this.malformed = true; } }); } diff --git a/lib/settings.dart b/lib/settings.dart index cc59de2..0b52cbb 100644 --- a/lib/settings.dart +++ b/lib/settings.dart @@ -16,7 +16,8 @@ class Settings extends ChangeNotifier { Locale locale; late PackageInfo packageInfo; OpaqueThemeType theme; - late bool experimentsEnabled; + // explicitly set experiments to false until told otherwise... + bool experimentsEnabled = false; HashMap experiments = HashMap.identity(); late bool blockUnknownConnections; @@ -38,6 +39,18 @@ class Settings extends ChangeNotifier { return theme; } + /// isExperimentEnabled can be used to safely check whether a particular + /// experiment is enabled + bool isExperimentEnabled(String experiment) { + if (this.experimentsEnabled) { + if (this.experiments.containsKey(experiment)) { + // We now know it cannot be null... + return this.experiments[experiment]! == true; + } + } + return false; + } + /// Called by the event bus. When new settings are loaded from a file the JSON will /// be sent to the function and new settings will be instantiated based on the contents. handleUpdate(dynamic settings) { diff --git a/lib/views/addcontactview.dart b/lib/views/addcontactview.dart index 6446aca..ead0518 100644 --- a/lib/views/addcontactview.dart +++ b/lib/views/addcontactview.dart @@ -50,8 +50,8 @@ class _AddContactViewState extends State { Widget _buildForm() { ctrlrOnion.text = Provider.of(context).onion; - /// We display a different number of tabs dependening on the experiment setup - bool groupsEnabled = Provider.of(context).experimentsEnabled && Provider.of(context).experiments[TapirGroupsExperiment]!; + /// We display a different number of tabs depending on the experiment setup + bool groupsEnabled = Provider.of(context).isExperimentEnabled(TapirGroupsExperiment); return Consumer(builder: (context, globalErrorHandler, child) { return DefaultTabController( length: groupsEnabled ? 2 : 1, diff --git a/lib/views/globalsettingsview.dart b/lib/views/globalsettingsview.dart index 1e8caf7..c17c6f0 100644 --- a/lib/views/globalsettingsview.dart +++ b/lib/views/globalsettingsview.dart @@ -142,7 +142,7 @@ class _GlobalSettingsViewState extends State { SwitchListTile( title: Text(AppLocalizations.of(context)!.enableGroups, style: TextStyle(color: settings.current().mainTextColor())), subtitle: Text(AppLocalizations.of(context)!.descriptionExperimentsGroups), - value: settings.experiments.containsKey(TapirGroupsExperiment) && settings.experiments[TapirGroupsExperiment]!, + value: settings.isExperimentEnabled(TapirGroupsExperiment), onChanged: (bool value) { if (value) { settings.enableExperiment(TapirGroupsExperiment); diff --git a/lib/views/messageview.dart b/lib/views/messageview.dart index 04e4e99..6131854 100644 --- a/lib/views/messageview.dart +++ b/lib/views/messageview.dart @@ -50,7 +50,10 @@ class _MessageViewState extends State { //IconButton(icon: Icon(Icons.chat), onPressed: _pushContactSettings), //IconButton(icon: Icon(Icons.list), onPressed: _pushContactSettings), //IconButton(icon: Icon(Icons.push_pin), onPressed: _pushContactSettings), - IconButton(icon: Provider.of(context, listen: false).isGroup == true ? Icon(CwtchIcons.group_settings_24px) : Icon(CwtchIcons.peer_settings_24px), tooltip: AppLocalizations.of(context)!.conversationSettings, onPressed: _pushContactSettings), + IconButton( + icon: Provider.of(context, listen: false).isGroup == true ? Icon(CwtchIcons.group_settings_24px) : Icon(CwtchIcons.peer_settings_24px), + tooltip: AppLocalizations.of(context)!.conversationSettings, + onPressed: _pushContactSettings), ], ), body: Padding(padding: EdgeInsets.fromLTRB(8.0, 8.0, 8.0, 108.0), child: MessageList()), diff --git a/lib/views/profilemgrview.dart b/lib/views/profilemgrview.dart index 2b977d6..e0f708f 100644 --- a/lib/views/profilemgrview.dart +++ b/lib/views/profilemgrview.dart @@ -59,10 +59,13 @@ class _ProfileMgrViewState extends State { Expanded(child: Text(AppLocalizations.of(context)!.titleManageProfiles, style: TextStyle(color: settings.current().mainTextColor()))) ]), actions: [ - IconButton(icon: TorIcon(), onPressed: _pushTorStatus, tooltip: Provider.of(context).progress == 100 - ? AppLocalizations.of(context)!.networkStatusOnline - : (Provider.of(context).progress == 0 ? AppLocalizations.of(context)!.networkStatusDisconnected : AppLocalizations.of(context)!.networkStatusAttemptingTor), - ), + IconButton( + icon: TorIcon(), + onPressed: _pushTorStatus, + tooltip: Provider.of(context).progress == 100 + ? AppLocalizations.of(context)!.networkStatusOnline + : (Provider.of(context).progress == 0 ? AppLocalizations.of(context)!.networkStatusDisconnected : AppLocalizations.of(context)!.networkStatusAttemptingTor), + ), IconButton(icon: Icon(Icons.bug_report_outlined), onPressed: _setLoggingLevelDebug), IconButton( icon: Icon(CwtchIcons.lock_open_24px), diff --git a/lib/widgets/malformedbubble.dart b/lib/widgets/malformedbubble.dart index 8c1339a..fea7c1a 100644 --- a/lib/widgets/malformedbubble.dart +++ b/lib/widgets/malformedbubble.dart @@ -1,7 +1,6 @@ import 'package:cwtch/cwtch_icons_icons.dart'; import 'package:flutter/material.dart'; - final Color malformedColor = Color(0xFFE85DA1); // MalformedBubble is displayed in the case of a malformed message @@ -38,7 +37,7 @@ class MalformedBubbleState extends State { padding: EdgeInsets.all(4), child: Icon( CwtchIcons.favorite_black_24dp_broken, - size: 24, + size: 24, ))), Center( widthFactor: 1.0, diff --git a/lib/widgets/messagerow.dart b/lib/widgets/messagerow.dart index 9c30359..8f02b96 100644 --- a/lib/widgets/messagerow.dart +++ b/lib/widgets/messagerow.dart @@ -31,10 +31,8 @@ class _MessageRowState extends State { fromMe = false; } - Widget wdgBubble = Flexible( - flex: 3, - fit: FlexFit.loose, - child: Provider.of(context).loaded == true ? widgetForOverlay(Provider.of(context).overlay) : MessageLoadingBubble()); + Widget wdgBubble = + Flexible(flex: 3, fit: FlexFit.loose, child: Provider.of(context).loaded == true ? widgetForOverlay(Provider.of(context).overlay) : MessageLoadingBubble()); Widget wdgIcons = Icon(Icons.delete_forever_outlined, color: Provider.of(context).theme.dropShadowColor()); Widget wdgSpacer = Expanded(child: SizedBox(width: 60, height: 10)); var widgetRow = []; diff --git a/lib/widgets/textfield.dart b/lib/widgets/textfield.dart index 4b68593..cd396c7 100644 --- a/lib/widgets/textfield.dart +++ b/lib/widgets/textfield.dart @@ -7,7 +7,7 @@ doNothing(String x) {} // Provides a styled Text Field for use in Form Widgets. // Callers must provide a text controller, label helper text and a validator. class CwtchTextField extends StatefulWidget { - CwtchTextField({required this.controller, required this.labelText, this.validator = null, this.autofocus=false, this.onChanged = doNothing}); + CwtchTextField({required this.controller, required this.labelText, this.validator = null, this.autofocus = false, this.onChanged = doNothing}); final TextEditingController controller; final String labelText; final FormFieldValidator? validator; diff --git a/lib/widgets/tor_icon.dart b/lib/widgets/tor_icon.dart index 8ebf1ad..796e2a5 100644 --- a/lib/widgets/tor_icon.dart +++ b/lib/widgets/tor_icon.dart @@ -17,9 +17,10 @@ class _TorIconState extends State { @override Widget build(BuildContext context) { return RepaintBoundary( - child: Icon(Provider.of(context).progress == 0 ? CwtchIcons.onion_off : (Provider.of(context).progress == 100 ? CwtchIcons.onion_on: CwtchIcons.onion_waiting), + child: Icon( + Provider.of(context).progress == 0 ? CwtchIcons.onion_off : (Provider.of(context).progress == 100 ? CwtchIcons.onion_on : CwtchIcons.onion_waiting), color: Provider.of(context).theme.mainTextColor(), - semanticLabel: Provider.of(context).progress == 100 + semanticLabel: Provider.of(context).progress == 100 ? AppLocalizations.of(context)!.networkStatusOnline : (Provider.of(context).progress == 0 ? AppLocalizations.of(context)!.networkStatusDisconnected : AppLocalizations.of(context)!.networkStatusAttemptingTor), ));