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;
|
const GLib = imports.gi.GLib;
|
||||||
import Gtk from "gi://Gtk?version=3.0";
|
import Gtk from "gi://Gtk?version=3.0";
|
||||||
import config from "services/configuration.ts";
|
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;
|
let theme_reload_lock = false;
|
||||||
const color_generator = `${GLib.get_home_dir()}/dotfiles/material-colors/generate.py`;
|
const color_generator = `${GLib.get_home_dir()}/dotfiles/material-colors/generate.py`;
|
||||||
|
|
||||||
@@ -86,7 +98,14 @@ const ReloadTheme = () => {
|
|||||||
theme_reload_lock = false;
|
theme_reload_lock = false;
|
||||||
})
|
})
|
||||||
.then(() => {
|
.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);
|
.catch(print);
|
||||||
}
|
}
|
||||||
@@ -99,7 +118,14 @@ const ReloadTheme = () => {
|
|||||||
theme_reload_lock = false;
|
theme_reload_lock = false;
|
||||||
})
|
})
|
||||||
.then(() => {
|
.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) => {
|
.catch((err) => {
|
||||||
print(err);
|
print(err);
|
||||||
@@ -243,7 +269,7 @@ const ColorScheme = () =>
|
|||||||
self.connect("changed", () => {
|
self.connect("changed", () => {
|
||||||
selected = self.get_active_text();
|
selected = self.get_active_text();
|
||||||
theme_settings.scheme.setValue(color_schemes[selected!]);
|
theme_settings.scheme.setValue(color_schemes[selected!]);
|
||||||
Utils.writeFile(color_schemes[selected!], generation_scheme_file).catch(print);
|
updateGenerationScheme(color_schemes[selected!]);
|
||||||
ReloadTheme();
|
ReloadTheme();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"custom-color": "none",
|
||||||
|
"swww-anim": "wipe",
|
||||||
|
"color-scheme": "dark",
|
||||||
|
"generation-scheme": "tonalSpot"
|
||||||
|
}
|
||||||
@@ -1,31 +1,49 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
GENERATOR="$HOME/dotfiles/material-colors/generate.py"
|
GENERATOR="$HOME/dotfiles/material-colors/generate.py"
|
||||||
FILE="$HOME/dotfiles/.settings/color-scheme"
|
SETTINGS_FILE="$HOME/dotfiles/ags/assets/settings.json"
|
||||||
SCHEME_FILE="$HOME/dotfiles/.settings/generation-scheme"
|
|
||||||
GENERATION_SCHEME="tonalSpot"
|
# Function to read a value from the JSON file
|
||||||
GENERATION_SCHEME=$(cat $SCHEME_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() {
|
toggle() {
|
||||||
VALUE=$(cat $FILE)
|
local color_scheme=$(get_json_value "color-scheme")
|
||||||
|
local generation_scheme=$(get_json_value "generation-scheme")
|
||||||
|
|
||||||
if [ "$VALUE" == "dark" ]; then
|
if [ "$color_scheme" == "dark" ]; then
|
||||||
python -O $GENERATOR -R --color-scheme light --scheme $GENERATION_SCHEME
|
python -O $GENERATOR -R --color-scheme light --scheme $generation_scheme
|
||||||
echo "light" >$FILE
|
update_json_value "color-scheme" "light"
|
||||||
|
elif [ "$color_scheme" == "light" ]; then
|
||||||
elif [ "$VALUE" == "light" ]; then
|
python -O $GENERATOR -R --color-scheme dark --scheme $generation_scheme
|
||||||
python -O $GENERATOR -R --color-scheme dark --scheme $GENERATION_SCHEME
|
update_json_value "color-scheme" "dark"
|
||||||
echo "dark" >$FILE
|
|
||||||
else
|
else
|
||||||
echo "Unknown value: $VALUE"
|
echo "Unknown color scheme: $color_scheme"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
set() {
|
set() {
|
||||||
python -O $GENERATOR -R --color-scheme $1 --scheme $GENERATION_SCHEME
|
local new_scheme=$1
|
||||||
echo $1 >$FILE
|
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
|
if [[ "$1" == "--toggle" ]]; then
|
||||||
toggle
|
toggle
|
||||||
elif [[ "$1" == "--set" ]]; then
|
elif [[ "$1" == "--set" ]]; then
|
||||||
set $2
|
set $2
|
||||||
|
else
|
||||||
|
echo "Usage: $0 --toggle | --set <color-scheme>"
|
||||||
fi
|
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 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 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 settings_file = `${GLib.get_home_dir()}/dotfiles/ags/assets/settings.json`;
|
||||||
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 wallpaper_cache_file = `${GLib.get_home_dir()}/.cache/current_wallpaper`;
|
export const wallpaper_cache_file = `${GLib.get_home_dir()}/.cache/current_wallpaper`;
|
||||||
|
|
||||||
function checkBrightness() {
|
function checkBrightness() {
|
||||||
@@ -116,29 +114,17 @@ export const current_brightness = Variable(100, {
|
|||||||
poll: [500, checkBrightness]
|
poll: [500, checkBrightness]
|
||||||
});
|
});
|
||||||
|
|
||||||
function readFiles() {
|
|
||||||
Utils.readFileAsync(custom_color_file)
|
function readSettingsFile() {
|
||||||
|
Utils.readFileAsync(settings_file)
|
||||||
.then((out) => {
|
.then((out) => {
|
||||||
let _out = out;
|
const settings = JSON.parse(out);
|
||||||
if (_out.startsWith("-")) {
|
theme_settings.color.setValue(settings["custom-color"].trim());
|
||||||
_out = _out.substring(1);
|
theme_settings.scheme.setValue(settings["generation-scheme"].trim());
|
||||||
}
|
theme.setValue(settings["color-scheme"].trim());
|
||||||
theme_settings.color.setValue(_out.trim());
|
|
||||||
})
|
})
|
||||||
.catch(print);
|
.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)
|
Utils.readFileAsync(wallpaper_cache_file)
|
||||||
.then((out) => {
|
.then((out) => {
|
||||||
current_wallpaper.setValue(out.trim());
|
current_wallpaper.setValue(out.trim());
|
||||||
@@ -147,36 +133,9 @@ function readFiles() {
|
|||||||
Utils.writeFileSync(current_wallpaper.value, wallpaper_cache_file);
|
Utils.writeFileSync(current_wallpaper.value, wallpaper_cache_file);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
readFiles();
|
readSettingsFile();
|
||||||
|
|
||||||
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) => {});
|
|
||||||
});
|
|
||||||
|
|
||||||
|
Utils.monitorFile(settings_file, readSettingsFile);
|
||||||
Utils.monitorFile(wallpaper_cache_file, () => {
|
Utils.monitorFile(wallpaper_cache_file, () => {
|
||||||
Utils.readFileAsync(wallpaper_cache_file)
|
Utils.readFileAsync(wallpaper_cache_file)
|
||||||
.then((out) => {
|
.then((out) => {
|
||||||
|
|||||||
@@ -7,11 +7,10 @@ import subprocess
|
|||||||
import asyncio
|
import asyncio
|
||||||
import random as _random
|
import random as _random
|
||||||
import colorsys
|
import colorsys
|
||||||
|
import json
|
||||||
|
|
||||||
lock_file_path = '/tmp/wallpaper.lock'
|
lock_file_path = '/tmp/wallpaper.lock'
|
||||||
|
|
||||||
|
|
||||||
def acquire_lock():
|
def acquire_lock():
|
||||||
global lock_file
|
global lock_file
|
||||||
lock_file = open(lock_file_path, 'w')
|
lock_file = open(lock_file_path, 'w')
|
||||||
@@ -23,25 +22,18 @@ def acquire_lock():
|
|||||||
print("Another instance of the script is already running.")
|
print("Another instance of the script is already running.")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
def release_lock():
|
def release_lock():
|
||||||
fcntl.flock(lock_file, fcntl.LOCK_UN)
|
fcntl.flock(lock_file, fcntl.LOCK_UN)
|
||||||
lock_file.close()
|
lock_file.close()
|
||||||
os.remove(lock_file_path)
|
os.remove(lock_file_path)
|
||||||
|
|
||||||
|
|
||||||
def hue_to_numeric_hex(hue):
|
def hue_to_numeric_hex(hue):
|
||||||
hue = hue / 360.0
|
hue = hue / 360.0
|
||||||
|
|
||||||
rgb = colorsys.hls_to_rgb(hue, 0.5, 1.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))
|
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)
|
numeric_hex_color = int(hex_color_str.lstrip('#'), 16)
|
||||||
|
|
||||||
return numeric_hex_color
|
return numeric_hex_color
|
||||||
|
|
||||||
|
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
group = parser.add_mutually_exclusive_group(required=True)
|
group = parser.add_mutually_exclusive_group(required=True)
|
||||||
group.add_argument('-I', '--image', type=str, help="Image")
|
group.add_argument('-I', '--image', type=str, help="Image")
|
||||||
@@ -60,6 +52,17 @@ status = args.status
|
|||||||
|
|
||||||
HOME = os.path.expanduser("~")
|
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'
|
module_path = f'{HOME}/dotfiles/material-colors'
|
||||||
sys.path.append(module_path)
|
sys.path.append(module_path)
|
||||||
|
|
||||||
@@ -73,48 +76,27 @@ spec.loader.exec_module(GENERATOR) # type: ignore
|
|||||||
cache_file = f"{HOME}/.cache/current_wallpaper"
|
cache_file = f"{HOME}/.cache/current_wallpaper"
|
||||||
square = f"{HOME}/.cache/square_wallpaper.png"
|
square = f"{HOME}/.cache/square_wallpaper.png"
|
||||||
png = f"{HOME}/.cache/current_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):
|
def current_state(str: str):
|
||||||
with open(status, 'w') as f:
|
with open(status, 'w') as f:
|
||||||
f.write(str)
|
f.write(str)
|
||||||
|
|
||||||
|
|
||||||
def send_notify(label: str, desc: str):
|
def send_notify(label: str, desc: str):
|
||||||
if not notify:
|
if not notify:
|
||||||
return
|
return
|
||||||
subprocess.run(["notify-send", label, desc])
|
subprocess.run(["notify-send", label, desc])
|
||||||
|
|
||||||
|
|
||||||
def state(name: str | None, label: str | None, desc: str | None):
|
def state(name: str | None, label: str | None, desc: str | None):
|
||||||
if name is not None:
|
if name is not None:
|
||||||
current_state(name)
|
current_state(name)
|
||||||
if label is not None:
|
if label is not None:
|
||||||
send_notify(label, desc or "")
|
send_notify(label, desc or "")
|
||||||
|
|
||||||
|
|
||||||
def join(*args):
|
def join(*args):
|
||||||
return os.path.join(*args)
|
return os.path.join(*args)
|
||||||
|
|
||||||
|
|
||||||
async def main():
|
async def main():
|
||||||
global color_scheme, custom_color
|
|
||||||
state("init", None, None)
|
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"
|
new_wallpaper = f"{HOME}/Pictures/wallpapers/1.jpg"
|
||||||
|
|
||||||
@@ -141,11 +123,6 @@ async def main():
|
|||||||
# -----------------------------------------------------
|
# -----------------------------------------------------
|
||||||
# Set the new wallpaper
|
# Set the new wallpaper
|
||||||
# -----------------------------------------------------
|
# -----------------------------------------------------
|
||||||
|
|
||||||
transition_type = "wipe"
|
|
||||||
# transition_type = "outer"
|
|
||||||
# transition_type = "random"
|
|
||||||
|
|
||||||
wallpaper_engine = "swww" # Default wallpaper engine
|
wallpaper_engine = "swww" # Default wallpaper engine
|
||||||
|
|
||||||
state("changing", "Changing wallpaper...", with_image)
|
state("changing", "Changing wallpaper...", with_image)
|
||||||
@@ -198,7 +175,6 @@ async def main():
|
|||||||
await asyncio.gather(square_task, png_task)
|
await asyncio.gather(square_task, png_task)
|
||||||
state("finish", "Wallpaper procedure complete!", with_image)
|
state("finish", "Wallpaper procedure complete!", with_image)
|
||||||
|
|
||||||
|
|
||||||
async def png_image(wallpaper: str):
|
async def png_image(wallpaper: str):
|
||||||
_from = (".jpg", "jpeg")
|
_from = (".jpg", "jpeg")
|
||||||
if not wallpaper.endswith(_from):
|
if not wallpaper.endswith(_from):
|
||||||
@@ -220,7 +196,6 @@ async def png_image(wallpaper: str):
|
|||||||
else:
|
else:
|
||||||
print(":: JPG successfully converted to PNG!")
|
print(":: JPG successfully converted to PNG!")
|
||||||
|
|
||||||
|
|
||||||
async def square_image(wallpaper):
|
async def square_image(wallpaper):
|
||||||
with_image = f"with image {wallpaper}"
|
with_image = f"with image {wallpaper}"
|
||||||
state(None, "Creating square version...", with_image)
|
state(None, "Creating square version...", with_image)
|
||||||
@@ -238,7 +213,6 @@ async def square_image(wallpaper):
|
|||||||
else:
|
else:
|
||||||
print(":: Square image created!")
|
print(":: Square image created!")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
acquire_lock()
|
acquire_lock()
|
||||||
try:
|
try:
|
||||||
|
|||||||
Reference in new issue
Block a user