From a9682dc113c2c2c2930e9d32b8352a63dfe97bd0 Mon Sep 17 00:00:00 2001 From: HuyNguyen Date: Sat, 30 Mar 2024 10:00:25 +0700 Subject: [PATCH] Create docs for public platform --- ...ig_build_mobile_app_for_public_platform.md | 28 ++++++++++ .../config_web_app_for_public_platform.md | 47 +++++++++++++++++ lib/config/app_config.dart | 51 ++++++++++++++----- macos/Flutter/GeneratedPluginRegistrant.swift | 2 +- 4 files changed, 113 insertions(+), 15 deletions(-) create mode 100644 docs/configurations/config_build_mobile_app_for_public_platform.md create mode 100644 docs/configurations/config_web_app_for_public_platform.md diff --git a/docs/configurations/config_build_mobile_app_for_public_platform.md b/docs/configurations/config_build_mobile_app_for_public_platform.md new file mode 100644 index 0000000000..7141595824 --- /dev/null +++ b/docs/configurations/config_build_mobile_app_for_public_platform.md @@ -0,0 +1,28 @@ +## Configuring apps with compilation environment declarations + +### 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. + +### How to config + +1.Flutter +- 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=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 + +If you want to disable it, please change the value or remove when use `--dart-define` option \ No newline at end of file diff --git a/docs/configurations/config_web_app_for_public_platform.md b/docs/configurations/config_web_app_for_public_platform.md new file mode 100644 index 0000000000..bddbebe4a9 --- /dev/null +++ b/docs/configurations/config_web_app_for_public_platform.md @@ -0,0 +1,47 @@ +## Configuration for config.json + +### Context + +- Twake Chat need to config env for Twake Chat service on web version +- Now only support to web + +### How to config + +1.Add environment +in [config.sample.json](https://github.com/linagora/twake-on-matrix/blob/main/config.sample.json) + +- Env for Twake Chat service: + +``` +{ + "application_name": "Twake Chat", + "application_welcome_message": "Welcome to Twake Chat!", + "default_homeserver": "matrix.linagora.com", + "privacy_url": "https://twake.app/en/privacy/", + "render_html": true, + "hide_redacted_events": false, + "hide_unknown_events": false, + "issue_id": "", + "registration_url": "https://example.com/", + "twake_workplace_homeserver": "https://example.com/", + "app_grid_dashboard_available": true, + "homeserver": "https://example.com/", + "platform": "platform" +} +``` + +- `application_name`: The name will be showed in App Grid +- `application_welcome_message`: The welcome message will be showed in App Grid +- `default_homeserver`: The default homeserver +- `privacy_url`: The privacy policy URL +- `render_html`: Render HTML in messages +- `hide_redacted_events`: Hide redacted events +- `hide_unknown_events`: Hide unknown events +- `issue_id`: Issue ID +- `registration_url`: Registration URL for public platform +- `twake_workplace_homeserver`: Twake workplace homeserver +- `app_grid_dashboard_available`: Enable App Grid +- `homeserver`: Homeserver +- `platform`: Platform, `saas` for the case of public platform + +If you want to disable it, please change the value or remove this from `config.sample.json` \ No newline at end of file diff --git a/lib/config/app_config.dart b/lib/config/app_config.dart index fa0c3b65ef..bde39e45ac 100644 --- a/lib/config/app_config.dart +++ b/lib/config/app_config.dart @@ -103,30 +103,53 @@ abstract class AppConfig { static const String appGridConfigurationPath = "configurations/app_dashboard.json"; + static const String _platformEnv = String.fromEnvironment( + 'PLATFORM', + defaultValue: 'platform', + ); + + static const String _twakeWorkplaceHomeserverEnv = String.fromEnvironment( + 'TWAKE_WORKPLACE_HOMESERVER', + defaultValue: 'https://example.com/', + ); + + static const String _registrationUrlEnv = String.fromEnvironment( + 'REGISTRATION_URL', + defaultValue: 'https://example.com/', + ); + + static const String _homeserverEnv = String.fromEnvironment( + 'HOME_SERVER', + defaultValue: 'https://example.com/', + ); + static void loadEnvironment() { - twakeWorkplaceHomeserver = const String.fromEnvironment( - 'TWAKE_WORKPLACE_HOMESERVER', - defaultValue: 'https://example.com/', + twakeWorkplaceHomeserver = _twakeWorkplaceHomeserverEnv; + + Logs().i( + '[Public Platform] AppConfig():: TWAKE_WORKPLACE_HOMESERVER $_twakeWorkplaceHomeserverEnv', ); - registrationUrl = const String.fromEnvironment( - 'REGISTRATION_URL', - defaultValue: 'https://example.com/', + registrationUrl = _registrationUrlEnv; + + Logs().i( + '[Public Platform] AppConfig():: REGISTRATION_URL $_registrationUrlEnv', ); - platform = const String.fromEnvironment( - 'PLATFORM', - defaultValue: 'platform', + platform = _platformEnv; + + Logs().i( + '[Public Platform] AppConfig():: Platform $_platformEnv', ); - homeserver = const String.fromEnvironment( - 'HOME_SERVER', - defaultValue: 'https://example.com/', + homeserver = _homeserverEnv; + + Logs().i( + '[Public Platform] AppConfig():: HOME_SERVER $_homeserverEnv', ); } - static bool get isSaasPlatForm => - platform != null && platform!.isNotEmpty && platform == 'saas'; + static bool get isSaasPlatForm => _platformEnv == 'saas'; static void loadFromJson(Map json) { if (json['homeserver'] != null && json['homeserver'] is String) { diff --git a/macos/Flutter/GeneratedPluginRegistrant.swift b/macos/Flutter/GeneratedPluginRegistrant.swift index 16840a23f3..f2af6f2ea8 100644 --- a/macos/Flutter/GeneratedPluginRegistrant.swift +++ b/macos/Flutter/GeneratedPluginRegistrant.swift @@ -83,4 +83,4 @@ func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { WakelockMacosPlugin.register(with: registry.registrar(forPlugin: "WakelockMacosPlugin")) WakelockPlusMacosPlugin.register(with: registry.registrar(forPlugin: "WakelockPlusMacosPlugin")) WindowToFrontPlugin.register(with: registry.registrar(forPlugin: "WindowToFrontPlugin")) -} \ No newline at end of file +}