-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
90 lines (80 loc) · 2.3 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
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
const path = require("path")
const fs = require("fs")
const util = require("util")
const envPaths = require("fix-esm").require("env-paths").default
const ical = require("ical")
const { Temporal, toTemporalInstant } = require("@js-temporal/polyfill")
const { app, BrowserWindow } = require("electron")
const paths = envPaths("local")
class Account {
constructor(dir, id) {
this.id = id
this.calendars = []
const calendars = fs.readdirSync(dir)
for (const calendar of calendars) {
this.calendars.push(
new Calendar(path.join(dir, calendar), calendar)
)
}
}
}
class Calendar {
constructor(dir, id) {
this.id = id
const files = fs.readdirSync(dir)
if (files.includes("displayname"))
this.displayName = fs
.readFileSync(path.join(dir, "displayname"))
.toString()
if (files.includes("color"))
this.color = fs.readFileSync(path.join(dir, "color")).toString()
this.events = []
for (const file of files) {
if (!file.endsWith(".ics")) continue
const parsed = ical.parseFile(path.join(dir, file))
for (const item in parsed) {
this.events.push(processItem(parsed[item]))
}
}
}
}
function processItem(item) {
switch (item.type) {
case "VEVENT":
return new Event(item)
}
}
class Event {
constructor(event) {
this.raw = event
this.start = processDate(event.start)
this.end = processDate(event.end)
this.uid = event.uid
this.summary = event.summary
}
}
function processDate(date) {
const timeZone = date.tz
return toTemporalInstant
.call(date)
.toZonedDateTimeISO(timeZone || "Etc/UTC")
}
const config = JSON.parse(
fs.readFileSync(path.join(paths.config, "config.json")).toString()
)
const accounts = []
const accountPaths = config.accounts
for (const account in accountPaths) {
accounts.push(new Account(accountPaths[account], account))
}
console.log(util.inspect(accounts, { depth: 5 }))
function createWindow() {
const win = new BrowserWindow({
width: 800,
height: 600,
})
win.loadFile("index.html")
}
app.whenReady().then(() => {
createWindow()
})