mirror of
https://github.com/gabehf/Fladder.git
synced 2026-03-11 08:20:49 -07:00
Web - Add docker image and baseUrl config support (#32)
This commit is contained in:
parent
80a0fdbee4
commit
bfcbf5402d
12 changed files with 144 additions and 138 deletions
|
|
@ -1,61 +0,0 @@
|
|||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
import 'package:media_kit/media_kit.dart';
|
||||
import 'package:package_info_plus/package_info_plus.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
import 'package:fladder/providers/shared_provider.dart';
|
||||
import 'package:fladder/util/application_info.dart';
|
||||
import 'package:fladder/util/string_extensions.dart';
|
||||
|
||||
void main() async {
|
||||
_setupLogging();
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
MediaKit.ensureInitialized();
|
||||
|
||||
final sharedPreferences = await SharedPreferences.getInstance();
|
||||
|
||||
PackageInfo packageInfo = await PackageInfo.fromPlatform();
|
||||
|
||||
runApp(
|
||||
ProviderScope(
|
||||
overrides: [
|
||||
sharedPreferencesProvider.overrideWith((ref) => sharedPreferences),
|
||||
applicationInfoProvider.overrideWith(
|
||||
(ref) => ApplicationInfo(
|
||||
name: packageInfo.appName,
|
||||
buildNumber: packageInfo.buildNumber,
|
||||
version: packageInfo.version,
|
||||
os: defaultTargetPlatform.name.capitalize(),
|
||||
),
|
||||
),
|
||||
],
|
||||
child: const Main(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _setupLogging() {
|
||||
Logger.root.level = Level.ALL;
|
||||
Logger.root.onRecord.listen((rec) {
|
||||
if (kDebugMode) {
|
||||
print('${rec.level.name}: ${rec.time}: ${rec.message}');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
class Main extends ConsumerWidget {
|
||||
const Main({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
return const MaterialApp(
|
||||
home: Scaffold(
|
||||
body: Center(child: Text("AndroidTV")),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,3 +1,5 @@
|
|||
import 'dart:convert';
|
||||
import 'dart:developer';
|
||||
import 'dart:io';
|
||||
import 'dart:ui';
|
||||
|
||||
|
|
@ -32,6 +34,7 @@ import 'package:fladder/screens/login/lock_screen.dart';
|
|||
import 'package:fladder/theme.dart';
|
||||
import 'package:fladder/util/adaptive_layout.dart';
|
||||
import 'package:fladder/util/application_info.dart';
|
||||
import 'package:fladder/util/fladder_config.dart';
|
||||
import 'package:fladder/util/string_extensions.dart';
|
||||
import 'package:fladder/util/themes_data.dart';
|
||||
|
||||
|
|
@ -57,14 +60,24 @@ class CustomCacheManager {
|
|||
);
|
||||
}
|
||||
|
||||
Future<Map<String, dynamic>> loadConfig() async {
|
||||
final configString = await rootBundle.loadString('config/config.json');
|
||||
return jsonDecode(configString);
|
||||
}
|
||||
|
||||
void main() async {
|
||||
if (kIsWeb) {
|
||||
html.document.onContextMenu.listen((event) => event.preventDefault());
|
||||
}
|
||||
_setupLogging();
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
MediaKit.ensureInitialized();
|
||||
|
||||
if (kIsWeb) {
|
||||
html.document.onContextMenu.listen((event) => event.preventDefault());
|
||||
final result = await loadConfig();
|
||||
log(result.toString());
|
||||
FladderConfig.fromJson(result);
|
||||
log(FladderConfig.baseUrl.toString());
|
||||
}
|
||||
|
||||
final sharedPreferences = await SharedPreferences.getInstance();
|
||||
|
||||
PackageInfo packageInfo = await PackageInfo.fromPlatform();
|
||||
|
|
|
|||
|
|
@ -1,11 +1,13 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:ficonsax/ficonsax.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
import 'package:fladder/models/account_model.dart';
|
||||
import 'package:fladder/providers/auth_provider.dart';
|
||||
import 'package:fladder/providers/shared_provider.dart';
|
||||
import 'package:fladder/util/list_padding.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
class LoginEditUser extends ConsumerWidget {
|
||||
final AccountModel user;
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ import 'package:fladder/screens/shared/outlined_text_field.dart';
|
|||
import 'package:fladder/screens/shared/passcode_input.dart';
|
||||
import 'package:fladder/util/adaptive_layout.dart';
|
||||
import 'package:fladder/util/auth_service.dart';
|
||||
import 'package:fladder/util/fladder_config.dart';
|
||||
import 'package:fladder/util/list_padding.dart';
|
||||
import 'package:fladder/util/localization_helper.dart';
|
||||
import 'package:fladder/util/string_extensions.dart';
|
||||
|
|
@ -43,7 +44,7 @@ class _LoginPageState extends ConsumerState<LoginScreen> {
|
|||
bool startCheckingForErrors = false;
|
||||
bool addingNewUser = false;
|
||||
bool editingUsers = false;
|
||||
late final TextEditingController serverTextController = TextEditingController(text: "");
|
||||
late final TextEditingController serverTextController = TextEditingController(text: '');
|
||||
|
||||
final usernameController = TextEditingController();
|
||||
final passwordController = TextEditingController();
|
||||
|
|
@ -64,6 +65,11 @@ class _LoginPageState extends ConsumerState<LoginScreen> {
|
|||
final currentAccounts = ref.read(authProvider.notifier).getSavedAccounts();
|
||||
addingNewUser = currentAccounts.isEmpty;
|
||||
ref.read(lockScreenActiveProvider.notifier).update((state) => true);
|
||||
if (FladderConfig.baseUrl != null) {
|
||||
serverTextController.text = FladderConfig.baseUrl!;
|
||||
_parseUrl(FladderConfig.baseUrl!);
|
||||
retrieveListOfUsers();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -258,7 +264,7 @@ class _LoginPageState extends ConsumerState<LoginScreen> {
|
|||
return Column(
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
if (accounts.isNotEmpty)
|
||||
|
|
@ -282,33 +288,35 @@ class _LoginPageState extends ConsumerState<LoginScreen> {
|
|||
),
|
||||
),
|
||||
),
|
||||
Flexible(
|
||||
child: OutlinedTextField(
|
||||
controller: serverTextController,
|
||||
onChanged: _parseUrl,
|
||||
onSubmitted: (value) => retrieveListOfUsers(),
|
||||
autoFillHints: const [AutofillHints.url],
|
||||
keyboardType: TextInputType.url,
|
||||
textInputAction: TextInputAction.go,
|
||||
label: context.localized.server,
|
||||
errorText: (invalidUrl == null || serverTextController.text.isEmpty || !startCheckingForErrors)
|
||||
? null
|
||||
: invalidUrl,
|
||||
if (FladderConfig.baseUrl == null) ...[
|
||||
Flexible(
|
||||
child: OutlinedTextField(
|
||||
controller: serverTextController,
|
||||
onChanged: _parseUrl,
|
||||
onSubmitted: (value) => retrieveListOfUsers(),
|
||||
autoFillHints: const [AutofillHints.url],
|
||||
keyboardType: TextInputType.url,
|
||||
textInputAction: TextInputAction.go,
|
||||
label: context.localized.server,
|
||||
errorText: (invalidUrl == null || serverTextController.text.isEmpty || !startCheckingForErrors)
|
||||
? null
|
||||
: invalidUrl,
|
||||
),
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Tooltip(
|
||||
message: context.localized.retrievePublicListOfUsers,
|
||||
waitDuration: const Duration(seconds: 1),
|
||||
child: IconButton.filled(
|
||||
onPressed: () => retrieveListOfUsers(),
|
||||
icon: const Icon(
|
||||
IconsaxOutline.refresh,
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Tooltip(
|
||||
message: context.localized.retrievePublicListOfUsers,
|
||||
waitDuration: const Duration(seconds: 1),
|
||||
child: IconButton.filled(
|
||||
onPressed: () => retrieveListOfUsers(),
|
||||
icon: const Icon(
|
||||
IconsaxOutline.refresh,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
AnimatedFadeSize(
|
||||
|
|
|
|||
17
lib/util/fladder_config.dart
Normal file
17
lib/util/fladder_config.dart
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
class FladderConfig {
|
||||
static FladderConfig _instance = FladderConfig._();
|
||||
FladderConfig._();
|
||||
|
||||
static String? get baseUrl => _instance._baseUrl;
|
||||
static set baseUrl(String? value) => _instance._baseUrl = value;
|
||||
String? _baseUrl;
|
||||
|
||||
static void fromJson(Map<String, dynamic> json) => _instance = FladderConfig._fromJson(json);
|
||||
|
||||
factory FladderConfig._fromJson(Map<String, dynamic> json) {
|
||||
final config = FladderConfig._();
|
||||
final newUrl = json['baseUrl'] as String?;
|
||||
config._baseUrl = newUrl?.isEmpty == true ? null : newUrl;
|
||||
return config;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue