library; import 'dart:io'; import 'package:dio/dio.dart'; import 'package:fikoyt_ui/core/http_overrides.dart'; import 'package:fikoyt_ui/fikoyt_ui.dart'; import 'package:fikoyt_ui/migration/dio/dio.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart' hide Intent; import 'package:flutter/services.dart'; import 'package:mobile_device_identifier/mobile_device_identifier.dart'; import 'package:receive_intent/receive_intent.dart'; import 'package:socket_io_client/socket_io_client.dart' as IO; import 'package:timezone/data/latest.dart' as tz; // ignore: constant_identifier_names // enum TemaModu { ACIK, KOYU, SISTEM } enum TemaModu { ACIK(0, "Açık Tema", "🔆", ThemeMode.light), KOYU(1, "Koyu Tema", "🌙", ThemeMode.dark), SISTEM(-1, "Sistem Teması", "⚡", ThemeMode.system); const TemaModu(this.value, this.ismi, this.simge, this.temaModu); final int value; final String ismi; final String simge; final ThemeMode temaModu; // List tumu() => [EkOdemeTuru.IKRAMIYE, EkOdemeTuru.PRIM, EkOdemeTuru.YOL, EkOdemeTuru.YEMEK, EkOdemeTuru.SEYYANEN, EkOdemeTuru.DIGER]; } class FikoYTCoreService { static GlobalKey navigatorKey = GlobalKey(); static FikoYTServiceSettings serviceSettings = FikoYTServiceSettings(); static TemaModu temaModu = TemaModu.SISTEM; static Rx parlaklik = Brightness.light.obs; /// static final AndroidInitializationSettings initializationSettingsAndroid = AndroidInitializationSettings('@mipmap/ic_launcher'); static final InitializationSettings initializationSettings = InitializationSettings(android: initializationSettingsAndroid); static final FlutterLocalNotificationsPlugin notificationPlugin = FlutterLocalNotificationsPlugin(); /// static late IO.Socket socket; /// static init({FikoYTServiceSettings? settings}) async { FikoYTCoreService.serviceSettings = settings ?? FikoYTServiceSettings(); WidgetsFlutterBinding.ensureInitialized(); await SystemChrome.setPreferredOrientations(serviceSettings.deviceOrientation); HttpOverrides.global = HttpSSlIptalUzerineYaz(); tz.initializeTimeZones(); dio?.interceptors.add(InterceptorsWrapper(onRequest: (options, handler) { options.extra["withCredentials"] = true; return handler.next(options); })); /// await SystemChrome.setEnabledSystemUIMode(serviceSettings.systemUiMode, overlays: serviceSettings.systemUiOverlay); /// await initializeNotifications(); /// await onInitialIntent(); /// if (serviceSettings.connectWebScoket) { socket = IO.io( serviceSettings.fikoytWebSocketUrl, IO.OptionBuilder() .setTransports(['websocket']) .enableReconnection() .enableAutoConnect() // for Flutter or Dart VM // .disableAutoConnect() // disable auto-connection // .setExtraHeaders({'foo': 'bar'}) // optional .build()); socket.connect(); } return FikoYTCoreService; } /// static initializeNotifications() async { await FlutterLocalNotificationsPlugin().initialize( initializationSettings, onDidReceiveNotificationResponse: serviceSettings.notificatinSettings.onDidReceiveNotificationResponse, onDidReceiveBackgroundNotificationResponse: serviceSettings.notificatinSettings.onDidReceiveBackNotificationResponse, ); for (var i = 0; i < serviceSettings.notificatinSettings.channels.length; i++) { final AndroidNotificationChannel channel = serviceSettings.notificatinSettings.channels[i]; await notificationPlugin.resolvePlatformSpecificImplementation()?.createNotificationChannel(channel); } } /// static onInitialIntent() async { if (Platform.isWindows == false) { try { final receivedIntent = await ReceiveIntent.getInitialIntent(); serviceSettings.onInitialIntent(receivedIntent); } on PlatformException { // Handle exception } } } /// static uygulamaCalistir() async { if (!kIsWeb) { if (Platform.isWindows || Platform.isLinux || Platform.isMacOS) { // await Window.initialize(); // await Window.setEffect( // effect: WindowEffect.transparent, // color: const Color.fromARGB(155, 0, 0, 0), // ); doWhenWindowReady(() async { // const initialSize = Size(600, 450); // appWindow.minSize = initialSize; // appWindow.size = initialSize;appWindow // appWindow.alignment = Alignment.center; // appWindow.maximize(); // await loadWindowSizeAndPosition(); appWindow.show(); }); runApp(FikoYTApp()); } else { runApp(FikoYTApp()); } } else { runApp(FikoYTApp()); } } Future getDeviceID() async { return await MobileDeviceIdentifier().getDeviceId(); } } class FikoYTServiceSettings { final List deviceOrientation; final String fikoytServerUrl; final String fikoytWebSocketUrl; final bool connectWebScoket; final SystemUiMode systemUiMode; final List systemUiOverlay; final FikoYTNotificationSettings notificatinSettings; final FikoYTAppSettings appSettings; final Function(Intent? intent) onInitialIntent; FikoYTServiceSettings({ this.deviceOrientation = DeviceOrientation.values, this.fikoytServerUrl = "https://fikoyt.com:8000/", this.fikoytWebSocketUrl = "https://fikoyt.com:8000/", this.connectWebScoket = false, this.systemUiMode = SystemUiMode.edgeToEdge, this.systemUiOverlay = SystemUiOverlay.values, FikoYTNotificationSettings? notificationSettings, Function(Intent? intent)? onInitialIntent, appSettings, }) : appSettings = appSettings ?? FikoYTAppSettings(), notificatinSettings = notificationSettings ?? FikoYTNotificationSettings(), onInitialIntent = onInitialIntent ?? defaultOnInitialIntent; static defaultOnInitialIntent(Intent? intent) {} } class FikoYTNotificationSettings { final List channels; final Function(NotificationResponse notificationResponse) onDidReceiveNotificationResponse; final Function(NotificationResponse notificationResponse) onDidReceiveBackNotificationResponse; FikoYTNotificationSettings({this.channels = const [], onDidReceiveNotificationResponse, onDidReceiveBackNotificationResponse}) : onDidReceiveNotificationResponse = onDidReceiveNotificationResponse ?? defaultOnDidReceiveNotificationResponse, onDidReceiveBackNotificationResponse = onDidReceiveBackNotificationResponse ?? defaultOnDidReceiveNotificationResponse; @pragma('vm:entry-point') static defaultOnDidReceiveNotificationResponse(NotificationResponse notificationResponse) async {} }