diff --git a/.config/ags/init.js b/.config/ags/init.js index 48c56dda..02304354 100644 --- a/.config/ags/init.js +++ b/.config/ags/init.js @@ -1,8 +1,28 @@ -import GLib from 'gi://GLib'; +const { Gio, GLib } = imports.gi; +import GtkSource from "gi://GtkSource?version=3.0"; import App from 'resource:///com/github/Aylur/ags/app.js' import * as Utils from 'resource:///com/github/Aylur/ags/utils.js' import { darkMode } from './modules/.miscutils/system.js'; + +const CUSTOM_SOURCEVIEW_SCHEME_PATH = `${App.configDir}/assets/themes/sourceviewtheme${darkMode.value ? '' : '-light'}.xml`; + export const COMPILED_STYLE_DIR = `${GLib.get_user_cache_dir()}/ags/user/generated` + +function loadSourceViewColorScheme(filePath) { + // Read the XML file content + const file = Gio.File.new_for_path(filePath); + const [success, contents] = file.load_contents(null); + + if (!success) { + logError('Failed to load the XML file.'); + return; + } + + // Parse the XML content and set the Style Scheme + const schemeManager = GtkSource.StyleSchemeManager.get_default(); + schemeManager.append_search_path(file.get_parent().get_path()); +} + globalThis['handleStyles'] = (resetMusic) => { // Reset Utils.exec(`mkdir -p "${GLib.get_user_state_dir()}/ags/scss"`); @@ -13,7 +33,8 @@ globalThis['handleStyles'] = (resetMusic) => { // Generate overrides let lightdark = darkMode.value ? "dark" : "light"; Utils.writeFileSync( - `@mixin symbolic-icon { + ` +@mixin symbolic-icon { -gtk-icon-theme: '${userOptions.icons.symbolicIconTheme[lightdark]}'; } `, @@ -26,5 +47,7 @@ globalThis['handleStyles'] = (resetMusic) => { App.applyCss(`${COMPILED_STYLE_DIR}/style.css`); console.log('[LOG] Styles loaded') } - applyStyle().catch(print); + applyStyle().then(() => { + loadSourceViewColorScheme(CUSTOM_SOURCEVIEW_SCHEME_PATH); + }).catch(print); } diff --git a/.config/ags/modules/.commonwidgets/configwidgets.js b/.config/ags/modules/.commonwidgets/configwidgets.js index d00c726f..2b49a7d2 100644 --- a/.config/ags/modules/.commonwidgets/configwidgets.js +++ b/.config/ags/modules/.commonwidgets/configwidgets.js @@ -92,6 +92,9 @@ export const ConfigToggle = ({ ...rest, }); const wholeThing = Box({ + attribute: { + 'enabled': enabled, + }, className: 'configtoggle-box spacing-h-5', children: [ interactionWrapper, diff --git a/.config/ags/modules/indicators/colorscheme.js b/.config/ags/modules/indicators/colorscheme.js index bb00558e..db6501e0 100644 --- a/.config/ags/modules/indicators/colorscheme.js +++ b/.config/ags/modules/indicators/colorscheme.js @@ -127,7 +127,7 @@ const ColorSchemeSettings = () => Widget.Box({ darkMode.value = !!newValue; }, extraSetup: (self) => self.hook(darkMode, (self) => { - self.enabled.value = darkMode.value; + self.attribute.enabled.value = darkMode.value; }), }), ConfigToggle({ diff --git a/.config/ags/modules/overview/miscfunctions.js b/.config/ags/modules/overview/miscfunctions.js index 91d84230..18abdd2c 100644 --- a/.config/ags/modules/overview/miscfunctions.js +++ b/.config/ags/modules/overview/miscfunctions.js @@ -3,7 +3,6 @@ import App from 'resource:///com/github/Aylur/ags/app.js'; import * as Utils from 'resource:///com/github/Aylur/ags/utils.js'; const { execAsync, exec } = Utils; import Todo from "../../services/todo.js"; -import { darkMode } from '../.miscutils/system.js'; export function hasUnterminatedBackslash(inputString) { // Use a regular expression to match a trailing odd number of backslashes @@ -35,10 +34,10 @@ export function launchCustomCommand(command) { execAsync([`bash`, `-c`, `${App.configDir}/scripts/color_generation/switchcolor.sh "${args[1]}"`, `&`]).catch(print); } else if (args[0] == '>light') { // Light mode - darkMode.value = false; + darkMode.setValue(false).catch(print); } else if (args[0] == '>dark') { // Dark mode - darkMode.value = true; + darkMode.setValue(true).catch(print); } else if (args[0] == '>badapple') { // Black and white execAsync([`bash`, `-c`, `mkdir -p ${GLib.get_user_state_dir()}/ags/user && sed -i "3s/.*/monochrome/" ${GLib.get_user_state_dir()}/ags/user/colormode.txt`]) diff --git a/.config/ags/modules/sideleft/apis/ai_chatmessage.js b/.config/ags/modules/sideleft/apis/ai_chatmessage.js index a1e041c3..e0047657 100644 --- a/.config/ags/modules/sideleft/apis/ai_chatmessage.js +++ b/.config/ags/modules/sideleft/apis/ai_chatmessage.js @@ -1,4 +1,4 @@ -const { Gdk, Gio, GLib, Gtk } = imports.gi; +const { GLib, Gtk } = imports.gi; import GtkSource from "gi://GtkSource?version=3.0"; import App from 'resource:///com/github/Aylur/ags/app.js'; import Widget from 'resource:///com/github/Aylur/ags/widget.js'; @@ -10,30 +10,8 @@ import md2pango from '../../.miscutils/md2pango.js'; import { darkMode } from "../../.miscutils/system.js"; const LATEX_DIR = `${GLib.get_user_cache_dir()}/ags/media/latex`; -const CUSTOM_SOURCEVIEW_SCHEME_PATH = `${App.configDir}/assets/themes/sourceviewtheme${darkMode.value ? '' : '-light'}.xml`; -const CUSTOM_SCHEME_ID = `custom${darkMode.value ? '' : '-light'}`; const USERNAME = GLib.get_user_name(); -/////////////////////// Custom source view colorscheme ///////////////////////// - -function loadCustomColorScheme(filePath) { - // Read the XML file content - const file = Gio.File.new_for_path(filePath); - const [success, contents] = file.load_contents(null); - - if (!success) { - logError('Failed to load the XML file.'); - return; - } - - // Parse the XML content and set the Style Scheme - const schemeManager = GtkSource.StyleSchemeManager.get_default(); - schemeManager.append_search_path(file.get_parent().get_path()); -} -loadCustomColorScheme(CUSTOM_SOURCEVIEW_SCHEME_PATH); - -////////////////////////////////////////////////////////////////////////////// - function substituteLang(str) { const subs = [ { from: 'javascript', to: 'js' }, @@ -62,7 +40,7 @@ const HighlightedCode = (content, lang) => { buffer.set_language(displayLang); } const schemeManager = GtkSource.StyleSchemeManager.get_default(); - buffer.set_style_scheme(schemeManager.get_scheme(CUSTOM_SCHEME_ID)); + buffer.set_style_scheme(schemeManager.get_scheme(`custom${darkMode.value ? '' : '-light'}`)); buffer.set_text(content, -1); return sourceView; } @@ -204,7 +182,13 @@ const CodeBlock = (content = '', lang = 'txt') => { child: sourceView, })], }) - ] + ], + setup: (self) => self.hook(darkMode, (self) => { + const schemeManager = GtkSource.StyleSchemeManager.get_default(); + Utils.timeout(1000, () => { // Wait for the theme to be loaded + sourceView.buffer.set_style_scheme(schemeManager.get_scheme(`custom${darkMode.value ? '' : '-light'}`)); + }); + }, "changed"), }) // const schemeIds = styleManager.get_scheme_ids();