mirror of
https://github.com/outbackdingo/hyprcosmic.git
synced 2026-08-25 07:10:09 +00:00
import-theme: say when the file it wrote is inert
Keeping the imported theme in its own file, sourced from cosmic.conf, is what stops a re-import from clobbering the keybindings. But a sourced file only does anything if something sources it, and until now `import-theme --out` reported "Wrote ..." whether or not anything did -- which looks like success while the desktop stays exactly as it was. It now checks the sibling cosmic.conf and prints the line to add when the file is unreachable. The match is by filename and deliberately loose: it is looking for evidence the user already knows about the file, not parsing the config. The shipped template carries that `source` line commented out rather than live, because `source` naming a file that does not exist is a hard error, and a fresh checkout has no theme.conf yet. Copying the template and running `apply` has to work before any theme is imported.
This commit is contained in:
@@ -4,6 +4,20 @@
|
||||
# every key here overwrites whatever COSMIC's own settings UI last stored, so
|
||||
# edit this rather than the GUI for anything it covers.
|
||||
|
||||
# --- Theme --------------------------------------------------------------
|
||||
#
|
||||
# `cosmic-conf import-theme <theme>/hypr.theme --out ~/.config/hyprcosmic/theme.conf`
|
||||
# turns a HyDE theme into conf keys. Sourcing it rather than pasting it in
|
||||
# keeps the two apart: re-importing overwrites theme.conf and cannot touch the
|
||||
# keybindings below, and anything you want to override can simply be repeated
|
||||
# later in this file, since the last assignment to a key wins.
|
||||
#
|
||||
# Commented out because a `source` pointing at a file that does not exist is a
|
||||
# hard error, and no theme is imported yet. Uncomment it once you have run the
|
||||
# command above -- import-theme will remind you.
|
||||
#
|
||||
# source = ~/.config/hyprcosmic/theme.conf
|
||||
|
||||
$mainMod = SUPER
|
||||
|
||||
# --- Launcher -----------------------------------------------------------
|
||||
|
||||
@@ -181,6 +181,9 @@ fn run_import(args: &[String]) -> Result<String, String> {
|
||||
std::fs::write(&p, &imported.conf)
|
||||
.map_err(|e| format!("error: cannot write {}: {e}\n", p.display()))?;
|
||||
out.push_str(&format!("Wrote {}\n", p.display()));
|
||||
if let Some(hint) = unsourced_hint(&p) {
|
||||
out.push_str(&hint);
|
||||
}
|
||||
}
|
||||
None => out.push_str(&imported.conf),
|
||||
}
|
||||
@@ -203,6 +206,44 @@ fn run_import(args: &[String]) -> Result<String, String> {
|
||||
Ok(out)
|
||||
}
|
||||
|
||||
/// Warn when the file just written is not reachable from its sibling
|
||||
/// cosmic.conf, and say what to add.
|
||||
///
|
||||
/// A theme lives in its own file so that re-importing cannot clobber the
|
||||
/// keybindings around it, but that only works if something sources it.
|
||||
/// Writing an inert file and reporting success is the worst of both: the tool
|
||||
/// looks like it worked and the desktop does not change.
|
||||
///
|
||||
/// The match is textual and deliberately loose -- it is looking for evidence
|
||||
/// that the user already knows about the file, not parsing the config. A false
|
||||
/// negative costs one redundant hint; a false positive would hide a real
|
||||
/// problem, so the substring searched for is the filename itself.
|
||||
fn unsourced_hint(written: &Path) -> Option<String> {
|
||||
let dir = written.parent()?;
|
||||
let name = written.file_name()?.to_string_lossy().to_string();
|
||||
let main = dir.join("cosmic.conf");
|
||||
|
||||
// Nothing to say when the theme *is* the config, or there is no config yet
|
||||
// to add a line to: `apply` will be pointed at this file directly.
|
||||
if main == written || !main.exists() {
|
||||
return None;
|
||||
}
|
||||
|
||||
let text = std::fs::read_to_string(&main).ok()?;
|
||||
if text
|
||||
.lines()
|
||||
.any(|l| l.trim_start().starts_with("source") && l.contains(&name))
|
||||
{
|
||||
return None;
|
||||
}
|
||||
|
||||
Some(format!(
|
||||
"\nNothing sources it yet, so `apply` will ignore it. Add this to {}:\n\n source = {}\n",
|
||||
main.display(),
|
||||
written.display(),
|
||||
))
|
||||
}
|
||||
|
||||
/// The half of a theme that is not config: wallpapers, GTK/icon tarballs, and
|
||||
/// the `.theme` files belonging to waybar, rofi and kitty.
|
||||
///
|
||||
|
||||
Reference in New Issue
Block a user