forked from Shinonome/dots-hyprland
ags: auto dark mode config option (#447)
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
const { Gio, GLib } = imports.gi;
|
||||
import Service from 'resource:///com/github/Aylur/ags/service.js';
|
||||
import * as Utils from 'resource:///com/github/Aylur/ags/utils.js';
|
||||
import { darkMode } from '../modules/.miscutils/system.js';
|
||||
const { exec, execAsync } = Utils;
|
||||
|
||||
const timeBefore = (time1, time2) => { // Arrays of [hour, minute]
|
||||
if (time1[0] == time2[0]) return time1[1] < time2[1];
|
||||
return time1[0] < time2[0];
|
||||
}
|
||||
|
||||
const timeSame = (time1, time2) => // Arrays of [hour, minute]
|
||||
(time1[0] == time2[0] && time1[1] == time2[1]);
|
||||
|
||||
const timeBeforeOrSame = (time1, time2) => // Arrays of [hour, minute]
|
||||
(timeBefore(time1, time2) || timeSame(time1, time2));
|
||||
|
||||
const timeInRange = (time, rangeStart, rangeEnd) => { // Arrays of [hour, minute]
|
||||
if (timeBefore(rangeStart, rangeEnd))
|
||||
return (timeBeforeOrSame(rangeStart, time) && timeBeforeOrSame(time, rangeEnd))
|
||||
else { // rangeEnd < rangeStart, meaning it ends the following day
|
||||
rangeEnd[0] += 24;
|
||||
if (timeBefore(time, rangeStart)) time[0] += 24;
|
||||
return (timeBeforeOrSame(rangeStart, time) && timeBeforeOrSame(time, rangeEnd))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export async function startAutoDarkModeService() {
|
||||
Utils.interval(userOptions.time.interval, () => {
|
||||
if ((!userOptions.appearance.autoDarkMode.enabled)) return;
|
||||
const fromTime = (userOptions.appearance.autoDarkMode.from).split(':').map(Number);
|
||||
const toTime = (userOptions.appearance.autoDarkMode.to).split(':').map(Number);
|
||||
if (fromTime == toTime) return;
|
||||
const currentDateTime = GLib.DateTime.new_now_local();
|
||||
const currentTime = [currentDateTime.get_hour(), currentDateTime.get_minute()];
|
||||
// console.log(currentTime, fromTime, toTime);
|
||||
darkMode.value = timeInRange(currentTime, fromTime, toTime);
|
||||
})
|
||||
}
|
||||
|
||||
@@ -14,6 +14,37 @@ const APP_NAME = "illogical-impulse";
|
||||
const FIRST_RUN_NOTIF_TITLE = "Welcome!";
|
||||
const FIRST_RUN_NOTIF_BODY = `First run? 👀 <span foreground="#FF0202" font_weight="bold">CTRL+SUPER+T</span> to pick a wallpaper (or styles will break!)\nFor a list of keybinds, hit <span foreground="#c06af1" font_weight="bold">Super + /</span>.`;
|
||||
|
||||
var batteryWarned = false;
|
||||
async function batteryMessage() {
|
||||
const perc = Battery.percent;
|
||||
const charging = Battery.charging;
|
||||
if (charging) {
|
||||
batteryWarned = false;
|
||||
return;
|
||||
}
|
||||
for (let i = userOptions.battery.warnLevels.length - 1; i >= 0; i--) {
|
||||
if (perc <= userOptions.battery.warnLevels[i] && !charging && !batteryWarned) {
|
||||
batteryWarned = true;
|
||||
Utils.execAsync(['bash', '-c',
|
||||
`notify-send "${userOptions.battery.warnTitles[i]}" "${userOptions.battery.warnMessages[i]}" -u critical -a '${APP_NAME}' -t 69420 &`
|
||||
]).catch(print);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (perc <= userOptions.battery.suspendThreshold) {
|
||||
Utils.execAsync(['bash', '-c',
|
||||
`notify-send "Suspending system" "Critical battery level (${perc}% remaining)" -u critical -a '${APP_NAME}' -t 69420 &`
|
||||
]).catch(print);
|
||||
Utils.execAsync('systemctl suspend').catch(print);
|
||||
}
|
||||
}
|
||||
|
||||
export async function startBatteryWarningService() {
|
||||
Utils.timeout(1, () => {
|
||||
Battery.connect('changed', () => batteryMessage().catch(print));
|
||||
})
|
||||
}
|
||||
|
||||
export async function firstRunWelcome() {
|
||||
GLib.mkdir_with_parents(`${GLib.get_user_state_dir()}/ags/user`, 755);
|
||||
if (!fileExists(FIRST_RUN_PATH)) {
|
||||
@@ -27,35 +58,4 @@ export async function firstRunWelcome() {
|
||||
})
|
||||
.catch(print);
|
||||
}
|
||||
}
|
||||
|
||||
var batteryWarned = false;
|
||||
async function batteryMessage() {
|
||||
const perc = Battery.percent;
|
||||
const charging = Battery.charging;
|
||||
if(charging) {
|
||||
batteryWarned = false;
|
||||
return;
|
||||
}
|
||||
for (let i = userOptions.battery.warnLevels.length - 1; i >= 0; i--) {
|
||||
if (perc <= userOptions.battery.warnLevels[i] && !charging && !batteryWarned) {
|
||||
batteryWarned = true;
|
||||
Utils.execAsync(['bash', '-c',
|
||||
`notify-send "${userOptions.battery.warnTitles[i]}" "${userOptions.battery.warnMessages[i]}" -u critical -a '${APP_NAME}' -t 69420 &`
|
||||
]).catch(print);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(perc <= userOptions.battery.suspendThreshold) {
|
||||
Utils.execAsync(['bash', '-c',
|
||||
`notify-send "Suspending system" "Critical battery level (${perc}% remaining)" -u critical -a '${APP_NAME}' -t 69420 &`
|
||||
]).catch(print);
|
||||
Utils.execAsync('systemctl suspend').catch(print);
|
||||
}
|
||||
}
|
||||
|
||||
// Run them
|
||||
firstRunWelcome().catch(print);
|
||||
Utils.timeout(1, () => {
|
||||
Battery.connect('changed', () => batteryMessage().catch(print));
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user