95: Fix light/dark mode mismatch causes preset to not load #124
@@ -590,14 +590,36 @@ def generate(
|
||||
raise typer.BadParameter(
|
||||
f"Accent '{accent}' not available for '{p_scheme}:{p_variant}'. Available accents: {available}"
|
||||
)
|
||||
|
||||
requested_mode = mode or config_mode
|
||||
resolved_mode = requested_mode
|
||||
if p_scheme in schemes:
|
||||
meta = schemes[p_scheme]
|
||||
variant = next(
|
||||
(vari for vari in meta.variants if vari.id == p_variant), None
|
||||
)
|
||||
if variant and requested_mode not in variant.modes and variant.modes:
|
||||
resolved_mode = sorted(variant.modes)[0]
|
||||
|
zach marked this conversation as resolved
|
||||
|
||||
palette_obj = get_palette(
|
||||
p_scheme, p_variant, mode or config_mode, accent=accent
|
||||
p_scheme, p_variant, resolved_mode, accent=accent
|
||||
)
|
||||
colors = palette_obj.colors
|
||||
effective_mode = palette_obj.mode
|
||||
name = palette_obj.scheme
|
||||
flavor = palette_obj.variant
|
||||
|
||||
display_name = schemes[p_scheme].name
|
||||
config["colors"]["presets"] = {
|
||||
"name": display_name,
|
||||
"variant": p_variant,
|
||||
"accent": accent or "",
|
||||
}
|
||||
tmp = CONFIG.with_suffix(".json.tmp")
|
||||
with tmp.open("w") as f:
|
||||
json.dump(config, f, indent=4)
|
||||
os.replace(tmp, CONFIG)
|
||||
|
||||
seed = hex_to_hct(colors.get("primary", "#000000").lstrip("#"))
|
||||
else:
|
||||
image_path = image_path or Path(WALL_PATH)
|
||||
|
||||
Reference in New Issue
Block a user
I personally think we shouldn't default to something here. Raising an exception would be better if the requested scheme is not found, maybe write exception trace to log file too. This is because the condition on line 601 should never return true and if it does then it means we are calling it incorrectly from QML/CLI.
The reason it is there is because the current implementation usually only has a single mode per colorscheme preset.
rosepine:dawnonly has light mode for example. The current implementation allows less friction when selecting a preset that is not aligning to the mode you are at currently.resolved_modecan only be light or dark (I am pretty sure).We can think of a different solution, but that would be a more complex solution that'd be more dynamic (a possible consequence of the implementation of #125). Lets say user is on
rosepine:main, which is a dark preset. If user switches to light, it could dynamically understand to move torosepine:dawn. The current implementation does not do this.I agree with error/exception trace to log file, good idea.