read a single json file for appeareance

This commit is contained in:
sankalp committed 2024-07-28 23:29:23 +05:45
1 parent 4aa99210a8
commit a43cd1c0e8
9 files changed
+91 -112

No files matched your search

+30 -4
View File
@@ -1,4 +1,4 @@
import { theme, theme_settings, generation_scheme_file } from "variables.ts";
import { theme, theme_settings, settings_file } from "variables.ts";
const GLib = imports.gi.GLib;
import Gtk from "gi://Gtk?version=3.0";
import config from "services/configuration.ts";
@@ -25,6 +25,18 @@ const color_schemes = {
}
};
export const updateGenerationScheme = async (scheme: string) => {
try {
const settingsContent = await Utils.readFile(settings_file);
const settings = JSON.parse(settingsContent);
settings["generation-scheme"] = scheme;
await Utils.writeFile(JSON.stringify(settings, null, 2), settings_file);
} catch (error) {
print(`Failed to update generation-scheme in settings.json: ${error}`);
}
};
let theme_reload_lock = false;
const color_generator = `${GLib.get_home_dir()}/dotfiles/material-colors/generate.py`;
@@ -86,7 +98,14 @@ const ReloadTheme = () => {
theme_reload_lock = false;
})
.then(() => {
Utils.writeFile("none", `${GLib.get_home_dir()}/dotfiles/.settings/custom-color`).catch(print);
// Update custom-color in settings.json
Utils.readFileAsync(settings_file)
.then((out) => {
const settings = JSON.parse(out);
settings["custom-color"] = "none";
Utils.writeFile(JSON.stringify(settings, null, 2), settings_file).catch(print);
})
.catch(print);
})
.catch(print);
}
@@ -99,7 +118,14 @@ const ReloadTheme = () => {
theme_reload_lock = false;
})
.then(() => {
Utils.writeFile(color_to_write, `${GLib.get_home_dir()}/dotfiles/.settings/custom-color`).catch(print);
// Update custom-color in settings.json
Utils.readFileAsync(settings_file)
.then((out) => {
const settings = JSON.parse(out);
settings["custom-color"] = color_to_write;
Utils.writeFile(JSON.stringify(settings, null, 2), settings_file).catch(print);
})
.catch(print);
})
.catch((err) => {
print(err);
@@ -243,7 +269,7 @@ const ColorScheme = () =>
self.connect("changed", () => {
selected = self.get_active_text();
theme_settings.scheme.setValue(color_schemes[selected!]);
Utils.writeFile(color_schemes[selected!], generation_scheme_file).catch(print);
updateGenerationScheme(color_schemes[selected!]);
ReloadTheme();
});
}
+6
View File
@@ -0,0 +1,6 @@
{
"custom-color": "none",
"swww-anim": "wipe",
"color-scheme": "dark",
"generation-scheme": "tonalSpot"
}
+33 -15
View File
@@ -1,31 +1,49 @@
#!/bin/bash
GENERATOR="$HOME/dotfiles/material-colors/generate.py"
FILE="$HOME/dotfiles/.settings/color-scheme"
SCHEME_FILE="$HOME/dotfiles/.settings/generation-scheme"
GENERATION_SCHEME="tonalSpot"
GENERATION_SCHEME=$(cat $SCHEME_FILE)
SETTINGS_FILE="$HOME/dotfiles/ags/assets/settings.json"
# Function to read a value from the JSON file
get_json_value() {
local key=$1
jq -r --arg key "$key" '.[$key]' $SETTINGS_FILE
}
# Function to update a value in the JSON file
update_json_value() {
local key=$1
local value=$2
jq --arg key "$key" --arg value "$value" \
'.[$key] = $value' $SETTINGS_FILE > "$SETTINGS_FILE.tmp" && mv "$SETTINGS_FILE.tmp" $SETTINGS_FILE
}
toggle() {
VALUE=$(cat $FILE)
local color_scheme=$(get_json_value "color-scheme")
local generation_scheme=$(get_json_value "generation-scheme")
if [ "$VALUE" == "dark" ]; then
python -O $GENERATOR -R --color-scheme light --scheme $GENERATION_SCHEME
echo "light" >$FILE
elif [ "$VALUE" == "light" ]; then
python -O $GENERATOR -R --color-scheme dark --scheme $GENERATION_SCHEME
echo "dark" >$FILE
if [ "$color_scheme" == "dark" ]; then
python -O $GENERATOR -R --color-scheme light --scheme $generation_scheme
update_json_value "color-scheme" "light"
elif [ "$color_scheme" == "light" ]; then
python -O $GENERATOR -R --color-scheme dark --scheme $generation_scheme
update_json_value "color-scheme" "dark"
else
echo "Unknown value: $VALUE"
echo "Unknown color scheme: $color_scheme"
fi
}
set() {
python -O $GENERATOR -R --color-scheme $1 --scheme $GENERATION_SCHEME
echo $1 >$FILE
local new_scheme=$1
local generation_scheme=$(get_json_value "generation-scheme")
python -O $GENERATOR -R --color-scheme $new_scheme --scheme $generation_scheme
update_json_value "color-scheme" $new_scheme
}
# Process arguments
if [[ "$1" == "--toggle" ]]; then
toggle
elif [[ "$1" == "--set" ]]; then
set $2
else
echo "Usage: $0 --toggle | --set <color-scheme>"
fi
+10 -51
View File
@@ -100,9 +100,7 @@ export const kernel_name = await Utils.execAsync(`${App.configDir}/scripts/syste
export const hostname = await Utils.execAsync(`${App.configDir}/scripts/system.sh --hostname`);
export const current_os = await Utils.execAsync(`${App.configDir}/scripts/system.sh --os`);
export const custom_color_file = `${GLib.get_home_dir()}/dotfiles/.settings/custom-color`;
export const generation_scheme_file = `${GLib.get_home_dir()}/dotfiles/.settings/generation-scheme`;
export const color_scheme_file = `${GLib.get_home_dir()}/dotfiles/.settings/color-scheme`;
export const settings_file = `${GLib.get_home_dir()}/dotfiles/ags/assets/settings.json`;
export const wallpaper_cache_file = `${GLib.get_home_dir()}/.cache/current_wallpaper`;
function checkBrightness() {
@@ -116,29 +114,17 @@ export const current_brightness = Variable(100, {
poll: [500, checkBrightness]
});
function readFiles() {
Utils.readFileAsync(custom_color_file)
function readSettingsFile() {
Utils.readFileAsync(settings_file)
.then((out) => {
let _out = out;
if (_out.startsWith("-")) {
_out = _out.substring(1);
}
theme_settings.color.setValue(_out.trim());
const settings = JSON.parse(out);
theme_settings.color.setValue(settings["custom-color"].trim());
theme_settings.scheme.setValue(settings["generation-scheme"].trim());
theme.setValue(settings["color-scheme"].trim());
})
.catch(print);
Utils.readFileAsync(generation_scheme_file)
.then((out) => {
theme_settings.scheme.setValue(out);
})
.catch(print);
Utils.readFileAsync(color_scheme_file)
.then((out) => {
theme.setValue(out.trim());
})
.catch((err) => {});
Utils.readFileAsync(wallpaper_cache_file)
.then((out) => {
current_wallpaper.setValue(out.trim());
@@ -147,36 +133,9 @@ function readFiles() {
Utils.writeFileSync(current_wallpaper.value, wallpaper_cache_file);
});
}
readFiles();
Utils.monitorFile(custom_color_file, () => {
Utils.readFileAsync(custom_color_file)
.then((out) => {
let _out = out;
if (_out.startsWith("-")) {
_out = _out.substring(1);
}
theme_settings.color.setValue(_out.trim());
})
.catch((err) => {});
});
Utils.monitorFile(generation_scheme_file, () => {
Utils.readFileAsync(generation_scheme_file)
.then((out) => {
theme_settings.scheme.setValue(out.trim());
})
.catch((err) => {});
});
Utils.monitorFile(color_scheme_file, () => {
Utils.readFileAsync(color_scheme_file)
.then((out) => {
theme.setValue(out.trim());
})
.catch((err) => {});
});
readSettingsFile();
Utils.monitorFile(settings_file, readSettingsFile);
Utils.monitorFile(wallpaper_cache_file, () => {
Utils.readFileAsync(wallpaper_cache_file)
.then((out) => {