Skip to content

Commit

Permalink
✨ added basic Kiosk mode and argument-support (--tv and --kiosk)
Browse files Browse the repository at this point in the history
  • Loading branch information
redinsch committed Nov 5, 2024
1 parent ea3de04 commit d7204c5
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 1 deletion.
11 changes: 11 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
},
{
Expand Down
1 change: 1 addition & 0 deletions lib/globals/platform_globals.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 ||
Expand Down
26 changes: 25 additions & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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<String> 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());
}

Expand Down
3 changes: 3 additions & 0 deletions lib/views/login.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
),
Expand Down
25 changes: 25 additions & 0 deletions linux/my_application.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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));
}

Expand Down

0 comments on commit d7204c5

Please sign in to comment.