diff --git a/.config/ags/modules/.miscutils/system.js b/.config/ags/modules/.miscutils/system.js index 3f81458f..53da1c3e 100644 --- a/.config/ags/modules/.miscutils/system.js +++ b/.config/ags/modules/.miscutils/system.js @@ -9,8 +9,13 @@ export const isArchDistro = (distroID == 'arch' || distroID == 'endeavouros' || export const hasFlatpak = !!exec(`bash -c 'command -v flatpak'`); const LIGHTDARK_FILE_LOCATION = `${GLib.get_user_state_dir()}/ags/user/colormode.txt`; -const colorMode = Utils.exec(`bash -c "sed -n '1p' '${LIGHTDARK_FILE_LOCATION}'"`); -export let darkMode = Variable(!(Utils.readFile(LIGHTDARK_FILE_LOCATION).split('\n')[0].trim() == 'light')); +export const darkMode = Variable(!(Utils.readFile(LIGHTDARK_FILE_LOCATION).split('\n')[0].trim() == 'light')); +darkMode.connect('changed', ({ value }) => { + let lightdark = value ? "dark" : "light"; + execAsync([`bash`, `-c`, `mkdir -p ${GLib.get_user_state_dir()}/ags/user && sed -i "1s/.*/${lightdark}/" ${GLib.get_user_state_dir()}/ags/user/colormode.txt`]) + .then(execAsync(['bash', '-c', `${App.configDir}/scripts/color_generation/switchcolor.sh`])) + .catch(print); +}); export const hasPlasmaIntegration = !!Utils.exec('bash -c "command -v plasma-browser-integration-host"'); export const getDistroIcon = () => { diff --git a/.config/ags/modules/indicators/colorscheme.js b/.config/ags/modules/indicators/colorscheme.js index 65906bd6..bb1b912a 100644 --- a/.config/ags/modules/indicators/colorscheme.js +++ b/.config/ags/modules/indicators/colorscheme.js @@ -7,6 +7,7 @@ const { execAsync } = Utils; import { setupCursorHover } from '../.widgetutils/cursorhover.js'; import { showColorScheme } from '../../variables.js'; import { MaterialIcon } from '../.commonwidgets/materialicon.js'; +import { darkMode } from '../.miscutils/system.js'; const ColorBox = ({ name = 'Color', @@ -97,8 +98,6 @@ const schemeOptionsArr = [ ]; const LIGHTDARK_FILE_LOCATION = `${GLib.get_user_state_dir()}/ags/user/colormode.txt`; -const initColorMode = Utils.exec(`bash -c "sed -n \'1p\' ${LIGHTDARK_FILE_LOCATION}"`); -const initColorVal = (initColorMode == "dark") ? 1 : 0; const initTransparency = Utils.exec(`bash -c "sed -n \'2p\' ${LIGHTDARK_FILE_LOCATION}"`); const initTransparencyVal = (initTransparency == "transparent") ? 1 : 0; const initScheme = Utils.exec(`bash -c "sed -n \'3p\' ${LIGHTDARK_FILE_LOCATION}"`); @@ -123,13 +122,13 @@ const ColorSchemeSettings = () => Widget.Box({ icon: 'dark_mode', name: 'Dark Mode', desc: 'Ya should go to sleep!', - initValue: initColorVal, - onChange: (self, newValue) => { - let lightdark = newValue == 0 ? "light" : "dark"; - execAsync([`bash`, `-c`, `mkdir -p ${GLib.get_user_state_dir()}/ags/user && sed -i "1s/.*/${lightdark}/" ${GLib.get_user_state_dir()}/ags/user/colormode.txt`]) - .then(execAsync(['bash', '-c', `${App.configDir}/scripts/color_generation/switchcolor.sh`])) - .catch(print); + initValue: darkMode.value, + onChange: (_, newValue) => { + darkMode.value = !!newValue; }, + extraSetup: (self) => self.hook(darkMode, (self) => { + self.enabled.value = darkMode.value; + }), }), ConfigToggle({ icon: 'border_clear', diff --git a/.config/ags/modules/overview/miscfunctions.js b/.config/ags/modules/overview/miscfunctions.js index b7d91de7..72556969 100644 --- a/.config/ags/modules/overview/miscfunctions.js +++ b/.config/ags/modules/overview/miscfunctions.js @@ -36,15 +36,9 @@ export function launchCustomCommand(command) { } else if (args[0] == '>light') { // Light mode darkMode.value = false; - execAsync([`bash`, `-c`, `mkdir -p ${GLib.get_user_state_dir()}/ags/user && sed -i "1s/.*/light/" ${GLib.get_user_state_dir()}/ags/user/colormode.txt`]) - .then(execAsync(['bash', '-c', `${App.configDir}/scripts/color_generation/switchcolor.sh`])) - .catch(print); } else if (args[0] == '>dark') { // Dark mode darkMode.value = true; - execAsync([`bash`, `-c`, `mkdir -p ${GLib.get_user_state_dir()}/ags/user && sed -i "1s/.*/dark/" ${GLib.get_user_state_dir()}/ags/user/colormode.txt`]) - .then(execAsync(['bash', '-c', `${App.configDir}/scripts/color_generation/switchcolor.sh`])) - .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`])