Last active
November 14, 2017 15:50
-
-
Save vojtech-cerveny/87a1f8d0e586fec477b7649b7095bbd0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const request = require('request'); | |
const fs = require('fs'); | |
const log = require('electron-log'); | |
const electron = require('electron'); | |
const {spawn} = require('child_process'); | |
const {Utils} = require('../Utils'); | |
const nameMap = { | |
"darwin": "mac", | |
"win32": "win", | |
"linux": "linux", | |
}; | |
const suffix = nameMap[process.platform]; | |
let checkRepo = new Promise((resolve, reject) => { | |
request( | |
{ | |
url: 'https://api.github.com/repos/spajak/cef-pdf/releases', | |
headers: {'User-Agent': 'Awesome-Octocat-App'} | |
}, | |
(error, requestx, body) => { | |
const data = JSON.parse(body); | |
resolve(data[0].assets); | |
}); | |
}); | |
module.exports = checkRepo | |
.then((assets) => { | |
if (!fs.existsSync("./cef-pdf")) { | |
fs.mkdirSync("./cef-pdf"); | |
} | |
for (let i in assets) { | |
let asset = assets[i]; | |
if(asset.browser_download_url.includes(suffix)){ | |
log.info(process.platform); | |
return asset; | |
} | |
} | |
}) | |
.then((asset)=> { | |
request({url: asset.browser_download_url}) | |
.pipe(fs.createWriteStream('./cef-pdf/' + asset.name)) | |
.on('finish', ()=> { | |
let pathTo7za = `${Utils.getPathToPublic()}/7z/${suffix}/7za`; | |
if(suffix == 'win') | |
pathTo7za += '.exe'; | |
const pathToFile = './cef-pdf/' + asset.name; | |
const unzip = spawn(pathTo7za, | |
['x', `-o${electron.app.getPath('userData')}/cef-pdf/${suffix}`, pathToFile, '-y']); | |
unzip.on('exit', ()=>{ | |
log.info('done'); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment