forked from ipfs/ipfs-desktop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
40 lines (35 loc) · 1.29 KB
/
index.js
File metadata and controls
40 lines (35 loc) · 1.29 KB
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
const { existsSync, mkdirSync } = require('fs')
const { join } = require('path')
const Countly = require('countly-sdk-nodejs')
const { ipcMain } = require('electron')
const { app } = require('electron')
const { COUNTLY_KEY } = require('../common/consts')
const ipcMainEvents = require('../common/ipc-main-events')
const logger = require('../common/logger')
const getCtx = require('../context')
module.exports = async function () {
logger.info('[analytics] init...')
// workaround: recursive mkdir https://github.com/Countly/countly-sdk-nodejs/pull/14
const countlyDataDir = join(app.getPath('userData'), 'countly-data')
if (!existsSync(countlyDataDir)) {
mkdirSync(countlyDataDir, { recursive: true })
}
// @ts-expect-error
Countly.init({
url: 'https://countly.ipfs.io',
app_key: COUNTLY_KEY,
debug: process.env.DEBUG_COUNTLY === 'true',
require_consent: true,
// countlyDataDir for read-only node_modules
storage_path: countlyDataDir
})
// @ts-expect-error
getCtx().setProp('countlyDeviceId', Countly.device_id)
ipcMain.on(ipcMainEvents.COUNTLY_ADD_CONSENT, (_, consent) => {
Countly.add_consent(consent)
})
ipcMain.on(ipcMainEvents.COUNTLY_REMOVE_CONSENT, (_, consent) => {
Countly.remove_consent(consent)
})
logger.info('[analytics] init done')
}