debug_section_widget.dart 4.5 KB

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