Skip to content

Commit

Permalink
fix: clear temp folder from main on startup before replay playback is…
Browse files Browse the repository at this point in the history
… setup

otherwise double clicking a replay when the launcher isn't yet open will delete the comm file before dolphin can read it
  • Loading branch information
NikhilNarayana committed Sep 17, 2024
1 parent ac5941a commit 4159a19
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 19 deletions.
13 changes: 12 additions & 1 deletion src/main/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import { fileExists } from "utils/file_exists";
import { getConfigFlags } from "./flags/flags";
import { installModules } from "./install_modules";
import { MenuBuilder } from "./menu";
import { resolveHtmlPath } from "./util";
import { clearTempFolder, resolveHtmlPath } from "./util";

const BACKGROUND_COLOR = "#1B0B28";

Expand Down Expand Up @@ -88,6 +88,17 @@ const createWindow = async () => {
await installExtensions();
}

// clear temp files safely before the app has fully started and replays are being loaded for playback
try {
await clearTempFolder();
} catch (err) {
// silently fail since this isn't a critical issue
log.error(
`Could not clear temp folder on startup due to:
${err instanceof Error ? err.message : JSON.stringify(err)}`,
);
}

mainWindow = new BrowserWindow({
show: false,
width: 1100,
Expand Down
7 changes: 2 additions & 5 deletions src/main/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { app, clipboard, dialog, ipcMain, nativeImage, shell } from "electron";
import electronLog from "electron-log";
import type { ProgressInfo, UpdateInfo } from "electron-updater";
import { autoUpdater } from "electron-updater";
import * as fs from "fs-extra";
import path from "path";
import { fileExists } from "utils/file_exists";

Expand All @@ -30,7 +29,7 @@ import {
} from "./ipc";
import { getNetworkDiagnostics } from "./network_diagnostics";
import { fetchNewsFeedData } from "./news_feed";
import { getAssetPath, readLastLines } from "./util";
import { clearTempFolder, getAssetPath, readLastLines } from "./util";
import { verifyIso } from "./verify_iso";

const log = electronLog.scope("main/listeners");
Expand Down Expand Up @@ -163,10 +162,8 @@ export default function setupMainIpc({
});

ipc_clearTempFolder.main!.handle(async () => {
const tmpDir = path.join(app.getPath("userData"), "temp");
try {
await fs.remove(tmpDir);
await fs.ensureDir(tmpDir);
await clearTempFolder();
} catch (err) {
log.error(err);
throw err;
Expand Down
6 changes: 6 additions & 0 deletions src/main/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,9 @@ export async function readLastLines(

return Buffer.from(allBytes).toString(encoding);
}

export async function clearTempFolder() {
const tmpDir = path.join(app.getPath("userData"), "temp");
await fs.remove(tmpDir);
await fs.ensureDir(tmpDir);
}
13 changes: 0 additions & 13 deletions src/renderer/lib/hooks/use_app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,19 +92,6 @@ export const useAppInitialization = () => {
// Check if there is an update to the launcher
promises.push(window.electron.common.checkForAppUpdates());

// Remove any temp files
promises.push(
(async () => {
window.electron.common.clearTempFolder().catch((err) => {
// silently fail since this isn't a critical issue
log.error(
`Could not clear temp folder on startup due to:
${err instanceof Error ? err.message : JSON.stringify(err)}`,
);
});
})(),
);

// Wait for all the promises to complete before completing
try {
await Promise.all(promises);
Expand Down

0 comments on commit 4159a19

Please sign in to comment.