Browse Source

tool, neon: Refactor dev container

pull/231/head
jld3103 2 years ago
parent
commit
13824036ee
No known key found for this signature in database
GPG Key ID: 9062417B9E8EB7B3
  1. 1
      packages/neon/assets/.gitignore
  2. 3
      packages/neon/integration_test/screenshot_test.dart
  3. 19
      packages/neon/lib/main.dart
  4. 2
      packages/neon/lib/src/app.dart
  5. 1
      packages/neon/lib/src/neon.dart
  6. 29
      packages/neon/lib/src/pages/login.dart
  7. 19
      packages/neon/lib/src/utils/env.dart
  8. 8
      packages/neon/pubspec.lock
  9. 1
      packages/neon/pubspec.yaml
  10. 0
      tool/build-dev-container.sh
  11. 8
      tool/dev.sh
  12. 2
      tool/generate-screenshots.sh
  13. 28
      tool/run-dev-instance.sh

1
packages/neon/assets/.gitignore vendored

@ -1 +0,0 @@
.env

3
packages/neon/integration_test/screenshot_test.dart

@ -147,9 +147,6 @@ Future pumpAppPage(
Provider<SharedPreferences>( Provider<SharedPreferences>(
create: (final _) => sharedPreferences, create: (final _) => sharedPreferences,
), ),
Provider<Env?>(
create: (final _) => null,
),
Provider<NeonPlatform>( Provider<NeonPlatform>(
create: (final _) => platform, create: (final _) => platform,
), ),

19
packages/neon/lib/main.dart

@ -1,6 +1,4 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:flutter_native_splash/flutter_native_splash.dart'; import 'package:flutter_native_splash/flutter_native_splash.dart';
import 'package:neon/src/neon.dart'; import 'package:neon/src/neon.dart';
import 'package:package_info_plus/package_info_plus.dart'; import 'package:package_info_plus/package_info_plus.dart';
@ -8,19 +6,6 @@ import 'package:provider/provider.dart';
import 'package:shared_preferences/shared_preferences.dart'; import 'package:shared_preferences/shared_preferences.dart';
Future main() async { Future main() async {
Env? env;
try {
await dotenv.load(fileName: 'assets/.env');
if (dotenv.env.keys.isNotEmpty) {
if (kReleaseMode) {
throw Exception('A release build can not contain a .env file');
}
env = Env.fromMap(dotenv.env);
}
} catch (e) {
debugPrint('Failed to load env: $e');
}
WidgetsFlutterBinding.ensureInitialized(); WidgetsFlutterBinding.ensureInitialized();
FlutterNativeSplash.preserve(widgetsBinding: WidgetsBinding.instance); FlutterNativeSplash.preserve(widgetsBinding: WidgetsBinding.instance);
@ -63,9 +48,6 @@ Future main() async {
Provider<SharedPreferences>( Provider<SharedPreferences>(
create: (final _) => sharedPreferences, create: (final _) => sharedPreferences,
), ),
Provider<Env?>(
create: (final _) => env,
),
Provider<NeonPlatform>( Provider<NeonPlatform>(
create: (final _) => platform, create: (final _) => platform,
), ),
@ -97,7 +79,6 @@ Future main() async {
child: NeonApp( child: NeonApp(
accountsBloc: accountsBloc, accountsBloc: accountsBloc,
sharedPreferences: sharedPreferences, sharedPreferences: sharedPreferences,
env: env,
platform: platform, platform: platform,
globalOptions: globalOptions, globalOptions: globalOptions,
), ),

2
packages/neon/lib/src/app.dart

@ -4,7 +4,6 @@ class NeonApp extends StatefulWidget {
const NeonApp({ const NeonApp({
required this.accountsBloc, required this.accountsBloc,
required this.sharedPreferences, required this.sharedPreferences,
required this.env,
required this.platform, required this.platform,
required this.globalOptions, required this.globalOptions,
super.key, super.key,
@ -12,7 +11,6 @@ class NeonApp extends StatefulWidget {
final AccountsBloc accountsBloc; final AccountsBloc accountsBloc;
final SharedPreferences sharedPreferences; final SharedPreferences sharedPreferences;
final Env? env;
final NeonPlatform platform; final NeonPlatform platform;
final GlobalOptions globalOptions; final GlobalOptions globalOptions;

1
packages/neon/lib/src/neon.dart

@ -69,7 +69,6 @@ part 'utils/account_options.dart';
part 'utils/app_implementation.dart'; part 'utils/app_implementation.dart';
part 'utils/bloc.dart'; part 'utils/bloc.dart';
part 'utils/confirmation_dialog.dart'; part 'utils/confirmation_dialog.dart';
part 'utils/env.dart';
part 'utils/global.dart'; part 'utils/global.dart';
part 'utils/global_options.dart'; part 'utils/global_options.dart';
part 'utils/global_popups.dart'; part 'utils/global_popups.dart';

29
packages/neon/lib/src/pages/login.dart

@ -38,9 +38,6 @@ class _LoginPageState extends State<LoginPage> {
await launchUrlString( await launchUrlString(
init.login, init.login,
mode: LaunchMode.externalApplication, mode: LaunchMode.externalApplication,
webViewConfiguration: WebViewConfiguration(
headers: _buildHeaders(context, Provider.of<Env?>(context, listen: false)),
),
); );
}); });
} }
@ -85,18 +82,6 @@ class _LoginPageState extends State<LoginPage> {
}); });
} }
Map<String, String> _buildHeaders(
final BuildContext context,
final Env? env,
) =>
{
HttpHeaders.userAgentHeader: userAgent(_packageInfo),
if (env != null) ...{
HttpHeaders.authorizationHeader:
'Basic ${base64.encode(utf8.encode('${env.testUsername}:${env.testPassword}'))}',
},
};
@override @override
void dispose() { void dispose() {
_loginBloc.dispose(); _loginBloc.dispose();
@ -104,10 +89,7 @@ class _LoginPageState extends State<LoginPage> {
} }
@override @override
Widget build(final BuildContext context) { Widget build(final BuildContext context) => StreamBuilder<List<Account>>(
final env = Provider.of<Env?>(context);
return StreamBuilder<List<Account>>(
stream: _accountsBloc.accounts, stream: _accountsBloc.accounts,
builder: (final context, final accountsSnapshot) => WillPopScope( builder: (final context, final accountsSnapshot) => WillPopScope(
onWillPop: () async { onWillPop: () async {
@ -161,10 +143,7 @@ class _LoginPageState extends State<LoginPage> {
final url = final url =
(await _loginBloc.loginFlowInit.firstWhere((final init) => init != null))!.login; (await _loginBloc.loginFlowInit.firstWhere((final init) => init != null))!.login;
if (mounted) { if (mounted) {
await _webViewController!.loadUrl( await _webViewController!.loadUrl(url);
url,
headers: _buildHeaders(context, env),
);
} }
}, },
) )
@ -211,8 +190,7 @@ class _LoginPageState extends State<LoginPage> {
decoration: const InputDecoration( decoration: const InputDecoration(
hintText: 'https://...', hintText: 'https://...',
), ),
initialValue: initialValue: widget.serverURL,
widget.serverURL ?? (env?.testHost != null ? 'http://${env!.testHost}' : null),
validator: (final input) => validateHttpUrl(context, input), validator: (final input) => validateHttpUrl(context, input),
onFieldSubmitted: (final input) { onFieldSubmitted: (final input) {
if (_formKey.currentState!.validate()) { if (_formKey.currentState!.validate()) {
@ -251,4 +229,3 @@ class _LoginPageState extends State<LoginPage> {
), ),
); );
} }
}

19
packages/neon/lib/src/utils/env.dart

@ -1,19 +0,0 @@
part of '../neon.dart';
class Env {
Env({
this.testHost,
this.testUsername,
this.testPassword,
});
factory Env.fromMap(final Map<String, String> data) => Env(
testHost: data['TEST_HOST'],
testUsername: data['TEST_USER'],
testPassword: data['TEST_PASSWORD'],
);
final String? testHost;
final String? testUsername;
final String? testPassword;
}

8
packages/neon/pubspec.lock

@ -293,14 +293,6 @@ packages:
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "3.3.0" version: "3.3.0"
flutter_dotenv:
dependency: "direct main"
description:
name: flutter_dotenv
sha256: d9283d92059a22e9834bc0a31336658ffba77089fb6f3cc36751f1fc7c6661a3
url: "https://pub.dev"
source: hosted
version: "5.0.2"
flutter_driver: flutter_driver:
dependency: transitive dependency: transitive
description: flutter description: flutter

1
packages/neon/pubspec.yaml

@ -16,7 +16,6 @@ dependencies:
flutter: flutter:
sdk: flutter sdk: flutter
flutter_cache_manager: ^3.3.0 flutter_cache_manager: ^3.3.0
flutter_dotenv: ^5.0.2
flutter_file_dialog: ^2.3.0 flutter_file_dialog: ^2.3.0
flutter_html: ^3.0.0-alpha.3 flutter_html: ^3.0.0-alpha.3
flutter_local_notifications: ^12.0.2 flutter_local_notifications: ^12.0.2

0
tool/build-dev-container-image.sh → tool/build-dev-container.sh

8
tool/dev.sh

@ -0,0 +1,8 @@
#!/bin/bash
set -euxo pipefail
cd "$(dirname "$0")/.."
./tool/build-dev-container.sh
echo "Running development instance on http://localhost. To access it in an Android Emulator use http://10.0.2.2"
docker run --rm -v nextcloud-neon-dev:/usr/src/nextcloud -v nextcloud-neon-dev:/var/www/html -p "80:80" --add-host host.docker.internal:host-gateway nextcloud-neon-dev

2
tool/generate-screenshots.sh

@ -2,7 +2,7 @@
set -euxo pipefail set -euxo pipefail
cd "$(dirname "$0")/.." cd "$(dirname "$0")/.."
./tool/build-dev-container-image.sh ./tool/build-dev-container.sh
container_id="$(docker run --rm -d -p "80:80" nextcloud-neon-dev)" container_id="$(docker run --rm -d -p "80:80" nextcloud-neon-dev)"
function cleanup() { function cleanup() {
docker kill "$container_id" docker kill "$container_id"

28
tool/run-dev-instance.sh

@ -1,28 +0,0 @@
#!/bin/bash
set -euxo pipefail
cd "$(dirname "$0")/.."
ip=""
if [ "$#" -ne 1 ]; then
echo "You need to give the platform type: localhost, android-emulator"
exit 1
elif [[ "$1" == "android-emulator" ]]; then
ip="10.0.2.2"
elif [[ "$1" == "localhost" ]]; then
ip="localhost"
else
echo "Unknown platform type: $1"
exit 1
fi
./tool/build-dev-container-image.sh
echo "TEST_HOST=$ip
TEST_USER=user1
TEST_PASSWORD=user1" > packages/neon/assets/.env
function cleanup() {
rm packages/neon/assets/.env
}
trap cleanup EXIT
docker run --rm -v nextcloud-neon-dev:/usr/src/nextcloud -v nextcloud-neon-dev:/var/www/html -p "80:80" --add-host host.docker.internal:host-gateway nextcloud-neon-dev
Loading…
Cancel
Save