aboutsummaryrefslogtreecommitdiff
path: root/lua/sleep.lua
blob: d84480e5ac91420b195ef4d164c64df597104e6b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
local timer = {
	minutes = 25,
	active = false,
	format = "%02d:%02d:%02d", -- (HH:MM:SS)
	remaining = nil,
	prev_state = {
		timestamp = nil,
		was_active = false,
	},
	config_file = "sleep.json"
}

local gesture_state = {
	last_trigger_sec = 0,
	trigger_count = 0,
	latency = 3, -- seconds
}

local function reinstate_tstamp()
	-- call read_config and grab the exported time stamp, then seek to that position in the file
end

local function read_config()
	-- if failed, then return mock/default settings defined here
end

local function export_time()
	-- we should retrieve the current time stamp and export it to sleep.json
	-- at this point, mpv should be paused or terminated.
end

local function stop_timer()
end

local function reset_timer()
end

local function format_time(seconds)
	-- return string format hours minutes seconds
end

local function set_timer()
	timer.minutes = read_config() or timer.minutes
	timer.active = true
	mp.osd_message("Timer has been set for " .. timer.minutes .. " minutes.", 3)
end

local function display_time()
end

-- user calls this
local function handle_gesture()
	    mp.osd_message("Gesture Received.", 3)
		set_timer()

		-- the firs time handle_gestures() is called, timer should be set
		-- if handle_gestures() is called a second time within a short period, then we should cycle timer off
		-- if handle_gestures() is called again a third time within a short period, then we should reinstate the last time export
		-- should include debouncing logic for clean gesture input (eg. ignore calls made within some tiny time before each other)
end

-- called immediately upon opening a media file
function main()
	    mp.osd_message("Sleep timer script initialized!", 3)
end

mp.add_key_binding(nil, "sleep", handle_gesture) -- the user invokes this by gesturing (user-set in input.conf)
main() -- this is run upon opening a media file