Update: 2026-06-12 01:23:54

This commit is contained in:
Hamza-Ayed
2026-06-12 01:23:54 +03:00
parent 7049c7468c
commit ef6b52d2e3
47 changed files with 1480 additions and 1472 deletions

View File

@@ -1,50 +1,50 @@
import 'dart:convert';
import 'package:googleapis_auth/auth_io.dart';
// import 'dart:convert';
// import 'package:googleapis_auth/auth_io.dart';
class AccessTokenManager {
static final AccessTokenManager _instance = AccessTokenManager._internal();
late final String serviceAccountJsonKey;
AccessToken? _accessToken;
DateTime? _expiryDate;
// class AccessTokenManager {
// static final AccessTokenManager _instance = AccessTokenManager._internal();
// late final String serviceAccountJsonKey;
// AccessToken? _accessToken;
// DateTime? _expiryDate;
AccessTokenManager._internal();
// AccessTokenManager._internal();
factory AccessTokenManager(String jsonKey) {
if (_instance._isServiceAccountKeyInitialized()) {
// Prevent re-initialization
return _instance;
}
_instance.serviceAccountJsonKey = jsonKey;
return _instance;
}
// factory AccessTokenManager(String jsonKey) {
// if (_instance._isServiceAccountKeyInitialized()) {
// // Prevent re-initialization
// return _instance;
// }
// _instance.serviceAccountJsonKey = jsonKey;
// return _instance;
// }
bool _isServiceAccountKeyInitialized() {
try {
serviceAccountJsonKey; // Access to check if initialized
return true;
} catch (e) {
return false;
}
}
// bool _isServiceAccountKeyInitialized() {
// try {
// serviceAccountJsonKey; // Access to check if initialized
// return true;
// } catch (e) {
// return false;
// }
// }
Future<String> getAccessToken() async {
if (_accessToken != null && DateTime.now().isBefore(_expiryDate!)) {
return _accessToken!.data;
}
try {
final serviceAccountCredentials = ServiceAccountCredentials.fromJson(
json.decode(serviceAccountJsonKey));
final client = await clientViaServiceAccount(
serviceAccountCredentials,
['https://www.googleapis.com/auth/firebase.messaging'],
);
// Future<String> getAccessToken() async {
// if (_accessToken != null && DateTime.now().isBefore(_expiryDate!)) {
// return _accessToken!.data;
// }
// try {
// final serviceAccountCredentials = ServiceAccountCredentials.fromJson(
// json.decode(serviceAccountJsonKey));
// final client = await clientViaServiceAccount(
// serviceAccountCredentials,
// ['https://www.googleapis.com/auth/firebase.messaging'],
// );
_accessToken = client.credentials.accessToken;
_expiryDate = client.credentials.accessToken.expiry;
client.close();
return _accessToken!.data;
} catch (e) {
throw Exception('Failed to obtain access token');
}
}
}
// _accessToken = client.credentials.accessToken;
// _expiryDate = client.credentials.accessToken.expiry;
// client.close();
// return _accessToken!.data;
// } catch (e) {
// throw Exception('Failed to obtain access token');
// }
// }
// }

View File

@@ -15,7 +15,6 @@ import '../../print.dart';
import '../../views/Rate/rate_captain.dart';
import '../../views/home/map_page_passenger.dart';
import '../../views/home/profile/promos_passenger_page.dart';
import '../auth/google_sign.dart';
import 'package:siro_rider/controller/voice_call_controller.dart';
import '../home/map/ride_lifecycle_controller.dart';
import '../home/map/ride_state.dart';
@@ -159,7 +158,7 @@ class FirebaseMessagesController extends GetxController {
if (Platform.isAndroid) {
notificationController.showNotification(title, body, 'cancel');
}
GoogleSignInHelper.signOut();
box.remove(BoxName.jwt);
} else if (category == 'Driver Is Going To Passenger') {
// <-- كان 'Driver Is Going To Passenger'
Get.find<RideLifecycleController>().isDriverInPassengerWay = true;
@@ -253,9 +252,7 @@ class FirebaseMessagesController extends GetxController {
rideIdVal: rideId.toString(),
);
}
}
else if (category == 'Order Applied') {
} else if (category == 'Order Applied') {
if (Platform.isAndroid) {
notificationController.showNotification(
'The order Accepted by another Driver'.tr,
@@ -317,7 +314,7 @@ class FirebaseMessagesController extends GetxController {
// notificationController.showNotification(
// 'token change'.tr, 'token change'.tr, 'cancel');
// }
// GoogleSignInHelper.signOut();
// // GoogleSignInHelper.signOut();
// } else if (message.notification!.title! == 'Driver Is Going To Passenger') {
// Get.find<RideLifecycleController>().isDriverInPassengerWay = true;
// Get.find<RideLifecycleController>().update();

View File

@@ -1,12 +1,12 @@
import 'dart:convert';
import 'package:http/http.dart' as http;
import 'package:get/get.dart';
import '../../constant/links.dart';
import '../../print.dart'; // للترجمة .tr
class NotificationService {
static const String _serverUrl =
'https://api.intaleq.xyz/siro/ride/firebase/send_fcm.php';
static String get _serverUrl => '${AppLink.server}/ride/firebase/send_fcm.php';
static Future<void> sendNotification({
required String target,