From 9a9af15e2e7c6f2e97ca297a73e2aeab8088e93d Mon Sep 17 00:00:00 2001 From: Agampreet Singh <68941022+agam778@users.noreply.github.com> Date: Mon, 22 Jul 2024 14:04:26 +0530 Subject: [PATCH] Introduce Aptabase tracking preference - Add an option to enable or disable Aptabase tracking for users, in the app menu. - Also give users a prompt on the app's first launch to choose their preference. --- app/config/menu.js | 29 +++++++++++++++++++++++++++++ app/config/store.js | 1 + app/main.js | 33 ++++++++++++++++++++++++++------- 3 files changed, 56 insertions(+), 7 deletions(-) diff --git a/app/config/menu.js b/app/config/menu.js index 0a0cb38..f7045d0 100644 --- a/app/config/menu.js +++ b/app/config/menu.js @@ -326,6 +326,35 @@ const commonPreferencesSubmenu = [ }, checked: getValue("discordrpcstatus") === "true", }, + { + label: "Enable Aptabase Tracking", + type: "checkbox", + click: () => { + if (getValue("aptabaseTracking") === true) { + setValue("aptabaseTracking", false); + dialog.showMessageBoxSync({ + type: "info", + title: "Aptabase Tracking", + message: "Aptabase Tracking has been disabled.", + buttons: ["OK"], + }); + return; + } else if ( + getValue("aptabaseTracking") === false || + getValue("aptabaseTracking") === undefined + ) { + setValue("aptabaseTracking", true); + dialog.showMessageBoxSync({ + type: "info", + title: "Aptabase Tracking", + message: "Aptabase Tracking has been enabled.", + buttons: ["OK"], + }); + return; + } + }, + checked: getValue("aptabaseTracking") === true, + }, { label: "Enable Auto Updates", type: "checkbox", diff --git a/app/config/store.js b/app/config/store.js index 9067d3a..61dc025 100644 --- a/app/config/store.js +++ b/app/config/store.js @@ -32,6 +32,7 @@ getValueOrDefault("custompage", "home"); getValueOrDefault("windowWidth", 0.71); getValueOrDefault("windowHeight", 0.74); getValueOrDefault("customWindowSize", false); +getValueOrDefault("aptabaseTracking", null); if (getValue("enterprise-or-normal") === "https://microsoft365.com/?auth=1") { setValue("enterprise-or-normal", "?auth=1"); diff --git a/app/main.js b/app/main.js index 95ef9b5..bb37a03 100644 --- a/app/main.js +++ b/app/main.js @@ -2,7 +2,7 @@ import { app, Menu, BrowserWindow, dialog, nativeImage, screen } from "electron" import { clearActivity, setActivity, loginToRPC } from "./config/rpc.js"; import { initialize, trackEvent } from "@aptabase/electron/main"; import { ElectronBlocker } from "@cliqz/adblocker-electron"; -import { getValue } from "./config/store.js"; +import { setValue, getValue } from "./config/store.js"; import { fileURLToPath } from "url"; import { dirname } from "path"; import { join } from "path"; @@ -27,9 +27,11 @@ transports.file.level = "verbose"; console.log = _log; Object.assign(console, functions); -initialize("A-US-2528580917").catch((error) => { - console.error("Error initializing:", error); -}); +if (getValue("aptabaseTracking") === true) { + initialize("A-US-2528580917").catch((error) => { + console.error("Error initializing:", error); + }); +} function createWindow() { const enterpriseOrNormal = getValue("enterprise-or-normal"); @@ -67,9 +69,11 @@ function createWindow() { win.webContents.on("did-finish-load", () => { splash.destroy(); win.show(); - trackEvent("app_started").catch((error) => { - console.error("Error tracking event:", error); - }); + if (getValue("aptabaseTracking") === true) { + trackEvent("app_started").catch((error) => { + console.error("Error tracking event:", error); + }); + } if (getValue("discordrpcstatus") === "true") { setActivity(`On "${win.webContents.getTitle()}"`); } @@ -118,6 +122,21 @@ Menu.setApplicationMenu(Menu.buildFromTemplate(menulayout)); app.on("ready", () => { createWindow(); + if (getValue("aptabaseTracking") === null) { + const aptabasedialog = dialog.showMessageBoxSync({ + type: "question", + buttons: ["Yes", "No"], + title: "Enable Aptabase Tracking", + message: "Would you like to enable Aptabase Tracking?", + detail: + "Aptabase Tracking helps us improve the app by collecting anonymous usage data. No personal information is collected.\n\nYou can always enable or disable this in the app menu.", + }); + if (aptabasedialog === 0) { + setValue("aptabaseTracking", true); + } else { + setValue("aptabaseTracking", false); + } + } }); app.on("web-contents-created", (event, contents) => {