diff --git a/lib/DrawerPage.dart b/lib/DrawerPage.dart index 7dee1c9..4ac0809 100644 --- a/lib/DrawerPage.dart +++ b/lib/DrawerPage.dart @@ -17,18 +17,14 @@ class DrawerPage extends StatefulWidget { enum Section { HOME, SHUFFLE, LOGOUT } class _DrawerPageState extends State { - Section sec = Section.HOME; + Section _sec = Section.HOME; @override Widget build(BuildContext context) { Widget body; String title; - /// You can easily control the section for example inside the initState where you check - /// if the user logged in, or other related logic - switch (sec) { - - /// Display the home section, simply by + switch (_sec) { case Section.HOME: body = const VideoFeed(); title = widget.title; @@ -45,13 +41,13 @@ class _DrawerPageState extends State { break; } - var loginctx = LoginContext.of(context); + final loginCtx = LoginContext.of(context); return Scaffold( appBar: AppBar(title: Text(title), actions: [ IconButton( onPressed: () { - loginctx.onLoggin(false); + loginCtx.onLoggin(false); Token.getInstance().setToken("", ""); }, icon: const Icon(Icons.logout)) @@ -64,7 +60,7 @@ class _DrawerPageState extends State { leading: const Icon(Icons.home), onTap: () { setState(() { - sec = Section.HOME; + _sec = Section.HOME; }); Navigator.pop(context); }, @@ -74,7 +70,7 @@ class _DrawerPageState extends State { leading: const Icon(Icons.update), onTap: () { setState(() { - sec = Section.SHUFFLE; + _sec = Section.SHUFFLE; }); Navigator.pop(context); }, @@ -84,7 +80,7 @@ class _DrawerPageState extends State { leading: const Icon(Icons.settings), onTap: () { setState(() { - sec = Section.LOGOUT; + _sec = Section.LOGOUT; }); Navigator.pop(context); }, diff --git a/lib/app.dart b/lib/app.dart index f13b296..dcac65a 100644 --- a/lib/app.dart +++ b/lib/app.dart @@ -3,26 +3,18 @@ import 'package:openmediacentermobile/log/log.dart'; import 'package:openmediacentermobile/login/login_screen.dart'; import 'DrawerPage.dart'; -import 'api/token.dart'; import 'login/logincontext.dart'; -import 'video_feed.dart'; - -// class App extends StatefulWidget { -// const App({Key? key}) : super(key: key); -// @override -// State createState() => AppState(); -// } class App extends StatelessWidget { const App({Key? key}) : super(key: key); @override Widget build(BuildContext context) { - var loginctx = LoginContext.of(context); + var loginCtx = LoginContext.of(context); - Log.d("We are logged in: ${loginctx.LoggedIn}"); + Log.d("We are logged in: ${loginCtx.loggedIn}"); - if (!loginctx.LoggedIn) { + if (!loginCtx.loggedIn) { return const MaterialApp(home: LoginScreen()); } else { return const MaterialApp( diff --git a/lib/login/login_screen.dart b/lib/login/login_screen.dart index 881e09e..e12c649 100644 --- a/lib/login/login_screen.dart +++ b/lib/login/login_screen.dart @@ -18,22 +18,28 @@ class _LoginScreenState extends State { final TextEditingController _domainTextController = TextEditingController(); final TextEditingController _passwordTextController = TextEditingController(); String error = ""; + bool _loginActive = false; Future login(String password, String domain) async { Log.i("logging in..."); - // final compl = Completer(); - final resp = await http.post( - Uri.parse(domain + '/api/login/login'), - headers: { - 'Content-Type': 'application/json; charset=UTF-8', - }, - body: jsonEncode({ - 'Password': password, - }), - ); + + http.Response resp; + try { + resp = await http.post( + Uri.parse(domain + '/api/login/login'), + headers: { + 'Content-Type': 'application/json; charset=UTF-8', + }, + body: jsonEncode({ + 'Password': password, + }), + ); + } catch (e) { + return "error" + e.toString(); + } if (resp.statusCode != 200) { - return resp.body; + return "error" + resp.body; // compl.complete(resp.body); } else { @@ -44,13 +50,7 @@ class _LoginScreenState extends State { LoginContext.of(context).onLoggin(true); return ""; - - // compl.complete(""); } - - // LoginContext.of(context).onLoggin(true); - - // return compl.future; } @override @@ -130,16 +130,26 @@ class _LoginScreenState extends State { backgroundColor: const Color(0xff4c505b), child: IconButton( color: Colors.white, - onPressed: () { + onPressed: () async { Log.d("clickkked"); final pwd = _passwordTextController.value.text; final domain = _domainTextController.value.text; - login(pwd, domain).then((value) { - if (value != "") { - setState(() { - error = value; - }); - } + + var err = ""; + if (domain.startsWith("https://") || domain.startsWith("http://")) { + err = await login(pwd, domain); + if (err.isEmpty) return; + } else { + // try to auto infering domain prefix + err = await login(pwd, "https://" + domain); + if (err.isEmpty) return; + err = await login(pwd, "http://" + domain); + if (err.isEmpty) return; + } + + Log.i(err); + setState(() { + error = err; }); }, icon: const Icon( diff --git a/lib/login/logincontext.dart b/lib/login/logincontext.dart index 8f30c2d..a1e6b2a 100644 --- a/lib/login/logincontext.dart +++ b/lib/login/logincontext.dart @@ -12,8 +12,8 @@ class LoginContainer extends StatefulWidget { } class _LoginContainerState extends State { - bool loggedIn = false; - bool loading = true; + bool _loggedIn = false; + bool _loading = true; @override void initState() { @@ -24,13 +24,13 @@ class _LoginContainerState extends State { Log.i("The token value is $value"); if (value != null) { setState(() { - loggedIn = true; - loading = false; + _loggedIn = true; + _loading = false; }); } else { setState(() { - loggedIn = false; - loading = false; + _loggedIn = false; + _loading = false; }); } }); @@ -39,8 +39,8 @@ class _LoginContainerState extends State { @override Widget build(BuildContext context) { return LoginContext( - LoggedIn: loggedIn, - child: loading + loggedIn: _loggedIn, + child: _loading ? MaterialApp( home: Container( color: Colors.white, @@ -49,9 +49,9 @@ class _LoginContainerState extends State { ) : widget.child, onLoggin: (bool login) { - if (loggedIn != login) { + if (_loggedIn != login) { setState(() { - loggedIn = login; + _loggedIn = login; }); } }, @@ -63,11 +63,11 @@ class LoginContext extends InheritedWidget { const LoginContext( {Key? key, required Widget child, - required this.LoggedIn, + required this.loggedIn, required this.onLoggin}) : super(key: key, child: child); - final bool LoggedIn; + final bool loggedIn; final void Function(bool) onLoggin; static LoginContext of(BuildContext context) { @@ -79,6 +79,6 @@ class LoginContext extends InheritedWidget { @override bool updateShouldNotify(LoginContext old) { - return LoggedIn != old.LoggedIn; + return loggedIn != old.loggedIn; } } diff --git a/lib/main.dart b/lib/main.dart index 4da33a4..39b3675 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -7,7 +7,6 @@ import 'log/log.dart'; import 'login/logincontext.dart'; import 'platform.dart'; -// main app entry point void main() async { Log.i("App init!"); DartVLC.initialize(); diff --git a/lib/preview_grid.dart b/lib/preview_grid.dart index d971eb9..2e1169a 100644 --- a/lib/preview_grid.dart +++ b/lib/preview_grid.dart @@ -16,10 +16,8 @@ class PreviewGrid extends StatefulWidget { class _PreviewGridState extends State { late Future> _data; - Image? _previewImage; - @override void initState() { super.initState(); @@ -28,7 +26,7 @@ class _PreviewGridState extends State { @override Widget build(BuildContext context) { - double width = MediaQuery.of(context).size.width; + final double width = MediaQuery.of(context).size.width; return FutureBuilder>( future: _data, // a previously-obtained Future or null diff --git a/lib/preview_tile.dart b/lib/preview_tile.dart index 7645c82..d2f07a4 100644 --- a/lib/preview_tile.dart +++ b/lib/preview_tile.dart @@ -12,9 +12,9 @@ import 'platform.dart'; class VideoT { int id; String title; - double Ratio; + double ratio; - VideoT(this.title, this.id, this.Ratio); + VideoT(this.title, this.id, this.ratio); factory VideoT.fromJson(dynamic json) { return VideoT(json['MovieName'] as String, json['MovieId'] as int, (json['Ratio'] as num).toDouble()); @@ -109,7 +109,7 @@ class _PreviewTileState extends State { Navigator.push( context, MaterialPageRoute( - builder: (context) => VideoScreen(MetaData: widget.dta), + builder: (context) => VideoScreen(metaData: widget.dta), ), ); }, diff --git a/lib/shufflescreen.dart b/lib/shufflescreen.dart index 1d82ed5..60816ba 100644 --- a/lib/shufflescreen.dart +++ b/lib/shufflescreen.dart @@ -3,7 +3,7 @@ import 'dart:math'; import 'package:flutter/material.dart'; import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart'; -import 'package:openmediacentermobile/preview_tile.dart'; +import 'preview_tile.dart'; import 'api/api.dart'; import 'platform.dart'; @@ -18,8 +18,8 @@ class ShuffleScreen extends StatefulWidget { class _ShuffleScreenState extends State { late Future> _data; - Future> loadData() async { - final data = await API.query("video", "getRandomMovies", {'Number': 4, 'Seed': Random().nextInt(0x7fffffff)}); + Future> loadData(int nr) async { + final data = await API.query("video", "getRandomMovies", {'Number': nr, 'Seed': Random().nextInt(0x7fffffff)}); final d = jsonDecode(data); @@ -32,7 +32,11 @@ class _ShuffleScreenState extends State { void initState() { super.initState(); - _data = loadData(); + _data = Future.delayed(Duration.zero).then((_) { + double width = MediaQuery.of(context).size.width; + return loadData((isTV() ? width ~/ 200 : width ~/ 330) * 2); + }); + } @override @@ -52,7 +56,7 @@ class _ShuffleScreenState extends State { mainAxisSpacing: 4, crossAxisSpacing: 4, padding: EdgeInsets.all(5), - itemCount: 4, + itemCount: snapshot.data!.length, itemBuilder: (context, index) { return PreviewTile(dta: snapshot.data![index]); }, @@ -63,7 +67,7 @@ class _ShuffleScreenState extends State { TextButton.icon( onPressed: () { setState(() { - _data = loadData(); + _data = loadData((isTV() ? width ~/ 200 : width ~/ 330) * 2); }); }, icon: const Icon(Icons.update), diff --git a/lib/videoscreen_desktop.dart b/lib/videoscreen_desktop.dart index 6a37ead..381d824 100644 --- a/lib/videoscreen_desktop.dart +++ b/lib/videoscreen_desktop.dart @@ -14,19 +14,19 @@ import 'log/log.dart'; import 'platform.dart'; class VideoScreen extends StatefulWidget { - const VideoScreen({Key? key, required this.MetaData}) : super(key: key); - final VideoT MetaData; + const VideoScreen({Key? key, required this.metaData}) : super(key: key); + final VideoT metaData; @override State createState() => _VideoScreenState(); } class _VideoScreenState extends State { - Player? player = isDesktop() ? Player(id: Random().nextInt(0x7fffffff)) : null; + Player? _player = isDesktop() ? Player(id: Random().nextInt(0x7fffffff)) : null; ChewieController? _chewieController; void loadData() async { - final data = await API.query("video", "loadVideo", {'MovieId': widget.MetaData.id}); + final data = await API.query("video", "loadVideo", {'MovieId': widget.metaData.id}); final d = jsonDecode(data); @@ -41,7 +41,7 @@ class _VideoScreenState extends State { if (isDesktop()) { final media2 = Media.network(path); - player?.open( + _player?.open( media2, autoStart: true, // default ); @@ -70,9 +70,9 @@ class _VideoScreenState extends State { if(isDesktop()){ RawKeyboard.instance.addListener((value) { if (value.logicalKey == LogicalKeyboardKey.arrowRight) { - player?.seek(player!.position.position! + const Duration(seconds: 5)); + _player?.seek(_player!.position.position! + const Duration(seconds: 5)); } else if (value.logicalKey == LogicalKeyboardKey.arrowLeft) { - player?.seek(player!.position.position! + const Duration(seconds: -5)); + _player?.seek(_player!.position.position! + const Duration(seconds: -5)); } }); } @@ -87,7 +87,7 @@ class _VideoScreenState extends State { void dispose() { super.dispose(); if (isDesktop()) { - player?.dispose(); + _player?.dispose(); } else { _chewieController?.videoPlayerController.dispose(); _chewieController?.dispose(); @@ -98,7 +98,7 @@ class _VideoScreenState extends State { Widget build(BuildContext context) { return Scaffold( appBar: AppBar( - title: Text(widget.MetaData.title), + title: Text(widget.metaData.title), ), body: Center(child: isDesktop() ? videoDesktop() : videoNotDesktop()), ); @@ -106,10 +106,9 @@ class _VideoScreenState extends State { Widget videoDesktop() { return Video( - player: player, + player: _player, scale: 1.0, // default - showControls: true, - playlistLength: 1, // default + showControls: true ); } diff --git a/linux/flutter/generated_plugin_registrant.cc b/linux/flutter/generated_plugin_registrant.cc index 93a5b7f..19daffd 100644 --- a/linux/flutter/generated_plugin_registrant.cc +++ b/linux/flutter/generated_plugin_registrant.cc @@ -8,6 +8,8 @@ #include #include +#include +#include void fl_register_plugins(FlPluginRegistry* registry) { g_autoptr(FlPluginRegistrar) dart_vlc_registrar = @@ -16,4 +18,10 @@ void fl_register_plugins(FlPluginRegistry* registry) { g_autoptr(FlPluginRegistrar) flutter_secure_storage_linux_registrar = fl_plugin_registry_get_registrar_for_plugin(registry, "FlutterSecureStorageLinuxPlugin"); flutter_secure_storage_linux_plugin_register_with_registrar(flutter_secure_storage_linux_registrar); + g_autoptr(FlPluginRegistrar) screen_retriever_registrar = + fl_plugin_registry_get_registrar_for_plugin(registry, "ScreenRetrieverPlugin"); + screen_retriever_plugin_register_with_registrar(screen_retriever_registrar); + g_autoptr(FlPluginRegistrar) window_manager_registrar = + fl_plugin_registry_get_registrar_for_plugin(registry, "WindowManagerPlugin"); + window_manager_plugin_register_with_registrar(window_manager_registrar); } diff --git a/linux/flutter/generated_plugins.cmake b/linux/flutter/generated_plugins.cmake index 91bddd1..3ee7e08 100644 --- a/linux/flutter/generated_plugins.cmake +++ b/linux/flutter/generated_plugins.cmake @@ -5,6 +5,8 @@ list(APPEND FLUTTER_PLUGIN_LIST dart_vlc flutter_secure_storage_linux + screen_retriever + window_manager ) list(APPEND FLUTTER_FFI_PLUGIN_LIST diff --git a/pubspec.lock b/pubspec.lock index 3cc3cbb..1da58ae 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -42,7 +42,7 @@ packages: name: chewie url: "https://pub.dartlang.org" source: hosted - version: "1.3.2" + version: "1.3.4" clock: dependency: transitive description: @@ -63,35 +63,35 @@ packages: name: csslib url: "https://pub.dartlang.org" source: hosted - version: "0.17.1" + version: "0.17.2" cupertino_icons: dependency: "direct main" description: name: cupertino_icons url: "https://pub.dartlang.org" source: hosted - version: "1.0.4" + version: "1.0.5" dart_vlc: dependency: "direct main" description: name: dart_vlc url: "https://pub.dartlang.org" source: hosted - version: "0.1.9" + version: "0.3.0" dart_vlc_ffi: dependency: transitive description: name: dart_vlc_ffi url: "https://pub.dartlang.org" source: hosted - version: "0.1.5+1" + version: "0.1.8" device_info_plus: dependency: "direct main" description: name: device_info_plus url: "https://pub.dartlang.org" source: hosted - version: "3.2.3" + version: "4.0.0" device_info_plus_linux: dependency: transitive description: @@ -112,7 +112,7 @@ packages: name: device_info_plus_platform_interface url: "https://pub.dartlang.org" source: hosted - version: "2.3.0+1" + version: "2.6.1" device_info_plus_web: dependency: transitive description: @@ -140,14 +140,14 @@ packages: name: ffi url: "https://pub.dartlang.org" source: hosted - version: "1.1.2" + version: "1.2.1" file: dependency: transitive description: name: file url: "https://pub.dartlang.org" source: hosted - version: "6.1.2" + version: "6.1.4" flutter: dependency: "direct main" description: flutter @@ -159,28 +159,35 @@ packages: name: flutter_lints url: "https://pub.dartlang.org" source: hosted - version: "1.0.4" + version: "2.0.1" + flutter_native_view: + dependency: transitive + description: + name: flutter_native_view + url: "https://pub.dartlang.org" + source: hosted + version: "0.0.2" flutter_secure_storage: dependency: "direct main" description: name: flutter_secure_storage url: "https://pub.dartlang.org" source: hosted - version: "5.0.2" + version: "6.0.0" flutter_secure_storage_linux: dependency: transitive description: name: flutter_secure_storage_linux url: "https://pub.dartlang.org" source: hosted - version: "1.1.0" + version: "1.1.1" flutter_secure_storage_macos: dependency: transitive description: name: flutter_secure_storage_macos url: "https://pub.dartlang.org" source: hosted - version: "1.1.0" + version: "1.1.1" flutter_secure_storage_platform_interface: dependency: transitive description: @@ -208,7 +215,7 @@ packages: name: flutter_staggered_grid_view url: "https://pub.dartlang.org" source: hosted - version: "0.6.1" + version: "0.6.2" flutter_test: dependency: "direct dev" description: flutter @@ -232,14 +239,14 @@ packages: name: http url: "https://pub.dartlang.org" source: hosted - version: "0.13.4" + version: "0.13.5" http_parser: dependency: transitive description: name: http_parser url: "https://pub.dartlang.org" source: hosted - version: "4.0.0" + version: "4.0.1" js: dependency: transitive description: @@ -253,7 +260,7 @@ packages: name: lints url: "https://pub.dartlang.org" source: hosted - version: "1.0.1" + version: "2.0.0" logger: dependency: "direct main" description: @@ -302,49 +309,49 @@ packages: name: path_provider url: "https://pub.dartlang.org" source: hosted - version: "2.0.9" + version: "2.0.11" path_provider_android: dependency: transitive description: name: path_provider_android url: "https://pub.dartlang.org" source: hosted - version: "2.0.12" + version: "2.0.19" path_provider_ios: dependency: transitive description: name: path_provider_ios url: "https://pub.dartlang.org" source: hosted - version: "2.0.8" + version: "2.0.11" path_provider_linux: dependency: transitive description: name: path_provider_linux url: "https://pub.dartlang.org" source: hosted - version: "2.1.5" + version: "2.1.7" path_provider_macos: dependency: transitive description: name: path_provider_macos url: "https://pub.dartlang.org" source: hosted - version: "2.0.5" + version: "2.0.6" path_provider_platform_interface: dependency: transitive description: name: path_provider_platform_interface url: "https://pub.dartlang.org" source: hosted - version: "2.0.1" + version: "2.0.4" path_provider_windows: dependency: transitive description: name: path_provider_windows url: "https://pub.dartlang.org" source: hosted - version: "2.0.5" + version: "2.0.7" platform: dependency: transitive description: @@ -372,7 +379,14 @@ packages: name: provider url: "https://pub.dartlang.org" source: hosted - version: "6.0.2" + version: "6.0.3" + screen_retriever: + dependency: transitive + description: + name: screen_retriever + url: "https://pub.dartlang.org" + source: hosted + version: "0.1.2" sky_engine: dependency: transitive description: flutter @@ -426,7 +440,7 @@ packages: name: typed_data url: "https://pub.dartlang.org" source: hosted - version: "1.3.0" + version: "1.3.1" vector_math: dependency: transitive description: @@ -434,55 +448,48 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.1.2" - very_good_analysis: - dependency: transitive - description: - name: very_good_analysis - url: "https://pub.dartlang.org" - source: hosted - version: "2.4.0" video_player: dependency: "direct main" description: name: video_player url: "https://pub.dartlang.org" source: hosted - version: "2.3.0" + version: "2.4.7" video_player_android: dependency: transitive description: name: video_player_android url: "https://pub.dartlang.org" source: hosted - version: "2.3.2" + version: "2.3.9" video_player_avfoundation: dependency: transitive description: name: video_player_avfoundation url: "https://pub.dartlang.org" source: hosted - version: "2.3.1" + version: "2.3.5" video_player_platform_interface: dependency: transitive description: name: video_player_platform_interface url: "https://pub.dartlang.org" source: hosted - version: "5.1.1" + version: "5.1.4" video_player_web: dependency: transitive description: name: video_player_web url: "https://pub.dartlang.org" source: hosted - version: "2.0.7" + version: "2.0.12" wakelock: dependency: transitive description: name: wakelock url: "https://pub.dartlang.org" source: hosted - version: "0.6.1+2" + version: "0.6.2" wakelock_macos: dependency: transitive description: @@ -517,14 +524,21 @@ packages: name: win32 url: "https://pub.dartlang.org" source: hosted - version: "2.5.1" + version: "2.6.1" + window_manager: + dependency: transitive + description: + name: window_manager + url: "https://pub.dartlang.org" + source: hosted + version: "0.2.6" xdg_directories: dependency: transitive description: name: xdg_directories url: "https://pub.dartlang.org" source: hosted - version: "0.2.0+1" + version: "0.2.0+2" sdks: - dart: ">=2.17.0-0 <3.0.0" - flutter: ">=2.8.0" + dart: ">=2.17.0 <3.0.0" + flutter: ">=2.10.0" diff --git a/pubspec.yaml b/pubspec.yaml index 2bf1652..ddb3b26 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -34,12 +34,12 @@ dependencies: # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons. cupertino_icons: ^1.0.2 - flutter_secure_storage: ^5.0.2 + flutter_secure_storage: ^6.0.0 logger: ^1.1.0 http: ^0.13.4 flutter_staggered_grid_view: ^0.6.1 - dart_vlc: ^0.1.9 - device_info_plus: ^3.2.3 + dart_vlc: ^0.3.0 + device_info_plus: ^4.0.0 video_player: ^2.3.0 chewie: ^1.3.2 @@ -52,7 +52,7 @@ dev_dependencies: # activated in the `analysis_options.yaml` file located at the root of your # package. See that file for information about deactivating specific lint # rules and activating additional ones. - flutter_lints: ^1.0.0 + flutter_lints: ^2.0.1 # For information on the generic Dart part of this file, see the # following page: https://dart.dev/tools/pub/pubspec