Files
tongxunruanjian/mobile-next/openim_common/lib/src/config.dart
T
bbc4dce0b6 fix: 验收包写入公司内网地址,避免 Windows 空 VITE 与 Android 假域名
Windows 补 .env.production 与 endpoints 兜底;Android 默认 host/端口改为内网,启动后重写 HttpUtil/ApiService,Urls 改为 getter。

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: multica-agent <github@multica.ai>
2026-08-20 16:21:40 +08:00

129 lines
3.6 KiB
Dart

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:media_kit/media_kit.dart';
import 'package:openim_common/openim_common.dart';
import 'package:openim_common/src/utils/api_service.dart';
import 'package:package_info_plus/package_info_plus.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);
MediaKit.ensureInitialized();
HttpUtil.init();
ApiService().setBaseUrl(imApiUrl);
} 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,
));
final packageInfo = await PackageInfo.fromPlatform();
_appName = packageInfo.appName;
}
static late String _appName;
static late String cachePath;
static const uiW = 375.0;
static const uiH = 812.0;
static const double textScaleFactor = 1.0;
static const discoverPageURL = 'https://docs.openim.io/';
static const allowSendMsgNotFriend = '1';
// amap key
static const webKey = 'webKey';
static const webServerKey = 'webServerKey';
static const locationHost = 'http://location.your-domain';
static OfflinePushInfo get offlinePushInfo => OfflinePushInfo(
title: _appName,
desc: StrRes.offlineMessage,
iOSBadgeCount: true,
);
static const friendScheme = "io.openim.app/addFriend/";
static const groupScheme = "io.openim.app/joinGroup/";
static const _host = "192.168.200.11";
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 chatTokenUrl {
String? url;
var server = DataSp.getServerConfig();
if (null != server) {
url = server['chatTokenUrl'];
}
return url ?? (_isIP ? "http://$_host:10010" : "https://$_host/chat");
}
static String get appAuthUrl {
String? url;
var server = DataSp.getServerConfig();
if (null != server) {
url = server['authUrl'];
}
return url ?? (_isIP ? "http://$_host:10010" : "https://$_host/chat");
}
static String get imApiUrl {
String? url;
var server = DataSp.getServerConfig();
if (null != server) {
url = server['apiUrl'];
}
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'];
}
return url ?? (_isIP ? "ws://$_host:10001" : "wss://$_host/msg_gateway");
}
static int get logLevel {
String? level;
var server = DataSp.getServerConfig();
if (null != server) {
level = server['logLevel'];
}
return level == null ? 5 : int.parse(level);
}
}