Skip to content
This repository has been archived by the owner on Nov 25, 2021. It is now read-only.

Commit

Permalink
auto updater
Browse files Browse the repository at this point in the history
  • Loading branch information
jackd248 committed Sep 25, 2016
1 parent 1bbc4c1 commit c08d3cf
Show file tree
Hide file tree
Showing 6 changed files with 167 additions and 26 deletions.
35 changes: 35 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ var globalShortcut = electron.globalShortcut
var AutoLaunch = require('auto-launch')
var menubar = require('menubar')
var Menu = electron.Menu
var dialog = electron.dialog
var ipcMain = electron.ipcMain
var shell = electron.shell
const superagent = require('superagent')
const semver = require('semver')
const config = require('./package.json')

var autoLaunch = true

Expand Down Expand Up @@ -37,6 +42,8 @@ var mb = menubar({

mb.on('ready', function ready () {

autoUpdater()

// ToDo: Not working anymore with electron 1.4
// mb.window.openDevTools();

Expand Down Expand Up @@ -178,3 +185,31 @@ var template = [{
}
]}
]

const autoUpdater = function() {
superagent
.get('https://raw.githubusercontent.com/jackd248/temps/master/package.json')
.end(function (err, res) {
if (err || !res.ok) {
console.log(err)
} else {
try {
const newVersion = JSON.parse(res.text).version
const oldVersion = config.version
if (semver.gt(newVersion, oldVersion)) {
const confirm = dialog.showMessageBox({
type: 'info',
message: 'A new version ' + newVersion + ' of Temps is available.',
detail: 'Do you want to download it now?',
buttons: ['Yes', 'No']
})
if (confirm === 0) {
shell.openExternal('https://github.com/jackd248/temps/releases')
}
}
} catch(err) {
console.log(err)
}
}
})
}
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@
"package:win64": "electron-builder dist/Temps-win32-x64/ --platform=win --out=dist --config=config.json && mv 'dist/Temps Setup.exe' dist/Temps_Windows64.exe",
"package:win32": "electron-builder dist/Temps-win32-ia32/ --platform=win --out=dist --config=config.json && mv 'dist/Temps Setup.exe' dist/Temps_Windows32.exe",
"package:osx": "hdiutil create -format UDZO -srcfolder dist/Temps-darwin-x64/Temps.app dist/Temps_Mac.dmg",
"package:linux": "cd dist/ && zip -r Temps_Linux_x64.zip Temps-linux-x64 && zip -r Temps_Linux_ia32.zip Temps-linux-ia32 && cd ../",
"test": "npm run lint",
"lint": "standard --fix"
"package:linux": "cd dist/ && zip -r Temps_Linux_x64.zip Temps-linux-x64 && zip -r Temps_Linux_ia32.zip Temps-linux-ia32 && cd ../"
},
"author": "Konrad Michalik <[email protected]>",
"license": "MIT",
Expand Down Expand Up @@ -57,6 +55,8 @@
"json-storage": "^2.1.1",
"localStorage": "^1.0.3",
"chart.js": "^2.2.1",
"countup.js": "^1.7.1"
"countup.js": "^1.7.1",
"semver": "^5.1.0",
"superagent": "^2.0.0"
}
}
56 changes: 56 additions & 0 deletions src/color.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
const setColor = function (c) {
color = c
jQuery('#main').css('background-color', c)
jQuery('.spinner > div').css('background-color', c)
}

