mirror of
https://github.com/frappe/books.git
synced 2025-02-10 07:59:03 +00:00
incr: complete telemetry sending of data
This commit is contained in:
parent
c295ba0416
commit
e348d14849
@ -15,7 +15,7 @@ import { autoUpdater } from 'electron-updater';
|
||||
import fs from 'fs/promises';
|
||||
import path from 'path';
|
||||
import { createProtocol } from 'vue-cli-plugin-electron-builder/lib';
|
||||
import { sendError } from './contactMothership';
|
||||
import { getUrlAndTokenString, sendError } from './contactMothership';
|
||||
import { getLanguageMap } from './getLanguageMap';
|
||||
import { IPC_ACTIONS, IPC_CHANNELS, IPC_MESSAGES } from './messages';
|
||||
import saveHtmlAsPdf from './saveHtmlAsPdf';
|
||||
@ -261,6 +261,10 @@ ipcMain.handle(IPC_ACTIONS.GET_FILE, async (event, options) => {
|
||||
return response;
|
||||
});
|
||||
|
||||
ipcMain.handle(IPC_ACTIONS.GET_CREDS, async (event) => {
|
||||
return await getUrlAndTokenString();
|
||||
});
|
||||
|
||||
/* ------------------------------
|
||||
* Register autoUpdater events lis
|
||||
* ------------------------------*/
|
||||
|
@ -1,10 +1,11 @@
|
||||
import config from '@/config';
|
||||
import { ipcRenderer } from 'electron';
|
||||
import SQLiteDatabase from 'frappe/backends/sqlite';
|
||||
import fs from 'fs';
|
||||
import models from '../models';
|
||||
import regionalModelUpdates from '../models/regionalModelUpdates';
|
||||
import postStart, { setCurrencySymbols } from '../server/postStart';
|
||||
import { DB_CONN_FAILURE } from './messages';
|
||||
import { DB_CONN_FAILURE, IPC_ACTIONS } from './messages';
|
||||
import runMigrate from './migrate';
|
||||
import { getId } from './telemetry/helpers';
|
||||
import telemetry from './telemetry/telemetry';
|
||||
@ -96,9 +97,11 @@ export async function connectToLocalDatabase(filePath) {
|
||||
|
||||
// second init with currency, normal usage
|
||||
await callInitializeMoneyMaker();
|
||||
|
||||
const creds = await ipcRenderer.invoke(IPC_ACTIONS.GET_CREDS);
|
||||
telemetry.setCreds(creds?.telemetryUrl ?? '', creds?.tokenString ?? '');
|
||||
telemetry.start();
|
||||
await telemetry.setCount();
|
||||
|
||||
return { connectionSuccess: true, reason: '' };
|
||||
}
|
||||
|
||||
|
@ -158,7 +158,7 @@ function registerIpcRendererListeners() {
|
||||
return;
|
||||
}
|
||||
|
||||
const telemetryData = telemetry.stop();
|
||||
navigator.sendBeacon('http://0.0.0.0:6969', telemetryData);
|
||||
const { url, data } = telemetry.stop();
|
||||
navigator.sendBeacon(url, data);
|
||||
});
|
||||
}
|
||||
|
@ -26,6 +26,7 @@ export const IPC_ACTIONS = {
|
||||
GET_LANGUAGE_MAP: 'get-language-map',
|
||||
CHECK_FOR_UPDATES: 'check-for-updates',
|
||||
GET_FILE: 'get-file',
|
||||
GET_CREDS: 'get-creds',
|
||||
};
|
||||
|
||||
// ipcMain.send(...)
|
||||
|
@ -5,6 +5,8 @@ import { getCounts, getDeviceId, getInstanceId, getLocale } from './helpers';
|
||||
import { Noun, Telemetry, Verb } from './types';
|
||||
|
||||
class TelemetryManager {
|
||||
#url: string = '';
|
||||
#token: string = '';
|
||||
#started = false;
|
||||
#telemetryObject: Partial<Telemetry> = {};
|
||||
|
||||
@ -23,6 +25,11 @@ class TelemetryManager {
|
||||
return telemetrySetting === TelemetrySetting.allow;
|
||||
}
|
||||
|
||||
setCreds(url: string, token: string) {
|
||||
this.#url ||= url;
|
||||
this.#token ||= token;
|
||||
}
|
||||
|
||||
log(verb: Verb, noun: Noun, more?: Record<string, unknown>) {
|
||||
if (!this.#started) {
|
||||
this.start();
|
||||
@ -70,7 +77,12 @@ class TelemetryManager {
|
||||
return '';
|
||||
}
|
||||
|
||||
return JSON.stringify(telemetryObject);
|
||||
const data = JSON.stringify({
|
||||
token: this.#token,
|
||||
telemetryData: telemetryObject,
|
||||
});
|
||||
|
||||
return { url: this.#url, data };
|
||||
}
|
||||
|
||||
get telemetryObject(): Readonly<Partial<Telemetry>> {
|
||||
|
Loading…
x
Reference in New Issue
Block a user