fix: adjust backups since we're not symlinking anymore
This commit is contained in:
parent
f2ef89831c
commit
e63948338a
1 changed files with 36 additions and 27 deletions
|
|
@ -243,7 +243,8 @@ widgetStyle=qt6ct-style
|
||||||
let src_file = Self::get_qt_colors_path(is_dark)?;
|
let src_file = Self::get_qt_colors_path(is_dark)?;
|
||||||
let src_ini = Self::read_ini(&src_file)?;
|
let src_ini = Self::read_ini(&src_file)?;
|
||||||
|
|
||||||
Self::backup_non_cosmic_kdeglobals(&kdeglobals_file).map_err(OutputError::Io)?;
|
Self::backup_non_cosmic_kdeglobals(&kdeglobals_ini, &kdeglobals_file)
|
||||||
|
.map_err(OutputError::Io)?;
|
||||||
|
|
||||||
for (section, key_value) in src_ini.get_map_ref() {
|
for (section, key_value) in src_ini.get_map_ref() {
|
||||||
for (key, value) in key_value {
|
for (key, value) in key_value {
|
||||||
|
|
@ -251,11 +252,14 @@ widgetStyle=qt6ct-style
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
kdeglobals_ini.write(kdeglobals_file).map_err(OutputError::Io)?;
|
kdeglobals_ini
|
||||||
|
.write(kdeglobals_file)
|
||||||
|
.map_err(OutputError::Io)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Reset the applied qt colors by deleting the `~/.config/kdeglobals` file.
|
/// Reset the applied qt colors by removing color scheme values from the
|
||||||
|
/// `~/.config/kdeglobals` file.
|
||||||
///
|
///
|
||||||
/// This does not restore the backed up kdeglobals file.
|
/// This does not restore the backed up kdeglobals file.
|
||||||
///
|
///
|
||||||
|
|
@ -267,14 +271,30 @@ widgetStyle=qt6ct-style
|
||||||
let Some(config_dir) = dirs::config_dir() else {
|
let Some(config_dir) = dirs::config_dir() else {
|
||||||
return Err(OutputError::MissingConfigDir);
|
return Err(OutputError::MissingConfigDir);
|
||||||
};
|
};
|
||||||
let dest_file = config_dir.join("kdeglobals");
|
let kdeglobals_file = config_dir.join("kdeglobals");
|
||||||
|
let mut kdeglobals_ini = Self::read_ini(&kdeglobals_file)?;
|
||||||
|
|
||||||
if Self::is_cosmic_kdeglobals(&dest_file)
|
if !Self::is_cosmic_kdeglobals(&kdeglobals_ini)
|
||||||
.map_err(OutputError::Io)?
|
.map_err(OutputError::Io)?
|
||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
{
|
{
|
||||||
fs::remove_file(dest_file).map_err(OutputError::Io)?
|
// Not a cosmic kdeglobals file, do nothing
|
||||||
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let is_dark = false; // doesn't matter since we're only reading keys
|
||||||
|
let src_file = Self::get_qt_colors_path(is_dark)?;
|
||||||
|
let src_ini = Self::read_ini(&src_file)?;
|
||||||
|
|
||||||
|
for (section, key_value) in src_ini.get_map_ref() {
|
||||||
|
for (key, _) in key_value {
|
||||||
|
kdeglobals_ini.remove_key(section, key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
kdeglobals_ini
|
||||||
|
.write(kdeglobals_file)
|
||||||
|
.map_err(OutputError::Io)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -310,8 +330,8 @@ widgetStyle=qt6ct-style
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cold]
|
#[cold]
|
||||||
fn backup_non_cosmic_kdeglobals(path: &Path) -> io::Result<()> {
|
fn backup_non_cosmic_kdeglobals(ini: &Ini, path: &Path) -> io::Result<()> {
|
||||||
if !Self::is_cosmic_kdeglobals(path)?.unwrap_or(true) {
|
if !Self::is_cosmic_kdeglobals(&ini)?.unwrap_or(true) {
|
||||||
let backup_path = path.with_extension("bak");
|
let backup_path = path.with_extension("bak");
|
||||||
fs::rename(path, &backup_path)?;
|
fs::rename(path, &backup_path)?;
|
||||||
}
|
}
|
||||||
|
|
@ -319,26 +339,15 @@ widgetStyle=qt6ct-style
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cold]
|
#[cold]
|
||||||
fn is_cosmic_kdeglobals(path: &Path) -> io::Result<Option<bool>> {
|
fn is_cosmic_kdeglobals(ini: &Ini) -> io::Result<Option<bool>> {
|
||||||
if !path.exists() {
|
let color_scheme = ini.get("General", "ColorScheme");
|
||||||
return Ok(None);
|
if let Some(color_scheme) = color_scheme {
|
||||||
|
Ok(Some(
|
||||||
|
color_scheme == "CosmicDark" || color_scheme == "CosmicLight",
|
||||||
|
))
|
||||||
|
} else {
|
||||||
|
Ok(None)
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Ok(metadata) = fs::symlink_metadata(path) {
|
|
||||||
if !metadata.file_type().is_symlink() {
|
|
||||||
return Ok(Some(false));
|
|
||||||
}
|
|
||||||
let Ok(target) = fs::read_link(path) else {
|
|
||||||
return Ok(Some(false));
|
|
||||||
};
|
|
||||||
let Some(target_filename) = target.file_name() else {
|
|
||||||
return Ok(Some(false));
|
|
||||||
};
|
|
||||||
return Ok(Some(
|
|
||||||
target_filename == "CosmicDark.colors" || target_filename == "CosmicLight.colors",
|
|
||||||
));
|
|
||||||
}
|
|
||||||
Ok(Some(false))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue