Skip to content

Commit

Permalink
fix: use constants for withAnalytics keys (#2224)
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Henrique Dias <hacdias@gmail.com>

Signed-off-by: Henrique Dias <hacdias@gmail.com>
  • Loading branch information
hacdias authored Aug 15, 2022
1 parent 8ed2733 commit 5430992
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 9 deletions.
3 changes: 2 additions & 1 deletion src/add-to-ipfs.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const last = require('it-last')
const fs = require('fs-extra')
const logger = require('./common/logger')
const { notify, notifyError } = require('./common/notify')
const { analyticsKeys } = require('./analytics/keys')

async function copyFileToMfs (ipfs, cid, filename) {
let i = 0
Expand Down Expand Up @@ -110,7 +111,7 @@ module.exports = async function ({ getIpfsd, launchWebUI }, files) {
const successes = []
const failures = []

const log = logger.start('[add to ipfs] started', { withAnalytics: 'ADD_VIA_DESKTOP' })
const log = logger.start('[add to ipfs] started', { withAnalytics: analyticsKeys.ADD_VIA_DESKTOP })

await Promise.all(files.map(async file => {
try {
Expand Down
5 changes: 3 additions & 2 deletions src/daemon/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const logger = require('../common/logger')
const { STATUS } = require('./consts')
const createDaemon = require('./daemon')
const ipcMainEvents = require('../common/ipc-main-events')
const { analyticsKeys } = require('../analytics/keys')

module.exports = async function (ctx) {
let ipfsd = null
Expand Down Expand Up @@ -40,7 +41,7 @@ module.exports = async function (ctx) {
return
}

const log = logger.start('[ipfsd] start daemon', { withAnalytics: 'DAEMON_START' })
const log = logger.start('[ipfsd] start daemon', { withAnalytics: analyticsKeys.DAEMON_START })
const config = store.get('ipfsConfig')
updateStatus(STATUS.STARTING_STARTED)

Expand Down Expand Up @@ -74,7 +75,7 @@ module.exports = async function (ctx) {
return
}

const log = logger.start('[ipfsd] stop daemon', { withAnalytics: 'DAEMON_STOP' })
const log = logger.start('[ipfsd] stop daemon', { withAnalytics: analyticsKeys.DAEMON_STOP })
updateStatus(STATUS.STOPPING_STARTED)

if (!fs.pathExistsSync(join(ipfsd.path, 'config'))) {
Expand Down
3 changes: 2 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const setupAutoUpdater = require('./auto-updater')
const setupTray = require('./tray')
const setupAnalytics = require('./analytics')
const setupSecondInstance = require('./second-instance')
const { analyticsKeys } = require('./analytics/keys')

// Hide Dock
if (app.dock) app.dock.hide()
Expand Down Expand Up @@ -94,7 +95,7 @@ async function run () {
setupTakeScreenshot(ctx)
])
const submitAppReady = () => {
logger.addAnalyticsEvent({ withAnalytics: 'APP_READY', dur: getSecondsSinceAppStart() })
logger.addAnalyticsEvent({ withAnalytics: analyticsKeys.APP_READY, dur: getSecondsSinceAppStart() })
}
if (ctx.webui.webContents.isLoading()) {
ctx.webui.webContents.once('dom-ready', submitAppReady)
Expand Down
3 changes: 2 additions & 1 deletion src/move-repository-location.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const store = require('./common/store')
const logger = require('./common/logger')
const { showDialog, recoverableErrorDialog, selectDirectory } = require('./dialogs')
const dock = require('./utils/dock')
const { analyticsKeys } = require('./analytics/keys')

module.exports = function ({ stopIpfs, startIpfs }) {
dock.run(async () => {
Expand Down Expand Up @@ -77,7 +78,7 @@ module.exports = function ({ stopIpfs, startIpfs }) {

config.path = newDir
store.set('ipfsConfig', config)
logger.info('[move repository] configuration updated', { withAnalytics: 'MOVE_REPOSITORY' })
logger.info('[move repository] configuration updated', { withAnalytics: analyticsKeys.MOVE_REPOSITORY })

showDialog({
title: i18n.t('moveRepositorySuccessDialog.title'),
Expand Down
3 changes: 2 additions & 1 deletion src/take-screenshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const { IS_MAC } = require('./common/consts')
const { notify, notifyError } = require('./common/notify')
const { SCREENSHOT_SHORTCUT: CONFIG_KEY } = require('./common/config-keys')
const setupGlobalShortcut = require('./utils/setup-global-shortcut')
const { analyticsKeys } = require('./analytics/keys')

const SHORTCUT = IS_MAC
? 'Command+Control+S'
Expand Down Expand Up @@ -79,7 +80,7 @@ function handleScreenshot (ctx) {
baseName += '.png'
}

logger.info(`[screenshot] started: writing screenshots to ${baseName}`, { withAnalytics: 'SCREENSHOT_TAKEN' })
logger.info(`[screenshot] started: writing screenshots to ${baseName}`, { withAnalytics: analyticsKeys.SCREENSHOT_TAKEN })
let lastImage = null

for (const { name, image } of output) {
Expand Down
7 changes: 4 additions & 3 deletions src/webui/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const { showDialog } = require('../dialogs')
const { getSecondsSinceAppStart } = require('../metrics/appStart')
const { performance } = require('perf_hooks')
const Countly = require('countly-sdk-nodejs')
const { analyticsKeys } = require('../analytics/keys')
serve({ scheme: 'webui', directory: join(__dirname, '../../assets/webui') })

const createWindow = () => {
Expand All @@ -39,7 +40,7 @@ const createWindow = () => {

window.webContents.once('did-start-loading', (event) => {
const msg = '[web ui] loading'
const webContentLoad = logger.start(msg, { withAnalytics: 'WEB_UI_READY' })
const webContentLoad = logger.start(msg, { withAnalytics: analyticsKeys.WEB_UI_READY })
window.webContents.once('did-finish-load', () => {
webContentLoad.end()
})
Expand Down Expand Up @@ -140,9 +141,9 @@ module.exports = async function (ctx) {
ctx.launchWebUI = (path, { focus = true, forceRefresh = false } = {}) => {
if (forceRefresh) window.webContents.reload()
if (!path) {
logger.info('[web ui] launching web ui', { withAnalytics: 'FN_LAUNCH_WEB_UI_FOO' })
logger.info('[web ui] launching web ui', { withAnalytics: analyticsKeys.FN_LAUNCH_WEB_UI })
} else {
logger.info(`[web ui] navigate to ${path}`, { withAnalytics: 'FN_LAUNCH_WEB_UI_WITH_PATH' })
logger.info(`[web ui] navigate to ${path}`, { withAnalytics: analyticsKeys.FN_LAUNCH_WEB_UI_WITH_PATH })
url.hash = path
window.webContents.loadURL(url.toString())
}
Expand Down

0 comments on commit 5430992

Please sign in to comment.