From 2fec837f7ffb01105c66b3ac9f61f20e454210b7 Mon Sep 17 00:00:00 2001 From: Reza Jelveh Date: Sun, 19 Nov 2023 13:46:54 +0800 Subject: [PATCH] add logger --- lua_configs/idle_config.lua | 41 +++++++++++++++++++++++-------------- src/main.rs | 6 +++++- 2 files changed, 31 insertions(+), 16 deletions(-) diff --git a/lua_configs/idle_config.lua b/lua_configs/idle_config.lua index a881cca..9108312 100644 --- a/lua_configs/idle_config.lua +++ b/lua_configs/idle_config.lua @@ -1,41 +1,52 @@ -print("Loading idle_config.lua") +IdleNotifier:log("Loading idle_config.lua") + +function LockScreen() + IdleNotifier:log("Locking Screen") + IdleNotifier:run_once("swaylock -f") +end + +function DpmsOn() + IdleNotifier:log("Turning screen on") + IdleNotifier:run_once("swaymsg output '*' dpms on") +end + +function DpmsOff() + IdleNotifier:log("Turning screen off") + IdleNotifier:run_once("swaymsg output '*' dpms off") +end function ScreenLockBattery(event) if event == "idled" then - print("Locking Screen") - IdleNotifier:run_once("swaylock -f") + LockScreen() end end function ScreenDpmsBattery(event) if event == "idled" then - print("Turning screen off") - IdleNotifier:run_once("swaymsg output '*' dpms off") + DpmsOff() elseif event == "resumed" then - print("Turning screen on") - IdleNotifier:run_once("swaymsg output '*' dpms on") + DpmsOn() end end function ScreenLockAC(event) if event == "idled" then - print("Locking Screen") - IdleNotifier:run_once("swaylock -f") + LockScreen() end end function ScreenDpmsAC(event) if event == "idled" then - print("Turning screen off") - IdleNotifier:run_once("swaymsg output '*' dpms off") + DpmsOff() elseif event == "resumed" then - print("Turning screen on") - IdleNotifier:run_once("swaymsg output '*' dpms on") + DpmsOn() end end IdleNotifier:get_notification(30, "ScreenLockBattery") -IdleNotifier:get_notification(10, "ScreenDpmsAC") +IdleNotifier:get_notification(10, "ScreenDpmsBattery") +IdleNotifier:get_notification(600, "ScreenLockAC") +IdleNotifier:get_notification(1200, "ScreenDpmsAC") -print("Finished loading idle_config.lua") +IdleNotifier:log("Finished loading idle_config.lua") diff --git a/src/main.rs b/src/main.rs index 7290b04..7791333 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,6 @@ use clap::Parser; use inotify::{EventMask, Inotify, WatchMask}; -use log::debug; +use log::{debug, info}; use mlua::{Function, Lua, UserData, UserDataMethods}; use std::collections::HashMap; use std::fs::{self, File}; @@ -106,6 +106,10 @@ impl UserData for MyLuaFunctions { Ok(()) }, ); + methods.add_method("log", |_lua, _this, message: String| { + info!("{}", message); + Ok(()) + }); methods.add_method("run_once", |_lua, this, command: String| { debug!("Running command: {}", command); this.tx