Skip to content

Commit 774e77a

Browse files
committed
add fance formating for most browsers
1 parent fac970b commit 774e77a

File tree

1 file changed

+45
-5
lines changed

1 file changed

+45
-5
lines changed

settings/js/authtoken_view.js

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,18 +103,58 @@
103103
viewData.title = viewData.name;
104104

105105
// pretty format sync client user agent
106-
var matches = viewData.name.match(/Mozilla\/5\.0 \((\w+)\) mirall\/(\d+\.\d+\.\d+)/);
106+
var matches = viewData.name.match(/Mozilla\/5\.0 \((\w+)\) (?:mirall|csyncoC)\/(\d+\.\d+\.\d+)/);
107+
108+
var userAgentMap = {
109+
ie: /(?:MSIE|Trident) (\d+)/,
110+
// Microsoft Edge User Agent from https://msdn.microsoft.com/en-us/library/hh869301(v=vs.85).aspx
111+
edge: /^Mozilla\/5\.0 \([^)]+\) AppleWebKit\/[0-9.]+ \(KHTML, like Gecko\) Chrome\/[0-9.]+ (?:Mobile Safari|Safari)\/[0-9.]+ Edge\/[0-9.]+$/,
112+
// Firefox User Agent from https://developer.mozilla.org/en-US/docs/Web/HTTP/Gecko_user_agent_string_reference
113+
firefox: /^Mozilla\/5\.0 \([^)]*(Windows|OS X|Linux)[^)]+\) Gecko\/[0-9.]+ Firefox\/(\d+)(?:\.\d)?$/,
114+
// Chrome User Agent from https://developer.chrome.com/multidevice/user-agent
115+
chrome: /^Mozilla\/5\.0 \([^)]*(Windows|OS X|Linux)[^)]+\) AppleWebKit\/[0-9.]+ \(KHTML, like Gecko\) Chrome\/(\d+)[0-9.]+ (?:Mobile Safari|Safari)\/[0-9.]+$/,
116+
// Safari User Agent from http://www.useragentstring.com/pages/Safari/
117+
safari: /^Mozilla\/5\.0 \([^)]+\) AppleWebKit\/[0-9.]+ \(KHTML, like Gecko\) Version\/([0-9]+)[0-9.]+ Safari\/[0-9.A-Z]+$/,
118+
// Android Chrome user agent: https://developers.google.com/chrome/mobile/docs/user-agent
119+
androidChrome: /Android.*(?:; (.*) Build\/).*Chrome\/(\d+)[0-9.]+/,
120+
iphone: / *CPU +iPhone +OS +(\d+)_\d+ +like +Mac +OS +X */,
121+
iosClient: /^Mozilla\/5\.0 \(iOS\) ownCloud\-iOS.*$/,
122+
androidClient:/^Mozilla\/5\.0 \(Android\) ownCloud\-android.*$/,
123+
// DAVdroid/1.2 (2016/07/03; dav4android; okhttp3) Android/6.0.1
124+
davDroid: /DAVdroid\/([0-9.]+)/
125+
};
126+
var nameMap = {
127+
ie: t('setting', 'Internet Explorer'),
128+
edge: t('setting', 'Edge'),
129+
firefox: t('setting', 'Firefox'),
130+
chrome: t('setting', 'Google Chrome'),
131+
safari: t('setting', 'Safari'),
132+
androidChrome: t('setting', 'Chrome'),
133+
iphone: t('setting', 'iPhone'),
134+
iosClient: t('setting', 'iOS Client'),
135+
androidClient: t('setting', 'Android Client'),
136+
davDroid: 'DAVdroid'
137+
};
107138

108139
if (matches) {
109-
viewData.name = t('settings', 'Sync client ({os}) - Version {version}', {
140+
viewData.name = t('settings', 'Sync client - {os}', {
110141
os: matches[1],
111142
version: matches[2]
112143
})
113144
}
145+
for (var client in userAgentMap) {
146+
if (matches = viewData.title.match(userAgentMap[client])) {
147+
if (matches[2] && matches[1]) { // version number and os
148+
viewData.name = nameMap[client] + ' ' + matches[2] + ' - ' + matches[1];
149+
}else if (matches[1]) { // only version number
150+
viewData.name = nameMap[client] + ' ' + matches[1];
151+
} else {
152+
viewData.name = nameMap[client];
153+
}
154+
}
155+
}
114156
if (viewData.current) {
115-
viewData.name = t('settings', 'Current session', {
116-
userAgent: viewData.name
117-
})
157+
viewData.name = t('settings', 'This session')
118158
}
119159
return viewData;
120160
}

0 commit comments

Comments
 (0)