read a single json file for appeareance
This commit is contained in:
1 parent
4aa99210a8
commit
a43cd1c0e8
9 files changed
+91
-112
No files matched your search
@@ -1 +0,0 @@
|
||||
dark
|
||||
@@ -1 +0,0 @@
|
||||
none
|
||||
@@ -1 +0,0 @@
|
||||
tonalSpot
|
||||
@@ -1 +0,0 @@
|
||||
wipe
|
||||
@@ -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();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"custom-color": "none",
|
||||
"swww-anim": "wipe",
|
||||
"color-scheme": "dark",
|
||||
"generation-scheme": "tonalSpot"
|
||||
}
|
||||
@@ -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
@@ -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) => {
|
||||
|
||||
@@ -7,11 +7,10 @@ import subprocess
|
||||
import asyncio
|
||||
import random as _random
|
||||
import colorsys
|
||||
|
||||
import json
|
||||
|
||||
lock_file_path = '/tmp/wallpaper.lock'
|
||||
|
||||
|
||||
def acquire_lock():
|
||||
global lock_file
|
||||
lock_file = open(lock_file_path, 'w')
|
||||
@@ -23,25 +22,18 @@ def acquire_lock():
|
||||
print("Another instance of the script is already running.")
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def release_lock():
|
||||
fcntl.flock(lock_file, fcntl.LOCK_UN)
|
||||
lock_file.close()
|
||||
os.remove(lock_file_path)
|
||||
|
||||
|
||||
def hue_to_numeric_hex(hue):
|
||||
hue = hue / 360.0
|
||||
|
||||
rgb = colorsys.hls_to_rgb(hue, 0.5, 1.0)
|
||||
|
||||
hex_color_str = '#{:02x}{:02x}{:02x}'.format(int(rgb[0] * 255), int(rgb[1] * 255), int(rgb[2] * 255))
|
||||
|
||||
numeric_hex_color = int(hex_color_str.lstrip('#'), 16)
|
||||
|
||||
return numeric_hex_color
|
||||
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
group = parser.add_mutually_exclusive_group(required=True)
|
||||
group.add_argument('-I', '--image', type=str, help="Image")
|
||||
@@ -60,6 +52,17 @@ status = args.status
|
||||
|
||||
HOME = os.path.expanduser("~")
|
||||
|
||||
# Load configuration from JSON file
|
||||
config_file = f"{HOME}/dotfiles/ags/assets/settings.json" # Path to your JSON configuration file
|
||||
|
||||
with open(config_file, 'r') as f:
|
||||
config = json.load(f)
|
||||
|
||||
color_scheme = config.get("color-scheme", "dark")
|
||||
custom_color = config.get("custom-color", "none")
|
||||
generation_scheme = config.get("generation-scheme", "tonalSpot")
|
||||
transition_type = config.get("swww-anim", "wipe")
|
||||
|
||||
module_path = f'{HOME}/dotfiles/material-colors'
|
||||
sys.path.append(module_path)
|
||||
|
||||
@@ -73,48 +76,27 @@ spec.loader.exec_module(GENERATOR) # type: ignore
|
||||
cache_file = f"{HOME}/.cache/current_wallpaper"
|
||||
square = f"{HOME}/.cache/square_wallpaper.png"
|
||||
png = f"{HOME}/.cache/current_wallpaper.png"
|
||||
color_scheme_file = f"{HOME}/dotfiles/.settings/color-scheme"
|
||||
custom_color_file = f"{HOME}/dotfiles/.settings/custom-color"
|
||||
generation_scheme_file = f"{HOME}/dotfiles/.settings/generation-scheme"
|
||||
swww_animation_file = f"{HOME}/dotfiles/.settings/swww-anim"
|
||||
|
||||
|
||||
def current_state(str: str):
|
||||
with open(status, 'w') as f:
|
||||
f.write(str)
|
||||
|
||||
|
||||
def send_notify(label: str, desc: str):
|
||||
if not notify:
|
||||
return
|
||||
subprocess.run(["notify-send", label, desc])
|
||||
|
||||
|
||||
def state(name: str | None, label: str | None, desc: str | None):
|
||||
if name is not None:
|
||||
current_state(name)
|
||||
if label is not None:
|
||||
send_notify(label, desc or "")
|
||||
|
||||
|
||||
def join(*args):
|
||||
return os.path.join(*args)
|
||||
|
||||
|
||||
async def main():
|
||||
global color_scheme, custom_color
|
||||
state("init", None, None)
|
||||
with open(color_scheme_file) as f:
|
||||
color_scheme = f.read().strip()
|
||||
|
||||
with open(custom_color_file) as f:
|
||||
custom_color = f.read().strip()
|
||||
|
||||
with open(generation_scheme_file) as f:
|
||||
generation_scheme = f.read().strip()
|
||||
|
||||
with open(swww_animation_file) as f:
|
||||
swww_animation = f.read().strip()
|
||||
|
||||
new_wallpaper = f"{HOME}/Pictures/wallpapers/1.jpg"
|
||||
|
||||
@@ -141,11 +123,6 @@ async def main():
|
||||
# -----------------------------------------------------
|
||||
# Set the new wallpaper
|
||||
# -----------------------------------------------------
|
||||
|
||||
transition_type = "wipe"
|
||||
# transition_type = "outer"
|
||||
# transition_type = "random"
|
||||
|
||||
wallpaper_engine = "swww" # Default wallpaper engine
|
||||
|
||||
state("changing", "Changing wallpaper...", with_image)
|
||||
@@ -198,7 +175,6 @@ async def main():
|
||||
await asyncio.gather(square_task, png_task)
|
||||
state("finish", "Wallpaper procedure complete!", with_image)
|
||||
|
||||
|
||||
async def png_image(wallpaper: str):
|
||||
_from = (".jpg", "jpeg")
|
||||
if not wallpaper.endswith(_from):
|
||||
@@ -220,7 +196,6 @@ async def png_image(wallpaper: str):
|
||||
else:
|
||||
print(":: JPG successfully converted to PNG!")
|
||||
|
||||
|
||||
async def square_image(wallpaper):
|
||||
with_image = f"with image {wallpaper}"
|
||||
state(None, "Creating square version...", with_image)
|
||||
@@ -238,7 +213,6 @@ async def square_image(wallpaper):
|
||||
else:
|
||||
print(":: Square image created!")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
acquire_lock()
|
||||
try:
|
||||
|
||||
Reference in new issue
Block a user