-
Notifications
You must be signed in to change notification settings - Fork 228
/
Copy pathconfig.dart
103 lines (84 loc) · 2.74 KB
/
config.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_openim_sdk/flutter_openim_sdk.dart';
import 'package:hive_flutter/hive_flutter.dart';
import 'package:openim_common/openim_common.dart';
import 'package:path_provider/path_provider.dart';
class Config {
static Future init(Function() runApp) async {
WidgetsFlutterBinding.ensureInitialized();
try {
final path = (await getApplicationDocumentsDirectory()).path;
cachePath = '$path/';
await DataSp.init();
await Hive.initFlutter(path);
HttpUtil.init();
} catch (_) {}
runApp();
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown,
]);
var brightness = Platform.isAndroid ? Brightness.dark : Brightness.light;
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
statusBarColor: Colors.transparent,
statusBarBrightness: brightness,
statusBarIconBrightness: brightness,
));
}
static late String cachePath;
static const uiW = 375.0;
static const uiH = 812.0;
static const String deptName = "OpenIM";
static const String deptID = '0';
static const double textScaleFactor = 1.0;
static const secret = 'tuoyun';
static const mapKey = '';
static OfflinePushInfo offlinePushInfo = OfflinePushInfo(
title: StrRes.offlineMessage,
desc: "",
iOSBadgeCount: true,
iOSPushSound: '+1',
);
static const friendScheme = "io.openim.app/addFriend/";
static const groupScheme = "io.openim.app/joinGroup/";
static const _host = "127.0.0.1";
static const _ipRegex = '((2[0-4]\\d|25[0-5]|[01]?\\d\\d?)\\.){3}(2[0-4]\\d|25[0-5]|[01]?\\d\\d?)';
static bool get _isIP => RegExp(_ipRegex).hasMatch(_host);
static String get serverIp {
String? ip;
var server = DataSp.getServerConfig();
if (null != server) {
ip = server['serverIP'];
}
return ip ?? _host;
}
static String get appAuthUrl {
String? url;
var server = DataSp.getServerConfig();
if (null != server) {
url = server['authUrl'];
Logger.print('authUrl: $url');
}
return url ?? (_isIP ? "http://$_host:10008" : "https://$_host/chat");
}
static String get imApiUrl {
String? url;
var server = DataSp.getServerConfig();
if (null != server) {
url = server['apiUrl'];
Logger.print('apiUrl: $url');
}
return url ?? (_isIP ? 'http://$_host:10002' : "https://$_host/api");
}
static String get imWsUrl {
String? url;
var server = DataSp.getServerConfig();
if (null != server) {
url = server['wsUrl'];
Logger.print('wsUrl: $url');
}
return url ?? (_isIP ? "ws://$_host:10001" : "wss://$_host/msg_gateway");
}
}