Skip to content

Commit

Permalink
code clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
jackd248 committed Oct 10, 2016
1 parent ee3d0b8 commit b1d5fec
Show file tree
Hide file tree
Showing 10 changed files with 392 additions and 373 deletions.
4 changes: 0 additions & 4 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,6 @@ <h1>
</div>
</div>

<script type="text/javascript" src="src/utils.js"></script>
<script type="text/javascript" src="src/store.js"></script>
<script type="text/javascript" src="src/timezone.js"></script>
<script type="text/javascript" src="src/weather.js"></script>
<script type="text/javascript" src="src/main.js"></script>
</body>
</html>
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"version": "0.6.0",
"icon": "assets/app.png",
"description": "A simple but smart menubar weather app",
"main": "app.js",
"main": "src/app.js",
"electronVersion": "1.4.2",
"keywords": [
"electron",
Expand Down
66 changes: 25 additions & 41 deletions app.js → src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ const ipcMain = electron.ipcMain
const shell = electron.shell
const superagent = require('superagent')
const semver = require('semver')
const config = require('./package.json')
const config = require('./../package.json')
const path = require('path')

let autoLaunch = true

Expand All @@ -30,9 +31,9 @@ app.on('will-quit', function () {
})

const mb = menubar({
index: 'file://' + __dirname + '/index.html',
icon: __dirname + '/assets/IconTemplate.png',
width: 280,
index: path.join('file://', __dirname, '/../index.html'),
icon: path.join(__dirname, '/../assets/IconTemplate.png'),
width: 580,
height: 480,
resizable: false,
'show-dock-icon': false,
Expand Down Expand Up @@ -65,9 +66,9 @@ mb.on('ready', function ready () {
mb.tray.setToolTip('temps')
mb.tray.setTitle('')
if (process.platform === 'darwin') {
mb.tray.setImage(__dirname + '/assets/IconTemplate.png')
mb.tray.setImage(path.join(__dirname, '/../assets/IconTemplate.png'))
} else {
mb.tray.setImage(__dirname + '/assets/icons/01dW.png')
mb.tray.setImage(path.join(__dirname, '/../assets/icons/01dW.png'))
}
})

Expand All @@ -76,9 +77,9 @@ mb.on('ready', function ready () {
mb.tray.setToolTip(args.location + ' - ' + temperature)
mb.tray.setTitle(temperature)
if (process.platform === 'darwin') {
mb.tray.setImage(__dirname + '/assets/icons/' + args.icon + 'Template.png')
mb.tray.setImage(path.join(__dirname, '/../assets/icons', args.icon + 'Template.png'))
} else {
mb.tray.setImage(__dirname + '/assets/icons/' + args.icon + 'W.png')
mb.tray.setImage(path.join(__dirname, '/../assets/icons', args.icon + 'W.png'))
}
})

Expand All @@ -92,8 +93,8 @@ mb.on('ready', function ready () {
})

ipcMain.on('auto-launch', function (event, args) {
// ToDo: appLauncher.isEnabled() not working for now
// console.log(appLauncher.isEnabled());
// ToDo: appLauncher.isEnabled() not working for now
// console.log(appLauncher.isEnabled());
if (autoLaunch) {
appLauncher.disable()
autoLaunch = false
Expand Down Expand Up @@ -125,7 +126,7 @@ appLauncher.isEnabled().then(function (enabled) {
if (enabled) return
return appLauncher.enable()
}).then(function (err) {

console.log(err)
})

appLauncher.enable()
Expand All @@ -134,10 +135,11 @@ appLauncher.enable()
const template = [{
label: 'Temps',
submenu: [
{ label: 'About Temps', selector: 'orderFrontStandardAboutPanel:' },
{ type: 'separator' },
{ label: 'Quit', accelerator: 'Command+Q', click: function () { app.quit() }}
]}, {
{ label: 'About Temps', selector: 'orderFrontStandardAboutPanel:' },
{ type: 'separator' },
{ label: 'Quit', accelerator: 'Command+Q', click: function () { app.quit() } }
]},
{
label: 'Edit',
submenu: [
{ label: 'Undo', accelerator: 'CmdOrCtrl+Z', selector: 'undo:' },
Expand Down Expand Up @@ -165,33 +167,15 @@ const template = [{
]}, {
label: 'Actions',
submenu: [
{ label: 'Details', accelerator: 'CmdOrCtrl+D', click: function (item, focusedWindow) {
if (focusedWindow) focusedWindow.webContents.send('toggle-details')
}
},
{ label: 'Settings', accelerator: 'CmdOrCtrl+S', click: function (item, focusedWindow) {
if (focusedWindow) focusedWindow.webContents.send('toggle-settings')
}
},
{ type: 'separator' },
{ label: 'Reload Data', accelerator: 'CmdOrCtrl+E', click: function (item, focusedWindow) {
if (focusedWindow) focusedWindow.webContents.send('reload-data')
}
},
{ label: 'Favorite City', accelerator: 'CmdOrCtrl+F', click: function (item, focusedWindow) {
if (focusedWindow) focusedWindow.webContents.send('favorite-city')
}
},
{
label: 'Randomn City', accelerator: 'CmdOrCtrl+W', click: function (item, focusedWindow) {
if (focusedWindow) focusedWindow.webContents.send('random-city')
}
},
{ label: 'Geolocation', accelerator: 'CmdOrCtrl+G', click: function (item, focusedWindow) {
if (focusedWindow) focusedWindow.webContents.send('geolocation')
}
{ label: 'Details', accelerator: 'CmdOrCtrl+D', click: function (item, focusedWindow) { if (focusedWindow) focusedWindow.webContents.send('toggle-details') } },
{ label: 'Settings', accelerator: 'CmdOrCtrl+S', click: function (item, focusedWindow) { if (focusedWindow) focusedWindow.webContents.send('toggle-settings') } },
{ type: 'separator' },
{ label: 'Reload Data', accelerator: 'CmdOrCtrl+E', click: function (item, focusedWindow) { if (focusedWindow) focusedWindow.webContents.send('reload-data') } },
{ label: 'Favorite City', accelerator: 'CmdOrCtrl+F', click: function (item, focusedWindow) { if (focusedWindow) focusedWindow.webContents.send('favorite-city') } },
{ label: 'Randomn City', accelerator: 'CmdOrCtrl+W', click: function (item, focusedWindow) { if (focusedWindow) focusedWindow.webContents.send('random-city') } },
{ label: 'Geolocation', accelerator: 'CmdOrCtrl+G', click: function (item, focusedWindow) { if (focusedWindow) focusedWindow.webContents.send('geolocation') } }
]
}
]}
]

const autoUpdater = function () {
Expand Down
25 changes: 21 additions & 4 deletions src/color.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,31 @@
const store = require('./store')
const utils = require('./utils')
const config = require('./config.json')

const jQuery = require('jquery')

let color = null

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) {
const getColor = function () {
return color
}

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

if (Store.getFormat() == 'metric') {
if (store.getFormat() === 'metric') {
if (temp > 30) {
setColor(colors[0])
} else if (temp > 26) {
Expand Down Expand Up @@ -54,3 +67,7 @@ const colorPalette = function (data) {
}
}
}

exports.setColor = setColor
exports.getColor = getColor
exports.colorPalette = colorPalette
44 changes: 0 additions & 44 deletions src/date.js

This file was deleted.

Loading

0 comments on commit b1d5fec

Please sign in to comment.