From 02361c17bb71d1a6b2933d8bcc3d29c8fb4ab4d4 Mon Sep 17 00:00:00 2001 From: honjow Date: Tue, 7 May 2024 20:42:58 +0800 Subject: [PATCH] fix font conf format (#71) --- py_modules/utils.py | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/py_modules/utils.py b/py_modules/utils.py index d51c399..3c0f007 100644 --- a/py_modules/utils.py +++ b/py_modules/utils.py @@ -2,8 +2,7 @@ import decky_plugin from config import logger -FONT_CONFIG = """ - +FONT_CONFIG = """ @@ -33,19 +32,32 @@ """ -FONT_CONF_DIR = f"{decky_plugin.DECKY_USER_HOME}/.config/fontconfig/conf.d" -FONT_CONF_FILE = f"{FONT_CONF_DIR}/75-noto-cjk.conf" +FONT_CONF_DIR = f"{decky_plugin.DECKY_USER_HOME}/.config/fontconfig" +FONT_CONF_D_DIR = f"{FONT_CONF_DIR}/conf.d" +FONT_CONF_FILE = f"{FONT_CONF_D_DIR}/76-noto-cjk.conf" def write_font_config(): - if not os.path.exists(FONT_CONF_DIR): - logger.info(f"Creating fontconfig directory: {FONT_CONF_DIR}") - os.makedirs(FONT_CONF_DIR) + if not os.path.exists(FONT_CONF_D_DIR): + logger.info(f"Creating fontconfig directory: {FONT_CONF_D_DIR}") + os.makedirs(FONT_CONF_D_DIR) + if not os.path.exists(FONT_CONF_FILE): logger.info(f"Creating fontconfig file: {FONT_CONF_FILE}") with open(FONT_CONF_FILE, "w") as f: f.write(FONT_CONFIG) f.close() + else: + logger.info(f"Fontconfig file already exists: {FONT_CONF_FILE}") + with open(FONT_CONF_FILE, "r") as f: + content = f.read() + f.close() + # if different, overwrite it + if content != FONT_CONFIG: + logger.info(f"Overwriting fontconfig file: {FONT_CONF_FILE}") + with open(FONT_CONF_FILE, "w") as f: + f.write(FONT_CONFIG) + f.close() user = decky_plugin.DECKY_USER # change fontconfig owner