global.dart 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. import 'dart:io';
  2. import 'package:flutter/material.dart';
  3. import 'package:flutter/services.dart';
  4. import 'package:flutter_inappwebview/flutter_inappwebview.dart';
  5. import 'package:get/get.dart';
  6. import 'package:local_notifier/local_notifier.dart';
  7. import 'package:logger/logger.dart';
  8. import 'package:o2oa_all_platform/environment_config.dart';
  9. import 'common/api/index.dart';
  10. import 'common/services/index.dart';
  11. import 'common/utils/index.dart';
  12. import 'pages/apps/yunpan/cloud_disk_helpler.dart';
  13. /// 全局的服务
  14. class Global {
  15. /// 初始化一些全局服务
  16. static Future init() async {
  17. // 日志
  18. Logger.level = EnvironmentConfig.isRelease() ? Level.info : Level.verbose;
  19. // 默认系统竖屏
  20. WidgetsFlutterBinding.ensureInitialized();
  21. List<DeviceOrientation> orientations = [DeviceOrientation.portraitUp];
  22. bool isPad = await O2FlutterMethodChannelUtils().isTabletDevice();
  23. if (isPad) { // 如果是 pad 则支持横屏、竖屏
  24. orientations = [DeviceOrientation.landscapeLeft, DeviceOrientation.landscapeRight, DeviceOrientation.portraitUp];
  25. }
  26. await SystemChrome.setPreferredOrientations(orientations);
  27. _setAndroidStatusBarTransparent();
  28. // 存储对象
  29. await Get.putAsync<SharedPreferenceService>(() => SharedPreferenceService().init());
  30. await SharedPreferenceService.to.putBool(SharedPreferenceService.isPadKey, isPad);
  31. // 服务类
  32. Get.put(O2OAWwwService());
  33. Get.put(ProgramCenterService());
  34. Get.put(CollectService());
  35. Get.put(OrgAuthenticationService());
  36. Get.put(OrganizationControlService());
  37. Get.put(OrganizationAssembleExpressService());
  38. Get.put(OrganizationPersonalService());
  39. Get.put(OrganizationPermissionService());
  40. Get.put(ProcessSurfaceService());
  41. Get.put(JpushAssembleControlService());
  42. Get.put(HotpicAssembleControlService());
  43. Get.put(CmsAssembleControlService());
  44. Get.put(MessageCommunicationService());
  45. Get.put(PortalSurfaceService());
  46. Get.put(FileAssembleService());
  47. Get.put(MindMapService());
  48. Get.put(MeetingAssembleService());
  49. Get.put(BBSAssembleControlService());
  50. Get.put(AttendanceAssembleControlService());
  51. Get.put(QueryAssembleSurfaceService());
  52. Get.put(CalendarAssembleControlService());
  53. Get.put(AppPackingClientAssembleControlService());
  54. // 网盘初始化
  55. CloudDiskHelper().initProgressQueue();
  56. // webview debug使用 Android上可以使用chrome://inspect 调试
  57. final isDebugger = SharedPreferenceService.to.getBool(SharedPreferenceService.webviewDebuggerKey);
  58. if (Platform.isAndroid && isDebugger) {
  59. await AndroidInAppWebViewController.setWebContentsDebuggingEnabled(true);
  60. }
  61. // 存储当前设备类型
  62. if (Platform.isAndroid) {
  63. SharedPreferenceService.to.putString(SharedPreferenceService.currentDeviceTypeKey, 'android');
  64. } else if (Platform.isIOS) {
  65. SharedPreferenceService.to.putString(SharedPreferenceService.currentDeviceTypeKey, 'ios');
  66. } else if (Platform.isMacOS) {
  67. SharedPreferenceService.to.putString(SharedPreferenceService.currentDeviceTypeKey, 'macos');
  68. } else if (Platform.isWindows) {
  69. SharedPreferenceService.to.putString(SharedPreferenceService.currentDeviceTypeKey, 'windows');
  70. } else if (Platform.isLinux) {
  71. SharedPreferenceService.to.putString(SharedPreferenceService.currentDeviceTypeKey, 'linux');
  72. }
  73. // pc 通知插件
  74. await localNotifier.setup(
  75. appName: 'appName'.tr,
  76. shortcutPolicy: ShortcutPolicy.requireCreate,
  77. );
  78. // 主题切换监听
  79. AppLifeCycleDelegate();
  80. // tts 初始化
  81. FlutterTTSHelper.instance.init();
  82. // loading组件
  83. Loading();
  84. }
  85. /// 设置 Android 状态栏背景透明
  86. static void _setAndroidStatusBarTransparent() {
  87. if (Platform.isAndroid) {
  88. SystemUiOverlayStyle systemUiOverlayStyle = const SystemUiOverlayStyle(
  89. statusBarColor: Colors.transparent);
  90. SystemChrome.setSystemUIOverlayStyle(systemUiOverlayStyle);
  91. }
  92. }
  93. /// 需要同意协议后才能继续执行的内容
  94. static Future<void> initLater() async {
  95. OLogger.d('initLater。。。。。。。。。。。。。。。。。');
  96. if (GetPlatform.isMobile) {
  97. // 启动极光推送插件
  98. O2ApiManager.instance.jpushInit();
  99. }
  100. }
  101. }
  102. class AppLifeCycleDelegate with WidgetsBindingObserver {
  103. static final AppLifeCycleDelegate _appLifeCycleDelegate =
  104. AppLifeCycleDelegate._inital();
  105. AppLifeCycleDelegate._inital() {
  106. WidgetsBinding.instance.addObserver(this);
  107. }
  108. factory AppLifeCycleDelegate() {
  109. return _appLifeCycleDelegate;
  110. }
  111. @override
  112. void didChangePlatformBrightness() {
  113. super.didChangePlatformBrightness();
  114. //强制触发 build
  115. Get.forceAppUpdate();
  116. }
  117. }