Skip to content

Commit

Permalink
feat: fetch netplay dolphin logs when copying logs
Browse files Browse the repository at this point in the history
  • Loading branch information
NikhilNarayana committed Aug 13, 2023
1 parent bdd5f6f commit 791f298
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/main/installModules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ export function installModules() {
setupReplaysIpc();
setupSettingsIpc({ settingsManager, dolphinManager });
setupConsoleIpc({ dolphinManager });
setupMainIpc();
setupMainIpc({ dolphinManager });
return { dolphinManager, settingsManager };
}
23 changes: 18 additions & 5 deletions src/main/setup.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { exists } from "@common/exists";
import { IsoValidity } from "@common/types";
import type { DolphinManager } from "@dolphin/manager";
import { DolphinLaunchType } from "@dolphin/types";
import { app, clipboard, dialog, ipcMain, nativeImage, shell } from "electron";
import electronLog from "electron-log";
import type { ProgressInfo, UpdateInfo } from "electron-updater";
Expand Down Expand Up @@ -37,7 +40,7 @@ autoUpdater.logger = log;

const LINES_TO_READ = 200;

export default function setupMainIpc() {
export default function setupMainIpc({ dolphinManager }: { dolphinManager: DolphinManager }) {
ipcMain.on("onDragStart", (event, files: string[]) => {
// The Electron.Item type declaration is missing the files attribute
// so we'll just cast it as unknown for now.
Expand Down Expand Up @@ -107,17 +110,27 @@ export default function setupMainIpc() {
const mainLogPath = path.join(logsFolder, "main.log");
const rendererLogPath = path.join(logsFolder, "renderer.log");

const netplayDolphin = dolphinManager.getInstallation(DolphinLaunchType.NETPLAY);
let netplayUserPath = null;
try {
netplayUserPath = path.join(netplayDolphin.userFolder, "Logs", "dolphin.log");
} catch (e: any) {
log.error("Failed to get the userFolder: ", e);
}

// Fetch log contents in parallel
const [mainLogs, rendererLogs] = await Promise.all(
[mainLogPath, rendererLogPath].map(async (logPath): Promise<string> => {
if (await fileExists(logPath)) {
const [mainLogs, rendererLogs, netplayLogs] = await Promise.all(
[mainLogPath, rendererLogPath, netplayUserPath].map(async (logPath): Promise<string> => {
if (exists(logPath) && (await fileExists(logPath))) {
return await readLastLines(logPath, LINES_TO_READ);
}
return "";
}),
);

clipboard.writeText(`MAIN START\n---------------\n${mainLogs}\n\nRENDERER START\n---------------\n${rendererLogs}`);
clipboard.writeText(
`MAIN START\n---------------\n${mainLogs}\n\nRENDERER START\n---------------\n${rendererLogs}\n\nNETPLAY DOLPHIN START\n---------------\n${netplayLogs}`,
);
return { success: true };
});

Expand Down

0 comments on commit 791f298

Please sign in to comment.