LCOV - code coverage report
Current view: top level - lib/views - globalsettingsexperimentsview.dart (source / functions) Hit Total Coverage
Test: lcov.info Lines: 0 178 0.0 %
Date: 2026-08-30 22:38:45 Functions: 0 0 -

          Line data    Source code
       1             : import 'dart:io';
       2             : 
       3             : import 'package:flutter/material.dart';
       4             : import 'package:provider/provider.dart';
       5             : import 'package:cwtch/l10n/app_localizations.dart';
       6             : 
       7             : import '../cwtch_icons_icons.dart';
       8             : import '../main.dart';
       9             : import '../models/servers.dart';
      10             : import '../models/hybridgroups.dart';
      11             : import '../settings.dart';
      12             : import '../themes/opaque.dart';
      13             : import '../widgets/folderpicker.dart';
      14             : import 'globalsettingsview.dart';
      15             : 
      16             : class GlobalSettingsExperimentsView extends StatefulWidget {
      17           0 :   @override
      18           0 :   _GlobalSettingsExperimentsViewState createState() => _GlobalSettingsExperimentsViewState();
      19             : }
      20             : 
      21             : class _GlobalSettingsExperimentsViewState extends State<GlobalSettingsExperimentsView> {
      22             :   ScrollController settingsListScrollController = ScrollController();
      23             : 
      24           0 :   Widget build(BuildContext context) {
      25           0 :     return Consumer<Settings>(
      26           0 :       builder: (ccontext, settings, child) {
      27           0 :         return LayoutBuilder(
      28           0 :           builder: (BuildContext context, BoxConstraints viewportConstraints) {
      29           0 :             return Scrollbar(
      30           0 :               key: Key("ExperimentsSettingsView"),
      31             :               trackVisibility: true,
      32           0 :               controller: settingsListScrollController,
      33           0 :               child: SingleChildScrollView(
      34             :                 clipBehavior: Clip.antiAlias,
      35           0 :                 controller: settingsListScrollController,
      36           0 :                 child: ConstrainedBox(
      37           0 :                   constraints: BoxConstraints(minHeight: viewportConstraints.maxHeight, maxWidth: viewportConstraints.maxWidth),
      38           0 :                   child: Container(
      39           0 :                     color: settings.theme.backgroundPaneColor,
      40           0 :                     child: Column(
      41           0 :                       children: [
      42           0 :                         SwitchListTile(
      43           0 :                           title: Text(AppLocalizations.of(context)!.experimentsEnabled),
      44           0 :                           subtitle: Text(AppLocalizations.of(context)!.descriptionExperiments),
      45           0 :                           value: settings.experimentsEnabled,
      46           0 :                           onChanged: (bool value) {
      47             :                             if (value) {
      48           0 :                               settings.enableExperiments();
      49             :                             } else {
      50           0 :                               settings.disableExperiments();
      51             :                             }
      52             :                             // Save Settings...
      53           0 :                             saveSettings(context);
      54             :                           },
      55           0 :                           activeTrackColor: settings.theme.defaultButtonColor,
      56           0 :                           inactiveTrackColor: settings.theme.defaultButtonDisabledColor,
      57           0 :                           secondary: Icon(CwtchIcons.enable_experiments, color: settings.current().mainTextColor),
      58             :                         ),
      59           0 :                         Visibility(
      60           0 :                           visible: settings.experimentsEnabled,
      61           0 :                           child: Column(
      62           0 :                             children: [
      63           0 :                               SwitchListTile(
      64           0 :                                 title: Text(AppLocalizations.of(context)!.enableGroups),
      65           0 :                                 subtitle: Text(AppLocalizations.of(context)!.descriptionExperimentsGroups),
      66           0 :                                 value: settings.isExperimentEnabled(TapirGroupsExperiment),
      67           0 :                                 onChanged: (bool value) {
      68             :                                   if (value) {
      69           0 :                                     settings.enableExperiment(TapirGroupsExperiment);
      70             :                                   } else {
      71           0 :                                     settings.disableExperiment(TapirGroupsExperiment);
      72             :                                   }
      73             :                                   // Save Settings...
      74           0 :                                   saveSettings(context);
      75             :                                 },
      76           0 :                                 activeTrackColor: settings.theme.defaultButtonColor,
      77           0 :                                 inactiveTrackColor: settings.theme.defaultButtonDisabledColor,
      78           0 :                                 secondary: Icon(CwtchIcons.enable_groups, color: settings.current().mainTextColor),
      79             :                               ),
      80           0 :                               Visibility(
      81           0 :                                 visible: !Platform.isAndroid && !Platform.isIOS,
      82           0 :                                 child: SwitchListTile(
      83           0 :                                   title: Text(AppLocalizations.of(context)!.settingServers),
      84           0 :                                   subtitle: Provider.of<FlwtchState>(context, listen: false).cwtch.IsServersCompiled()
      85           0 :                                       ? Text(AppLocalizations.of(context)!.settingServersDescription)
      86           0 :                                       : Text("This version of Cwtch has been compiled without support for the server hosting experiment."),
      87           0 :                                   value: Provider.of<FlwtchState>(context, listen: false).cwtch.IsServersCompiled() && settings.isExperimentEnabled(ServerManagementExperiment),
      88           0 :                                   onChanged: Provider.of<FlwtchState>(context, listen: false).cwtch.IsServersCompiled()
      89           0 :                                       ? (bool value) {
      90           0 :                                           Provider.of<ServerListState>(context, listen: false).clear();
      91             :                                           if (value) {
      92           0 :                                             settings.enableExperiment(ServerManagementExperiment);
      93             :                                           } else {
      94           0 :                                             settings.disableExperiment(ServerManagementExperiment);
      95             :                                           }
      96             :                                           // Save Settings...
      97           0 :                                           saveSettings(context);
      98             :                                         }
      99             :                                       : null,
     100           0 :                                   activeTrackColor: settings.theme.defaultButtonColor,
     101           0 :                                   inactiveTrackColor: settings.theme.defaultButtonDisabledColor,
     102           0 :                                   secondary: Icon(CwtchIcons.dns_24px),
     103             :                                 ),
     104             :                               ),
     105           0 :                               Visibility(
     106             :                                 visible: true,
     107           0 :                                 child: SwitchListTile(
     108           0 :                                   title: Text(AppLocalizations.of(context)!.settingHybridGroups),
     109           0 :                                   subtitle: Text(AppLocalizations.of(context)!.settingHybridGroupsDescription),
     110           0 :                                   value: Provider.of<FlwtchState>(context, listen: false).cwtch.IsManagedGroupsCompiled() && settings.isExperimentEnabled(GroupManagerExperiment),
     111           0 :                                   onChanged: (bool value) {
     112           0 :                                     Provider.of<HybridGroupsListState>(context, listen: false).clear();
     113             :                                     if (value) {
     114           0 :                                       settings.enableExperiment(GroupManagerExperiment);
     115             :                                     } else {
     116           0 :                                       settings.disableExperiment(GroupManagerExperiment);
     117             :                                     }
     118             :                                     // Save Settings...
     119           0 :                                     saveSettings(context);
     120             :                                   },
     121           0 :                                   activeTrackColor: settings.theme.defaultButtonColor,
     122           0 :                                   inactiveTrackColor: settings.theme.defaultButtonDisabledColor,
     123           0 :                                   secondary: Icon(CwtchIcons.dns_24px),
     124             :                                 ),
     125             :                               ),
     126           0 :                               SwitchListTile(
     127           0 :                                 title: Text(AppLocalizations.of(context)!.settingFileSharing),
     128           0 :                                 subtitle: Text(AppLocalizations.of(context)!.descriptionFileSharing),
     129           0 :                                 value: settings.isExperimentEnabled(FileSharingExperiment),
     130           0 :                                 onChanged: (bool value) {
     131             :                                   if (value) {
     132           0 :                                     if (checkDownloadDirectory(context, settings)) {
     133           0 :                                       settings.enableExperiment(FileSharingExperiment);
     134             :                                     } else {
     135           0 :                                       settings.enableExperiment(FileSharingExperiment);
     136           0 :                                       settings.disableExperiment(ImagePreviewsExperiment);
     137             :                                     }
     138             :                                   } else {
     139           0 :                                     settings.disableExperiment(FileSharingExperiment);
     140           0 :                                     settings.disableExperiment(ImagePreviewsExperiment);
     141             :                                   }
     142           0 :                                   saveSettings(context);
     143             :                                 },
     144           0 :                                 activeTrackColor: settings.theme.defaultButtonColor,
     145           0 :                                 inactiveTrackColor: settings.theme.defaultButtonDisabledColor,
     146           0 :                                 secondary: Icon(CwtchIcons.attached_file_3, color: settings.current().mainTextColor),
     147             :                               ),
     148           0 :                               Visibility(
     149           0 :                                 visible: settings.isExperimentEnabled(FileSharingExperiment),
     150           0 :                                 child: Column(
     151           0 :                                   children: [
     152           0 :                                     SwitchListTile(
     153           0 :                                       title: Text(AppLocalizations.of(context)!.settingImagePreviews),
     154           0 :                                       subtitle: Text(AppLocalizations.of(context)!.settingImagePreviewsDescription),
     155           0 :                                       value: settings.isExperimentEnabled(ImagePreviewsExperiment),
     156           0 :                                       onChanged: (bool value) {
     157             :                                         if (value) {
     158           0 :                                           if (checkDownloadDirectory(context, settings)) {
     159           0 :                                             settings.enableExperiment(ImagePreviewsExperiment);
     160             :                                           } else {
     161           0 :                                             settings.disableExperiment(ImagePreviewsExperiment);
     162             :                                           }
     163             :                                         } else {
     164           0 :                                           settings.disableExperiment(ImagePreviewsExperiment);
     165             :                                         }
     166           0 :                                         saveSettings(context);
     167             :                                       },
     168           0 :                                       activeTrackColor: settings.theme.defaultButtonColor,
     169           0 :                                       inactiveTrackColor: settings.theme.defaultButtonDisabledColor,
     170           0 :                                       secondary: Icon(Icons.photo, color: settings.current().mainTextColor),
     171             :                                     ),
     172           0 :                                     Visibility(
     173           0 :                                       visible: settings.isExperimentEnabled(ImagePreviewsExperiment) && !Platform.isAndroid,
     174           0 :                                       child: CwtchFolderPicker(
     175           0 :                                         testKey: Key("DownloadFolderPicker"),
     176           0 :                                         label: AppLocalizations.of(context)!.settingDownloadFolder,
     177           0 :                                         initialValue: settings.downloadPath,
     178           0 :                                         textStyle: settings.scaleFonts(defaultDropDownMenuItemTextStyle),
     179           0 :                                         description: AppLocalizations.of(context)!.fileSharingSettingsDownloadFolderDescription,
     180           0 :                                         tooltip: AppLocalizations.of(context)!.fileSharingSettingsDownloadFolderTooltip,
     181           0 :                                         onSave: (newVal) {
     182           0 :                                           settings.downloadPath = newVal;
     183           0 :                                           saveSettings(context);
     184             :                                         },
     185             :                                       ),
     186             :                                     ),
     187             :                                   ],
     188             :                                 ),
     189             :                               ),
     190           0 :                               Visibility(
     191           0 :                                 visible: Provider.of<FlwtchState>(context, listen: false).cwtch.IsBlodeuweddSupported(),
     192           0 :                                 child: SwitchListTile(
     193           0 :                                   title: Text(AppLocalizations.of(context)!.blodeuweddExperimentEnable),
     194           0 :                                   subtitle: Provider.of<FlwtchState>(context, listen: false).cwtch.IsBlodeuweddSupported()
     195           0 :                                       ? Text(AppLocalizations.of(context)!.blodeuweddDescription)
     196           0 :                                       : Text(AppLocalizations.of(context)!.blodeuweddNotSupported),
     197           0 :                                   value: Provider.of<FlwtchState>(context, listen: false).cwtch.IsBlodeuweddSupported() && settings.isExperimentEnabled(BlodeuweddExperiment),
     198           0 :                                   onChanged: Provider.of<FlwtchState>(context, listen: false).cwtch.IsBlodeuweddSupported()
     199           0 :                                       ? (bool value) {
     200             :                                           if (value) {
     201           0 :                                             settings.enableExperiment(BlodeuweddExperiment);
     202             :                                           } else {
     203           0 :                                             settings.disableExperiment(BlodeuweddExperiment);
     204             :                                           }
     205           0 :                                           saveSettings(context);
     206             :                                         }
     207             :                                       : null,
     208           0 :                                   activeTrackColor: settings.theme.defaultButtonColor,
     209           0 :                                   inactiveTrackColor: settings.theme.defaultButtonDisabledColor,
     210           0 :                                   secondary: Icon(Icons.assistant, color: settings.current().mainTextColor),
     211             :                                 ),
     212             :                               ),
     213           0 :                               Visibility(
     214           0 :                                 visible: Provider.of<FlwtchState>(context, listen: false).cwtch.IsBlodeuweddSupported() && settings.isExperimentEnabled(BlodeuweddExperiment),
     215           0 :                                 child: CwtchFolderPicker(
     216           0 :                                   testKey: Key("DownloadFolderPicker"),
     217           0 :                                   label: AppLocalizations.of(context)!.settingDownloadFolder,
     218           0 :                                   initialValue: settings.blodeuweddPath,
     219           0 :                                   description: AppLocalizations.of(context)!.blodeuweddPath,
     220           0 :                                   tooltip: AppLocalizations.of(context)!.blodeuweddPath,
     221           0 :                                   onSave: (newVal) {
     222           0 :                                     settings.blodeuweddPath = newVal;
     223           0 :                                     saveSettings(context);
     224             :                                   },
     225             :                                 ),
     226             :                               ),
     227             :                             ],
     228             :                           ),
     229             :                         ),
     230           0 :                         Visibility(
     231           0 :                           visible: settings.experimentsEnabled,
     232           0 :                           child: SwitchListTile(
     233           0 :                             title: Text(AppLocalizations.of(context)!.enableExperimentClickableLinks),
     234           0 :                             subtitle: Text(AppLocalizations.of(context)!.experimentClickableLinksDescription),
     235           0 :                             value: settings.isExperimentEnabled(ClickableLinksExperiment),
     236           0 :                             onChanged: (bool value) {
     237             :                               if (value) {
     238           0 :                                 settings.enableExperiment(ClickableLinksExperiment);
     239             :                               } else {
     240           0 :                                 settings.disableExperiment(ClickableLinksExperiment);
     241             :                               }
     242           0 :                               saveSettings(context);
     243             :                             },
     244           0 :                             activeTrackColor: settings.theme.defaultButtonColor,
     245           0 :                             inactiveTrackColor: settings.theme.defaultButtonDisabledColor,
     246           0 :                             secondary: Icon(Icons.link, color: settings.current().mainTextColor),
     247             :                           ),
     248             :                         ),
     249           0 :                         Visibility(
     250           0 :                           visible: settings.experimentsEnabled,
     251           0 :                           child: SwitchListTile(
     252           0 :                             title: Text(AppLocalizations.of(context)!.enableExperimentQRCode),
     253           0 :                             subtitle: Text(AppLocalizations.of(context)!.experimentQRCodeDescription),
     254           0 :                             value: settings.isExperimentEnabled(QRCodeExperiment),
     255           0 :                             onChanged: (bool value) {
     256             :                               if (value) {
     257           0 :                                 settings.enableExperiment(QRCodeExperiment);
     258             :                               } else {
     259           0 :                                 settings.disableExperiment(QRCodeExperiment);
     260             :                               }
     261           0 :                               saveSettings(context);
     262             :                             },
     263           0 :                             activeTrackColor: settings.theme.defaultButtonColor,
     264           0 :                             inactiveTrackColor: settings.theme.defaultButtonDisabledColor,
     265           0 :                             secondary: Icon(Icons.qr_code, color: settings.current().mainTextColor),
     266             :                           ),
     267             :                         ),
     268             :                       ],
     269             :                     ),
     270             :                   ),
     271             :                 ),
     272             :               ),
     273             :             );
     274             :           },
     275             :         );
     276             :       },
     277             :     );
     278             :   }
     279             : 
     280           0 :   bool checkDownloadDirectory(context, settings) {
     281             :     bool showError = false;
     282           0 :     if (settings.downloadPath != "") {
     283             :     } else {
     284             :       // check if the default download path exists
     285           0 :       var path = Provider.of<FlwtchState>(context, listen: false).cwtch.defaultDownloadPath();
     286             :       if (path != null) {
     287           0 :         settings.downloadPath = path;
     288             :       } else {
     289             :         showError = true;
     290             :       }
     291             :     }
     292             : 
     293           0 :     if (!showError && Directory(settings.downloadPath).existsSync()) {
     294             :       return true;
     295             :     } else {
     296           0 :       final snackBar = SnackBar(content: Text(AppLocalizations.of(context)!.errorDownloadDirectoryDoesNotExist));
     297           0 :       ScaffoldMessenger.of(context).showSnackBar(snackBar);
     298             :       return false;
     299             :     }
     300             :   }
     301             : }

Generated by: LCOV version 1.14