diff --git a/.config/ags/config.js b/.config/ags/config.js
index f440dbd22..f5cbf5ac8 100644
--- a/.config/ags/config.js
+++ b/.config/ags/config.js
@@ -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'
// Stuff
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
import { Bar, BarCornerTopleft, BarCornerTopright } from './modules/bar/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))
}
+// Start stuff
handleStyles(true);
+startAutoDarkModeService().catch(print);
+firstRunWelcome().catch(print);
+startBatteryWarningService().catch(print)
const Windows = () => [
// forMonitors(DesktopBackground),
diff --git a/.config/ags/modules/.configuration/user_options.js b/.config/ags/modules/.configuration/user_options.js
index f8fb4d981..05483add7 100644
--- a/.config/ags/modules/.configuration/user_options.js
+++ b/.config/ags/modules/.configuration/user_options.js
@@ -20,6 +20,11 @@ let configOptions = {
'durationLarge': 180,
},
'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
'layerSmoke': false,
'layerSmokeStrength': 0.2,
diff --git a/.config/ags/services/darkmode.js b/.config/ags/services/darkmode.js
new file mode 100644
index 000000000..35cc81180
--- /dev/null
+++ b/.config/ags/services/darkmode.js
@@ -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);
+ })
+}
+
diff --git a/.config/ags/services/messages.js b/.config/ags/services/messages.js
index 11e7c564d..fb94c7bbd 100644
--- a/.config/ags/services/messages.js
+++ b/.config/ags/services/messages.js
@@ -14,6 +14,37 @@ const APP_NAME = "illogical-impulse";
const FIRST_RUN_NOTIF_TITLE = "Welcome!";
const FIRST_RUN_NOTIF_BODY = `First run? 👀 CTRL+SUPER+T to pick a wallpaper (or styles will break!)\nFor a list of keybinds, hit Super + /.`;
+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));
-})
+}
\ No newline at end of file