forked from Shinonome/dots-hyprland
ags: auto dark mode config option (#447)
This commit is contained in:
@@ -6,7 +6,8 @@ import App from 'resource:///com/github/Aylur/ags/app.js'
|
|||||||
import * as Utils from 'resource:///com/github/Aylur/ags/utils.js'
|
import * as Utils from 'resource:///com/github/Aylur/ags/utils.js'
|
||||||
// Stuff
|
// Stuff
|
||||||
import userOptions from './modules/.configuration/user_options.js';
|
import userOptions from './modules/.configuration/user_options.js';
|
||||||
import { firstRunWelcome } from './services/messages.js';
|
import { firstRunWelcome, startBatteryWarningService } from './services/messages.js';
|
||||||
|
import { startAutoDarkModeService } from './services/darkmode.js';
|
||||||
// Widgets
|
// Widgets
|
||||||
import { Bar, BarCornerTopleft, BarCornerTopright } from './modules/bar/main.js';
|
import { Bar, BarCornerTopleft, BarCornerTopright } from './modules/bar/main.js';
|
||||||
import Cheatsheet from './modules/cheatsheet/main.js';
|
import Cheatsheet from './modules/cheatsheet/main.js';
|
||||||
@@ -32,7 +33,11 @@ function forMonitorsAsync(widget) {
|
|||||||
return range(n, 0).forEach((n) => widget(n).catch(print))
|
return range(n, 0).forEach((n) => widget(n).catch(print))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Start stuff
|
||||||
handleStyles(true);
|
handleStyles(true);
|
||||||
|
startAutoDarkModeService().catch(print);
|
||||||
|
firstRunWelcome().catch(print);
|
||||||
|
startBatteryWarningService().catch(print)
|
||||||
|
|
||||||
const Windows = () => [
|
const Windows = () => [
|
||||||
// forMonitors(DesktopBackground),
|
// forMonitors(DesktopBackground),
|
||||||
|
|||||||
@@ -20,6 +20,11 @@ let configOptions = {
|
|||||||
'durationLarge': 180,
|
'durationLarge': 180,
|
||||||
},
|
},
|
||||||
'appearance': {
|
'appearance': {
|
||||||
|
'autoDarkMode': { // Turns on dark mode in certain hours. Time in 24h format
|
||||||
|
'enabled': false,
|
||||||
|
'from': "18:10",
|
||||||
|
'to': "6:10",
|
||||||
|
},
|
||||||
'keyboardUseFlag': false, // Use flag emoji instead of abbreviation letters
|
'keyboardUseFlag': false, // Use flag emoji instead of abbreviation letters
|
||||||
'layerSmoke': false,
|
'layerSmoke': false,
|
||||||
'layerSmokeStrength': 0.2,
|
'layerSmokeStrength': 0.2,
|
||||||
|
|||||||
@@ -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_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>.`;
|
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() {
|
export async function firstRunWelcome() {
|
||||||
GLib.mkdir_with_parents(`${GLib.get_user_state_dir()}/ags/user`, 755);
|
GLib.mkdir_with_parents(`${GLib.get_user_state_dir()}/ags/user`, 755);
|
||||||
if (!fileExists(FIRST_RUN_PATH)) {
|
if (!fileExists(FIRST_RUN_PATH)) {
|
||||||
@@ -28,34 +59,3 @@ export async function firstRunWelcome() {
|
|||||||
.catch(print);
|
.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