|
|
@ -18,6 +18,9 @@ import { |
|
|
|
TRAITS, |
|
|
|
TRAITS, |
|
|
|
} from '../../../shared/constants/metametrics'; |
|
|
|
} from '../../../shared/constants/metametrics'; |
|
|
|
import { SECOND } from '../../../shared/constants/time'; |
|
|
|
import { SECOND } from '../../../shared/constants/time'; |
|
|
|
|
|
|
|
import { isManifestV3 } from '../../../shared/modules/mv3.utils'; |
|
|
|
|
|
|
|
import { METAMETRICS_FINALIZE_EVENT_FRAGMENT_ALARM } from '../../../shared/constants/alarms'; |
|
|
|
|
|
|
|
import { checkAlarmExists } from '../lib/util'; |
|
|
|
|
|
|
|
|
|
|
|
const EXTENSION_UNINSTALL_URL = 'https://metamask.io/uninstalled'; |
|
|
|
const EXTENSION_UNINSTALL_URL = 'https://metamask.io/uninstalled'; |
|
|
|
|
|
|
|
|
|
|
@ -144,16 +147,49 @@ export default class MetaMetricsController { |
|
|
|
// within the fragment's timeout window. When creating a new event fragment
|
|
|
|
// within the fragment's timeout window. When creating a new event fragment
|
|
|
|
// a timeout can be specified that will cause an abandoned event to be
|
|
|
|
// a timeout can be specified that will cause an abandoned event to be
|
|
|
|
// tracked if the event isn't progressed within that amount of time.
|
|
|
|
// tracked if the event isn't progressed within that amount of time.
|
|
|
|
setInterval(() => { |
|
|
|
if (isManifestV3) { |
|
|
|
Object.values(this.store.getState().fragments).forEach((fragment) => { |
|
|
|
/* eslint-disable no-undef */ |
|
|
|
if ( |
|
|
|
chrome.alarms.getAll((alarms) => { |
|
|
|
fragment.timeout && |
|
|
|
const hasAlarm = checkAlarmExists( |
|
|
|
Date.now() - fragment.lastUpdated / 1000 > fragment.timeout |
|
|
|
alarms, |
|
|
|
) { |
|
|
|
METAMETRICS_FINALIZE_EVENT_FRAGMENT_ALARM, |
|
|
|
this.finalizeEventFragment(fragment.id, { abandoned: true }); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!hasAlarm) { |
|
|
|
|
|
|
|
chrome.alarms.create(METAMETRICS_FINALIZE_EVENT_FRAGMENT_ALARM, { |
|
|
|
|
|
|
|
delayInMinutes: 1, |
|
|
|
|
|
|
|
periodInMinutes: 1, |
|
|
|
|
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
}, SECOND * 30); |
|
|
|
chrome.alarms.onAlarm.addListener(() => { |
|
|
|
|
|
|
|
chrome.alarms.getAll((alarms) => { |
|
|
|
|
|
|
|
const hasAlarm = checkAlarmExists( |
|
|
|
|
|
|
|
alarms, |
|
|
|
|
|
|
|
METAMETRICS_FINALIZE_EVENT_FRAGMENT_ALARM, |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (hasAlarm) { |
|
|
|
|
|
|
|
this.finalizeAbandonedFragments(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
setInterval(() => { |
|
|
|
|
|
|
|
this.finalizeAbandonedFragments(); |
|
|
|
|
|
|
|
}, SECOND * 30); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
finalizeAbandonedFragments() { |
|
|
|
|
|
|
|
Object.values(this.store.getState().fragments).forEach((fragment) => { |
|
|
|
|
|
|
|
if ( |
|
|
|
|
|
|
|
fragment.timeout && |
|
|
|
|
|
|
|
Date.now() - fragment.lastUpdated / 1000 > fragment.timeout |
|
|
|
|
|
|
|
) { |
|
|
|
|
|
|
|
this.finalizeEventFragment(fragment.id, { abandoned: true }); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
generateMetaMetricsId() { |
|
|
|
generateMetaMetricsId() { |
|
|
|