forked from Shinonome/dots-hyprland
save ai options
This commit is contained in:
@@ -0,0 +1,150 @@
|
||||
import * as Utils from 'resource:///com/github/Aylur/ags/utils.js';
|
||||
const { execAsync, exec } = Utils;
|
||||
|
||||
import { getNestedProperty, updateNestedProperty } from "../.miscutils/objects.js";
|
||||
import { ConfigSpinButton, ConfigToggle } from "./configwidgets.js";
|
||||
|
||||
const AGS_CONFIG_FILE = `${App.configDir}/user_options.jsonc`;
|
||||
|
||||
export const AgsToggle = ({
|
||||
icon, name, desc = null,
|
||||
option, resetButton = true, save = true,
|
||||
extraOnChange = () => { }, extraOnReset = () => { },
|
||||
}) => ConfigToggle({
|
||||
icon: icon,
|
||||
name: name,
|
||||
desc: desc,
|
||||
resetButton: resetButton,
|
||||
initValue: getNestedProperty(userOptions, option),
|
||||
fetchValue: () => getNestedProperty(userOptions, option),
|
||||
onChange: (self, newValue) => {
|
||||
updateNestedProperty(userOptions, option, newValue);
|
||||
if (save) execAsync(['bash', '-c', `${App.configDir}/scripts/ags/agsconfigurator.py \
|
||||
--key ${option} \
|
||||
--value ${newValue} \
|
||||
--file ${AGS_CONFIG_FILE}`
|
||||
]).catch(print);
|
||||
extraOnChange(self, newValue);
|
||||
},
|
||||
onReset: async (self) => {
|
||||
updateNestedProperty(userOptions, option,
|
||||
getNestedProperty(userOptionsDefaults, option));
|
||||
if (save) exec(`bash -c '${App.configDir}/scripts/ags/agsconfigurator.py \
|
||||
--key ${option} \
|
||||
--reset \
|
||||
--file ${AGS_CONFIG_FILE}'`);
|
||||
extraOnReset(self);
|
||||
},
|
||||
});
|
||||
|
||||
export const AgsSpinButton = ({
|
||||
icon, name, desc = null,
|
||||
option, resetButton = true,
|
||||
save = true, extraOnChange = () => { }, extraOnReset = () => { },
|
||||
...rest
|
||||
}) => ConfigSpinButton({
|
||||
icon: icon,
|
||||
name: name,
|
||||
desc: desc,
|
||||
resetButton: resetButton,
|
||||
initValue: getNestedProperty(userOptions, option),
|
||||
fetchValue: () => getNestedProperty(userOptions, option),
|
||||
step: 10, minValue: 0, maxValue: 1000,
|
||||
onChange: (self, newValue) => {
|
||||
updateNestedProperty(userOptions, option, newValue);
|
||||
if (save) execAsync(['bash', '-c', `${App.configDir}/scripts/ags/agsconfigurator.py \
|
||||
--key ${option} \
|
||||
--value ${newValue} \
|
||||
--file ${AGS_CONFIG_FILE}`
|
||||
]).catch(print);
|
||||
extraOnChange(self, newValue);
|
||||
},
|
||||
onReset: async () => {
|
||||
updateNestedProperty(userOptions, option,
|
||||
getNestedProperty(userOptionsDefaults, option));
|
||||
if (save) exec(`bash -c '${App.configDir}/scripts/ags/agsconfigurator.py \
|
||||
--key ${option} \
|
||||
--reset \
|
||||
--file ${AGS_CONFIG_FILE}'`);
|
||||
extraOnReset(self);
|
||||
},
|
||||
...rest,
|
||||
});
|
||||
|
||||
export const HyprlandToggle = ({
|
||||
icon, name, desc = null,
|
||||
option, resetButton = true,
|
||||
enableValue = 1, disableValue = 0,
|
||||
extraOnChange = () => { }, extraOnReset = () => { }, save = true
|
||||
}) => ConfigToggle({
|
||||
icon: icon,
|
||||
name: name,
|
||||
desc: desc,
|
||||
resetButton: resetButton,
|
||||
initValue: JSON.parse(exec(`hyprctl getoption -j ${option}`))["int"] != 0,
|
||||
fetchValue: () => JSON.parse(exec(`hyprctl getoption -j ${option}`))["int"] != 0,
|
||||
onChange: (self, newValue) => {
|
||||
if (save)
|
||||
execAsync(['bash', '-c', `${App.configDir}/scripts/hyprland/hyprconfigurator.py \
|
||||
--key ${option} \
|
||||
--value ${newValue ? enableValue : disableValue} \
|
||||
--file \${XDG_CONFIG_HOME:-$HOME/.config}/hypr/custom/general.conf`
|
||||
]).catch(print);
|
||||
|
||||
else
|
||||
execAsync(['hyprctl', 'keyword', option, `${newValue ? enableValue : disableValue}`]).catch(print);
|
||||
|
||||
extraOnChange(self, newValue);
|
||||
},
|
||||
onReset: async (self) => {
|
||||
if (save)
|
||||
exec(`bash -c '${App.configDir}/scripts/hyprland/hyprconfigurator.py \
|
||||
--key ${option} \
|
||||
--reset \
|
||||
--file "\${XDG_CONFIG_HOME:-$HOME/.config}/hypr/custom/general.conf"'`);
|
||||
|
||||
else
|
||||
exec('hyprctl reload');
|
||||
extraOnReset(self);
|
||||
},
|
||||
});
|
||||
|
||||
export const HyprlandSpinButton = ({
|
||||
icon, name, desc = null,
|
||||
option, resetButton = true, save = true,
|
||||
extraOnChange = () => { }, extraOnReset = () => { },
|
||||
...rest
|
||||
}) => ConfigSpinButton({
|
||||
icon: icon,
|
||||
name: name,
|
||||
desc: desc,
|
||||
resetButton: resetButton,
|
||||
initValue: Number(JSON.parse(exec(`hyprctl getoption -j ${option}`))["int"]),
|
||||
fetchValue: () => Number(JSON.parse(exec(`hyprctl getoption -j ${option}`))["int"]),
|
||||
onChange: (self, newValue) => {
|
||||
if (save)
|
||||
execAsync(['bash', '-c', `${App.configDir}/scripts/hyprland/hyprconfigurator.py \
|
||||
--key ${option} \
|
||||
--value ${newValue} \
|
||||
--file \${XDG_CONFIG_HOME:-$HOME/.config}/hypr/custom/general.conf`
|
||||
]).catch(print);
|
||||
|
||||
else
|
||||
execAsync(['hyprctl', 'keyword', option, `${newValue}`]).catch(print);
|
||||
|
||||
extraOnChange(self, newValue);
|
||||
},
|
||||
onReset: async (self) => {
|
||||
if (save)
|
||||
exec(`bash -c '${App.configDir}/scripts/hyprland/hyprconfigurator.py \
|
||||
--key ${option} \
|
||||
--reset \
|
||||
--file "\${XDG_CONFIG_HOME:-$HOME/.config}/hypr/custom/general.conf"'`);
|
||||
|
||||
else
|
||||
exec('hyprctl reload');
|
||||
extraOnReset(self);
|
||||
},
|
||||
...rest,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user