system property
Returns the operating system of this UserAgent.
Implementation
String get system {
// If [UserAgent] starts with [Config.userAgentProduct], then it's probably
// the one generated by us via [WebUtils.userAgent] method.
if (val.startsWith(Config.userAgentProduct)) {
final String meta = val.substring(
max(val.indexOf('(') + 1, 0),
val.endsWith(')') ? val.length - 1 : val.length,
);
// First part should have the name of operating system.
final List<String> parts = meta.split(';');
final String system = parts.first.trim();
if (system.startsWith('Android')) {
return 'Android';
} else if (system.startsWith('macOS')) {
return 'macOS';
} else if (system.startsWith('iOS')) {
return 'iOS';
} else if (system.startsWith('iPadOS')) {
return 'iPadOS';
} else if (system.startsWith('visionOS')) {
return 'visionOS';
} else if (system.startsWith('watchOS')) {
return 'watchOS';
} else if (system.startsWith('tvOS')) {
return 'tvOS';
} else if (system.startsWith('Windows')) {
return 'Windows';
} else {
return system;
}
}
// Otherwise it may be a browser's `User-Agent` header.
else {
if (val.contains('Windows NT')) {
return 'Windows';
} else if (val.contains('iPad')) {
return 'iPadOS';
} else if (val.contains('iPhone')) {
return 'iOS';
} else if (val.contains('Macintosh')) {
return 'macOS';
} else if (val.contains('Android')) {
return 'Android';
} else if (val.contains('X11') || val.contains('Linux')) {
return 'Linux';
} else {
return 'Unknown';
}
}
}