Skip to content

Commit

Permalink
Machine id fetching improvements.
Browse files Browse the repository at this point in the history
  • Loading branch information
ganeshrvel committed Jun 11, 2024
1 parent aa04989 commit 5b09e73
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 7 deletions.
18 changes: 18 additions & 0 deletions app/helpers/identifiers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { machineId } from 'node-machine-id';
import { settingsStorage } from './storageHelper';

export async function getMachineId() {
const settings = settingsStorage.getItems(['machineId']);

if (!settings?.machineId) {
const _machineId = await machineId();

settingsStorage.setItems({
machineId: _machineId,
});

return _machineId;
}

return settings.machineId;
}
4 changes: 2 additions & 2 deletions app/services/analytics/mixpanelAnalytics.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { isObject } from 'nice-utils';
import mixpanel from 'mixpanel-browser';
import { machineId } from 'node-machine-id';
import { release } from 'os';
import { log } from '../../utils/log';
import { isEmpty } from '../../utils/funcs';
Expand All @@ -15,6 +14,7 @@ import { unixTimestampNow } from '../../utils/date';
import { getCurrentWindowHash } from '../../helpers/windowHelper';
import { getPlatform } from '../../utils/getPlatform';
import { APP_VERSION } from '../../constants/meta';
import { getMachineId } from '../../helpers/identifiers';

export class MixpanelAnalytics {
constructor() {
Expand Down Expand Up @@ -48,7 +48,7 @@ export class MixpanelAnalytics {
}

// this is a hashed value (sha-256)
this.machineId = await machineId();
this.machineId = await getMachineId();

if (ENV_FLAVOR.enableMixpanelAnalytics) {
mixpanel.init(SERVICE_KEYS.mixpanelAnalytics);
Expand Down
4 changes: 2 additions & 2 deletions app/services/sentry/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import * as Sentry from '@sentry/electron';
import { machineId } from 'node-machine-id';
import { ENV_FLAVOR } from '../../constants/env';
import { SERVICE_KEYS } from '../../constants/serviceKeys';
import { getDeviceInfo } from '../../helpers/deviceInfo';
import { isEmpty } from '../../utils/funcs';
import { pkginfo } from '../../utils/pkginfo';
import { checkIf } from '../../utils/checkIf';
import { MTP_MODE } from '../../enums';
import { getMachineId } from '../../helpers/identifiers';

class SentryService {
constructor() {
Expand All @@ -25,7 +25,7 @@ class SentryService {
release: pkginfo.version,
});

this.machineId = await machineId();
this.machineId = await getMachineId();
}

async report({ error, title, mtpMode }) {
Expand Down
4 changes: 2 additions & 2 deletions app/utils/log.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import clp from 'console-log-plus';
import os, { EOL } from 'os';
import { machineId } from 'node-machine-id';
import { IS_PROD } from '../constants/env';
import { APP_NAME, APP_VERSION } from '../constants/meta';
import { PATHS } from '../constants/paths';
Expand All @@ -12,6 +11,7 @@ import { isEmpty } from './funcs';
import { getMtpModeSetting } from '../helpers/settings';
import { redactHomeDirectory } from '../helpers/logs';
import { isConsoleError } from './errors';
import { getMachineId } from '../helpers/identifiers';

const { logFile } = PATHS;

Expand Down Expand Up @@ -121,7 +121,7 @@ export const log = {
let _deviceInfoStrigified = '';
const deviceInfo = getDeviceInfo();
const mtpMode = getMtpModeSetting();
const uuid = await machineId();
const uuid = await getMachineId();

if (!isEmpty(deviceInfo)) {
Object.keys(deviceInfo).forEach((a) => {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "openmtp",
"productName": "OpenMTP",
"version": "3.2.20",
"version": "3.2.21",
"description": "OpenMTP | Android File Transfer for macOS",
"scripts": {
"build": "yarn lint && concurrently \"yarn build-main\" \"yarn build-renderer\"",
Expand Down

0 comments on commit 5b09e73

Please sign in to comment.