Compare commits
5 commits
Author | SHA1 | Date | |
---|---|---|---|
4dd5fd95fe | |||
cf9880281f | |||
1f5e245541 | |||
39dadd8cfa | |||
5bd7ff14e2 |
4 changed files with 53 additions and 25 deletions
|
@ -16,10 +16,12 @@ jobs:
|
|||
apt-get install -y mingw-w64 zip
|
||||
|
||||
- name: Build
|
||||
run: make
|
||||
run: |
|
||||
make &&
|
||||
mv LICENSE LICENSE-AORBR
|
||||
|
||||
- name: Create ZIP file
|
||||
run: zip -r auto-obs-rp-restart.zip LICENSE AutoOBSRPRestart.lua monitor.dll
|
||||
run: zip -r auto-obs-rb-restart.zip LICENSE-AORBR AutoOBSRBRestart.lua monitor.dll
|
||||
|
||||
- name: Create release
|
||||
uses: akkuman/gitea-release-action@v1
|
||||
|
@ -27,4 +29,4 @@ jobs:
|
|||
token: ${{ secrets.TOKEN }}
|
||||
name: Latest version
|
||||
tag_name: latest
|
||||
files: auto-obs-rp-restart.zip
|
||||
files: auto-obs-rb-restart.zip
|
||||
|
|
|
@ -4,7 +4,10 @@ local wait_time = 7200 -- Wait 2 hours before checks
|
|||
local idle_time = 120 -- Wait for any input in the last 2 minutes
|
||||
|
||||
function script_description()
|
||||
return "Automatically restarts the replay buffer when IDLE"
|
||||
return [[
|
||||
Automatically restarts the replay buffer when IDLE
|
||||
Author: Mylloon
|
||||
]]
|
||||
end
|
||||
|
||||
function script_load()
|
||||
|
@ -12,40 +15,52 @@ function script_load()
|
|||
ffi.cdef[[
|
||||
void start_hook(void);
|
||||
void stop_hook(void);
|
||||
int last_time_input_received(void);
|
||||
long long last_input_received(void);
|
||||
]]
|
||||
monitor = ffi.load(script_path() .. "monitor.dll")
|
||||
|
||||
obs.timer_add(check_restart, wait_time * 1000)
|
||||
start_loop()
|
||||
end
|
||||
|
||||
function script_unload()
|
||||
obs.timer_remove(check_restart)
|
||||
obs.timer_remove(check_idle)
|
||||
monitor.stop_hook()
|
||||
end
|
||||
|
||||
function start_loop()
|
||||
print("Start idle")
|
||||
obs.timer_add(check_restart, wait_time * 1000)
|
||||
end
|
||||
|
||||
|
||||
function check_restart()
|
||||
obs.timer_remove(check_restart)
|
||||
|
||||
print("Start check every " .. idle_time .. "secs")
|
||||
|
||||
monitor.start_hook()
|
||||
obs.timer_add(check_idle, idle_time * 1000)
|
||||
end
|
||||
|
||||
function check_idle()
|
||||
obs.timer_remove(check_idle)
|
||||
local current_time = os.time()
|
||||
local last_input_time = monitor.last_time_input_received()
|
||||
local last_input_time = monitor.last_input_received()
|
||||
|
||||
if current_time - last_input_time >= wait_time then
|
||||
if current_time - last_input_time >= idle_time then
|
||||
monitor.stop_hook()
|
||||
obs.timer_remove(check_idle)
|
||||
restart_replay_buffer()
|
||||
end
|
||||
end
|
||||
|
||||
function restart_replay_buffer()
|
||||
obs.obs_frontend_replay_buffer_stop()
|
||||
obs.timer_add(start_replay_buffer, 2000)
|
||||
print("No activity detected, restart replay buffer")
|
||||
obs.obs_frontend_replay_buffer_stop()
|
||||
obs.timer_add(start_replay_buffer, 2000)
|
||||
else
|
||||
obs.timer_add(check_idle, idle_time * 1000)
|
||||
end
|
||||
end
|
||||
|
||||
function start_replay_buffer()
|
||||
obs.timer_remove(start_replay_buffer)
|
||||
obs.obs_frontend_replay_buffer_start()
|
||||
|
||||
start_loop()
|
||||
end
|
|
@ -1,5 +1,10 @@
|
|||
# Auto OBS RP Restart [![status-badge](https://git.mylloon.fr/Anri/auto-obs-rp-restart/badges/workflows/release.yml/badge.svg)](https://git.mylloon.fr/Anri/auto-obs-rp-restart/actions?workflow=release.yml)
|
||||
# Automatic OBS ReplayBuffer Restart [![status-badge](https://git.mylloon.fr/Anri/auto-obs-rb-restart/badges/workflows/release.yml/badge.svg)](https://git.mylloon.fr/Anri/auto-obs-rb-restart/actions?workflow=release.yml)
|
||||
|
||||
Automatically restarts the replay buffer when IDLE
|
||||
|
||||
- [Download the latest release here](https://git.mylloon.fr/Anri/auto-obs-rp-restart/releases/tag/latest)
|
||||
- [Download the latest release here](https://git.mylloon.fr/Anri/auto-obs-rb-restart/releases/tag/latest)
|
||||
|
||||
The script wait 2 hours before looking for any input for the last 2 minutes.
|
||||
If there is none, then it restarts the replay buffer.
|
||||
Else it waits for the next 2 minutes, etc.
|
||||
Once restarted, the script wait 2 other hours.
|
||||
|
|
20
monitor.c
20
monitor.c
|
@ -1,26 +1,32 @@
|
|||
#include <stdatomic.h>
|
||||
#include <time.h>
|
||||
#include <windows.h>
|
||||
|
||||
static DWORD last_input_time = 0; // Store the last input time in milliseconds
|
||||
static atomic_llong last_input_time = 0;
|
||||
|
||||
HHOOK hKeyboardHook;
|
||||
HHOOK hKeyboardHook = NULL;
|
||||
|
||||
LRESULT CALLBACK KeyboardHookProc(int nCode, WPARAM wParam, LPARAM lParam) {
|
||||
if (nCode == HC_ACTION) {
|
||||
last_input_time = GetTickCount();
|
||||
atomic_store(&last_input_time, time(NULL));
|
||||
}
|
||||
|
||||
return CallNextHookEx(hKeyboardHook, nCode, wParam, lParam);
|
||||
}
|
||||
|
||||
__declspec(dllexport) void start_hook(void) {
|
||||
hKeyboardHook = SetWindowsHookEx(WH_KEYBOARD_LL, KeyboardHookProc, NULL, 0);
|
||||
if (!hKeyboardHook) {
|
||||
hKeyboardHook = SetWindowsHookEx(WH_KEYBOARD_LL, KeyboardHookProc, NULL, 0);
|
||||
}
|
||||
}
|
||||
|
||||
__declspec(dllexport) void stop_hook(void) {
|
||||
UnhookWindowsHookEx(hKeyboardHook);
|
||||
if (hKeyboardHook) {
|
||||
UnhookWindowsHookEx(hKeyboardHook);
|
||||
hKeyboardHook = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
__declspec(dllexport) int last_time_input_received(void) {
|
||||
return last_input_time;
|
||||
__declspec(dllexport) long long last_input_received(void) {
|
||||
return atomic_load(&last_input_time);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue