Download Event
(url)
Will-download event that triggers session
('will-download', (event, downloadItem, webContents) => { // Set the file saving path // If the user does not set the save path, Electron will use the default method to determine the save path (usually prompts for a save dialog) (savePath) ('updated', (event, state) => { // Listen to the download process, there are two situations in state // interrupted download is interrupted and can be restored // progressing download is in progress, you can get the download progress if (state === 'interrupted') { // Recoverable download } else if (state === 'progressing') { if (()) { ('Download is paused') } else { // The progress bar can be set according to the byte size (`Total bytes: ${()}`) (`Received bytes: ${()}`) } } }) ('done', (event, state) => { // Download ends if (state === 'completed') { // Download successfully ('Download successfully') // Open the file with the application openFile(()) } else { // state is cancelled or interrupted // Download cancellation or download has been interrupted and cannot be restored (`Download failed: ${state}`) } // Here you can pass the status of the download to the rendering process ('downstate', state) }) })
The shell uses default applications to manage files and urls to provide features related to desktop integration
(path) Opens the given file in the default mode of the desktop.
function openFile(filePath) { const path = require('path'); ((filePath)); }
This is the article about opening wps preview based on vue+electron file download. For more related content on vue+electron wps preview, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!