const colorPalette = function (data) {
if (data[0].cod == 404) {
setColor('#444444')
return
}
var temp = roundTemp(data[0].main.temp)
var colors = config.colors

if (Store.getFormat() == 'metric') {
if (temp > 30) {
setColor(colors[0])
} else if (temp > 26) {
setColor(colors[1])
} else if (temp > 22) {
setColor(colors[2])
} else if (temp > 18) {
setColor(colors[3])
} else if (temp > 14) {
setColor(colors[4])
} else if (temp > 10) {
setColor(colors[5])
} else if (temp > 6) {
setColor(colors[6])
} else if (temp > 2) {
setColor(colors[7])
} else {
setColor(colors[8])
}
} else {
if (temp > 86) {
setColor(colors[0])
} else if (temp > 78) {
setColor(colors[1])
} else if (temp > 71) {
setColor(colors[2])
} else if (temp > 64) {
setColor(colors[3])
} else if (temp > 57) {
setColor(colors[4])
} else if (temp > 50) {
setColor(colors[5])
} else if (temp > 42) {
setColor(colors[6])
} else if (temp > 35) {
setColor(colors[7])
} else {
setColor(colors[8])
}
}
}
44 changes: 44 additions & 0 deletions src/date.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
const months = ['jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug', 'sep', 'oct', 'nov', 'dec']

const getTodayDay = function () {
var days = [
'sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'
]
var date = getDate(new Date())
return days[(date.getDay())]
}

const getTodayDate = function () {
var date = getDate(new Date())
return getTodayDay() + ', ' + months[date.getMonth()] + ' ' + date.getDate()
}

const addZero = function (i) {
if (i < 10) {
i = '0' + i
}
return i
}

const getTime = function () {
var dt = getDate(new Date())
return dt.getHours() + ':' + addZero(dt.getMinutes())
}

const getStyledDate = function (num) {
var days = [
'mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun'
]
var date = new Date()
return days[(date.getDay() + num) % 7]
}

const showDate = function () {
jQuery('#details .header .date').html(getTodayDate())
jQuery('#main .clock').html(getTime())
var clock = setInterval(function ()
{
refreshClock()
}, 60000)
}

3 changes: 2 additions & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,11 @@ var startLoading = function () {
loading[0] = true
loading[1] = true
loading[2] = true
loading[3] = true
}

var checkLoading = function () {
if (!loading[0] && !loading[1] && !loading[2]) {
if (!loading[0] && !loading[1] && !loading[2] && !loading[3]) {
jQuery('.spinner').fadeOut()
}
}
Expand Down
47 changes: 26 additions & 21 deletions src/weather.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,28 @@
function getWeather (url, city, option, callback) {
jQuery.get(url + '&q=' + city + '&units=' + getFormat() + '&appid=' + getApiKey(), function (weatherdata) {
console.log(weatherdata)
wdata[option] = weatherdata
}).done(function () {
loading[option] = false
checkLoading()
if (wdata[option].cod != 404) {
setCity(city)
if (callback && typeof (callback) === 'function') {
callback()
}
} else {
showErrorMessage(wdata[option].message)
}
}).fail(function (xhr, statusText) {
showErrorMessage('Failure during data fetching')
console.log(xhr)
console.log(statusText)
})
const superagent = require('superagent')

const getWeather = function (url, city, option, callback) {
superagent
.get(url)
.query({q: city})
.query({units: getFormat()})
.query({appid: getApiKey()})
.end(function (err, res) {
if (err || !res.ok) {
showErrorMessage('Failure during data fetching')
} else {
wdata[option] = res.body
loading[option] = false
checkLoading
if (wdata[option].cod != 404) {
setCity(city)
if (callback && typeof (callback) === 'function') {
callback()
}
} else {
showErrorMessage(wdata[option].message)
}
}
})
}

var refreshInfo = function () {
Expand Down Expand Up @@ -107,6 +112,7 @@ var showHourlyWeatherData = function () {
var wrap = jQuery('#details .hourly #canvas-holder')
wrap.html('<canvas id="chart" width="280" height="100"></canvas>')
var c = jQuery('#details .hourly #canvas-holder #chart')
jQuery('#details .hourly #chartjs-tooltip').html()
var d = []
var e = []
var max = 0
Expand Down Expand Up @@ -151,7 +157,6 @@ var showHourlyWeatherData = function () {
e.push(icon)
}
}
console.log(d)

var format = (getFormat() == 'metric') ? '°C' : '°F'

Expand Down

0 comments on commit c08d3cf

Please sign in to comment.