Skip to content
This repository has been archived by the owner on Jan 26, 2020. It is now read-only.

Commit

Permalink
fix variable name
Browse files Browse the repository at this point in the history
  • Loading branch information
gokberkakdeniz committed Dec 12, 2018
1 parent ef8d353 commit d1f67b3
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 34 deletions.
87 changes: 53 additions & 34 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const {get} = require('https');
const compareVersions = require('compare-versions');
const appIcon = join(__dirname, 'assets', 'img', 'png', 'icon_normal.png')
const appIconFocused = join(__dirname, 'assets', 'img', 'png', 'icon_focused.png')
const fetch = require('node-fetch')
let win, tray, page, child

console.log("Electron " + process.versions.electron + " | Chromium " + process.versions.chrome)
Expand All @@ -20,42 +21,60 @@ if (!app.requestSingleInstanceLock()) {
return app.quit()
}

get({
hostname: "api.github.com",
path: "/repos/tncga/whats-up-darkness/releases",
headers: {
"user-agent": "Whats-Up-Darkness"
}
}, (res) => {
let err, data = ""

if (res.statusCode !== 200) {
error = new Error(`Cannot retrieve version data (Status Code: ${res.statusCode}).`)
} else if (!/^application\/json/.test(res.headers['content-type'])) {
error = new Error(`Expected application/json but received ${res.headers['content-type']}.`)
}

if (err) {
console.log(err.message);
res.resume()
return
}

res.setEncoding("utf8")
res.on("data", c => data += c)
res.on("end", () => {
const latest_version = JSON.parse(data)[0]
if (compareVersions(latest_version.tag_name, app.getVersion()) === 1) {
dialog.showMessageBox(win, {type: 'question', buttons: ['OK', 'Cancel'], message: `Do you want to download it?\n\n Current version: ${app.getVersion()}\n Latest version: ${latest_version.tag_name}\n\n${latest_version.body}`}, (r) => {
if (!r) {
shell.openExternal(latest_version.html_url)
}
})
fetch("https://api.github.com/repos/tncga/whats-up-darkness/releases", {
headers: {
"user-agent": "Whats-Up-Darkness"
}
}).on("error", e => {
console.log(e.message)
})
})
.then(res => res.json())
.then(json => json["0"])
.then((latest_version) => {
if (compareVersions(latest_version.tag_name, app.getVersion()) === 1) {
dialog.showMessageBox(win, {type: 'question', buttons: ['OK', 'Cancel'], message: `Do you want to download it?\n\n Current version: ${app.getVersion()}\n Latest version: ${latest_version.tag_name}\n\n${latest_version.body}`}, (r) => {
if (!r) {
shell.openExternal(latest_version.html_url)
}
})
}
})
.catch(err => console.error(err))

// get({
// hostname: "api.github.com",
// path: "/repos/tncga/whats-up-darkness/releases",
// headers: {
// "user-agent": "Whats-Up-Darkness"
// }
// }, (res) => {
// let err, data = ""

// if (res.statusCode !== 200) {
// error = new Error(`Cannot retrieve version data (Status Code: ${res.statusCode}).`)
// } else if (!/^application\/json/.test(res.headers['content-type'])) {
// error = new Error(`Expected application/json but received ${res.headers['content-type']}.`)
// }

// if (err) {
// console.log(err.message);
// res.resume()
// return
// }

// res.setEncoding("utf8")
// res.on("data", c => data += c)
// res.on("end", () => {
// const latest_version = JSON.parse(data)[0]
// if (compareVersions(latest_version.tag_name, app.getVersion()) === 1) {
// dialog.showMessageBox(win, {type: 'question', buttons: ['OK', 'Cancel'], message: `Do you want to download it?\n\n Current version: ${app.getVersion()}\n Latest version: ${latest_version.tag_name}\n\n${latest_version.body}`}, (r) => {
// if (!r) {
// shell.openExternal(latest_version.html_url)
// }
// })
// }
// }).on("error", e => {
// console.log(e.message)
// })
// })

function createWindow() {
win = new BrowserWindow({
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"license": "MIT",
"dependencies": {
"compare-versions": "^3.3.1",
"node-fetch": "^2.3.0",
"usercss-meta": "^0.6.1"
},
"devDependencies": {
Expand Down

0 comments on commit d1f67b3

Please sign in to comment.