|
| 1 | +import 'dart:io'; |
| 2 | + |
| 3 | +import 'package:dio/dio.dart'; |
| 4 | +import 'package:loftify/Utils/app_provider.dart'; |
| 5 | +import 'package:loftify/Utils/cloud_control_provider.dart'; |
| 6 | +import 'package:loftify/Utils/constant.dart'; |
| 7 | +import 'package:loftify/Utils/hive_util.dart'; |
| 8 | +import 'package:loftify/Widgets/Dialog/dialog_builder.dart'; |
| 9 | + |
| 10 | +import '../Models/cloud_control.dart'; |
| 11 | +import '../Utils/ilogger.dart'; |
| 12 | +import '../Utils/utils.dart'; |
| 13 | + |
| 14 | +class ServerApi { |
| 15 | + static Future<LoftifyControl?> getCloudControl() async { |
| 16 | + try { |
| 17 | + final response = await Dio().get(cloudControlUrl); |
| 18 | + if (response.statusCode == 200) { |
| 19 | + final data = response.data; |
| 20 | + var cloudControl = LoftifyControl.fromJson(data); |
| 21 | + ILogger.info( |
| 22 | + "Loaded cloudControl from $cloudControlUrl: ${cloudControl.toJson()}"); |
| 23 | + controlProvider.originalCloudControl = cloudControl; |
| 24 | + controlProvider.globalControl = cloudControl; |
| 25 | + if (cloudControl.enableAppNotNull) { |
| 26 | + if (HiveUtil.getBool(HiveUtil.overrideCloudControlKey, |
| 27 | + defaultValue: false)) { |
| 28 | + controlProvider.globalControl = |
| 29 | + LoftifyControl.getOverridedCloudControl(cloudControl); |
| 30 | + } |
| 31 | + } else { |
| 32 | + Utils.initSimpleTray(); |
| 33 | + DialogBuilder.showInfoDialog( |
| 34 | + rootContext, |
| 35 | + title: cloudControl.disableReasonTitle, |
| 36 | + message: cloudControl.disableReasonMessage, |
| 37 | + barrierDismissible: false, |
| 38 | + onTapDismiss: () { |
| 39 | + exit(0); |
| 40 | + }, |
| 41 | + ); |
| 42 | + } |
| 43 | + } |
| 44 | + } catch (e, t) { |
| 45 | + ILogger.error("Failed to load cloudControl from $cloudControlUrl", e, t); |
| 46 | + } |
| 47 | + return null; |
| 48 | + } |
| 49 | +} |
0 commit comments