Skip to content

Commit

Permalink
Add popup for agreeing to CTRE license terms
Browse files Browse the repository at this point in the history
  • Loading branch information
jwbonner committed Oct 16, 2024
1 parent 2234085 commit 23a040b
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 23 deletions.
3 changes: 2 additions & 1 deletion src/main/Constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
74 changes: 53 additions & 21 deletions src/main/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Electron.MessageBoxReturnValue>((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<PLACEHOLDER>",
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;
Expand Down Expand Up @@ -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;
}
Expand Down
3 changes: 2 additions & 1 deletion src/preferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions src/shared/Preferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ export default interface Preferences {
skipHootNonProWarning: boolean;
skipNumericArrayDeprecationWarning: boolean;
skipFrcLogFolderDefault: boolean;
ctreLicenseAccepted: boolean;
usb?: boolean;
}

0 comments on commit 23a040b

Please sign in to comment.