Fix lock file: timestamp-based staleness, periodic refresh

- Lock file now contains a timestamp, refreshed every 0.5s
- Stale locks (>5s old) are ignored and cleaned up automatically
- Fixes: Aseprite crash leaving orphan lock, lock not cleaned on close
- Silent ignore still works for active instances
This commit is contained in:
Cidwel Highwind 2026-04-03 21:32:21 +02:00
parent c6b4ff17e1
commit 68557e2a21
1 changed files with 16 additions and 3 deletions

View File

@ -1267,6 +1267,11 @@ local function removeLockFile()
os.remove(LOCK_FILE) os.remove(LOCK_FILE)
end end
local function refreshLockFile()
local lf = io.open(LOCK_FILE, "w")
if lf then lf:write(tostring(os.time())); lf:close() end
end
---------------------------------------------------------------------- ----------------------------------------------------------------------
-- Preview Window (primary window) -- Preview Window (primary window)
---------------------------------------------------------------------- ----------------------------------------------------------------------
@ -1502,6 +1507,7 @@ openPreviewWindow = function()
interval = 0.5, interval = 0.5,
ontick = function() ontick = function()
refreshSource() refreshSource()
refreshLockFile()
pcall(function() previewDlg:repaint() end) pcall(function() previewDlg:repaint() end)
-- Auto-detect file change -- Auto-detect file change
@ -3273,14 +3279,21 @@ local function run()
return return
end end
-- Check if already running via lock file - silently ignore -- Check if already running via lock file - silently ignore
-- Lock file contains a timestamp; if older than 5 seconds, consider it stale
local lockF = io.open(LOCK_FILE, "r") local lockF = io.open(LOCK_FILE, "r")
if lockF then if lockF then
local content = lockF:read("*a")
lockF:close() lockF:close()
return local lockTime = tonumber(content)
if lockTime and (os.time() - lockTime) < 5 then
return -- Still running, ignore
end end
-- Create lock file -- Stale lock, remove and continue
os.remove(LOCK_FILE)
end
-- Create lock file with current timestamp
local lf = io.open(LOCK_FILE, "w") local lf = io.open(LOCK_FILE, "w")
if lf then lf:write("running"); lf:close() end if lf then lf:write(tostring(os.time())); lf:close() end
S.currentTab = "Animations" S.currentTab = "Animations"
refreshSource() refreshSource()