Added default config & warning about it

This commit is contained in:
vaxerski
2022-04-08 22:07:40 +02:00
parent 7347a72ba6
commit 7449a0c44c
4 changed files with 98 additions and 5 deletions

View File

@@ -40,6 +40,8 @@ CConfigManager::CConfigManager() {
configValues["input:kb_options"].strValue = "";
configValues["input:kb_rules"].strValue = "";
configValues["input:kb_model"].strValue = "";
configValues["autogenerated"].intValue = 0;
}
void CConfigManager::init() {
@@ -289,14 +291,27 @@ void CConfigManager::loadConfigLoadVars() {
const std::string CONFIGPATH = ENVHOME + (ISDEBUG ? (std::string) "/.config/hypr/hyprlandd.conf" : (std::string) "/.config/hypr/hyprland.conf");
std::ifstream ifs;
ifs.open(CONFIGPATH.c_str());
ifs.open(CONFIGPATH);
if (!ifs.good()) {
Debug::log(WARN, "Config reading error. (No file?)");
parseError = "The config could not be read. (No file?)";
Debug::log(WARN, "Config reading error. (No file? Attempting to generate, backing up old one if exists)");
try {
std::filesystem::rename(CONFIGPATH, CONFIGPATH + ".backup");
} catch(...) { /* Probably doesn't exist */}
ifs.close();
return;
std::ofstream ofs;
ofs.open(CONFIGPATH, std::ios::trunc);
ofs << AUTOCONFIG;
ofs.close();
ifs.open(CONFIGPATH);
if (!ifs.good()) {
parseError = "Broken config file! (Could not open)";
return;
}
}
std::string line = "";
@@ -335,6 +350,8 @@ void CConfigManager::loadConfigLoadVars() {
// parseError will be displayed next frame
if (parseError != "")
g_pHyprError->queueCreate(parseError + "\nHyprland may not work correctly.", CColor(255, 50, 50, 255));
else if (configValues["autogenerated"].intValue == 1)
g_pHyprError->queueCreate("Warning: You're using an autogenerated config! (config file: " + CONFIGPATH + " )\nSUPER+Enter -> kitty\nSUPER+T -> Alacritty\nSUPER+M -> exit Hyprland", CColor(255, 255, 70, 255));
else
g_pHyprError->destroy();
}
@@ -344,6 +361,11 @@ void CConfigManager::tick() {
const std::string CONFIGPATH = ENVHOME + (ISDEBUG ? (std::string) "/.config/hypr/hyprlandd.conf" : (std::string) "/.config/hypr/hyprland.conf");
if (!std::filesystem::exists(CONFIGPATH)) {
loadConfigLoadVars();
return;
}
struct stat fileStat;
int err = stat(CONFIGPATH.c_str(), &fileStat);
if (err != 0) {