This repository has been archived by the owner on Dec 17, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
56 lines (52 loc) · 2.13 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
'use strict';
const { app, BrowserWindow, ipcMain } = require('electron');
app.setName('WeatherZ');
app.addListener('window-all-closed', () => { app.quit(); });
let mainWindow;
app.addListener('ready', () => {
mainWindow = new BrowserWindow({
width: require('electron').screen.getPrimaryDisplay().size.width * .64,
height: require('electron').screen.getPrimaryDisplay().size.height * .4,
center: true,
autoHideMenuBar: true,
webPreferences: { nodeIntegration: true }
});
mainWindow.loadFile("./pages/main.html");
});
// selected country, place and pair of them holder
// weatherForecast will hold an instance of WeatherData class, which will
// eventually keep record of weather for selected place
let currentCountrySelection, currentPlaceSelection, selectedPlace,
weatherForecast;
let isoToIso3Obj;
require('./iso_2_iso3')().then((value) => isoToIso3Obj = value,
(err) => console.log(err));
ipcMain.on('DOMContentLoaded',
(event) => require('./countryList')
.get.then((data) => event.reply('CountryList', data),
(err) => event.reply('CountryList', err)));
ipcMain.on('CountrySelectionChanged', (event, data) => {
currentCountrySelection = data; // selection gets changed
event.reply('UpdateBackground', isoToIso3Obj.getByISO(currentCountrySelection));
require('./placeList')
.get(currentCountrySelection)
.then((data) => event.reply('CountrySelectionChanged', data),
(err) => event.reply('CountrySelectionChanged', err));
});
ipcMain.on('AddPlace', (event, data) => {
currentPlaceSelection = data;
require('./weatherURL')
.get(currentCountrySelection, currentPlaceSelection)
.then(
(value) => {
selectedPlace = value;
require('./weatherQuery')(selectedPlace.url)
.then(
(resp) => {
weatherForecast = resp;
console.log(weatherForecast);
},
(err) => { console.log(err); });
},
(err) => { console.log(err); });
});