From 605bb1a246273b51bd94d62e6ced70f0dd9e05c5 Mon Sep 17 00:00:00 2001 From: Redume Date: Wed, 2 Nov 2022 20:53:23 +0300 Subject: [PATCH] Delete functions directory --- functions/connect.go | 11 ----- functions/createLnk.go | 55 --------------------- functions/database.go | 44 ----------------- functions/logger.go | 71 --------------------------- functions/tray.go | 66 ------------------------- functions/wallpaper.go | 108 ----------------------------------------- 6 files changed, 355 deletions(-) delete mode 100644 functions/connect.go delete mode 100644 functions/createLnk.go delete mode 100644 functions/database.go delete mode 100644 functions/logger.go delete mode 100644 functions/tray.go delete mode 100644 functions/wallpaper.go diff --git a/functions/connect.go b/functions/connect.go deleted file mode 100644 index 8e955d3..0000000 --- a/functions/connect.go +++ /dev/null @@ -1,11 +0,0 @@ -package functions - -import "net/http" - -func Connected() (ok bool) { - _, err := http.Get("http://clients3.google.com/generate_204") - if err != nil { - return false - } - return true -} diff --git a/functions/createLnk.go b/functions/createLnk.go deleted file mode 100644 index 1ba2ed0..0000000 --- a/functions/createLnk.go +++ /dev/null @@ -1,55 +0,0 @@ -package functions - -import ( - "os" - - "github.com/go-ole/go-ole" - "github.com/go-ole/go-ole/oleutil" -) - -func CreateLnk(src, dst string) error { - err := ole.CoInitializeEx(0, ole.COINIT_APARTMENTTHREADED|ole.COINIT_SPEED_OVER_MEMORY) - if err != nil { - Logger(err.Error()) - } - - oleShellObject, err := oleutil.CreateObject("WScript.Shell") - if err != nil { - Logger(err.Error()) - } - - defer oleShellObject.Release() - wshell, err := oleShellObject.QueryInterface(ole.IID_IDispatch) - if err != nil { - Logger(err.Error()) - } - - defer wshell.Release() - cs, err := oleutil.CallMethod(wshell, "CreateShortcut", dst) - if err != nil { - Logger(err.Error()) - } - - idispatch := cs.ToIDispatch() - _, err = oleutil.PutProperty(idispatch, "TargetPath", src) - if err != nil { - Logger(err.Error()) - } - - dir, err := os.Getwd() - if err != nil { - Logger(err.Error()) - } - - _, err = oleutil.PutProperty(idispatch, "WorkingDirectory", dir) - if err != nil { - Logger(err.Error()) - } - - _, err = oleutil.CallMethod(idispatch, "Save") - if err != nil { - Logger(err.Error()) - } - - return nil -} diff --git a/functions/database.go b/functions/database.go deleted file mode 100644 index 26c836c..0000000 --- a/functions/database.go +++ /dev/null @@ -1,44 +0,0 @@ -package functions - -import ( - "database/sql" - - _ "github.com/mattn/go-sqlite3" -) - -func Database() { - db, err := sql.Open("sqlite3", "EveryNasa.db") - if err != nil { - Logger(err.Error()) - } - - var existsSettings bool - err = db.QueryRow("SELECT EXISTS(SELECT name FROM sqlite_master WHERE type='table' AND name='settings')").Scan(&existsSettings) - - if err != nil { - Logger(err.Error()) - } - - if existsSettings == false { - sqlTable := ` - CREATE TABLE IF NOT EXISTS settings ( - startup INTEGER DEFAULT 0, - wallpaper INTEGER DEFAULT 0 - );` - - _, err = db.Exec(sqlTable) - if err != nil { - Logger(err.Error()) - } - - stmt, err := db.Prepare("INSERT INTO settings(startup, wallpaper) values(?,?)") - if err != nil { - Logger(err.Error()) - } - - _, err = stmt.Exec(0, 0) - if err != nil { - Logger(err.Error()) - } - } -} diff --git a/functions/logger.go b/functions/logger.go deleted file mode 100644 index 3f25309..0000000 --- a/functions/logger.go +++ /dev/null @@ -1,71 +0,0 @@ -package functions - -import ( - "fmt" - "os" - "runtime" - "strings" - "time" -) - -func Logger(text string) { - if !FileExists("logger.log") { - err := CreateFile("logger.log") - if err != nil { - panic(err) - } - } - f, err := os.OpenFile("logger.log", os.O_APPEND|os.O_WRONLY, 0600) - if err != nil { - panic(err) - } - now := time.Now() - - _, file, line, ok := runtime.Caller(1) - - if !ok { - file = "???" - } - - dir, err := os.Getwd() - if err != nil { - Logger(err.Error()) - } - - if strings.Contains(file, dir) { - file = strings.Replace(file, dir, "", -1) - } - - var lineString string - if ok { - lineString = fmt.Sprintf("%d", line) - } - - _, err = f.Write([]byte(now.Format("Mon Jan 2 15:04:05 2006") + " | " + text + " [" + file + "] [" + lineString + "]\n")) - if err != nil { - panic(err) - } -} - -func FileExists(name string) bool { - if _, err := os.Stat(name); err != nil { - if os.IsNotExist(err) { - return false - } - } - return true -} - -func CreateFile(name string) error { - fo, err := os.Create(name) - if err != nil { - return err - } - defer func() { - err := fo.Close() - if err != nil { - return - } - }() - return nil -} diff --git a/functions/tray.go b/functions/tray.go deleted file mode 100644 index a0a27e6..0000000 --- a/functions/tray.go +++ /dev/null @@ -1,66 +0,0 @@ -package functions - -import ( - "fmt" - "os" - - "github.com/getlantern/systray" - "github.com/shirou/gopsutil/v3/process" - "github.com/skratchdot/open-golang/open" -) - -func Tray() { - systray.SetIcon(GetIcon("web/static/image/icons/icon.ico")) - systray.SetTitle("EveryNasa") - systray.SetTooltip("EveryNasa") - ui := systray.AddMenuItem("Open UI", "Open UI") - exit := systray.AddMenuItem("Quit", "Quit the whole app") - - for { - select { - case <-ui.ClickedCh: - err := open.Run("http://localhost:3000") - if err != nil { - Logger(err.Error()) - } - case <-exit.ClickedCh: - Quit() - } - } -} - -func Quit() { - err := KillProcess("EveryNasa.exe") - if err != nil { - Logger(err.Error()) - } - - systray.Quit() -} - -func KillProcess(name string) error { - processes, err := process.Processes() - if err != nil { - Logger(err.Error()) - } - - for _, p := range processes { - n, err := p.Name() - if err != nil { - Logger(err.Error()) - } - - if n == name { - return p.Kill() - } - } - return fmt.Errorf("process not found") -} - -func GetIcon(s string) []byte { - b, err := os.ReadFile(s) - if err != nil { - Logger(err.Error()) - } - return b -} diff --git a/functions/wallpaper.go b/functions/wallpaper.go deleted file mode 100644 index f376b41..0000000 --- a/functions/wallpaper.go +++ /dev/null @@ -1,108 +0,0 @@ -package functions - -import ( - "encoding/json" - "time" - - "github.com/jasonlvhit/gocron" - "github.com/reujab/wallpaper" - "github.com/rodkranz/fetch" -) - -func GetWallpaper(date string) string { - type WallpaperStruct struct { - Hdurl string `json:"hdurl"` - Url string `json:"url"` - Media_type string `json:"media_type"` - } - - client := fetch.NewDefault() - res, err := client.Get("https://api.nasa.gov/planetary/apod?api_key=1gI9G84ZafKDEnrbydviGknReOGiVK9jqrQBE3et&date="+ - date, - nil) - if err != nil { - Logger(err.Error()) - } - - body, err := res.ToString() - if err != nil { - Logger(err.Error()) - } - - var Wallpaper WallpaperStruct - err = json.Unmarshal([]byte(body), &Wallpaper) - if err != nil { - Logger(err.Error()) - } - - if Wallpaper.Media_type == "video" { - return "https://img.youtube.com/vi/" + Wallpaper.Url[30:41] + "/maxresdefault.jpg" - } - - return Wallpaper.Hdurl -} - -func SetWallpaper() { - times := time.Now() - t := time.Date(times.Year(), - times.Month(), - times.Day(), - times.Hour(), - times.Minute(), - times.Second(), - times.Nanosecond(), - time.UTC) - - err := wallpaper.SetFromURL(GetWallpaper(t.Format("2006-01-02"))) - if err != nil { - t = t.AddDate(0, 0, -1) - err = wallpaper.SetFromURL(GetWallpaper(t.Format("2006-01-02"))) - if err != nil { - Logger(err.Error()) - } - } -} - -func StartWallpaper() { - type Autostart struct { - Wallpaper int `json:"wallpaper"` - } - - client := fetch.NewDefault() - res, err := client.Get("http://localhost:3000/api/get/settings", nil) - if err != nil { - Logger(err.Error()) - } - - body, err := res.ToString() - if err != nil { - Logger(err.Error()) - } - - var AutostartSetWallpaper Autostart - err = json.Unmarshal([]byte(body), &AutostartSetWallpaper) - if err != nil { - Logger(err.Error()) - } - - if AutostartSetWallpaper.Wallpaper == 1 { - times := time.Now() - t := time.Date(times.Year(), - times.Month(), - times.Day(), - 4, - 50, - times.Second(), - times.Nanosecond(), - time.UTC) - - SetWallpaper() - - err = gocron.Every(1).Day().From(&t).Do(SetWallpaper) - if err != nil { - Logger(err.Error()) - } - - gocron.Start() - } -}