Skip to content

Commit

Permalink
add logger
Browse files Browse the repository at this point in the history
  • Loading branch information
fishman committed Nov 19, 2023
1 parent 57a751b commit 2fec837
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 16 deletions.
41 changes: 26 additions & 15 deletions lua_configs/idle_config.lua
Original file line number Diff line number Diff line change
@@ -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")
6 changes: 5 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 2fec837

Please sign in to comment.