Skip to content

Commit

Permalink
Add hook to automatically open replay log from AdvantageKit
Browse files Browse the repository at this point in the history
  • Loading branch information
jwbonner committed Oct 31, 2024
1 parent b94f45f commit 0104a95
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/main/Constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ export const BUNDLED_ASSETS = path.join(__dirname, "..", "bundledAssets");
export const AUTO_ASSETS = path.join(app.getPath("userData"), "autoAssets");
export const DEFAULT_USER_ASSETS = path.join(app.getPath("userData"), "userAssets");
export const LEGACY_ASSETS = path.join(app.getPath("userData"), "frcData");
export const LAST_OPEN_FILE = path.join(app.getPath("temp"), "akit-log-path.txt");
export const AKIT_PATH_OUTPUT = path.join(app.getPath("temp"), "akit-log-path.txt");
export const AKIT_PATH_INPUT = path.join(app.getPath("temp"), "ascope-log-path.txt");
export const AKIT_PATH_INPUT_PERIOD = 250;
export const VIDEO_CACHE = path.join(app.getPath("temp"), "advantagescope-video-cache");
export const VIDEO_CACHE_FALLBACK = path.join(app.getPath("userData"), "video-cache");
export const FRC_LOG_FOLDER = "C:\\Users\\Public\\Documents\\FRC\\Log Files";
Expand Down
25 changes: 22 additions & 3 deletions src/main/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ import {
shouldPromptBetaSurvey
} from "./BetaConfig";
import {
AKIT_PATH_INPUT,
AKIT_PATH_INPUT_PERIOD,
AKIT_PATH_OUTPUT,
APP_VERSION,
DEFAULT_PREFS,
DOWNLOAD_CONNECT_TIMEOUT_MS,
Expand All @@ -55,7 +58,6 @@ import {
FRC_LOG_FOLDER,
HUB_DEFAULT_HEIGHT,
HUB_DEFAULT_WIDTH,
LAST_OPEN_FILE,
PATHPLANNER_CONNECT_TIMEOUT_MS,
PATHPLANNER_DATA_TIMEOUT_MS,
PATHPLANNER_PING_DELAY_MS,
Expand Down Expand Up @@ -257,7 +259,7 @@ async function handleHubMessage(window: BrowserWindow, message: NamedMessage) {
const uuid: string = message.data.uuid;
const path: string = message.data.path;
app.addRecentDocument(path);
fs.writeFile(LAST_OPEN_FILE, path, () => {});
fs.writeFile(AKIT_PATH_OUTPUT, path, () => {});

// Send data if all file reads finished
let completedCount = 0;
Expand Down Expand Up @@ -3270,8 +3272,25 @@ app.on("open-file", (_, path) => {
}
});

// Monitor for AdvantageKit path input
if (fs.existsSync(AKIT_PATH_INPUT)) {
fs.unlinkSync(AKIT_PATH_INPUT);
}
setInterval(() => {
if (fs.existsSync(AKIT_PATH_INPUT)) {
fs.readFile(AKIT_PATH_INPUT, "utf8", (error, path) => {
if (error !== null) return;
fs.unlinkSync(AKIT_PATH_INPUT);
if (hubWindows.length > 0) {
hubWindows[0].focus();
sendMessage(hubWindows[0], "open-files", { files: [path.trim()], merge: false });
}
});
}
}, AKIT_PATH_INPUT_PERIOD);

// Clean up files on quit
app.on("quit", () => {
fs.unlink(LAST_OPEN_FILE, () => {});
fs.unlink(AKIT_PATH_OUTPUT, () => {});
VideoProcessor.cleanup();
});

0 comments on commit 0104a95

Please sign in to comment.