forked from worron/redflat
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimestamp.lua
More file actions
66 lines (56 loc) · 2.46 KB
/
timestamp.lua
File metadata and controls
66 lines (56 loc) · 2.46 KB
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
-----------------------------------------------------------------------------------------------------------------------
-- RedFlat time stamp --
-----------------------------------------------------------------------------------------------------------------------
-- Make time stamp on every awesome exit or restart
-- It still working if user config was broken and default rc loaded
-- Time stamp may be useful for making diffrence between awesome wm first run or restart
-----------------------------------------------------------------------------------------------------------------------
-- Grab environment
-----------------------------------------------------------------------------------------------------------------------
local tonumber = tonumber
local io = io
local os = os
-- Initialize tables for module
-----------------------------------------------------------------------------------------------------------------------
local timestamp = {}
timestamp.path = "/tmp/awesome-stamp"
timestamp.timeout = 5
timestamp.bin = "awesome-client"
timestamp.lock = false
-- Grab environment
-----------------------------------------------------------------------------------------------------------------------
local awful = require("awful")
local redutil = require("redflat.util")
-- Stamp functions
-----------------------------------------------------------------------------------------------------------------------
-- make time stamp
function timestamp.make()
local file = io.open(timestamp.path, "w")
file:write(os.time())
file:close()
end
-- get time stamp
function timestamp.get()
local res = redutil.read.file(timestamp.path)
if res then return tonumber(res) end
end
-- check if it is first start
function timestamp.is_startup()
local stamp = timestamp.get()
return (not stamp or (os.time() - stamp) > timestamp.timeout) and not timestamp.lock
end
-- Connect exit signal on module initialization
-----------------------------------------------------------------------------------------------------------------------
awesome.connect_signal("exit",
function()
timestamp.make()
awful.spawn.with_shell(
string.format(
"sleep 2 && %s %s",
timestamp.bin, [["if timestamp == nil then timestamp = require('redflat.timestamp') end"]]
)
)
end
)
-----------------------------------------------------------------------------------------------------------------------
return timestamp