-
Notifications
You must be signed in to change notification settings - Fork 0
/
addon.lua
45 lines (40 loc) · 1.23 KB
/
addon.lua
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
local fcitx = require("fcitx")
fcitx.watchEvent(fcitx.EventType.KeyEvent, "migrate4to5")
function migrate4to5(sym, state, release)
local xdg_config_home = os.getenv("XDG_CONFIG_HOME")
local home = os.getenv("HOME")
if xdg_config_home == nil then
xdg_config_home = home .. "/.config"
end
local path = debug.getinfo(1).source:match("@?(.*/)")
local reminder = "lua " .. path .. "reminder.lua"
local f = io.open(xdg_config_home .. "/fcitx/config", "r")
if f == nil then
return false
else
io.close(f)
end
f = io.open(xdg_config_home .. "/fcitx/.migration-complete", "r")
if f ~= nil then
io.close(f)
return false
end
f = io.open(xdg_config_home .. "/fcitx5/.timestamp", "r")
if f ~= nil then
io.close(f)
local cmd = "stat -c %Y " .. xdg_config_home .. "/fcitx5/.timestamp"
local timestamp = io.popen(cmd)
local last_modified = timestamp:read()
local day = math.floor(os.difftime(os.time(), last_modified) / (24*60*60))
if day > 0 then
if state == fcitx.KeyState.Ctrl and sym == 32 and not release then
io.popen(reminder)
end
end
else
if state == fcitx.KeyState.Ctrl and sym == 32 and not release then
io.popen(reminder)
end
end
return false
end