update config

parent 6246bbc3
......@@ -3,6 +3,7 @@ package config
import (
"os"
"path/filepath"
"ximperconf/utils"
)
type CreateEnv struct {
......@@ -22,6 +23,7 @@ type RepoEnv struct {
type Environment struct {
Version string
IsRoot bool
Create *CreateEnv
Hyprland *HyprEnv
Repo *RepoEnv
......@@ -31,46 +33,24 @@ var Env Environment
func InitConfig() error {
Env.Version = "0.1.0"
if _, err := os.Stat("/usr/bin/Hyprland"); os.IsNotExist(err) {
Env.Hyprland = nil
} else {
Env.Hyprland = &HyprEnv{}
}
home, _ := os.UserHomeDir()
Env.IsRoot = os.Geteuid() == 0
Env.Create = &CreateEnv{
Config: "/etc/ximperdistro/ximperconf/profiles.yaml",
}
if Env.Hyprland != nil {
userModulesPath := filepath.Join(home, ".config", "hypr")
systemModulesPath := "/etc/ximperdistro/hyprland/hypr"
confPath := filepath.Join(userModulesPath, "hyprland.conf")
pluginsPath := "/usr/lib64/hyprland"
if _, err := os.Stat(userModulesPath); os.IsNotExist(err) {
_ = os.MkdirAll(userModulesPath, 0755)
}
Env.Hyprland.UserModulesDir = userModulesPath
if _, err := os.Stat(systemModulesPath); os.IsNotExist(err) {
Env.Hyprland.SystemModulesDir = ""
} else {
Env.Hyprland.SystemModulesDir = systemModulesPath
}
if _, err := os.Stat(pluginsPath); os.IsNotExist(err) {
Env.Hyprland.PluginsDir = ""
} else {
Env.Hyprland.PluginsDir = pluginsPath
}
if _, err := os.Stat(confPath); err == nil {
Env.Hyprland.Config = confPath
} else {
Env.Hyprland.Config = ""
if utils.FileExists("/usr/bin/hyprland") {
home, _ := os.UserHomeDir()
userModules := filepath.Join(home, ".config", "hypr")
systemModules := "/etc/ximperdistro/hyprland/hypr"
pluginsDir := "/usr/lib64/hyprland"
confFile := filepath.Join(userModules, "hyprland.conf")
Env.Hyprland = &HyprEnv{
Config: confFile,
UserModulesDir: userModules,
SystemModulesDir: optionalPath(systemModules),
PluginsDir: optionalPath(pluginsDir),
}
}
......@@ -80,3 +60,10 @@ func InitConfig() error {
return nil
}
func optionalPath(path string) string {
if utils.FileExists(path) {
return path
}
return ""
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment