Skip to content

Commit

Permalink
TW-1768: Define saas environment for mobile [hardcode]
Browse files Browse the repository at this point in the history
  • Loading branch information
nqhhdev authored and hoangdat committed May 17, 2024
1 parent 691a00f commit 2789506
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 20 deletions.
46 changes: 34 additions & 12 deletions docs/configurations/config_build_mobile_app_for_public_platform.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,49 @@

### Context

- Twake Chat app can use the values of environment declarations to change its functionality or behavior.
Dart compilers can eliminate the code made unreachable due to
control flow using the environment declaration values.
- Only support for mobile app.
- Twake Chat need to config env for Twake Chat service on mobile app for public platform, two ways
to config env:

### How to config
#### 1. Enable for `SaaS` platform

1.Flutter
1.1. Use `--dart-define` option to config env for mobile app.

- Specify `platform` is `saas`.
- To specify environment declarations to the Flutter tool, use the `--dart-define` option instead:

```
flutter run --dart-define=REGISTRATION_URL=https://example.com/
--dart-define=TWAKE_WORKPLACE_HOMESERVER=https://example.com/
--dart-define=PLATFORM=platfomrm
--dart-define=PLATFORM=saas
--dart-define=HOME_SERVER=https://example.com/
```

- `REGISTRATION_URL`: Registration URL for public platform
- `TWAKE_WORKPLACE_HOMESERVER`: Twake workplace homeserver
- `PLATFORM`: Platform, `saas` for the case of public platform
- `HOME_SERVER`: Homeserver
1.2. Use `config_saas.dart` to config env for mobile app.

```
class ConfigurationSaas {
static const String registrationUrl = 'https://example.com/';
static const String twakeWorkplaceHomeserver = 'https://example.com/';
static const String homeserver = 'https://example.com/';
static const String platform = 'saas';
}
```

#### 2. Disable for `SaaS` platform

- Build without `--dart-define`.

- Change the value `platform` in `config_saas.dart` to any value except `saas`.

```
class ConfigurationSaas {
If you want to disable it, please change the value or remove when use `--dart-define` option
// ...
static const String platform = 'platform';
}
```
20 changes: 13 additions & 7 deletions lib/config/app_config.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:async';
import 'dart:io';

import 'package:fluffychat/config/config_saas/config_saas.dart';
import 'package:fluffychat/di/global/get_it_initializer.dart';
import 'package:fluffychat/utils/responsive/responsive_utils.dart';
import 'package:flutter/foundation.dart';
Expand Down Expand Up @@ -28,11 +29,16 @@ abstract class AppConfig {
static double bubbleSizeFactor = 1;
static double fontSizeFactor = 1;

static String registrationUrl = 'https://example.com/';
static String sampleValue = 'sampleValue';

static String twakeWorkplaceHomeserver = 'https://example.com/';
///`REGISTRATION_URL`: Registration URL for public platform, sample is `https://example.com`
static String registrationUrl = sampleValue;

static String homeserver = 'https://example.com/';
///`TWAKE_WORKPLACE_HOMESERVER`: Twake workplace homeserver, sample is `https://example.com`
static String twakeWorkplaceHomeserver = sampleValue;

///`HOME_SERVER`: Homeserver, sample is `https://example.com`
static String homeserver = sampleValue;

static String? platform;

Expand Down Expand Up @@ -112,22 +118,22 @@ abstract class AppConfig {

static const String _platformEnv = String.fromEnvironment(
'PLATFORM',
defaultValue: 'platform',
defaultValue: ConfigurationSaas.platform,
);

static const String _twakeWorkplaceHomeserverEnv = String.fromEnvironment(
'TWAKE_WORKPLACE_HOMESERVER',
defaultValue: 'https://example.com/',
defaultValue: ConfigurationSaas.twakeWorkplaceHomeserver,
);

static const String _registrationUrlEnv = String.fromEnvironment(
'REGISTRATION_URL',
defaultValue: 'https://example.com/',
defaultValue: ConfigurationSaas.registrationUrl,
);

static const String _homeserverEnv = String.fromEnvironment(
'HOME_SERVER',
defaultValue: 'https://example.com/',
defaultValue: ConfigurationSaas.homeserver,
);

static void loadEnvironment() {
Expand Down
10 changes: 10 additions & 0 deletions lib/config/config_saas/config_saas.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class ConfigurationSaas {
static const String registrationUrl = 'https://sign-up.stg.lin-saas.com/';

static const String twakeWorkplaceHomeserver =
'https://matrix.stg.lin-saas.com/';

static const String homeserver = 'https://matrix.stg.lin-saas.com/';

static const String platform = 'saas';
}
2 changes: 1 addition & 1 deletion lib/presentation/mixins/connect_page_mixin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ mixin ConnectPageMixin {
}

bool get homeserverIsConfigured =>
AppConfig.homeserver != 'https://example.com/' ||
AppConfig.homeserver != AppConfig.sampleValue ||
AppConfig.homeserver.isNotEmpty;

String _getRedirectUrlScheme(String redirectUrl) {
Expand Down

0 comments on commit 2789506

Please sign in to comment.