forked from Shinonome/dots-hyprland
ags: make dark mode status consistent and simplify switching
This commit is contained in:
@@ -9,8 +9,13 @@ export const isArchDistro = (distroID == 'arch' || distroID == 'endeavouros' ||
|
|||||||
export const hasFlatpak = !!exec(`bash -c 'command -v flatpak'`);
|
export const hasFlatpak = !!exec(`bash -c 'command -v flatpak'`);
|
||||||
|
|
||||||
const LIGHTDARK_FILE_LOCATION = `${GLib.get_user_state_dir()}/ags/user/colormode.txt`;
|
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 const darkMode = Variable(!(Utils.readFile(LIGHTDARK_FILE_LOCATION).split('\n')[0].trim() == 'light'));
|
||||||
export let 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 hasPlasmaIntegration = !!Utils.exec('bash -c "command -v plasma-browser-integration-host"');
|
||||||
|
|
||||||
export const getDistroIcon = () => {
|
export const getDistroIcon = () => {
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ const { execAsync } = Utils;
|
|||||||
import { setupCursorHover } from '../.widgetutils/cursorhover.js';
|
import { setupCursorHover } from '../.widgetutils/cursorhover.js';
|
||||||
import { showColorScheme } from '../../variables.js';
|
import { showColorScheme } from '../../variables.js';
|
||||||
import { MaterialIcon } from '../.commonwidgets/materialicon.js';
|
import { MaterialIcon } from '../.commonwidgets/materialicon.js';
|
||||||
|
import { darkMode } from '../.miscutils/system.js';
|
||||||
|
|
||||||
const ColorBox = ({
|
const ColorBox = ({
|
||||||
name = 'Color',
|
name = 'Color',
|
||||||
@@ -97,8 +98,6 @@ const schemeOptionsArr = [
|
|||||||
];
|
];
|
||||||
|
|
||||||
const LIGHTDARK_FILE_LOCATION = `${GLib.get_user_state_dir()}/ags/user/colormode.txt`;
|
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 initTransparency = Utils.exec(`bash -c "sed -n \'2p\' ${LIGHTDARK_FILE_LOCATION}"`);
|
||||||
const initTransparencyVal = (initTransparency == "transparent") ? 1 : 0;
|
const initTransparencyVal = (initTransparency == "transparent") ? 1 : 0;
|
||||||
const initScheme = Utils.exec(`bash -c "sed -n \'3p\' ${LIGHTDARK_FILE_LOCATION}"`);
|
const initScheme = Utils.exec(`bash -c "sed -n \'3p\' ${LIGHTDARK_FILE_LOCATION}"`);
|
||||||
@@ -123,13 +122,13 @@ const ColorSchemeSettings = () => Widget.Box({
|
|||||||
icon: 'dark_mode',
|
icon: 'dark_mode',
|
||||||
name: 'Dark Mode',
|
name: 'Dark Mode',
|
||||||
desc: 'Ya should go to sleep!',
|
desc: 'Ya should go to sleep!',
|
||||||
initValue: initColorVal,
|
initValue: darkMode.value,
|
||||||
onChange: (self, newValue) => {
|
onChange: (_, newValue) => {
|
||||||
let lightdark = newValue == 0 ? "light" : "dark";
|
darkMode.value = !!newValue;
|
||||||
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);
|
|
||||||
},
|
},
|
||||||
|
extraSetup: (self) => self.hook(darkMode, (self) => {
|
||||||
|
self.enabled.value = darkMode.value;
|
||||||
|
}),
|
||||||
}),
|
}),
|
||||||
ConfigToggle({
|
ConfigToggle({
|
||||||
icon: 'border_clear',
|
icon: 'border_clear',
|
||||||
|
|||||||
@@ -36,15 +36,9 @@ export function launchCustomCommand(command) {
|
|||||||
}
|
}
|
||||||
else if (args[0] == '>light') { // Light mode
|
else if (args[0] == '>light') { // Light mode
|
||||||
darkMode.value = false;
|
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
|
else if (args[0] == '>dark') { // Dark mode
|
||||||
darkMode.value = true;
|
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
|
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`])
|
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`])
|
||||||
|
|||||||
Reference in New Issue
Block a user