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

Generated by: LCOV version 1.14