81 lines
2.3 KiB
Dart
81 lines
2.3 KiB
Dart
enum Environment {
|
|
production,
|
|
}
|
|
|
|
class AppConfig {
|
|
static const Environment currentEnvironment = Environment.production;
|
|
static const String appName = '本地打包';
|
|
static const String appLogo = '';
|
|
|
|
static final Map<Environment, List<String>> _environmentHosts = {
|
|
Environment.production: [
|
|
'h5-im.imharry.work',
|
|
],
|
|
};
|
|
|
|
static List<String> get environmentHosts {
|
|
return _environmentHosts[currentEnvironment] ?? const [];
|
|
}
|
|
|
|
static String homeUrl({String? appName, String? appLogo}) {
|
|
final host = environmentHosts.isNotEmpty
|
|
? environmentHosts.first
|
|
: 'h5-im.imharry.work';
|
|
return _withShellBranding(
|
|
_normalizeHomeUrl(host),
|
|
appName: appName,
|
|
appLogo: appLogo,
|
|
);
|
|
}
|
|
|
|
static String withFreshShellCacheBust(String url) {
|
|
final uri = Uri.parse(url);
|
|
final queryParameters = Map<String, String>.from(uri.queryParameters)
|
|
..['shell_cache_bust'] = DateTime.now().millisecondsSinceEpoch.toString();
|
|
|
|
return uri.replace(queryParameters: queryParameters).toString();
|
|
}
|
|
|
|
static String _normalizeHomeUrl(String host) {
|
|
final value = host.trim();
|
|
final normalized =
|
|
value.startsWith('http://') || value.startsWith('https://')
|
|
? value
|
|
: 'https://$value';
|
|
final uri = Uri.parse(normalized);
|
|
final path = uri.path.isEmpty ? '/' : uri.path;
|
|
return uri.replace(path: path).toString();
|
|
}
|
|
|
|
static String _withShellBranding(
|
|
String url, {
|
|
String? appName,
|
|
String? appLogo,
|
|
}) {
|
|
final uri = Uri.parse(url);
|
|
final queryParameters = Map<String, String>.from(uri.queryParameters)
|
|
..['flutter_shell'] = '1'
|
|
..['shell_cache_bust'] = DateTime.now().millisecondsSinceEpoch.toString();
|
|
final fragmentParameters = Uri.splitQueryString(uri.fragment);
|
|
|
|
final trimmedName = (appName ?? AppConfig.appName).trim();
|
|
if (trimmedName.isNotEmpty) {
|
|
queryParameters['shell_app_name'] = trimmedName;
|
|
}
|
|
|
|
final trimmedLogo = (appLogo ?? AppConfig.appLogo).trim();
|
|
if (trimmedLogo.isNotEmpty) {
|
|
fragmentParameters['shell_app_logo'] = trimmedLogo;
|
|
}
|
|
|
|
return uri
|
|
.replace(
|
|
queryParameters: queryParameters,
|
|
fragment: fragmentParameters.isEmpty
|
|
? null
|
|
: Uri(queryParameters: fragmentParameters).query,
|
|
)
|
|
.toString();
|
|
}
|
|
}
|