From 23a040bbddebf830fa6777659ece8daab6b5af68 Mon Sep 17 00:00:00 2001 From: Jonah <47046556+jwbonner@users.noreply.github.com> Date: Wed, 16 Oct 2024 17:20:55 -0400 Subject: [PATCH] Add popup for agreeing to CTRE license terms --- src/main/Constants.ts | 3 +- src/main/main.ts | 74 ++++++++++++++++++++++++++++----------- src/preferences.ts | 3 +- src/shared/Preferences.ts | 1 + 4 files changed, 58 insertions(+), 23 deletions(-) diff --git a/src/main/Constants.ts b/src/main/Constants.ts index 42b6e833..cc78d397 100644 --- a/src/main/Constants.ts +++ b/src/main/Constants.ts @@ -38,7 +38,8 @@ export const DEFAULT_PREFS: Preferences = { userAssetsFolder: null, skipHootNonProWarning: false, skipFrcLogFolderDefault: false, - skipNumericArrayDeprecationWarning: false + skipNumericArrayDeprecationWarning: false, + ctreLicenseAccepted: false }; export const HUB_DEFAULT_WIDTH = 1100; export const HUB_DEFAULT_HEIGHT = 650; diff --git a/src/main/main.ts b/src/main/main.ts index eaf69720..d9eadf8e 100644 --- a/src/main/main.ts +++ b/src/main/main.ts @@ -324,28 +324,57 @@ async function handleHubMessage(window: BrowserWindow, message: NamedMessage) { } else if (path.endsWith(".hoot")) { // Hoot, convert to WPILOG targetCount += 1; - checkHootIsPro(path) - .then((isPro) => { - hasHootNonPro = hasHootNonPro || !isPro; - }) - .finally(() => { - convertHoot(path) - .then((wpilogPath) => { - openPath(wpilogPath, (buffer) => { - results[0] = buffer; - fs.rmSync(wpilogPath); - }); + let prefs: Preferences = jsonfile.readFileSync(PREFS_FILENAME); + if (!prefs.ctreLicenseAccepted) { + let response = await new Promise((resolve) => + dialog + .showMessageBox(window, { + type: "info", + title: "Alert", + message: "CTRE Terms & Conditions", + detail: + "Hoot log file decoding requires agreement to CTRE's terms and conditions. Please navigate to the address below to view the full license agreement.\n\n", + checkboxLabel: "I Agree", + icon: WINDOW_ICON }) - .catch((reason) => { - if (typeof reason === "string") { - errorMessage = reason; - } else { - errorMessage = reason.message; - } - completedCount++; - sendIfReady(); - }); - }); + .then((response) => resolve(response)) + ); + // TODO: Enable license agreement once CTRE publishes terms and conditions + // + // if (response.checkboxChecked) { + // prefs.ctreLicenseAccepted = true; + // jsonfile.writeFileSync(PREFS_FILENAME, prefs); + // sendAllPreferences(); + // } + } + if (!prefs.ctreLicenseAccepted) { + errorMessage = "Hoot log files cannot be decoded without agreeing to CTRE's terms and conditions."; + completedCount++; + sendIfReady(); + } else { + checkHootIsPro(path) + .then((isPro) => { + hasHootNonPro = hasHootNonPro || !isPro; + }) + .finally(() => { + convertHoot(path) + .then((wpilogPath) => { + openPath(wpilogPath, (buffer) => { + results[0] = buffer; + fs.rmSync(wpilogPath); + }); + }) + .catch((reason) => { + if (typeof reason === "string") { + errorMessage = reason; + } else { + errorMessage = reason.message; + } + completedCount++; + sendIfReady(); + }); + }); + } } else { // Normal log, open normally targetCount += 1; @@ -3188,6 +3217,9 @@ app.whenReady().then(() => { if ("skipFrcLogFolderDefault" in oldPrefs && typeof oldPrefs.skipFrcLogFolderDefault === "boolean") { prefs.skipFrcLogFolderDefault = oldPrefs.skipFrcLogFolderDefault; } + if ("ctreLicenseAccepted" in oldPrefs && typeof oldPrefs.ctreLicenseAccepted === "boolean") { + prefs.ctreLicenseAccepted = oldPrefs.ctreLicenseAccepted; + } jsonfile.writeFileSync(PREFS_FILENAME, prefs); nativeTheme.themeSource = prefs.theme; } diff --git a/src/preferences.ts b/src/preferences.ts index f7cf5763..aee5d8d1 100644 --- a/src/preferences.ts +++ b/src/preferences.ts @@ -95,7 +95,8 @@ window.addEventListener("message", (event) => { userAssetsFolder: oldPrefs.userAssetsFolder, skipHootNonProWarning: oldPrefs.skipHootNonProWarning, skipFrcLogFolderDefault: oldPrefs.skipFrcLogFolderDefault, - skipNumericArrayDeprecationWarning: oldPrefs.skipNumericArrayDeprecationWarning + skipNumericArrayDeprecationWarning: oldPrefs.skipNumericArrayDeprecationWarning, + ctreLicenseAccepted: oldPrefs.ctreLicenseAccepted }; messagePort.postMessage(newPrefs); } else { diff --git a/src/shared/Preferences.ts b/src/shared/Preferences.ts index c3c3377b..5e3b54e4 100644 --- a/src/shared/Preferences.ts +++ b/src/shared/Preferences.ts @@ -15,5 +15,6 @@ export default interface Preferences { skipHootNonProWarning: boolean; skipNumericArrayDeprecationWarning: boolean; skipFrcLogFolderDefault: boolean; + ctreLicenseAccepted: boolean; usb?: boolean; }