Skip to content

Commit

Permalink
added notifications about new releases + fix manual location search +…
Browse files Browse the repository at this point in the history
… win10 minor bug fixed
  • Loading branch information
Stachuu87 committed Feb 1, 2018
1 parent ad46f06 commit db09e8f
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 56 deletions.
3 changes: 2 additions & 1 deletion app/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ let settings = {
updates: 2*60*60*1000
},
environment: 'production',
updateUrl:'https://api.github.com/Stachuu87/winair/releases'
updateUrl:'https://api.github.com/repos/Stachuu87/winair/releases',
downloadUpdateUrl: 'https://github.com/Stachuu87/WinAir/releases'
}

module.exports = settings;
6 changes: 3 additions & 3 deletions app/main.html → main.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
<script>require('electron-react-devtools').install()</script>
<title>WinAir - monitor jakości powietrza</title>
<meta charset="UTF-8">
<link rel="stylesheet" href="./../assets/material/dist/material.min.css">
<link rel="stylesheet" href="./../dist/css/main.css">
<link rel="stylesheet" href="./assets/material/dist/material.min.css">
<link rel="stylesheet" href="./dist/css/main.css">
</head>
<body class="dark-theme">
<div id="root"></div>
<script src="./../dist/js/main.js"></script>
<script src="./dist/js/main.js"></script>

</body>
</html>
47 changes: 23 additions & 24 deletions app/main.js → main.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const electron = require('electron');
const {app, Menu, BrowserWindow, Tray, globalShortcut, ipcMain} = require('electron');
const apikeys = require('./keys');
const messages = require('./messages');
const balloonNotifications = require('./balloonNotifications');
const settings = require('./settings');
const {app, Menu, BrowserWindow, Tray, globalShortcut, ipcMain, shell} = require('electron');
const apikeys = require('./app/keys');
const messages = require('./app/messages');
const balloonNotifications = require('./app/balloonNotifications');
const settings = require('./app/settings');

