mirror of
https://github.com/Starlio-app/StarlioX
synced 2024-11-21 08:36:22 +03:00
66 lines
1.5 KiB
Go
66 lines
1.5 KiB
Go
package controllers
|
|
|
|
import (
|
|
"github.com/gofiber/fiber/v2"
|
|
"os"
|
|
"os/user"
|
|
"strings"
|
|
|
|
"github.com/Redume/EveryNasa/utils"
|
|
)
|
|
|
|
var Startup = func(c *fiber.Ctx) error {
|
|
startup := c.FormValue("startup")
|
|
if startup == "" {
|
|
utils.Respond(c, utils.Message(false, "All fields are required."))
|
|
return nil
|
|
}
|
|
|
|
if startup == "1" {
|
|
SetStartup(c)
|
|
} else if startup == "0" {
|
|
RemoveStartup(c)
|
|
} else {
|
|
utils.Respond(c, utils.Message(false, "Invalid field."))
|
|
return nil
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
var SetStartup = func(c *fiber.Ctx) error {
|
|
u, err := user.Current()
|
|
if err != nil {
|
|
utils.Logger(err.Error())
|
|
}
|
|
|
|
dir, err := os.Getwd()
|
|
if err != nil {
|
|
utils.Logger(err.Error())
|
|
}
|
|
|
|
dir = strings.Replace(dir, "\\", "\\\\", -1) + "\\EveryNasa.exe"
|
|
|
|
err = utils.CreateLnk(dir, strings.Replace(u.HomeDir, "\\", "\\\\", -1)+"\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\Startup\\EveryNasa.lnk")
|
|
if err != nil {
|
|
utils.Logger(err.Error())
|
|
}
|
|
|
|
utils.Respond(c, utils.Message(true, "The settings have been applied successfully."))
|
|
return nil
|
|
}
|
|
|
|
var RemoveStartup = func(c *fiber.Ctx) error {
|
|
u, err := user.Current()
|
|
if err != nil {
|
|
utils.Logger(err.Error())
|
|
}
|
|
|
|
err = os.Remove(strings.Replace(u.HomeDir, "\\", "\\\\", -1) + "\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\Startup\\EveryNasa.lnk")
|
|
if err != nil {
|
|
utils.Logger(err.Error())
|
|
}
|
|
|
|
utils.Respond(c, utils.Message(true, "The settings have been applied successfully."))
|
|
return nil
|
|
}
|