mirror of
https://github.com/adelphes/android-dev-ext.git
synced 2025-12-22 17:39:19 +00:00
v1.2.1 (#94)
* update java-mti to support new type cache format * add IP and platform info to events * add warning about closing Android Studio if an ADB or JDWP error occurs * version 1.2.1 notes * add debug_mode to disconnect event
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
const os = require('os');
|
||||
let mp;
|
||||
/** @type {string} */
|
||||
let uid;
|
||||
@@ -6,6 +7,11 @@ let sid;
|
||||
/** @type {Map<string,[number,number]>} */
|
||||
const timeLabels = new Map();
|
||||
let session_start = Date.now();
|
||||
/** @type {string|Promise<string>} */
|
||||
let ip = getCurrentIP()
|
||||
.catch(() => null)
|
||||
.then(res => ip = res);
|
||||
let queued_events = null;
|
||||
|
||||
/**
|
||||
* @param {string} [t]
|
||||
@@ -30,7 +36,6 @@ function init(t = '0cca95950055c6553804a46ce7e3df18', u, s, package_json, props)
|
||||
if (!props) {
|
||||
return;
|
||||
}
|
||||
const os = require('os');
|
||||
const now = new Date();
|
||||
event(`${package_json.name}-start`, {
|
||||
extension: package_json.name,
|
||||
@@ -47,6 +52,17 @@ function init(t = '0cca95950055c6553804a46ce7e3df18', u, s, package_json, props)
|
||||
});
|
||||
}
|
||||
|
||||
function getCurrentIP() {
|
||||
return new Promise((resolve, reject) => {
|
||||
require('https').get(
|
||||
Buffer.from('aHR0cHM6Ly91YTF4c3JhM2ZhLmV4ZWN1dGUtYXBpLmV1LXdlc3QtMi5hbWF6b25hd3MuY29tL3JlbA==','base64').toString(),
|
||||
{ headers: { 'Content-Type': 'application/json' } },
|
||||
res => resolve(res.headers['x-request-ip'])
|
||||
)
|
||||
.on('error', err => reject(err));
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {string} eventName
|
||||
@@ -56,16 +72,36 @@ function event(eventName, properties) {
|
||||
if (!mp) {
|
||||
return;
|
||||
}
|
||||
if (queued_events) {
|
||||
queued_events.push({eventName, properties});
|
||||
return;
|
||||
}
|
||||
if (ip instanceof Promise) {
|
||||
queued_events = [{eventName, properties}]
|
||||
ip.catch(() => {}).then(() => {
|
||||
const e = queued_events;
|
||||
queued_events = null;
|
||||
e.forEach(({eventName, properties}) => event(eventName, properties));
|
||||
});
|
||||
return;
|
||||
}
|
||||
try {
|
||||
if (uid) {
|
||||
mp.track(eventName, {
|
||||
ip,
|
||||
distinct_id: uid,
|
||||
session_id: sid,
|
||||
session_length: Math.trunc((Date.now() - session_start) / 60e3),
|
||||
...properties,
|
||||
});
|
||||
} else {
|
||||
mp.track(eventName, properties);
|
||||
mp.track(eventName, {
|
||||
ip,
|
||||
platform: process.platform,
|
||||
release: os.release(),
|
||||
node_version: process.version,
|
||||
...properties,
|
||||
});
|
||||
}
|
||||
} catch {}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user