Starlio-web/api/controllers/startup.go

64 lines
1.5 KiB
Go
Raw Normal View History

2022-09-25 11:05:14 +03:00
package controllers
import (
"net/http"
"os"
"os/user"
"strings"
2022-10-02 12:22:05 +03:00
"github.com/Redume/EveryNasa/api/utils"
"github.com/Redume/EveryNasa/functions"
2022-09-25 11:05:14 +03:00
)
2022-10-02 12:22:05 +03:00
var Startup = func(w http.ResponseWriter, r *http.Request) {
startup := r.FormValue("startup")
if startup == "" {
utils.Respond(w, utils.Message(false, "All fields are required."))
return
}
if startup == "1" {
SetStartup(w, r)
} else if startup == "0" {
RemoveStartup(w, r)
} else {
utils.Respond(w, utils.Message(false, "Invalid field."))
return
}
}
2022-09-25 11:05:14 +03:00
var SetStartup = func(w http.ResponseWriter, r *http.Request) {
u, err := user.Current()
if err != nil {
functions.Logger(err.Error())
}
dir, err := os.Getwd()
if err != nil {
functions.Logger(err.Error())
}
dir = strings.Replace(dir, "\\", "\\\\", -1) + "\\EveryNasa.exe"
2022-10-02 12:22:05 +03:00
err = functions.CreateLnk(dir, strings.Replace(u.HomeDir, "\\", "\\\\", -1)+"\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\Startup\\EveryNasa.lnk")
2022-09-25 11:05:14 +03:00
if err != nil {
functions.Logger(err.Error())
}
utils.Respond(w, utils.Message(true, "The settings have been applied successfully."))
}
var RemoveStartup = func(w http.ResponseWriter, r *http.Request) {
u, err := user.Current()
if err != nil {
functions.Logger(err.Error())
}
err = os.Remove(strings.Replace(u.HomeDir, "\\", "\\\\", -1) + "\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\Startup\\EveryNasa.lnk")
if err != nil {
functions.Logger(err.Error())
}
utils.Respond(w, utils.Message(true, "The settings have been applied successfully."))
}