Delete functions directory

This commit is contained in:
Данил 2022-11-02 20:53:23 +03:00 committed by GitHub
parent b02a34b366
commit 605bb1a246
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 0 additions and 355 deletions

View file

@ -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
}

View file

@ -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
}

View file

@ -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())
}
}
}

View file

@ -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
}

View file

@ -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
}

View file

@ -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()
}
}