How to use electron-dl - 10 common examples

To help you get started, we’ve selected a few electron-dl examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Rawnly / vscode-icons-manager--electron / app / app.js View on Github external
ipcMain.on('selected', (ev, source) => {
	let filename = source.split('/').pop();

	presentLoading(ev.sender);

	// If the icon exists prevent download
	if ( fs.existsSync( path.join(__dirname, '..', 'icons', filename) ) === true  )
	{
		logger.log('Icon exists!');
		return setIcon(path.join(__dirname, '..', 'icons', filename), ev.sender);
	}

	logger.log('Starting download');
		
	// Download the icon from git repo
	download(BrowserWindow.getFocusedWindow(), source, {
		directory: path.join(__dirname, '..', 'icons')
	}).then(dl => {
		let p = dl.getSavePath();
		setIcon(p, ev.sender);
	}).catch((error) => {
		logger.error(error);
		
		dismissLoading(ev.sender);
	});
});
github paritytech / fether / packages / parity-electron / src / fetchParity.ts View on Github external
// Get the binary's url
        const {
          name,
          downloadUrl,
          checksum: expectedChecksum
        }: {
          name: string;
          downloadUrl: string;
          checksum: string;
        } = data[0].files.find(
          ({ name }) => name === 'parity' || name === 'parity.exe'
        );

        // Start downloading.
        const downloadItem = await download(mainWindow, downloadUrl, {
          directory: app.getPath('userData'),
          filename: `${name}.part`,
          onProgress
        });
        const downloadPath: string = downloadItem.getSavePath();

        // Once downloaded, we check the sha256 checksum
        // Calculate the actual checksum
        const actualChecksum: string = await checksum(downloadPath, {
          algorithm: 'sha256'
        });
        // The 2 checksums should of course match
        if (expectedChecksum !== actualChecksum) {
          throw new Error(
            `Checksum mismatch, expecting ${expectedChecksum}, got ${actualChecksum}.`
          );
github tinoji / twemoji-image-picker / main.js View on Github external
ipcMain.on('download', async (event, url, size) => {
    const win = BrowserWindow.getFocusedWindow();
    await download(win, url, {
        directory: tmpDir,
        filename: svgFilename
    });

    let img;
    if (process.platform === 'win32' || process.platform === 'win64') {
        // See: https://github.com/electron/electron/issues/17081
        img = nativeImage.createFromPath(svgFilepath);
    } else {
        // See: https://github.com/lovell/sharp/issues/729
        let density = parseInt(defaultSvgDpi * size / svgSize);
        if (density > 2400) density = 2400;

        const buffer = await sharp(svgFilepath, { density: density })
            .resize(size, size)
            .png()
github willnewii / qiniuClient / src / main / index.js View on Github external
ipcMain.on(Constants.Listener.downloadFile, function (event, file, option) {
        option.onProgress = function (num) {
            if (num !== 1) {
                event.sender.send(Constants.Listener.updateDownloadProgress, num);
            }
        };
        if (!option.directory) {
            option.directory = DEFAULT_PATH;
        }
        if (option.folder) {
            option.directory = path.join(option.directory, option.folder);
        }

        download(mainWindow, file, option).then(dl => {
            if (option.count === 1) {
                shell.showItemInFolder(dl.getSavePath());
            }
            event.sender.send(Constants.Listener.updateDownloadProgress, 1);
        }).catch(error => {
            console.error(error);
            event.sender.send(Constants.Listener.updateDownloadProgress, 1);
        });
    });
github timche / gmail-desktop / src / downloads.ts View on Github external
export function init(): void {
  electronDl({
    showBadge: false,
    onStarted: item => {
      item.on('done', (_, state) => {
        onDownloadComplete(item.getFilename(), state)
      })
    }
  })
}
github sarthology / dragula / main.js View on Github external
ipcMain.on('download', (event,args) => {
	download(BrowserWindow.getFocusedWindow(),args.url);
});
github sindresorhus / electron-context-menu / index.js View on Github external
click(menuItem) {
					props.srcURL = menuItem.transform ? menuItem.transform(props.srcURL) : props.srcURL;
					download(win, props.srcURL, {saveAs: true});
				}
			}),
github burst-apps-team / phoenix / desktop / wallet / main.js View on Github external
function downloadUpdate($event, assetUrl) {
  download(win, assetUrl, {
    openFolderWhenDone: true,
    saveAs: true,
    onStarted: (handle) => {
      downloadHandle = handle;
      win.webContents.send('new-version-download-started');
    },
    onProgress: (progress) => {
      if (progress === 1) {
        downloadHandle = null;
        win.webContents.send('new-version-download-finished');
      }
    }
  })
}
github fluidtrends / carmel / studio / src / Session.js View on Github external
syncEnv() {
        const url = `${STUDIO_FILES_URL}/env.json`
        const directory = path.resolve(HOME)
        const manifestFile = path.resolve(directory, 'env.json')

        fs.existsSync(directory) || fs.mkdirsSync(directory)

        if (fs.existsSync(manifestFile)) {
            fs.removeSync(manifestFile)
        }

        return download(this.window, url, { 
            url,
            saveAs: false,
            directory
        })
        .then(() => { 
            const all = JSON.parse(fs.readFileSync(manifestFile, 'utf8'))
            const versions = Object.keys(all).map(v => parseFloat(v))
            versions.sort((a, b) => b-a)
            const latest = Object.assign({}, all[`${versions[0]}`], { version: `${versions[0]}` })
            this._env = { all, versions, latest }
        })
    }

electron-dl

Simplified file downloads for your Electron app

MIT
Latest version published 7 months ago

Package Health Score

66 / 100
Full package analysis

Popular electron-dl functions