debug_section_widget.dart 4.2 KB

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