Download File Option (#80)

This adds to the context menu to give the ability to download a file. It
also fixes a couple bugs and improves some formatting of the directory
view.
This commit is contained in:
Sylvie Crowe
2024-06-26 12:14:59 -07:00
committed by GitHub
parent 566f6764c2
commit 0a8c97858c
6 changed files with 42 additions and 6 deletions
+8
View File
@@ -1,6 +1,7 @@
// Copyright 2024, Command Line Inc.
// SPDX-License-Identifier: Apache-2.0
import { getBackendHostPort } from "@/app/store/global";
import * as keyutil from "@/util/keyutil";
import * as electron from "electron";
import fs from "fs";
@@ -421,6 +422,13 @@ electron.ipcMain.on("getPlatform", (event) => {
event.returnValue = unamePlatform;
});
electron.ipcMain.on("download", (event, payload) => {
const window = electron.BrowserWindow.fromWebContents(event.sender);
const baseName = payload.filePath.split(/[\\/]/).pop();
const streamingUrl = getBackendHostPort() + "/wave/stream-file?path=" + encodeURIComponent(payload.filePath);
window.webContents.downloadURL(streamingUrl);
});
electron.ipcMain.on("getCursorPoint", (event) => {
const window = electron.BrowserWindow.fromWebContents(event.sender);
const screenPoint = electron.screen.getCursorScreenPoint();
+1
View File
@@ -11,4 +11,5 @@ contextBridge.exposeInMainWorld("api", {
openNewWindow: () => ipcRenderer.send("openNewWindow"),
showContextMenu: (menu, position) => ipcRenderer.send("contextmenu-show", menu, position),
onContextMenuClick: (callback) => ipcRenderer.on("contextmenu-click", callback),
downloadFile: (filePath) => ipcRenderer.send("download", { filePath }),
});