2023-05-21 10:53:59 +00:00
|
|
|
// lib/env/env.dart
|
2023-08-03 00:48:04 +00:00
|
|
|
import 'package:appflowy/startup/startup.dart';
|
2023-10-02 09:22:22 +00:00
|
|
|
import 'package:appflowy_backend/log.dart';
|
2023-05-21 10:53:59 +00:00
|
|
|
import 'package:envied/envied.dart';
|
|
|
|
|
|
|
|
part 'env.g.dart';
|
|
|
|
|
2023-07-05 12:57:09 +00:00
|
|
|
/// The environment variables are defined in `.env` file that is located in the
|
|
|
|
/// appflowy_flutter.
|
|
|
|
/// Run `dart run build_runner build --delete-conflicting-outputs`
|
|
|
|
/// to generate the keys from the env file.
|
|
|
|
///
|
|
|
|
/// If you want to regenerate the keys, you need to run `dart run
|
|
|
|
/// build_runner clean` before running `dart run build_runner build
|
|
|
|
/// --delete-conflicting-outputs`.
|
|
|
|
|
|
|
|
/// Follow the guide on https://supabase.com/docs/guides/auth/social-login/auth-google to setup the auth provider.
|
|
|
|
///
|
2023-05-21 10:53:59 +00:00
|
|
|
@Envied(path: '.env')
|
|
|
|
abstract class Env {
|
2023-10-02 09:22:22 +00:00
|
|
|
@EnviedField(
|
|
|
|
obfuscate: true,
|
|
|
|
varName: 'CLOUD_TYPE',
|
|
|
|
defaultValue: '0',
|
|
|
|
)
|
|
|
|
static final int cloudType = _Env.cloudType;
|
|
|
|
|
|
|
|
/// AppFlowy Cloud Configuration
|
|
|
|
@EnviedField(
|
|
|
|
obfuscate: true,
|
|
|
|
varName: 'APPFLOWY_CLOUD_BASE_URL',
|
|
|
|
defaultValue: '',
|
|
|
|
)
|
|
|
|
static final String afCloudBaseUrl = _Env.afCloudBaseUrl;
|
|
|
|
|
|
|
|
@EnviedField(
|
|
|
|
obfuscate: true,
|
2023-10-07 01:58:44 +00:00
|
|
|
varName: 'APPFLOWY_CLOUD_WS_BASE_URL',
|
2023-10-02 09:22:22 +00:00
|
|
|
defaultValue: '',
|
|
|
|
)
|
2023-10-07 01:58:44 +00:00
|
|
|
static final String afCloudWSBaseUrl = _Env.afCloudWSBaseUrl;
|
|
|
|
|
|
|
|
@EnviedField(
|
|
|
|
obfuscate: true,
|
|
|
|
varName: 'APPFLOWY_CLOUD_GOTRUE_URL',
|
|
|
|
defaultValue: '',
|
|
|
|
)
|
|
|
|
static final String afCloudGoTrueUrl = _Env.afCloudGoTrueUrl;
|
2023-10-02 09:22:22 +00:00
|
|
|
|
|
|
|
// Supabase Configuration:
|
2023-05-21 10:53:59 +00:00
|
|
|
@EnviedField(
|
|
|
|
obfuscate: true,
|
|
|
|
varName: 'SUPABASE_URL',
|
|
|
|
defaultValue: '',
|
|
|
|
)
|
2023-05-28 04:09:39 +00:00
|
|
|
static final String supabaseUrl = _Env.supabaseUrl;
|
2023-05-21 10:53:59 +00:00
|
|
|
@EnviedField(
|
|
|
|
obfuscate: true,
|
|
|
|
varName: 'SUPABASE_ANON_KEY',
|
|
|
|
defaultValue: '',
|
|
|
|
)
|
2023-05-28 04:09:39 +00:00
|
|
|
static final String supabaseAnonKey = _Env.supabaseAnonKey;
|
2023-05-21 10:53:59 +00:00
|
|
|
}
|
|
|
|
|
2023-10-02 09:22:22 +00:00
|
|
|
bool get isCloudEnabled {
|
2023-08-03 00:48:04 +00:00
|
|
|
// Only enable supabase in release and develop mode.
|
2023-08-22 07:40:22 +00:00
|
|
|
if (integrationMode().isRelease || integrationMode().isDevelop) {
|
2023-10-02 09:22:22 +00:00
|
|
|
return currentCloudType().isEnabled;
|
2023-08-03 00:48:04 +00:00
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2023-10-02 09:22:22 +00:00
|
|
|
|
2023-10-07 01:58:44 +00:00
|
|
|
bool get isSupabaseEnabled {
|
|
|
|
// Only enable supabase in release and develop mode.
|
|
|
|
if (integrationMode().isRelease || integrationMode().isDevelop) {
|
|
|
|
return currentCloudType() == CloudType.supabase;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool get isAppFlowyCloudEnabled {
|
|
|
|
// Only enable appflowy cloud in release and develop mode.
|
|
|
|
if (integrationMode().isRelease || integrationMode().isDevelop) {
|
|
|
|
return currentCloudType() == CloudType.appflowyCloud;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-02 09:22:22 +00:00
|
|
|
enum CloudType {
|
|
|
|
unknown,
|
|
|
|
supabase,
|
|
|
|
appflowyCloud;
|
|
|
|
|
|
|
|
bool get isEnabled => this != CloudType.unknown;
|
|
|
|
}
|
|
|
|
|
|
|
|
CloudType currentCloudType() {
|
|
|
|
final value = Env.cloudType;
|
|
|
|
if (value == 1) {
|
|
|
|
if (Env.supabaseUrl.isEmpty || Env.supabaseAnonKey.isEmpty) {
|
|
|
|
Log.error("Supabase is not configured");
|
|
|
|
return CloudType.unknown;
|
|
|
|
} else {
|
|
|
|
return CloudType.supabase;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (value == 2) {
|
2023-10-07 01:58:44 +00:00
|
|
|
if (Env.afCloudBaseUrl.isEmpty || Env.afCloudWSBaseUrl.isEmpty) {
|
2023-10-02 09:22:22 +00:00
|
|
|
Log.error("AppFlowy cloud is not configured");
|
|
|
|
return CloudType.unknown;
|
|
|
|
} else {
|
|
|
|
return CloudType.appflowyCloud;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return CloudType.unknown;
|
|
|
|
}
|