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:
parent
c6b4ff17e1
commit
68557e2a21
|
|
@ -1267,6 +1267,11 @@ local function removeLockFile()
|
|||
os.remove(LOCK_FILE)
|
||||
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)
|
||||
----------------------------------------------------------------------
|
||||
|
|
@ -1502,6 +1507,7 @@ openPreviewWindow = function()
|
|||
interval = 0.5,
|
||||
ontick = function()
|
||||
refreshSource()
|
||||
refreshLockFile()
|
||||
pcall(function() previewDlg:repaint() end)
|
||||
|
||||
-- Auto-detect file change
|
||||
|
|
@ -3273,14 +3279,21 @@ local function run()
|
|||
return
|
||||
end
|
||||
-- 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")
|
||||
if lockF then
|
||||
local content = lockF:read("*a")
|
||||
lockF:close()
|
||||
return
|
||||
local lockTime = tonumber(content)
|
||||
if lockTime and (os.time() - lockTime) < 5 then
|
||||
return -- Still running, ignore
|
||||
end
|
||||
-- Stale lock, remove and continue
|
||||
os.remove(LOCK_FILE)
|
||||
end
|
||||
-- Create lock file
|
||||
-- Create lock file with current timestamp
|
||||
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"
|
||||
refreshSource()
|
||||
|
|
|
|||
Loading…
Reference in New Issue