debug_section_widget.dart 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. // @dart=2.9
  2. import 'package:flutter/material.dart';
  3. import 'package:flutter_sodium/flutter_sodium.dart';
  4. import 'package:photos/core/configuration.dart';
  5. import 'package:photos/services/ignored_files_service.dart';
  6. import 'package:photos/services/local_sync_service.dart';
  7. import 'package:photos/services/sync_service.dart';
  8. import 'package:photos/services/update_service.dart';
  9. import 'package:photos/theme/ente_theme.dart';
  10. import 'package:photos/ui/components/captioned_text_widget.dart';
  11. import 'package:photos/ui/components/expandable_menu_item_widget.dart';
  12. import 'package:photos/ui/components/menu_item_widget.dart';
  13. import 'package:photos/ui/settings/common_settings.dart';
  14. import 'package:photos/utils/toast_util.dart';
  15. class DebugSectionWidget extends StatelessWidget {
  16. const DebugSectionWidget({Key key}) : super(key: key);
  17. @override
  18. Widget build(BuildContext context) {
  19. return ExpandableMenuItemWidget(
  20. title: "Debug",
  21. selectionOptionsWidget: _getSectionOptions(context),
  22. leadingIcon: Icons.bug_report_outlined,
  23. );
  24. }
  25. Widget _getSectionOptions(BuildContext context) {
  26. return Column(
  27. children: [
  28. sectionOptionSpacing,
  29. MenuItemWidget(
  30. captionedTextWidget: const CaptionedTextWidget(
  31. title: "Key attributes",
  32. ),
  33. pressedColor: getEnteColorScheme(context).fillFaint,
  34. trailingIcon: Icons.chevron_right_outlined,
  35. trailingIconIsMuted: true,
  36. onTap: () async {
  37. await UpdateService.instance.resetChangeLog();
  38. _showKeyAttributesDialog(context);
  39. },
  40. ),
  41. sectionOptionSpacing,
  42. MenuItemWidget(
  43. captionedTextWidget: const CaptionedTextWidget(
  44. title: "Delete Local Import DB",
  45. ),
  46. pressedColor: getEnteColorScheme(context).fillFaint,
  47. trailingIcon: Icons.chevron_right_outlined,
  48. trailingIconIsMuted: true,
  49. onTap: () async {
  50. await LocalSyncService.instance.resetLocalSync();
  51. showToast(context, "Done");
  52. },
  53. ),
  54. sectionOptionSpacing,
  55. MenuItemWidget(
  56. captionedTextWidget: const CaptionedTextWidget(
  57. title: "Allow auto-upload for ignored files",
  58. ),
  59. pressedColor: getEnteColorScheme(context).fillFaint,
  60. trailingIcon: Icons.chevron_right_outlined,
  61. trailingIconIsMuted: true,
  62. onTap: () async {
  63. await IgnoredFilesService.instance.reset();
  64. SyncService.instance.sync();
  65. showToast(context, "Done");
  66. },
  67. ),
  68. sectionOptionSpacing,
  69. ],
  70. );
  71. }
  72. void _showKeyAttributesDialog(BuildContext context) {
  73. final keyAttributes = Configuration.instance.getKeyAttributes();
  74. final AlertDialog alert = AlertDialog(
  75. title: const Text("key attributes"),
  76. content: SingleChildScrollView(
  77. child: Column(
  78. children: [
  79. const Text(
  80. "Key",
  81. style: TextStyle(fontWeight: FontWeight.bold),
  82. ),
  83. Text(Sodium.bin2base64(Configuration.instance.getKey())),
  84. const Padding(padding: EdgeInsets.all(12)),
  85. const Text(
  86. "Encrypted Key",
  87. style: TextStyle(fontWeight: FontWeight.bold),
  88. ),
  89. Text(keyAttributes.encryptedKey),
  90. const Padding(padding: EdgeInsets.all(12)),
  91. const Text(
  92. "Key Decryption Nonce",
  93. style: TextStyle(fontWeight: FontWeight.bold),
  94. ),
  95. Text(keyAttributes.keyDecryptionNonce),
  96. const Padding(padding: EdgeInsets.all(12)),
  97. const Text(
  98. "KEK Salt",
  99. style: TextStyle(fontWeight: FontWeight.bold),
  100. ),
  101. Text(keyAttributes.kekSalt),
  102. const Padding(padding: EdgeInsets.all(12)),
  103. ],
  104. ),
  105. ),
  106. actions: [
  107. TextButton(
  108. child: const Text("OK"),
  109. onPressed: () {
  110. Navigator.of(context, rootNavigator: true).pop('dialog');
  111. },
  112. ),
  113. ],
  114. );
  115. showDialog(
  116. context: context,
  117. builder: (BuildContext context) {
  118. return alert;
  119. },
  120. );
  121. }
  122. }