debug_section_widget.dart 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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. ),
  34. isHeaderOfExpansion: true,
  35. leadingIcon: Icons.bug_report_outlined,
  36. trailingIcon: Icons.expand_more,
  37. menuItemColor:
  38. Theme.of(context).colorScheme.enteTheme.colorScheme.fillFaint,
  39. expandableController: expandableController,
  40. ),
  41. collapsed: const SizedBox.shrink(),
  42. expanded: _getSectionOptions(context),
  43. theme: getExpandableTheme(context),
  44. controller: expandableController,
  45. );
  46. }
  47. Widget _getSectionOptions(BuildContext context) {
  48. return Column(
  49. children: [
  50. sectionOptionDivider,
  51. GestureDetector(
  52. behavior: HitTestBehavior.translucent,
  53. onTap: () async {
  54. _showKeyAttributesDialog(context);
  55. },
  56. child: const SettingsTextItem(
  57. text: "Key attributes",
  58. icon: Icons.navigate_next,
  59. ),
  60. ),
  61. GestureDetector(
  62. behavior: HitTestBehavior.translucent,
  63. onTap: () async {
  64. await LocalSyncService.instance.resetLocalSync();
  65. showToast(context, "Done");
  66. },
  67. child: const SettingsTextItem(
  68. text: "Delete Local Import DB",
  69. icon: Icons.navigate_next,
  70. ),
  71. ),
  72. GestureDetector(
  73. behavior: HitTestBehavior.translucent,
  74. onTap: () async {
  75. await IgnoredFilesService.instance.reset();
  76. SyncService.instance.sync();
  77. showToast(context, "Done");
  78. },
  79. child: const SettingsTextItem(
  80. text: "Allow auto-upload for ignored files",
  81. icon: Icons.navigate_next,
  82. ),
  83. ),
  84. ],
  85. );
  86. }
  87. void _showKeyAttributesDialog(BuildContext context) {
  88. final keyAttributes = Configuration.instance.getKeyAttributes();
  89. final AlertDialog alert = AlertDialog(
  90. title: const Text("key attributes"),
  91. content: SingleChildScrollView(
  92. child: Column(
  93. children: [
  94. const Text(
  95. "Key",
  96. style: TextStyle(fontWeight: FontWeight.bold),
  97. ),
  98. Text(Sodium.bin2base64(Configuration.instance.getKey())),
  99. const Padding(padding: EdgeInsets.all(12)),
  100. const Text(
  101. "Encrypted Key",
  102. style: TextStyle(fontWeight: FontWeight.bold),
  103. ),
  104. Text(keyAttributes.encryptedKey),
  105. const Padding(padding: EdgeInsets.all(12)),
  106. const Text(
  107. "Key Decryption Nonce",
  108. style: TextStyle(fontWeight: FontWeight.bold),
  109. ),
  110. Text(keyAttributes.keyDecryptionNonce),
  111. const Padding(padding: EdgeInsets.all(12)),
  112. const Text(
  113. "KEK Salt",
  114. style: TextStyle(fontWeight: FontWeight.bold),
  115. ),
  116. Text(keyAttributes.kekSalt),
  117. const Padding(padding: EdgeInsets.all(12)),
  118. ],
  119. ),
  120. ),
  121. actions: [
  122. TextButton(
  123. child: const Text("OK"),
  124. onPressed: () {
  125. Navigator.of(context, rootNavigator: true).pop('dialog');
  126. },
  127. ),
  128. ],
  129. );
  130. showDialog(
  131. context: context,
  132. builder: (BuildContext context) {
  133. return alert;
  134. },
  135. );
  136. }
  137. }