diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 2422505e..566930cc 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -45,6 +45,10 @@ build_windows: - cd ..; git clone https://github.com/flutter/flutter.git -b dev; $env:path += ";C:\GitLab-Runner\builds\ChristianPauly\flutter\bin"; cd fluffychat-flutter - flutter doctor - flutter config --enable-windows-desktop + - "$package_override = \"`r`ndependency_overrides:`r`n intl: 0.17.0-nullsafety.2\"" + - "[System.IO.File]::AppendAllText(\"$CI_PROJECT_DIR/pubspec.yaml\", $package_override, [System.Text.Encoding]::UTF8)" + - flutter clean + - flutter pub get - flutter build windows needs: [] artifacts: @@ -87,7 +91,7 @@ build_android_appbundle: resource_group: playstore_release only: - main - + upload_to_fdroid_repo: stage: release before_script: diff --git a/README.md b/README.md index f134134c..4e7511ce 100644 --- a/README.md +++ b/README.md @@ -77,6 +77,11 @@ flutter pub get flutter build web --release --verbose ``` +* Optionally configure by serving a `config.json` at the same path as fluffychat. + An example can be found at `config.sample.json`. None of these + values have to exist, the ones stated here are the default ones. If you e.g. only want + to change the default homeserver, then only modify the `default_homeserver` key. + ### Desktop (Linux, Windows, macOS) * Enable Desktop support in Flutter: https://flutter.dev/desktop diff --git a/config.sample.json b/config.sample.json new file mode 100644 index 00000000..27ad9f73 --- /dev/null +++ b/config.sample.json @@ -0,0 +1,10 @@ +{ + "application_name": "FluffyChat", + "application_welcome_message": null, + "default_homeserver": "matrix.org", + "jitsi_instance": "https://meet.jit.si/", + "privacy_url": "https://fluffychat.im/en/privacy.html", + "render_html": false, + "hide_redacted_events": false, + "hide_unknown_events": false +} diff --git a/lib/app_config.dart b/lib/app_config.dart index fcce160f..de426dfb 100644 --- a/lib/app_config.dart +++ b/lib/app_config.dart @@ -1,11 +1,15 @@ abstract class AppConfig { - static const String applicationName = 'FluffyChat'; - static const String applicationWelcomeMessage = null; - static const String defaultHomeserver = 'matrix.org'; + static String _applicationName = 'FluffyChat'; + static String get applicationName => _applicationName; + static String _applicationWelcomeMessage; + static String get applicationWelcomeMessage => _applicationWelcomeMessage; + static String _defaultHomeserver = 'matrix.org'; + static String get defaultHomeserver => _defaultHomeserver; static String jitsiInstance = 'https://meet.jit.si/'; static const bool allowOtherHomeservers = true; static const bool enableRegistration = true; - static const String privacyUrl = 'https://fluffychat.im/en/privacy.html'; + static String _privacyUrl = 'https://fluffychat.im/en/privacy.html'; + static String get privacyUrl => _privacyUrl; static const String sourceCodeUrl = 'https://gitlab.com/ChristianPauly/fluffychat-flutter'; static const String supportUrl = @@ -26,4 +30,31 @@ abstract class AppConfig { static const String pushNotificationsAppId = 'chat.fluffy.fluffychat'; static const String pushNotificationsGatewayUrl = 'https://janian.de:7023/'; static const String pushNotificationsPusherFormat = 'event_id_only'; + + static void loadFromJson(Map json) { + if (json['application_name'] is String) { + _applicationName = json['application_name']; + } + if (json['application_welcome_message'] is String) { + _applicationWelcomeMessage = json['application_welcome_message']; + } + if (json['default_homeserver'] is String) { + _defaultHomeserver = json['default_homeserver']; + } + if (json['jitsi_instance'] is String) { + jitsiInstance = json['jitsi_instance']; + } + if (json['privacy_url'] is String) { + _privacyUrl = json['privacy_url']; + } + if (json['render_html'] is bool) { + renderHtml = json['render_html']; + } + if (json['hide_redacted_events'] is bool) { + hideRedactedEvents = json['hide_redacted_events']; + } + if (json['hide_unknown_events'] is bool) { + hideUnknownEvents = json['hide_unknown_events']; + } + } } diff --git a/lib/components/matrix.dart b/lib/components/matrix.dart index 3eec6beb..f9c7c192 100644 --- a/lib/components/matrix.dart +++ b/lib/components/matrix.dart @@ -1,5 +1,6 @@ import 'dart:async'; import 'dart:io'; +import 'dart:convert'; import 'package:adaptive_dialog/adaptive_dialog.dart'; import 'package:famedlysdk/encryption.dart'; @@ -16,6 +17,8 @@ import 'package:flutter/material.dart'; import 'package:flutter_gen/gen_l10n/l10n.dart'; import 'package:universal_html/prefer_universal/html.dart' as html; import 'package:url_launcher/url_launcher.dart'; +import 'package:path_provider/path_provider.dart'; +import 'package:http/http.dart' as http; /*import 'package:fluffychat/views/chat.dart'; import 'package:fluffychat/app_config.dart'; import 'package:dbus/dbus.dart'; @@ -275,6 +278,33 @@ class MatrixState extends State { void initState() { super.initState(); initMatrix(); + initConfig().then((_) => initSettings()); + } + + Future initConfig() async { + if (PlatformInfos.isMobile) { + return; + } + try { + var configJsonString = ''; + if (PlatformInfos.isWeb) { + configJsonString = + utf8.decode((await http.get('config.json')).bodyBytes); + } else if (PlatformInfos.isBetaDesktop) { + final appDocDir = await getApplicationSupportDirectory(); + configJsonString = + await File('${appDocDir.path}/config.json').readAsString(); + } else { + final appDocDir = await getApplicationDocumentsDirectory(); + configJsonString = + await File('${appDocDir.path}/config.json').readAsString(); + } + final configJson = json.decode(configJsonString); + AppConfig.loadFromJson(configJson); + } catch (error) { + debugPrint( + '[ConfigLoader] Failed to load config.json: ' + error.toString()); + } } void initMatrix() { @@ -369,7 +399,6 @@ class MatrixState extends State { .listen(_showLocalNotification); }); } - initSettings(); } void initSettings() { diff --git a/scripts/build-linux.sh b/scripts/build-linux.sh index 879dea8e..e8941645 100755 --- a/scripts/build-linux.sh +++ b/scripts/build-linux.sh @@ -2,6 +2,7 @@ flutter channel dev flutter upgrade flutter config --enable-linux-desktop +echo "dependency_overrides:\n intl: 0.17.0-nullsafety.2" >> pubspec.yaml flutter clean flutter pub get flutter build linux --release -v diff --git a/scripts/build-web.sh b/scripts/build-web.sh index d6e11a16..5626e710 100755 --- a/scripts/build-web.sh +++ b/scripts/build-web.sh @@ -1,6 +1,6 @@ #!/bin/sh -ve -flutter channel beta -flutter upgrade +#flutter channel beta +#flutter upgrade flutter config --enable-web flutter clean flutter pub get