diff --git a/gcs/electron/main.ts b/gcs/electron/main.ts index c554dbb54..2bd38fc71 100644 --- a/gcs/electron/main.ts +++ b/gcs/electron/main.ts @@ -180,6 +180,27 @@ ipcMain.on("window:zoom-out", () => { ipcMain.on("window:open-file-in-explorer", (_event, filePath) => { shell.showItemInFolder(filePath) }) +ipcMain.handle("window:select-file-in-explorer", async (_event, filters) => { + const { canceled, filePaths } = await dialog.showOpenDialog({ + properties: ["openFile"], + filters: [...filters, { name: "All Files", extensions: ["*"] }], + }) + if (!canceled && filePaths.length > 0) { + const filePath = filePaths[0] + try { + const stats = fs.statSync(filePath) + return { + path: filePath, + name: path.basename(filePath), + size: stats.size, + } + } catch (err) { + // File is inaccessible or deleted + return null + } + } + return null +}) function createWindow() { win = new BrowserWindow({ diff --git a/gcs/electron/preload.js b/gcs/electron/preload.js index c5a229acf..8e090d95d 100644 --- a/gcs/electron/preload.js +++ b/gcs/electron/preload.js @@ -19,6 +19,7 @@ const ALLOWED_INVOKE_CHANNELS = [ "app:open-link-stats-window", "app:close-link-stats-window", "app:update-link-stats", + "window:select-file-in-explorer", ] const ALLOWED_SEND_CHANNELS = [ diff --git a/gcs/src/components/fla/SelectFlightLog.jsx b/gcs/src/components/fla/SelectFlightLog.jsx index 9c733c9fc..9667a3745 100644 --- a/gcs/src/components/fla/SelectFlightLog.jsx +++ b/gcs/src/components/fla/SelectFlightLog.jsx @@ -1,7 +1,6 @@ import { Button, Divider, - FileButton, LoadingOverlay, Progress, ScrollArea, @@ -34,6 +33,16 @@ export default function SelectFlightLog({ processLoadedFile }) { getFgcsLogs() } + const selectFile = async () => { + const result = await window.ipcRenderer.invoke( + "window:select-file-in-explorer", + [{ name: "Flight Logs", extensions: ["log", "ftlog"] }], + ) + if (result) { + handleFile(result) + } + } + const handleFile = useCallback( async function (file) { if (!file) return @@ -111,14 +120,9 @@ export default function SelectFlightLog({ processLoadedFile }) {