LCOV - code coverage report
Current view: top level - lib/views - globalsettingsexperimentsview.dart (source / functions) Hit Total Coverage
Test: lcov.info Lines: 0 182 0.0 %
Date: 2026-08-30 05:23:47 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           0 :                                 visible: !Platform.isAndroid && !Platform.isIOS,
     107           0 :                                 child: SwitchListTile(
     108           0 :                                   title: Text(AppLocalizations.of(context)!.settingHybridGroups),
     109           0 :                                   subtitle: Provider.of<FlwtchState>(context, listen: false).cwtch.IsManagedGroupsCompiled()
     110           0 :                                       ? Text(AppLocalizations.of(context)!.settingHybridGroupsDescription)
     111           0 :                                       : Text("This version of Cwtch has been compiled without support for the hybrid groups experiment."),
     112           0 :                                   value: Provider.of<FlwtchState>(context, listen: false).cwtch.IsManagedGroupsCompiled() && settings.isExperimentEnabled(GroupManagerExperiment),
     113           0 :                                   onChanged: Provider.of<FlwtchState>(context, listen: false).cwtch.IsManagedGroupsCompiled()
     114           0 :                                       ? (bool value) {
     115           0 :                                           Provider.of<HybridGroupsListState>(context, listen: false).clear();
     116             :                                           if (value) {
     117           0 :                                             settings.enableExperiment(GroupManagerExperiment);
     118             :                                           } else {
     119           0 :                                             settings.disableExperiment(GroupManagerExperiment);
     120             :                                           }
     121             :                                           // Save Settings...
     122           0 :                                           saveSettings(context);
     123             :                                         }
     124             :                                       : null,
     125           0 :                                   activeTrackColor: settings.theme.defaultButtonColor,
     126           0 :                                   inactiveTrackColor: settings.theme.defaultButtonDisabledColor,
     127           0 :                                   secondary: Icon(CwtchIcons.dns_24px),
     128             :                                 ),
     129             :                               ),
     130           0 :                               SwitchListTile(
     131           0 :                                 title: Text(AppLocalizations.of(context)!.settingFileSharing),
     132           0 :                                 subtitle: Text(AppLocalizations.of(context)!.descriptionFileSharing),
     133           0 :                                 value: settings.isExperimentEnabled(FileSharingExperiment),
     134           0 :                                 onChanged: (bool value) {
     135             :                                   if (value) {
     136           0 :                                     if (checkDownloadDirectory(context, settings)) {
     137           0 :                                       settings.enableExperiment(FileSharingExperiment);
     138             :                                     } else {
     139           0 :                                       settings.enableExperiment(FileSharingExperiment);
     140           0 :                                       settings.disableExperiment(ImagePreviewsExperiment);
     141             :                                     }
     142             :                                   } else {
     143           0 :                                     settings.disableExperiment(FileSharingExperiment);
     144           0 :                                     settings.disableExperiment(ImagePreviewsExperiment);
     145             :                                   }
     146           0 :                                   saveSettings(context);
     147             :                                 },
     148           0 :                                 activeTrackColor: settings.theme.defaultButtonColor,
     149           0 :                                 inactiveTrackColor: settings.theme.defaultButtonDisabledColor,
     150           0 :                                 secondary: Icon(CwtchIcons.attached_file_3, color: settings.current().mainTextColor),
     151             :                               ),
     152           0 :                               Visibility(
     153           0 :                                 visible: settings.isExperimentEnabled(FileSharingExperiment),
     154           0 :                                 child: Column(
     155           0 :                                   children: [
     156           0 :                                     SwitchListTile(
     157           0 :                                       title: Text(AppLocalizations.of(context)!.settingImagePreviews),
     158           0 :                                       subtitle: Text(AppLocalizations.of(context)!.settingImagePreviewsDescription),
     159           0 :                                       value: settings.isExperimentEnabled(ImagePreviewsExperiment),
     160           0 :                                       onChanged: (bool value) {
     161             :                                         if (value) {
     162           0 :                                           if (checkDownloadDirectory(context, settings)) {
     163           0 :                                             settings.enableExperiment(ImagePreviewsExperiment);
     164             :                                           } else {
     165           0 :                                             settings.disableExperiment(ImagePreviewsExperiment);
     166             :                                           }
     167             :                                         } else {
     168           0 :                                           settings.disableExperiment(ImagePreviewsExperiment);
     169             :                                         }
     170           0 :                                         saveSettings(context);
     171             :                                       },
     172           0 :                                       activeTrackColor: settings.theme.defaultButtonColor,
     173           0 :                                       inactiveTrackColor: settings.theme.defaultButtonDisabledColor,
     174           0 :                                       secondary: Icon(Icons.photo, color: settings.current().mainTextColor),
     175             :                                     ),
     176           0 :                                     Visibility(
     177           0 :                                       visible: settings.isExperimentEnabled(ImagePreviewsExperiment) && !Platform.isAndroid,
     178           0 :                                       child: CwtchFolderPicker(
     179           0 :                                         testKey: Key("DownloadFolderPicker"),
     180           0 :                                         label: AppLocalizations.of(context)!.settingDownloadFolder,
     181           0 :                                         initialValue: settings.downloadPath,
     182           0 :                                         textStyle: settings.scaleFonts(defaultDropDownMenuItemTextStyle),
     183           0 :                                         description: AppLocalizations.of(context)!.fileSharingSettingsDownloadFolderDescription,
     184           0 :                                         tooltip: AppLocalizations.of(context)!.fileSharingSettingsDownloadFolderTooltip,
     185           0 :                                         onSave: (newVal) {
     186           0 :                                           settings.downloadPath = newVal;
     187           0 :                                           saveSettings(context);
     188             :                                         },
     189             :                                       ),
     190             :                                     ),
     191             :                                   ],
     192             :                                 ),
     193             :                               ),
     194           0 :                               Visibility(
     195           0 :                                 visible: Provider.of<FlwtchState>(context, listen: false).cwtch.IsBlodeuweddSupported(),
     196           0 :                                 child: SwitchListTile(
     197           0 :                                   title: Text(AppLocalizations.of(context)!.blodeuweddExperimentEnable),
     198           0 :                                   subtitle: Provider.of<FlwtchState>(context, listen: false).cwtch.IsBlodeuweddSupported()
     199           0 :                                       ? Text(AppLocalizations.of(context)!.blodeuweddDescription)
     200           0 :                                       : Text(AppLocalizations.of(context)!.blodeuweddNotSupported),
     201           0 :                                   value: Provider.of<FlwtchState>(context, listen: false).cwtch.IsBlodeuweddSupported() && settings.isExperimentEnabled(BlodeuweddExperiment),
     202           0 :                                   onChanged: Provider.of<FlwtchState>(context, listen: false).cwtch.IsBlodeuweddSupported()
     203           0 :                                       ? (bool value) {
     204             :                                           if (value) {
     205           0 :                                             settings.enableExperiment(BlodeuweddExperiment);
     206             :                                           } else {
     207           0 :                                             settings.disableExperiment(BlodeuweddExperiment);
     208             :                                           }
     209           0 :                                           saveSettings(context);
     210             :                                         }
     211             :                                       : null,
     212           0 :                                   activeTrackColor: settings.theme.defaultButtonColor,
     213           0 :                                   inactiveTrackColor: settings.theme.defaultButtonDisabledColor,
     214           0 :                                   secondary: Icon(Icons.assistant, color: settings.current().mainTextColor),
     215             :                                 ),
     216             :                               ),
     217           0 :                               Visibility(
     218           0 :                                 visible: Provider.of<FlwtchState>(context, listen: false).cwtch.IsBlodeuweddSupported() && settings.isExperimentEnabled(BlodeuweddExperiment),
     219           0 :                                 child: CwtchFolderPicker(
     220           0 :                                   testKey: Key("DownloadFolderPicker"),
     221           0 :                                   label: AppLocalizations.of(context)!.settingDownloadFolder,
     222           0 :                                   initialValue: settings.blodeuweddPath,
     223           0 :                                   description: AppLocalizations.of(context)!.blodeuweddPath,
     224           0 :                                   tooltip: AppLocalizations.of(context)!.blodeuweddPath,
     225           0 :                                   onSave: (newVal) {
     226           0 :                                     settings.blodeuweddPath = newVal;
     227           0 :                                     saveSettings(context);
     228             :                                   },
     229             :                                 ),
     230             :                               ),
     231             :                             ],
     232             :                           ),
     233             :                         ),
     234           0 :                         Visibility(
     235           0 :                           visible: settings.experimentsEnabled,
     236           0 :                           child: SwitchListTile(
     237           0 :                             title: Text(AppLocalizations.of(context)!.enableExperimentClickableLinks),
     238           0 :                             subtitle: Text(AppLocalizations.of(context)!.experimentClickableLinksDescription),
     239           0 :                             value: settings.isExperimentEnabled(ClickableLinksExperiment),
     240           0 :                             onChanged: (bool value) {
     241             :                               if (value) {
     242           0 :                                 settings.enableExperiment(ClickableLinksExperiment);
     243             :                               } else {
     244           0 :                                 settings.disableExperiment(ClickableLinksExperiment);
     245             :                               }
     246           0 :                               saveSettings(context);
     247             :                             },
     248           0 :                             activeTrackColor: settings.theme.defaultButtonColor,
     249           0 :                             inactiveTrackColor: settings.theme.defaultButtonDisabledColor,
     250           0 :                             secondary: Icon(Icons.link, color: settings.current().mainTextColor),
     251             :                           ),
     252             :                         ),
     253           0 :                         Visibility(
     254           0 :                           visible: settings.experimentsEnabled,
     255           0 :                           child: SwitchListTile(
     256           0 :                             title: Text(AppLocalizations.of(context)!.enableExperimentQRCode),
     257           0 :                             subtitle: Text(AppLocalizations.of(context)!.experimentQRCodeDescription),
     258           0 :                             value: settings.isExperimentEnabled(QRCodeExperiment),
     259           0 :                             onChanged: (bool value) {
     260             :                               if (value) {
     261           0 :                                 settings.enableExperiment(QRCodeExperiment);
     262             :                               } else {
     263           0 :                                 settings.disableExperiment(QRCodeExperiment);
     264             :                               }
     265           0 :                               saveSettings(context);
     266             :                             },
     267           0 :                             activeTrackColor: settings.theme.defaultButtonColor,
     268           0 :                             inactiveTrackColor: settings.theme.defaultButtonDisabledColor,
     269           0 :                             secondary: Icon(Icons.qr_code, color: settings.current().mainTextColor),
     270             :                           ),
     271             :                         ),
     272             :                       ],
     273             :                     ),
     274             :                   ),
     275             :                 ),
     276             :               ),
     277             :             );
     278             :           },
     279             :         );
     280             :       },
     281             :     );
     282             :   }
     283             : 
     284           0 :   bool checkDownloadDirectory(context, settings) {
     285             :     bool showError = false;
     286           0 :     if (settings.downloadPath != "") {
     287             :     } else {
     288             :       // check if the default download path exists
     289           0 :       var path = Provider.of<FlwtchState>(context, listen: false).cwtch.defaultDownloadPath();
     290             :       if (path != null) {
     291           0 :         settings.downloadPath = path;
     292             :       } else {
     293             :         showError = true;
     294             :       }
     295             :     }
     296             : 
     297           0 :     if (!showError && Directory(settings.downloadPath).existsSync()) {
     298             :       return true;
     299             :     } else {
     300           0 :       final snackBar = SnackBar(content: Text(AppLocalizations.of(context)!.errorDownloadDirectoryDoesNotExist));
     301           0 :       ScaffoldMessenger.of(context).showSnackBar(snackBar);
     302             :       return false;
     303             :     }
     304             :   }
     305             : }

Generated by: LCOV version 1.14