env.dart 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. // lib/env/env.dart
  2. import 'package:appflowy/startup/startup.dart';
  3. import 'package:appflowy_backend/log.dart';
  4. import 'package:envied/envied.dart';
  5. part 'env.g.dart';
  6. /// The environment variables are defined in `.env` file that is located in the
  7. /// appflowy_flutter.
  8. /// Run `dart run build_runner build --delete-conflicting-outputs`
  9. /// to generate the keys from the env file.
  10. ///
  11. /// If you want to regenerate the keys, you need to run `dart run
  12. /// build_runner clean` before running `dart run build_runner build
  13. /// --delete-conflicting-outputs`.
  14. /// Follow the guide on https://supabase.com/docs/guides/auth/social-login/auth-google to setup the auth provider.
  15. ///
  16. @Envied(path: '.env')
  17. abstract class Env {
  18. @EnviedField(
  19. obfuscate: true,
  20. varName: 'CLOUD_TYPE',
  21. defaultValue: '0',
  22. )
  23. static final int cloudType = _Env.cloudType;
  24. /// AppFlowy Cloud Configuration
  25. @EnviedField(
  26. obfuscate: true,
  27. varName: 'APPFLOWY_CLOUD_BASE_URL',
  28. defaultValue: '',
  29. )
  30. static final String afCloudBaseUrl = _Env.afCloudBaseUrl;
  31. @EnviedField(
  32. obfuscate: true,
  33. varName: 'APPFLOWY_CLOUD_BASE_WS_URL',
  34. defaultValue: '',
  35. )
  36. static final String afCloudBaseWSUrl = _Env.afCloudBaseWSUrl;
  37. // Supabase Configuration:
  38. @EnviedField(
  39. obfuscate: true,
  40. varName: 'SUPABASE_URL',
  41. defaultValue: '',
  42. )
  43. static final String supabaseUrl = _Env.supabaseUrl;
  44. @EnviedField(
  45. obfuscate: true,
  46. varName: 'SUPABASE_ANON_KEY',
  47. defaultValue: '',
  48. )
  49. static final String supabaseAnonKey = _Env.supabaseAnonKey;
  50. }
  51. bool get isCloudEnabled {
  52. // Only enable supabase in release and develop mode.
  53. if (integrationMode().isRelease || integrationMode().isDevelop) {
  54. return currentCloudType().isEnabled;
  55. } else {
  56. return false;
  57. }
  58. }
  59. enum CloudType {
  60. unknown,
  61. supabase,
  62. appflowyCloud;
  63. bool get isEnabled => this != CloudType.unknown;
  64. }
  65. CloudType currentCloudType() {
  66. final value = Env.cloudType;
  67. if (value == 1) {
  68. if (Env.supabaseUrl.isEmpty || Env.supabaseAnonKey.isEmpty) {
  69. Log.error("Supabase is not configured");
  70. return CloudType.unknown;
  71. } else {
  72. return CloudType.supabase;
  73. }
  74. }
  75. if (value == 2) {
  76. if (Env.afCloudBaseUrl.isEmpty || Env.afCloudBaseWSUrl.isEmpty) {
  77. Log.error("AppFlowy cloud is not configured");
  78. return CloudType.unknown;
  79. } else {
  80. return CloudType.appflowyCloud;
  81. }
  82. }
  83. return CloudType.unknown;
  84. }