forked from jasonkneen/UTiL
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreporter.js
74 lines (56 loc) · 2.53 KB
/
reporter.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
exports.recipients = null;
exports.alert_title = L('reporter_alert_title', 'Error');
exports.alert_message = L('reporter_alert_message', 'Please let me prepare a report for you to send to the developers.');
exports.alert_no = L('reporter_alert_no', 'No');
exports.alert_yes = L('reporter_alert_yes', 'Yes');
exports.email_describe = L('reporter_email_describe', 'Please describe what steps led to the error so the developers can reproduce the error:');
require("yy.logcatcher").addEventListener('error', function(error) {
try {
Ti.Media.takeScreenshot(function(screenshot) {
sendReport(error, screenshot);
});
} catch (e) {
sendReport(error);
}
});
function sendReport(error, screenshot) {
var alertDialog = Ti.UI.createAlertDialog({
title: exports.alert_title,
message: exports.alert_message,
buttonNames: [exports.alert_no, exports.alert_yes],
cancel: 0
});
alertDialog.addEventListener('click', function(e) {
if (e.index === e.source.cancel) {
return;
}
var messageBody = '<b>' + exports.email_describe + '</b><br><br><br><br><br>';
messageBody += '<hr>';
messageBody += '<ul>';
for (var key in error) {
messageBody += '<li><b>' + key + '</b><br>' + error[key] + '</li>';
}
messageBody += '</ul>';
messageBody += '<hr>';
messageBody += '<ul>';
['deployType', 'guid', 'id', 'installId', 'keyboardVisible', 'sessionId', 'version'].forEach(function(key) {
messageBody += '<li><b>' + key + '</b><br>' + Ti.App[key] + '</li>';
});
['architecture', 'availableMemory', 'batteryLevel', 'batteryState', 'id', 'locale', 'macaddress', 'ip', 'manufacturer', 'model', 'name', 'netmask', 'osname', 'ostype', 'processorCount', 'runtime', 'username', 'version'].forEach(function(key) {
messageBody += '<li><b>' + key + '</b><br>' + Ti.Platform[key] + '</li>';
});
['density', 'dpi', 'logicalDensityFactor', 'platformHeight', 'platformWidth', 'xdpi', 'ydpi'].forEach(function(key) {
messageBody += '<li><b>' + key + '</b><br>' + Ti.Platform.displayCaps[key] + '</li>';
});
messageBody += '</ul>';
var emailDialog = Ti.UI.createEmailDialog({
subject: '[' + Ti.App.name + ' ' + Ti.App.version + '] ' + error.message,
toRecipients: exports.recipients ? ((typeof exports.recipients === 'string') ? [exports.recipients] : exports.recipients) : undefined,
messageBody: messageBody,
html: true
});
screenshot && emailDialog.addAttachment(screenshot.media);
emailDialog.open();
});
alertDialog.show();
}