From d1f67b31dd16a8b0fa0593278d933f1a158d0d04 Mon Sep 17 00:00:00 2001 From: tncga Date: Wed, 12 Dec 2018 20:08:28 +0300 Subject: [PATCH] fix variable name --- main.js | 87 ++++++++++++++++++++++++++++++++-------------------- package.json | 1 + 2 files changed, 54 insertions(+), 34 deletions(-) diff --git a/main.js b/main.js index 2f7cd95..edd55d5 100644 --- a/main.js +++ b/main.js @@ -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) @@ -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({ diff --git a/package.json b/package.json index 05a7f0e..752a158 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,7 @@ "license": "MIT", "dependencies": { "compare-versions": "^3.3.1", + "node-fetch": "^2.3.0", "usercss-meta": "^0.6.1" }, "devDependencies": {