Compare commits
No commits in common. "main" and "latest" have entirely different histories.
4 changed files with 25 additions and 53 deletions
|
@ -16,12 +16,10 @@ jobs:
|
|||
apt-get install -y mingw-w64 zip
|
||||
|
||||
- name: Build
|
||||
run: |
|
||||
make &&
|
||||
mv LICENSE LICENSE-AORBR
|
||||
run: make
|
||||
|
||||
- name: Create ZIP file
|
||||
run: zip -r auto-obs-rb-restart.zip LICENSE-AORBR AutoOBSRBRestart.lua monitor.dll
|
||||
run: zip -r auto-obs-rp-restart.zip LICENSE AutoOBSRPRestart.lua monitor.dll
|
||||
|
||||
- name: Create release
|
||||
uses: akkuman/gitea-release-action@v1
|
||||
|
@ -29,4 +27,4 @@ jobs:
|
|||
token: ${{ secrets.TOKEN }}
|
||||
name: Latest version
|
||||
tag_name: latest
|
||||
files: auto-obs-rb-restart.zip
|
||||
files: auto-obs-rp-restart.zip
|
||||
|
|
|
@ -4,10 +4,7 @@ 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
|
||||
Author: Mylloon
|
||||
]]
|
||||
return "Automatically restarts the replay buffer when IDLE"
|
||||
end
|
||||
|
||||
function script_load()
|
||||
|
@ -15,52 +12,40 @@ function script_load()
|
|||
ffi.cdef[[
|
||||
void start_hook(void);
|
||||
void stop_hook(void);
|
||||
long long last_input_received(void);
|
||||
int last_time_input_received(void);
|
||||
]]
|
||||
monitor = ffi.load(script_path() .. "monitor.dll")
|
||||
start_loop()
|
||||
|
||||
obs.timer_add(check_restart, wait_time * 1000)
|
||||
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_input_received()
|
||||
local last_input_time = monitor.last_time_input_received()
|
||||
|
||||
if current_time - last_input_time >= idle_time then
|
||||
if current_time - last_input_time >= wait_time then
|
||||
monitor.stop_hook()
|
||||
obs.timer_remove(check_idle)
|
||||
restart_replay_buffer()
|
||||
end
|
||||
end
|
||||
|
||||
print("No activity detected, restart replay buffer")
|
||||
function 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,10 +1,5 @@
|
|||
# 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)
|
||||
# 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)
|
||||
|
||||
Automatically restarts the replay buffer when IDLE
|
||||
|
||||
- [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.
|
||||
- [Download the latest release here](https://git.mylloon.fr/Anri/auto-obs-rp-restart/releases/tag/latest)
|
||||
|
|
16
monitor.c
16
monitor.c
|
@ -1,32 +1,26 @@
|
|||
#include <stdatomic.h>
|
||||
#include <time.h>
|
||||
#include <windows.h>
|
||||
|
||||
static atomic_llong last_input_time = 0;
|
||||
static DWORD last_input_time = 0; // Store the last input time in milliseconds
|
||||
|
||||
HHOOK hKeyboardHook = NULL;
|
||||
HHOOK hKeyboardHook;
|
||||
|
||||
LRESULT CALLBACK KeyboardHookProc(int nCode, WPARAM wParam, LPARAM lParam) {
|
||||
if (nCode == HC_ACTION) {
|
||||
atomic_store(&last_input_time, time(NULL));
|
||||
last_input_time = GetTickCount();
|
||||
}
|
||||
|
||||
return CallNextHookEx(hKeyboardHook, nCode, wParam, lParam);
|
||||
}
|
||||
|
||||
__declspec(dllexport) void start_hook(void) {
|
||||
if (!hKeyboardHook) {
|
||||
hKeyboardHook = SetWindowsHookEx(WH_KEYBOARD_LL, KeyboardHookProc, NULL, 0);
|
||||
}
|
||||
}
|
||||
|
||||
__declspec(dllexport) void stop_hook(void) {
|
||||
if (hKeyboardHook) {
|
||||
UnhookWindowsHookEx(hKeyboardHook);
|
||||
hKeyboardHook = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
__declspec(dllexport) long long last_input_received(void) {
|
||||
return atomic_load(&last_input_time);
|
||||
__declspec(dllexport) int last_time_input_received(void) {
|
||||
return last_input_time;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue