Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const registerAppCache = (browserWindow, userDataPath) => {
// Attempt to fetch the list.json to determine if we're online
// and the contents are available, in this case, we will always
// fetch the latest list of available compilers, but fallback
// to a local version if available.
let getList = false
const listURL = 'https://solc-bin.ethereum.org/bin/list.json'
const resp = fetch(listURL)
resp.then((resp) => {
if (resp.status === 200) {
getList = true
}
}).catch((err) => {
getList = false
})
const filter = {
urls: ['https://solc-bin.ethereum.org/bin/*']
}
const session = browserWindow.webContents.session
session.webRequest.onBeforeRequest(filter, (details, callback) => {
const resourceURL = details.url
export default function fetchNotifications(win) {
const {rpc} = win;
const retry = err => {
setTimeout(() => fetchNotifications(win), ms('30m'));
if (err) {
//eslint-disable-next-line no-console
console.error('Notification messages fetch error', err.stack);
}
};
//eslint-disable-next-line no-console
console.log('Checking for notification messages');
fetch(NEWS_URL, {
headers: {
'X-Hyper-Version': version,
'X-Hyper-Platform': process.platform
}
})
.then(res => res.json())
.then(data => {
const {message} = data || {};
if (typeof message !== 'object' && message !== '') {
throw new Error('Bad response');
}
if (message === '') {
//eslint-disable-next-line no-console
console.log('No matching notification messages');
} else {
rpc.emit('add notification', message);
session.webRequest.onCompleted(filter, (details) => {
const resourceURL = details.url
const resp = fetch(resourceURL)
resp.then((resp) => {
if (resp.status === 200) {
const filename = getFilename(resourceURL)
const dest = fs.createWriteStream(cachedFilePath(userDataPath, resourceURL))
resp.body.pipe(dest)
}
}).catch((err) => {})
})
export default () => {
try {
const version = `v${appData.version}`;
fetch('https://api.github.com/repos/canisminor1990/bilibili-client/releases/latest')
.then(res => res.text())
.then(body => {
const Body = JSON.parse(body);
const newVersion = Body['tag_name'];
Log(
`[app][check-update] Local: ${chalk.green(version)} Repo: ${chalk.green(
newVersion
)} Check: ${compare(version, newVersion)}`
);
if (compare(version, newVersion)) {
dialog.showMessageBox(
null,
{
buttons: ['取消', '去更新'],
message: `检查到新版本${newVersion},您正在使用的版本是${version},是否前往更新?`,
},
.then(() => {
return fetch(url, {
...options,
credentials: isSessionlessRequest ? options.credentials : undefined,
useElectronNet: true,
session: ses
})
})
.then((res) => {
const getFeed = () =>
fetch(`https://raw.githubusercontent.com/${repo}/master/auto_updater.json`).then(res =>
res.json()
);
.then(() => fetch(reqURL, { useElectronNet: true }))
.then((res) => res.ok ? Promise.resolve(res) : Promise.reject(new Error(`Http Status not ok: ${res.httpStatus}`)))
const processItems = (rowItems, filePath, outputPath, win) => {
const itemUrl = new URL(rowItems.pop());
const itemName = path.basename(itemUrl.pathname);
fetch(itemUrl)
.then(response => {
if (response.ok) {
const dest = fs.createWriteStream(path.join(outputPath, itemName));
response.body.pipe(dest);
const percentage = Math.abs(++processedItemsCount / initialItemsLength) * 100;
win.webContents.send('progress', percentage);
if (rowItems.length) {
processItems(rowItems, filePath, outputPath, win);
} else {
const logFileStream = fs.createWriteStream(path.join(
.then(() => fetch(downloadUrl, { useElectronNet: true }))
.then((res) => res.ok ? Promise.resolve(res) : Promise.reject(new Error(`Http Status not ok: ${res.httpStatus}`)))