feat: 添加应用品牌信息支持,重构主页 URL 生成逻辑
This commit is contained in:
@@ -4,6 +4,8 @@ enum Environment {
|
||||
|
||||
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: [
|
||||
@@ -15,11 +17,15 @@ class AppConfig {
|
||||
return _environmentHosts[currentEnvironment] ?? const [];
|
||||
}
|
||||
|
||||
static String get homeUrl {
|
||||
static String homeUrl({String? appName, String? appLogo}) {
|
||||
final host = environmentHosts.isNotEmpty
|
||||
? environmentHosts.first
|
||||
: 'h5-im.imharry.work';
|
||||
return _normalizeHomeUrl(host);
|
||||
return _withShellBranding(
|
||||
_normalizeHomeUrl(host),
|
||||
appName: appName,
|
||||
appLogo: appLogo,
|
||||
);
|
||||
}
|
||||
|
||||
static String _normalizeHomeUrl(String host) {
|
||||
@@ -29,4 +35,26 @@ class AppConfig {
|
||||
}
|
||||
return 'https://$value/';
|
||||
}
|
||||
|
||||
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';
|
||||
|
||||
final trimmedName = (appName ?? AppConfig.appName).trim();
|
||||
if (trimmedName.isNotEmpty) {
|
||||
queryParameters['shell_app_name'] = trimmedName;
|
||||
}
|
||||
|
||||
final trimmedLogo = (appLogo ?? AppConfig.appLogo).trim();
|
||||
if (trimmedLogo.isNotEmpty) {
|
||||
queryParameters['shell_app_logo'] = trimmedLogo;
|
||||
}
|
||||
|
||||
return uri.replace(queryParameters: queryParameters).toString();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user