From e8f01a4461bb94045054be16abb91d596627fe28 Mon Sep 17 00:00:00 2001 From: end-4 <97237370+end-4@users.noreply.github.com> Date: Sat, 5 Apr 2025 23:49:49 +0200 Subject: [PATCH] save ai options --- .../.commonwidgets/configwidgets_apps.js | 150 ++++++++++++++++++ .config/ags/modules/sideleft/apis/gemini.js | 30 ++-- .../sideright/centermodules/configure.js | 99 +----------- .config/ags/services/gemini.js | 2 +- 4 files changed, 173 insertions(+), 108 deletions(-) create mode 100644 .config/ags/modules/.commonwidgets/configwidgets_apps.js diff --git a/.config/ags/modules/.commonwidgets/configwidgets_apps.js b/.config/ags/modules/.commonwidgets/configwidgets_apps.js new file mode 100644 index 000000000..b26da8160 --- /dev/null +++ b/.config/ags/modules/.commonwidgets/configwidgets_apps.js @@ -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, +}); + diff --git a/.config/ags/modules/sideleft/apis/gemini.js b/.config/ags/modules/sideleft/apis/gemini.js index e5f22dcd1..4e1b0ce86 100644 --- a/.config/ags/modules/sideleft/apis/gemini.js +++ b/.config/ags/modules/sideleft/apis/gemini.js @@ -9,6 +9,7 @@ import { SystemMessage, ChatMessage } from "./ai_chatmessage.js"; import { ConfigToggle, ConfigSegmentedSelection, ConfigGap } from '../../.commonwidgets/configwidgets.js'; import { markdownTest } from '../../.miscutils/md2pango.js'; import { MarginRevealer } from '../../.widgethacks/advancedrevealers.js'; +import { AgsToggle } from '../../.commonwidgets/configwidgets_apps.js'; const MODEL_NAME = `Gemini`; @@ -92,33 +93,42 @@ export const GeminiSettings = () => MarginRevealer({ hpack: 'center', className: 'sidebar-chat-settings-toggles', children: [ - ConfigToggle({ + AgsToggle({ icon: 'model_training', name: getString('Prompt'), desc: getString("Tells Gemini:\n- It's a Linux sidebar assistant\n- Be brief and use bullet points"), - initValue: GeminiService.assistantPrompt, - onChange: (self, newValue) => { + option: "ai.enhancements", + extraOnChange: (self, newValue) => { GeminiService.assistantPrompt = newValue; }, + extraOnReset: (self, newValue) => { + GeminiService.assistantPrompt = userOptions.ai.enhancements; + }, }), - ConfigToggle({ + AgsToggle({ icon: 'shield', name: getString('Safety'), desc: getString("When turned off, tells the API (not the model) \nto not block harmful/explicit content"), - initValue: GeminiService.safe, - onChange: (self, newValue) => { + option: "ai.safety", + extraOnChange: (self, newValue) => { GeminiService.safe = newValue; }, + extraOnReset: (self, newValue) => { + GeminiService.safe = userOptions.ai.safety; + }, }), - ConfigToggle({ + AgsToggle({ icon: 'history', name: getString('History'), desc: getString("Saves chat history\nMessages in previous chats won't show automatically, but they are there"), - initValue: GeminiService.useHistory, - onChange: (self, newValue) => { + option: "ai.useHistory", + extraOnChange: (self, newValue) => { GeminiService.useHistory = newValue; }, - }), + extraOnReset: (self, newValue) => { + GeminiService.useHistory = userOptions.ai.useHistory; + }, + }) ] }) ] diff --git a/.config/ags/modules/sideright/centermodules/configure.js b/.config/ags/modules/sideright/centermodules/configure.js index 14947798a..572c77c21 100644 --- a/.config/ags/modules/sideright/centermodules/configure.js +++ b/.config/ags/modules/sideright/centermodules/configure.js @@ -6,103 +6,8 @@ const { Box, Button, Icon, Label, Scrollable, Slider, Stack, Overlay } = Widget; const { execAsync, exec } = Utils; import { MaterialIcon } from '../../.commonwidgets/materialicon.js'; import { setupCursorHover } from '../../.widgetutils/cursorhover.js'; -import { ConfigGap, ConfigSpinButton, ConfigToggle } from '../../.commonwidgets/configwidgets.js'; -import { getNestedProperty, updateNestedProperty } from '../../.miscutils/objects.js'; - -const HyprlandToggle = ({ icon, name, desc = null, option, enableValue = 1, disableValue = 0, extraOnChange = () => { }, extraOnReset = () => { }, save = true }) => ConfigToggle({ - icon: icon, - name: name, - desc: desc, - resetButton: true, - 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); - }, -}); - -const HyprlandSpinButton = ({ icon, name, desc = null, option, save = true, extraOnChange = () => { }, extraOnReset = () => { }, ...rest }) => ConfigSpinButton({ - icon: icon, - name: name, - desc: desc, - resetButton: true, - 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, -}); - -const AgsSpinButton = ({ - icon, name, desc = null, option, - save = true, extraOnChange = () => { }, - ...rest -}) => ConfigSpinButton({ - icon: icon, - name: name, - desc: desc, - resetButton: true, - 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 ${App.configDir}/user_options.jsonc` - ]).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 ${App.configDir}/user_options.jsonc'`); - }, - ...rest, -}) +import { ConfigGap, ConfigToggle } from '../../.commonwidgets/configwidgets.js'; +import { AgsSpinButton, HyprlandSpinButton, HyprlandToggle } from '../../.commonwidgets/configwidgets_apps.js'; const Subcategory = (children) => Box({ className: 'margin-left-20', diff --git a/.config/ags/services/gemini.js b/.config/ags/services/gemini.js index e8ea220fb..46fc9118c 100644 --- a/.config/ags/services/gemini.js +++ b/.config/ags/services/gemini.js @@ -188,7 +188,7 @@ class GeminiService extends Service { get useHistory() { return this._usingHistory; } set useHistory(value) { - if (value && !this._usingHistory) this.loadHistory(); + // if (value && !this._usingHistory) this.loadHistory(); this._usingHistory = value; }