let tray = null;
let window = null;
Expand All @@ -22,38 +22,42 @@ app.on('ready', () => {

const {screen} = require('electron');

tray = new Tray(`${__dirname}/../assets/icons/icon.ico`);
window = new BrowserWindow({show: false, frame: frames, resizable: false, width: windowW, height: windowH, x:x, y:y, alwaysOnTop: false, minimizable: true});
tray = new Tray(`${__dirname}/assets/icons/icon.ico`);
window = new BrowserWindow({show: false, frame: frames, resizable: false, width: windowW, height: windowH, maxHeight:550, maxWidth:350, x:x, y:y, alwaysOnTop: false, minimizable: true});
window.loadURL(`file://${__dirname}/main.html`);

ipcMain.on('response:quality', function(e, item){
ipcMain.on('response:quality', (e, item) => {
airQuality = item;
setIcons();
displayBalloonNotification();
lastQual = airQuality;
});

function setIcons() {
ipcMain.on('updatenLink:clicked', (e, link) => {
shell.openExternal(link);
});

setIcons = () => {
if (airQuality == 0) {
tray.setImage(`${__dirname}/../assets/icons/icon.ico`, messages.noData);
tray.setImage(`${__dirname}/assets/icons/icon.ico`, messages.noData);
window.setOverlayIcon(null, messages.noData);
tray.setToolTip(messages.noData);
} else if (airQuality <= 2) {
tray.setImage(`${__dirname}/../assets/icons/green.ico`);
window.setOverlayIcon(`${__dirname}/../assets/icons/green.ico`, messages.goodQual);
tray.setImage(`${__dirname}/assets/icons/green.ico`);
window.setOverlayIcon(`${__dirname}/assets/icons/green.ico`, messages.goodQual);
tray.setToolTip(messages.goodQual);
} else if(airQuality <= 4) {
tray.setImage(`${__dirname}/../assets/icons/yellow.ico`);
window.setOverlayIcon(`${__dirname}/../assets/icons/yellow.ico`, messages.mediumQual);
tray.setImage(`${__dirname}/assets/icons/yellow.ico`);
window.setOverlayIcon(`${__dirname}/assets/icons/yellow.ico`, messages.mediumQual);
tray.setToolTip(messages.mediumQual);
} else {
tray.setImage(`${__dirname}/../assets/icons/red.ico`);
window.setOverlayIcon(`${__dirname}/../assets/icons/red.ico`, messages.lowQual);
tray.setImage(`${__dirname}/assets/icons/red.ico`);
window.setOverlayIcon(`${__dirname}/assets/icons/red.ico`, messages.lowQual);
tray.setToolTip(messages.lowQual);
};
};

function displayBalloonNotification() {
displayBalloonNotification = () => {
if(lastQual == 0) {
setBalloonContent(balloonNotifications.title, balloonNotifications.dataReceived);
} else if(airQuality == 0) {
Expand All @@ -62,11 +66,11 @@ app.on('ready', () => {
}
}

function setBalloonContent(title, content) {
setBalloonContent = (title, content) => {
tray.displayBalloon({title: title, content: content});
}

function setWindowPosition() {
setWindowPosition = () => {
let cursorPosition = electron.screen.getCursorScreenPoint()
let display = electron.screen.getDisplayNearestPoint(cursorPosition)
const {width, height} = display.workAreaSize;
Expand All @@ -86,10 +90,6 @@ app.on('ready', () => {
}
]);

const mainMenu = Menu.buildFromTemplate([
{}
])

tray.setToolTip(messages.noData);
tray.setContextMenu(contextMenu);

Expand All @@ -105,7 +105,6 @@ app.on('ready', () => {
});

if(process.env.NODE_ENV === 'production') {
window.setMenu(mainMenu);
app.setLoginItemSettings({
openAtLogin: true
})
Expand Down
10 changes: 5 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
{
"name": "WinAir",
"version": "0.1.0",
"version": "0.1.1",
"description": "",
"main": "./app/main.js",
"main": "main.js",
"scripts": {
"windows": "electron-packager . WinAir --overwrite --asar=true --platform=win32 --arch=ia32 --icon=assets/icons/icon.ico --prune=true --out=release-builds --version-string.CompanyName=CE --version-string.FileDescription=CE --version-string.ProductName=\"WinAir\"",
"start": "webpack && electron ."
},
"author": "Piotr Stanisławski",
"license": "ISC",
"repository": {
"type": "git",
"url": "https://github.com/Stachuu87/WinAir"
},
"dependencies": {
"electron": "^1.7.11"
},
Expand Down
7 changes: 6 additions & 1 deletion src/js/searchBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,13 @@ class SearchBar extends Component {
}
}

catchLocationName(e) {
this.setState({
locationName: e.target.value
})
}

handleSearchFormSubmit(e) {
console.log(e);
e.preventDefault();
fetch(`https://maps.googleapis.com/maps/api/geocode/json?address=${this.state.locationName}&key=${apikeys.googleMan}`)
.then(res => res.json())
Expand Down
47 changes: 27 additions & 20 deletions src/js/topBar.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import React, {Component} from "react";
import { clearInterval } from "timers";
import { clearInterval, setTimeout } from "timers";
const electron = require('electron');
const {ipcRenderer} = require('electron');

const version = require('../../package.json').version;
const settings = require('../../app/settings.js');

Expand All @@ -18,6 +21,7 @@ class TopBar extends Component {
presentVersion: version,
latestVersion: version
})

this.checkConnection();
this.checkForUpdates();
var checkConnection = setInterval(() => {
Expand All @@ -32,6 +36,7 @@ class TopBar extends Component {
componentWillUnmount() {
clearInterval(this.checkConnection);
clearInterval(this.checkUpdates);
clearTimeout(this.delayChecks);
}

checkConnection() {
Expand All @@ -53,37 +58,39 @@ class TopBar extends Component {
.then(res => res.json())
.then(
(result) => {
console.log(result);
if(result.status == '200') {

result.sort(function(a, b) {
if(result[0]) {
result.sort((a, b) => {
return b.id - a.id
});
this.setState({
latestVersion: result[0].tag_name
}, this.notifyUpdate());
}, this.notifyUpdate);
} else {
this.setState({
latestVersion: this.state.presentVersion
}, this.notifyUpdate());
}, this.notifyUpdate);
}
},
(error) => {
}
)
}
)
}

notifyUpdate() {
if (this.state.latestVersion != this.state.presentVersion) {
this.setState({
updateAvailable: true
})
} else {
this.setState({
updateAvailable: false
})
}
notifyUpdate() {
if (this.state.latestVersion != this.state.presentVersion) {
this.setState({
updateAvailable: true
})
} else {
this.setState({
updateAvailable: false
})
}
}

handleUpdateLinkClick() {
ipcRenderer.send('updatenLink:clicked', settings.downloadUpdateUrl);
}

render () {
if(!this.state.updateAvailable) {
Expand All @@ -92,7 +99,7 @@ class TopBar extends Component {
)
} else {
return (
<div className={this.state.className}><i className="icon-cloud"></i> WinAir <a href="https://github.com/Stachuu87/WinAir/releases" target="_blank" className="c-topbar__update">Pobierz nową wersję <i className="icon-file-download"></i></a></div>
<div className={this.state.className}><i className="icon-cloud"></i> WinAir <a onClick={this.handleUpdateLinkClick} target="_blank" className="c-topbar__update">Pobierz nową wersję <i className="icon-file-download"></i></a></div>
)
}

Expand Down

0 comments on commit db09e8f

Please sign in to comment.