mirror of
https://github.com/danbulant/dots-hyprland
synced 2026-05-24 12:22:09 +00:00
ai: code blocks: update colorscheme along with other stuff
This commit is contained in:
parent
cbfb8f6ddb
commit
ac59f23ca4
5 changed files with 41 additions and 32 deletions
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -92,6 +92,9 @@ export const ConfigToggle = ({
|
|||
...rest,
|
||||
});
|
||||
const wholeThing = Box({
|
||||
attribute: {
|
||||
'enabled': enabled,
|
||||
},
|
||||
className: 'configtoggle-box spacing-h-5',
|
||||
children: [
|
||||
interactionWrapper,
|
||||
|
|
|
|||
|
|
@ -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({
|
||||
|
|
|
|||
|
|
@ -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`])
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
Loading…
Reference in a new issue