{"id":15528846,"url":"https://github.com/danielnieto/electron-download-manager","last_synced_at":"2025-04-07T11:04:15.400Z","repository":{"id":52837885,"uuid":"70642890","full_name":"danielnieto/electron-download-manager","owner":"danielnieto","description":"Manage downloadItems from Electron's BrowserWindows without user interaction, allowing single file download and bulk downloading","archived":false,"fork":false,"pushed_at":"2021-11-19T16:25:21.000Z","size":46,"stargazers_count":121,"open_issues_count":19,"forks_count":50,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-31T10:04:27.274Z","etag":null,"topics":["bulk","bulk-download","downloaditem","downloadmanager","electron"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/danielnieto.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-10-11T23:11:46.000Z","updated_at":"2025-02-13T14:24:25.000Z","dependencies_parsed_at":"2022-08-29T01:51:04.437Z","dependency_job_id":null,"html_url":"https://github.com/danielnieto/electron-download-manager","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielnieto%2Felectron-download-manager","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielnieto%2Felectron-download-manager/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielnieto%2Felectron-download-manager/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielnieto%2Felectron-download-manager/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/danielnieto","download_url":"https://codeload.github.com/danielnieto/electron-download-manager/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247640461,"owners_count":20971557,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bulk","bulk-download","downloaditem","downloadmanager","electron"],"created_at":"2024-10-02T11:15:20.019Z","updated_at":"2025-04-07T11:04:15.363Z","avatar_url":"https://github.com/danielnieto.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# electron-download-manager\n\n\u003e Manage downloadItems from [Electron](https://electronjs.org)'s BrowserWindows without user interaction, allowing single file download and bulk downloading asynchronously\n\n\n## Why?\n\n- Register global listener that attaches to all newly created BrowserWindow instances\n- Automatically download the file to a given folder, without user prompt\n- Callback when download has completed (or failed)\n- Bulk download: pass a bunch of links and all will get downloaded, with a callback once they're all done.\n\n\n## Install\n\n```\n$ npm install electron-download-manager\n```\n\n\n## Usage\n\n### Register it for all windows\n\nRegister the listener (that will catch all DownloadItems)\n\n```js\nconst electron = require(\"electron\");\nconst { app, BrowserWindow } = electron;\n\nconst DownloadManager = require(\"electron-download-manager\");\n\nDownloadManager.register();\n\napp.on(\"ready\", () =\u003e {\n    let mainWindow = new BrowserWindow();\n});\n```\n\n### Examples\n\nAfter registering you must wait until at least 1 window is created to call DownloadManager.download function\n\n#### Single file download from the Main Process\n\n```js\nconst electron = require(\"electron\");\nconst { app, BrowserWindow } = electron;\n\nconst DownloadManager = require(\"electron-download-manager\");\n\nDownloadManager.register({\n    downloadFolder: app.getPath(\"downloads\") + \"/my-app\"\n});\n\napp.on(\"ready\", () =\u003e {\n\n    let mainWindow = new BrowserWindow();\n\n    mainWindow.loadURL(`file://${__dirname}/app/index.html`);\n\n    //Single file download\n    DownloadManager.download({\n        url: \"https://i.imgur.com/H124sSq.jpg\"\n    }, function (error, info) {\n        if (error) {\n            console.log(error);\n            return;\n        }\n\n        console.log(\"DONE: \" + info.url);\n    });\n\n});\n```\n\nThis example downloads *https://i.imgur.com/H124sSq.jpg* file to *user-downloads-folder/my-app/H124sSq.jpg*\n\n#### Bulk file download from the Main Process\n\n```js\nconst electron = require(\"electron\");\nconst {app, BrowserWindow} = electron;\n\nconst DownloadManager = require(\"electron-download-manager\");\n\nDownloadManager.register({downloadFolder: app.getPath(\"downloads\") + \"/my-app\"});;\n\napp.on(\"ready\", () =\u003e {\n    let mainWindow = new BrowserWindow();\n\n    mainWindow.loadURL(`file://${__dirname}/app/index.html`);\n\n    var links = [\n        \"https://i.imgur.com/xineeuw.jpg\",\n        \"https://i.imgur.com/RguiWa6.jpg\",\n        \"https://i.imgur.com/JR4Z0aD.jpg\",\n        \"https://i.imgur.com/ccvEJO1.jpg\",\n        \"https://i.imgur.com/yqZoShd.jpg\"\n    ];\n\n    //Bulk file download    \n    DownloadManager.bulkDownload({\n        urls: links,\n        path: \"bulk-download\"\n    }, function (error, finished, errors) {\n        if (error) {\n            console.log(\"finished: \" + finished);\n            console.log(\"errors: \" + errors);\n            return;\n        }\n\n        console.log(\"all finished\");\n    });\n\n});\n\n\n```\nThis example downloads 5 files to *user-downloads-folder/my-app/bulk-downloads*\n\n#### Use from Renderer Process\n\nOnce you've registered the listener on the Main process at any time you can call the download function through electron's [`remote`](https://electronjs.org/docs/api/remote)\n\n```js\nrequire(\"electron\").remote.require(\"electron-download-manager\").download({\n    url: \"https://i.imgur.com/H124sSq.jpg\"\n}, function (error, info) {\n    if (error) {\n        console.log(error);\n        return;\n    }\n\n    console.log(\"DONE: \" + info.url);\n});\n```\n\n## API\n\n### DownloadManager.register([options])\n\n### options\n\n#### downloadFolder\n\nType: `string`\u003cbr\u003e\nDefault: `app.getPath(\"downloads\")]`\n\nSet a folder where all downloadItems will be downloaded to. It will also be the parent folder for individual folders of each download. Explained below in Download function.\n\nBy default, this \"root\" folder will be user's OS downloads folder\n([read about this](http://electron.atom.io/docs/api/app/#appgetpathname))\n\nIf the file already exists in the location it will check the file's size against the size on the server, if it is lower than the server it will attempt to resume downloading the file. This is good for downloading large files. E.G Downloading a 200MB file and only 100MB downloaded (app closed/crashed) it will resume the download from where it left off automatically.\n\nIf the file size on the disk is the same as the server it will not download and return a successful callback.\n\n### DownloadManager.download(options, callback(error, {url, filePath}))\n\n### options\n\n#### url\nType: `string`\n\nThe url of the file to be downloaded\n\n#### path\nType: `string`\u003cbr\u003e\nDefault: `\"\"`\n\nSet a folder where this downloadItems will be downloaded to. This folder is relative to downloadFolder location set in the register function. By default it will be downloaded to root of downloadFolder which would be user download's folder.\n\n#### onLogin(authInfo, callback)\nType: `function`\u003cbr\u003e\n\nEmitted when an authenticating proxy is asking for user credentials.\n\n```js\n    DownloadManager.download({\n        url: \"https://i.imgur.com/H124sSq.jpg\",\n        onLogin: (authInfo, callback) =\u003e {\n            callback('username', 'password');\n        },\n    }, function (error, info) {\n        if (error) {\n            console.log(error);\n            return;\n        }\n\n        console.log(\"DONE: \" + info.url);\n    });\n\n```\n\n\u003e Please see [Class ClientRequest's 'login' event](http://electronjs.org/docs/api/client-request#event-login) for detail.\n\n#### onProgress(progress, item)\nType: `function`\u003cbr\u003e\n\nA function to be called whenever the file being downloaded progresses, this function will be constantly called with the updated value. \n\n`progress` an object with various metrics for the downloading file\n```\n{\n    downloaded          // downloaded amount in ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']\n    downloadedBytes     // same as previous only in bytes for calculation if required (eg. 4061073)\n    progress            // float progress of downloaing file (0 to 100)\n    remaining           // remaining amount of file download in ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'] (eg. 28.36 MB)\n    remainingBytes      // same as previous only in bytes for calculation if required (eg. 28360919)\n    speed               // download speed (eg. 311.3 KB/sec)\n    speedBytes          // same as previous only in bytes for calculation if required (eg. 311296)\n    total               // file size in ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'] (eg. 32.42 MB)\n    totalBytes          // same as previous only in bytes for calculation if required (eg. 32421992)\n    }\n```\n\n`item` instance of [DownloadItem](https://electronjs.org/docs/api/download-item#class-downloaditem) class. Useful for pausing and cancelling among other things.\n\n\u003e This feature currently exists only for single file downloads and hasn't been implemented (yet) for bulk processing.\n\n\n### callback(error, {url, filePath})\n\nCallback to be called when the download has reached a \"done\" state, which could mean two things either it was successful, or it failed.\n\nif the download was successful the callback's error will be `null`, otherwise it will contain the error message\n\n`url` returns the url of the downloaded file\u003cbr\u003e\n`filePath` location of where the file was saved\n\n### DownloadManager.bulkDownload(options, callback(error, finished, failed))\n\n### options\n\n#### urls\nType: `array`\n\nArray of `url` strings of the files to be downloaded\n\n#### path\nType: `string`\u003cbr\u003e\nDefault: `\"\"`\n\nSet a path to save all the bulk downloaded files. This folder is relative to downloadFolder location set in the register function. By default it will be downloaded to root of downloadFolder which would be user download's folder.\n\n#### onResult(finishedCount, errorsCount, itemUrl)\nType: `function`\u003cbr\u003e\n\nA function to be called whenever a file has been downloaded or whenever a download failed. \n\n`finishedCount` integer. Represents the number of file successfully downloaded. example: `4`\n\n`errorsCount` integer. Represents the number of file that couldn't be downloaded. example: `5`\n\n`itemUrl` string. Represents the `url` of the item.\n\n\u003e This feature is really different as the `onProgress` feature for single files as it doesn't take the size in the calculation.\n\n\n### callback(error, finished, failed)\nCallback to be executed when all downloadItems in this bulk process have been completed\n\n`error` will be `null` if everything was successful \u003cbr\u003e\n`finished` is an array containing the `url` of successfully downloaded items \u003cbr\u003e\n`failed` is an array containing the `url` of failed downloaded items (if any)\n\n## Questions\nFeel free to open Issues to ask questions about using this module, PRs are very welcome and encouraged.\n\n## License\n\nMIT © Daniel Nieto, loosely based on code from [Sindre Sorhus](https://sindresorhus.com)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanielnieto%2Felectron-download-manager","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdanielnieto%2Felectron-download-manager","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanielnieto%2Felectron-download-manager/lists"}