-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrenderer.js
More file actions
123 lines (90 loc) · 2.99 KB
/
Copy pathrenderer.js
File metadata and controls
123 lines (90 loc) · 2.99 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
const { shell, ipcRenderer } = require("electron");
const fs = require("fs");
const { json } = require("stream/consumers");
const path = require('path');
const configPath = path.join(__dirname, 'config.json');
const config = JSON.parse(
fs.readFileSync(configPath, 'utf-8')
);
// minimize and close buttons
document.getElementById('minimize-btn').addEventListener('click', () => {
ipcRenderer.send('minimize-window');
});
document.getElementById('close-btn').addEventListener('click', () => {
ipcRenderer.send('close-window');
});
function bindLink(id, url) {
const el = document.getElementById(id);
if (!el || !url) return;
el.addEventListener("click", () => {
shell.openExternal(url);
});
}
bindLink("notion", config.notion);
bindLink("rooster", config.rooster);
// clock
function updateClock() {
const now = new Date();
const time = now.toLocaleTimeString([], {
hour: '2-digit',
minute: '2-digit'
});
const date = now.toLocaleDateString([], {
weekday: 'short',
day: 'numeric',
month: 'short'
})
document.getElementById("clock").textContent = `Hi! It's ${time}\n${date}`;
}
updateClock(); //run once
setInterval(updateClock, 1000); // update every second
// froggy jump
let count = 0;
document.getElementById("frog").addEventListener("click", () => {
frog.classList.add("jump");
setTimeout(() => {
frog.classList.remove("jump");
}, 150);
});
//get weather code from open-meteo api
function getWeatherText(code) {
if (code === 0) return "☀️";
if (code < 3) return "🌤️";
if (code < 50) return "☁️";
if (code < 70) return "🌧️";
return "⛈️";
}
// Weather apeldoorn
const latApeldoorn = 52.21;
const lonApeldoorn = 5.97;
fetch(
`https://api.open-meteo.com/v1/forecast?latitude=${latApeldoorn}&longitude=${lonApeldoorn}¤t_weather=true`,
)
.then((res) => res.json())
.then((data) => {
const tempApeldoorn = data.current_weather.temperature;
const windApeldoorn = data.current_weather.windspeed;
const codeApeldoorn = data.current_weather.weathercode;
const weatherTextApeldoorn = getWeatherText(codeApeldoorn);
document.getElementById("weather-apeldoorn").textContent =
`${weatherTextApeldoorn}`;
document.getElementById("temp-apeldoorn").textContent =
`${tempApeldoorn} C°`
});
// Weather Utrecht
const latUtrecht = 52.09;
const lonUtrecht = 5.12;
fetch(
`https://api.open-meteo.com/v1/forecast?latitude=${latUtrecht}&longitude=${lonUtrecht}¤t_weather=true`,
)
.then((res) => res.json())
.then((data) => {
const tempUtrecht = data.current_weather.temperature;
const windUtrecht = data.current_weather.windspeed;
const codeUtrecht = data.current_weather.weathercode;
const weatherTextUtrecht = getWeatherText(codeUtrecht);
document.getElementById("weather-utrecht").textContent =
`${weatherTextUtrecht}`;
document.getElementById("temp-utrecht").textContent =
`${tempUtrecht} C°`
});