diff --git a/.vscode/launch.json b/.vscode/launch.json index a8f2f8e..b63f4ee 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -8,6 +8,17 @@ "name": "OpenMediaStation.FE.MovieTV", "request": "launch", "type": "dart", + }, + { + "name": "KioskMode", + "request": "launch", + "type": "dart", + "args": ["--dart-entrypoint-args","--kiosk"] + }, + { + "name": "OpenMediaStation.FE.MovieTV (Chrome Debug)", + "request": "launch", + "type": "dart", "args": ["-d", "chrome","--web-port", "8000"] }, { diff --git a/lib/globals/platform_globals.dart b/lib/globals/platform_globals.dart index f777b4b..5ecf710 100644 --- a/lib/globals/platform_globals.dart +++ b/lib/globals/platform_globals.dart @@ -6,6 +6,7 @@ class PlatformGlobals { static bool isAndroidTv = false; static bool isMobile = false; static bool isWeb = false; + static bool isKiosk = false; static Future setGlobals() async { PlatformGlobals.isMobile = defaultTargetPlatform == TargetPlatform.iOS || diff --git a/lib/main.dart b/lib/main.dart index 2d85049..19e5779 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,4 +1,8 @@ +import 'dart:developer'; +import 'dart:io'; + import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; import 'package:media_kit/media_kit.dart'; import 'package:open_media_server_app/globals/auth_globals.dart'; import 'package:open_media_server_app/globals/platform_globals.dart'; @@ -8,15 +12,35 @@ import 'package:open_media_server_app/helpers/preferences.dart'; import 'package:open_media_server_app/views/login.dart'; import 'package:shared_preferences/shared_preferences.dart'; -Future main() async { +Future main(List args) async { WidgetsFlutterBinding.ensureInitialized(); MediaKit.ensureInitialized(); await PlatformGlobals.setGlobals(); + args = args.map((arg) => arg.toLowerCase()).toList(); + if (args.contains('--kiosk')) { + PlatformGlobals.isKiosk = true; + PlatformGlobals.isTv = true; + } + if (args.contains('--tv')) { + PlatformGlobals.isTv = true; + } + var prefs = await SharedPreferences.getInstance(); Preferences.prefs = prefs; + if (PlatformGlobals.isKiosk) { + SystemChrome.setEnabledSystemUIMode(SystemUiMode.immersiveSticky); + if (Platform.isLinux) { + try { + await const MethodChannel('my_app/fullscreen').invokeMapMethod('enableFullscreen'); + } on PlatformException catch (e) + { + log("Failed to enable fullscreen: '${e.message}'."); + } + } + } runApp(const MyApp()); } diff --git a/lib/views/login.dart b/lib/views/login.dart index d388e76..dc63934 100644 --- a/lib/views/login.dart +++ b/lib/views/login.dart @@ -3,6 +3,7 @@ import 'package:open_media_server_app/apis/auth_info_api.dart'; import 'package:open_media_server_app/auth/login_manager.dart'; import 'package:open_media_server_app/globals/auth_globals.dart'; import 'package:open_media_server_app/globals/globals.dart'; +import 'package:open_media_server_app/globals/platform_globals.dart'; import 'package:open_media_server_app/helpers/preferences.dart'; class LoginView extends StatelessWidget { @@ -146,6 +147,8 @@ class LoginView extends StatelessWidget { surfaceTintColor: Colors.transparent, title: Text(Globals.Title), automaticallyImplyLeading: false, + actions: + PlatformGlobals.isKiosk ? [IconButton(onPressed: ()=>exit(0), icon: const Icon(Icons.close))]: [] ), body: widget, ), diff --git a/linux/my_application.cc b/linux/my_application.cc index 6bd9f69..c5d24be 100644 --- a/linux/my_application.cc +++ b/linux/my_application.cc @@ -14,6 +14,24 @@ struct _MyApplication { G_DEFINE_TYPE(MyApplication, my_application, GTK_TYPE_APPLICATION) +void enable_fullscreen(GtkWindow* window) { + gtk_window_fullscreen(window); +} + +static void method_call_handler(FlMethodChannel* channel, + FlMethodCall* method_call, + gpointer user_data) { + const gchar* method = fl_method_call_get_name(method_call); + + if (strcmp(method, "enableFullscreen") == 0) { + GtkWindow* window = GTK_WINDOW(user_data); + enable_fullscreen(window); + fl_method_call_respond_success(method_call, nullptr, nullptr); + } else { + fl_method_call_respond_not_implemented(method_call, nullptr); + } +} + // Implements GApplication::activate. static void my_application_activate(GApplication* application) { MyApplication* self = MY_APPLICATION(application); @@ -59,6 +77,13 @@ static void my_application_activate(GApplication* application) { fl_register_plugins(FL_PLUGIN_REGISTRY(view)); + FlEngine* engine = fl_view_get_engine(view); + FlMethodChannel* channel = fl_method_channel_new( + fl_engine_get_binary_messenger(engine), + "my_app/fullscreen", + FL_METHOD_CODEC(fl_standard_method_codec_new())); + fl_method_channel_set_method_call_handler(channel, method_call_handler, window, nullptr); + gtk_widget_grab_focus(GTK_WIDGET(view)); }