Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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);
});
});
// 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}.`
);
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()
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);
});
});
export function init(): void {
electronDl({
showBadge: false,
onStarted: item => {
item.on('done', (_, state) => {
onDownloadComplete(item.getFilename(), state)
})
}
})
}
ipcMain.on('download', (event,args) => {
download(BrowserWindow.getFocusedWindow(),args.url);
});
click(menuItem) {
props.srcURL = menuItem.transform ? menuItem.transform(props.srcURL) : props.srcURL;
download(win, props.srcURL, {saveAs: true});
}
}),
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');
}
}
})
}
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 }
})
}