2022-09-25 11:05:14 +03:00
|
|
|
package controllers
|
|
|
|
|
|
|
|
import (
|
2022-10-23 15:27:36 +03:00
|
|
|
"github.com/gofiber/fiber/v2"
|
2022-09-25 11:05:14 +03:00
|
|
|
"os"
|
|
|
|
"os/user"
|
|
|
|
"strings"
|
2022-10-02 12:22:05 +03:00
|
|
|
|
2023-03-18 16:40:05 +03:00
|
|
|
"github.com/Redume/EveryNasa/utils"
|
2022-09-25 11:05:14 +03:00
|
|
|
)
|
|
|
|
|
2022-10-23 15:27:36 +03:00
|
|
|
var Startup = func(c *fiber.Ctx) error {
|
|
|
|
startup := c.FormValue("startup")
|
2022-10-02 12:22:05 +03:00
|
|
|
if startup == "" {
|
2022-10-23 15:27:36 +03:00
|
|
|
utils.Respond(c, utils.Message(false, "All fields are required."))
|
|
|
|
return nil
|
2022-10-02 12:22:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if startup == "1" {
|
2022-10-23 15:27:36 +03:00
|
|
|
SetStartup(c)
|
2022-10-02 12:22:05 +03:00
|
|
|
} else if startup == "0" {
|
2022-10-23 15:27:36 +03:00
|
|
|
RemoveStartup(c)
|
2022-10-02 12:22:05 +03:00
|
|
|
} else {
|
2022-10-23 15:27:36 +03:00
|
|
|
utils.Respond(c, utils.Message(false, "Invalid field."))
|
|
|
|
return nil
|
2022-10-02 12:22:05 +03:00
|
|
|
}
|
2022-10-23 15:27:36 +03:00
|
|
|
|
|
|
|
return nil
|
2022-10-02 12:22:05 +03:00
|
|
|
}
|
|
|
|
|
2022-10-23 15:27:36 +03:00
|
|
|
var SetStartup = func(c *fiber.Ctx) error {
|
2022-09-25 11:05:14 +03:00
|
|
|
u, err := user.Current()
|
|
|
|
if err != nil {
|
2023-03-18 16:40:05 +03:00
|
|
|
utils.Logger(err.Error())
|
2022-09-25 11:05:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
dir, err := os.Getwd()
|
|
|
|
if err != nil {
|
2023-03-18 16:40:05 +03:00
|
|
|
utils.Logger(err.Error())
|
2022-09-25 11:05:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
dir = strings.Replace(dir, "\\", "\\\\", -1) + "\\EveryNasa.exe"
|
|
|
|
|
2023-03-18 16:40:05 +03:00
|
|
|
err = utils.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 {
|
2023-03-18 16:40:05 +03:00
|
|
|
utils.Logger(err.Error())
|
2022-09-25 11:05:14 +03:00
|
|
|
}
|
|
|
|
|
2022-10-23 15:27:36 +03:00
|
|
|
utils.Respond(c, utils.Message(true, "The settings have been applied successfully."))
|
|
|
|
return nil
|
2022-09-25 11:05:14 +03:00
|
|
|
}
|
|
|
|
|
2022-10-23 15:27:36 +03:00
|
|
|
var RemoveStartup = func(c *fiber.Ctx) error {
|
2022-09-25 11:05:14 +03:00
|
|
|
u, err := user.Current()
|
|
|
|
if err != nil {
|
2023-03-18 16:40:05 +03:00
|
|
|
utils.Logger(err.Error())
|
2022-09-25 11:05:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
err = os.Remove(strings.Replace(u.HomeDir, "\\", "\\\\", -1) + "\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\Startup\\EveryNasa.lnk")
|
|
|
|
if err != nil {
|
2023-03-18 16:40:05 +03:00
|
|
|
utils.Logger(err.Error())
|
2022-09-25 11:05:14 +03:00
|
|
|
}
|
|
|
|
|
2022-10-23 15:27:36 +03:00
|
|
|
utils.Respond(c, utils.Message(true, "The settings have been applied successfully."))
|
|
|
|
return nil
|
2022-09-25 11:05:14 +03:00
|
|
|
}
|