debug_section_widget.dart 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. // @dart=2.9
  2. import 'package:expandable/expandable.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:flutter_sodium/flutter_sodium.dart';
  5. import 'package:photos/core/configuration.dart';
  6. import 'package:photos/ente_theme_data.dart';
  7. import 'package:photos/services/ignored_files_service.dart';
  8. import 'package:photos/services/local_sync_service.dart';
  9. import 'package:photos/services/sync_service.dart';
  10. import 'package:photos/ui/components/captioned_text_widget.dart';
  11. import 'package:photos/ui/components/menu_item_widget.dart';
  12. import 'package:photos/ui/settings/common_settings.dart';
  13. import 'package:photos/ui/settings/settings_text_item.dart';
  14. import 'package:photos/utils/toast_util.dart';
  15. class DebugSectionWidget extends StatefulWidget {
  16. const DebugSectionWidget({Key key}) : super(key: key);
  17. @override
  18. State<DebugSectionWidget> createState() => _DebugSectionWidgetState();
  19. }
  20. class _DebugSectionWidgetState extends State<DebugSectionWidget> {
  21. final expandableController = ExpandableController(initialExpanded: false);
  22. @override
  23. void dispose() {
  24. expandableController.dispose();
  25. super.dispose();
  26. }
  27. @override
  28. Widget build(BuildContext context) {
  29. return ExpandablePanel(
  30. header: MenuItemWidget(
  31. captionedTextWidget: const CaptionedTextWidget(
  32. text: "Debug",
  33. makeTextBold: true,
  34. ),
  35. isHeaderOfExpansion: true,
  36. leadingIcon: Icons.bug_report_outlined,
  37. trailingIcon: Icons.expand_more,
  38. menuItemColor:
  39. Theme.of(context).colorScheme.enteTheme.colorScheme.fillFaint,
  40. expandableController: expandableController,
  41. ),
  42. collapsed: const SizedBox.shrink(),
  43. expanded: _getSectionOptions(context),
  44. theme: getExpandableTheme(context),
  45. controller: expandableController,
  46. );
  47. }
  48. Widget _getSectionOptions(BuildContext context) {
  49. return Column(
  50. children: [
  51. sectionOptionDivider,
  52. GestureDetector(
  53. behavior: HitTestBehavior.translucent,
  54. onTap: () async {
  55. _showKeyAttributesDialog(context);
  56. },
  57. child: const SettingsTextItem(
  58. text: "Key attributes",
  59. icon: Icons.navigate_next,
  60. ),
  61. ),
  62. GestureDetector(
  63. behavior: HitTestBehavior.translucent,
  64. onTap: () async {
  65. await LocalSyncService.instance.resetLocalSync();
  66. showToast(context, "Done");
  67. },
  68. child: const SettingsTextItem(
  69. text: "Delete Local Import DB",
  70. icon: Icons.navigate_next,
  71. ),
  72. ),
  73. GestureDetector(
  74. behavior: HitTestBehavior.translucent,
  75. onTap: () async {
  76. await IgnoredFilesService.instance.reset();
  77. SyncService.instance.sync();
  78. showToast(context, "Done");
  79. },
  80. child: const SettingsTextItem(
  81. text: "Allow auto-upload for ignored files",
  82. icon: Icons.navigate_next,
  83. ),
  84. ),
  85. ],
  86. );
  87. }
  88. void _showKeyAttributesDialog(BuildContext context) {
  89. final keyAttributes = Configuration.instance.getKeyAttributes();
  90. final AlertDialog alert = AlertDialog(
  91. title: const Text("key attributes"),
  92. content: SingleChildScrollView(
  93. child: Column(
  94. children: [
  95. const Text(
  96. "Key",
  97. style: TextStyle(fontWeight: FontWeight.bold),
  98. ),
  99. Text(Sodium.bin2base64(Configuration.instance.getKey())),
  100. const Padding(padding: EdgeInsets.all(12)),
  101. const Text(
  102. "Encrypted Key",
  103. style: TextStyle(fontWeight: FontWeight.bold),
  104. ),
  105. Text(keyAttributes.encryptedKey),
  106. const Padding(padding: EdgeInsets.all(12)),
  107. const Text(
  108. "Key Decryption Nonce",
  109. style: TextStyle(fontWeight: FontWeight.bold),
  110. ),
  111. Text(keyAttributes.keyDecryptionNonce),
  112. const Padding(padding: EdgeInsets.all(12)),
  113. const Text(
  114. "KEK Salt",
  115. style: TextStyle(fontWeight: FontWeight.bold),
  116. ),
  117. Text(keyAttributes.kekSalt),
  118. const Padding(padding: EdgeInsets.all(12)),
  119. ],
  120. ),
  121. ),
  122. actions: [
  123. TextButton(
  124. child: const Text("OK"),
  125. onPressed: () {
  126. Navigator.of(context, rootNavigator: true).pop('dialog');
  127. },
  128. ),
  129. ],
  130. );
  131. showDialog(
  132. context: context,
  133. builder: (BuildContext context) {
  134. return alert;
  135. },
  136. );
  137. }
  138. }