2024-06-17 08:06:32 +00:00
|
|
|
|
package main
|
|
|
|
|
|
|
|
|
|
import (
|
2024-07-10 01:35:14 +00:00
|
|
|
|
"crypto/tls"
|
2024-06-17 08:06:32 +00:00
|
|
|
|
"fmt"
|
2024-07-02 09:17:21 +00:00
|
|
|
|
"net/http"
|
2024-07-10 01:35:14 +00:00
|
|
|
|
"os"
|
2024-06-29 01:00:39 +00:00
|
|
|
|
// "sync"
|
|
|
|
|
// "time"
|
2024-06-21 18:38:41 +00:00
|
|
|
|
|
2024-06-29 01:00:39 +00:00
|
|
|
|
// "github.com/charmbracelet/bubbles/list"
|
2024-06-21 18:38:41 +00:00
|
|
|
|
tea "github.com/charmbracelet/bubbletea"
|
2024-06-29 01:00:39 +00:00
|
|
|
|
|
|
|
|
|
"github.com/emersion/go-webdav/caldav"
|
|
|
|
|
// "slices"
|
2024-06-21 18:38:41 +00:00
|
|
|
|
// "strconv"
|
2024-07-03 02:51:53 +00:00
|
|
|
|
// "github.com/charmbracelet/bubbles/list"
|
2024-06-21 18:38:41 +00:00
|
|
|
|
)
|
2024-06-17 08:06:32 +00:00
|
|
|
|
|
2024-07-10 01:35:14 +00:00
|
|
|
|
//TODO autoupdate?
|
|
|
|
|
//TODO predefined filters (missed tasks, upcoming important tasks, tasks without tag, tasks without priority)
|
|
|
|
|
//TODO custom filters
|
|
|
|
|
//TODO alarms
|
|
|
|
|
//TODO search in all tasks
|
|
|
|
|
|
2024-06-29 01:00:39 +00:00
|
|
|
|
// var waitGroup sync.WaitGroup
|
2024-06-17 08:06:32 +00:00
|
|
|
|
|
2024-06-19 19:27:13 +00:00
|
|
|
|
func errHandler(err error, message string) {
|
|
|
|
|
if err != nil {
|
2024-07-03 02:51:53 +00:00
|
|
|
|
//TODO double err!=nil
|
|
|
|
|
//TODO copy error to clipboard
|
2024-06-19 19:27:13 +00:00
|
|
|
|
fmt.Printf("\n\n%s: %s\n", message, err)
|
|
|
|
|
os.Exit(1)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-17 08:06:32 +00:00
|
|
|
|
func main() {
|
2024-07-10 01:35:14 +00:00
|
|
|
|
http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
|
2024-06-17 08:06:32 +00:00
|
|
|
|
options, err := ParseOptions()
|
|
|
|
|
errHandler(err, "Error parsing options")
|
2024-06-29 01:00:39 +00:00
|
|
|
|
m := InitModel()
|
2024-06-21 18:38:41 +00:00
|
|
|
|
|
|
|
|
|
// debugKeyring()
|
|
|
|
|
|
2024-06-29 01:00:39 +00:00
|
|
|
|
// err = storeCredentialsToKeyring("https://pkg.go.dev/encoding/base64#Encoding.EncodeToString", "casual", "h>ÕdzPlÇqQ+çCQ{ð±;Kм7¸Âhð~Ümy)v")
|
|
|
|
|
// errHandler(err, "Error parsing options:")
|
|
|
|
|
|
|
|
|
|
// if we provide login credentials via cli
|
|
|
|
|
var calendars []caldav.Calendar
|
|
|
|
|
if options.URL != "" {
|
|
|
|
|
err = options.InitDAVclients()
|
|
|
|
|
errHandler(err, "Unexpected error (we couldn't initiate WebDAV/CalDAV client)")
|
|
|
|
|
calendars, err = GetCalendars()
|
|
|
|
|
errHandler(err, "Error getting calendars (incorrect url/login/password)")
|
2024-07-10 01:35:14 +00:00
|
|
|
|
|
|
|
|
|
//TODO BUG crush START
|
2024-06-29 01:00:39 +00:00
|
|
|
|
var found bool
|
|
|
|
|
// var calPath string
|
2024-07-03 02:51:53 +00:00
|
|
|
|
if options.Calendar == "" {
|
|
|
|
|
m.LoginToCalendar()
|
|
|
|
|
// m.ActiveWindow = "login"
|
|
|
|
|
}
|
2024-06-29 01:00:39 +00:00
|
|
|
|
if options.Calendar != "" {
|
2024-07-10 01:35:14 +00:00
|
|
|
|
for _, calendar := range calendars {
|
2024-06-29 01:00:39 +00:00
|
|
|
|
if calendar.Name == options.Calendar {
|
|
|
|
|
found = true
|
|
|
|
|
// calPath = calendar.Path
|
|
|
|
|
m.Creds.CalendarPath = calendar.Path
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-07-10 01:35:14 +00:00
|
|
|
|
if !found {
|
2024-06-29 01:00:39 +00:00
|
|
|
|
fmt.Println("we don't have calendar ", options.Calendar, ". We have:")
|
2024-07-10 01:35:14 +00:00
|
|
|
|
for _, calendar := range calendars {
|
2024-06-29 01:00:39 +00:00
|
|
|
|
fmt.Println(calendar.Name)
|
|
|
|
|
}
|
|
|
|
|
os.Exit(1)
|
|
|
|
|
}
|
2024-07-02 09:17:21 +00:00
|
|
|
|
|
2024-07-03 02:51:53 +00:00
|
|
|
|
// fmt.Println(m)
|
2024-07-02 09:17:21 +00:00
|
|
|
|
m.LoginToCalendar()
|
2024-07-03 02:51:53 +00:00
|
|
|
|
m.CalendarToTodo()
|
2024-06-29 01:00:39 +00:00
|
|
|
|
|
2024-07-10 01:35:14 +00:00
|
|
|
|
//TODO BUG crush End
|
2024-06-29 01:00:39 +00:00
|
|
|
|
}
|
|
|
|
|
} else {
|
2024-07-10 01:35:14 +00:00
|
|
|
|
//TODO I'm on a highway to (IfElse) hell!
|
|
|
|
|
//TODO probably need to do more careful debug
|
2024-06-29 01:00:39 +00:00
|
|
|
|
creds, err := getCredentialsFromKeyring()
|
|
|
|
|
m.Creds = creds
|
|
|
|
|
if err != nil {
|
|
|
|
|
//we don't have saved credentials, go to login page
|
|
|
|
|
m.ActiveWindow = "login"
|
|
|
|
|
} else {
|
|
|
|
|
err = m.LoginToCalendar()
|
|
|
|
|
if err != nil {
|
|
|
|
|
//we have problem to auth! Go to relogin
|
|
|
|
|
//TODO say that there is a problem with login
|
|
|
|
|
m.ActiveWindow = "login"
|
|
|
|
|
} else {
|
|
|
|
|
err = m.GatherTodos()
|
|
|
|
|
if err != nil {
|
|
|
|
|
//we have problem to auth! Go to relogin
|
|
|
|
|
//TODO say that there is a problem with login
|
|
|
|
|
m.ActiveWindow = "login"
|
|
|
|
|
} else {
|
|
|
|
|
m.LoggedIn = true
|
|
|
|
|
m.ActiveWindow = "today"
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-07-10 01:35:14 +00:00
|
|
|
|
|
2024-06-29 01:00:39 +00:00
|
|
|
|
}
|
2024-06-17 08:06:32 +00:00
|
|
|
|
|
2024-07-10 01:35:14 +00:00
|
|
|
|
}
|
2024-06-21 18:38:41 +00:00
|
|
|
|
|
2024-06-29 01:00:39 +00:00
|
|
|
|
//DEBUG stuff
|
2024-07-02 09:17:21 +00:00
|
|
|
|
// task, err := CreateTodo("testName","description",3,time.Now())
|
|
|
|
|
// errHandler(err,"test fail")
|
|
|
|
|
// err = m.UploadTodo(task)
|
|
|
|
|
// errHandler(err,"test fail2")
|
2024-07-10 01:35:14 +00:00
|
|
|
|
// m.ActiveWindow = "addTODO"
|
2024-06-29 01:00:39 +00:00
|
|
|
|
//DEBUG stuff
|
2024-06-21 18:38:41 +00:00
|
|
|
|
|
2024-07-03 02:51:53 +00:00
|
|
|
|
//TODO if task have alarm - make a notification / play sound...
|
|
|
|
|
p := tea.NewProgram(m, tea.WithAltScreen()) //TODO DEBUG bring me back
|
2024-06-21 18:38:41 +00:00
|
|
|
|
if _, err := p.Run(); err != nil {
|
|
|
|
|
fmt.Println("Error running program:", err)
|
|
|
|
|
os.Exit(1)
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-29 01:00:39 +00:00
|
|
|
|
// fmt.Println(m.)
|
|
|
|
|
|
2024-06-21 18:38:41 +00:00
|
|
|
|
}
|