From bd395b27755e7daac6d019b5feb4df757251fb1b Mon Sep 17 00:00:00 2001 From: ParticleG Date: Sun, 3 Nov 2024 01:05:39 +0800 Subject: [PATCH] - Fix pop logic - Retrieve data onlye when triggered - Show message when thread is dead - Push timer to thread --- Zframework/clipboard.lua | 13 +++++++++++-- Zframework/clipboard_thread.lua | 18 ++++++++---------- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/Zframework/clipboard.lua b/Zframework/clipboard.lua index 8e80cd0e..62548b76 100644 --- a/Zframework/clipboard.lua +++ b/Zframework/clipboard.lua @@ -70,7 +70,12 @@ local getCHN=love.thread.getChannel('CLIP_get') local setCHN=love.thread.getChannel('CLIP_set') local trigCHN=love.thread.getChannel('CLIP_trig') -love.thread.newThread('Zframework/clipboard_thread.lua'):start() +local clipboard_thread=love.thread.newThread('Zframework/clipboard_thread.lua') +local isStarted,errorMessage=clipboard_thread:start() + +if not isStarted then + MES.new("error",errorMessage,26) +end local freshInterval=1 local timer=0 @@ -83,8 +88,12 @@ return { _update=function(dt) timer=timer+dt if timer>freshInterval then + if isStarted and not clipboard_thread:isRunning() then + MES.new("warn",clipboard_thread:getError(),26) + isStarted=false + end + trigCHN:push(timer) timer=0 - trigCHN:push(0) end end, } diff --git a/Zframework/clipboard_thread.lua b/Zframework/clipboard_thread.lua index 4e8e1d07..69090cab 100644 --- a/Zframework/clipboard_thread.lua +++ b/Zframework/clipboard_thread.lua @@ -3,14 +3,14 @@ local setCHN=love.thread.getChannel('CLIP_set') local trigCHN=love.thread.getChannel('CLIP_trig') JS=require'Zframework.js' -love.timer=require'love.timer' +local sleep=require'love.timer'.sleep local retrieving=false while true do if trigCHN:getCount()>0 then - trigCHN:pop() + local dt = trigCHN:pop() if setCHN:getCount()>0 then - repeat setCHN:pop() until setCHN:getCount()==1 + while setCHN:getCount()>1 do setCHN:pop() end -- Set Clipboard JS.callJS(JS.stringFunc( [[ @@ -32,19 +32,17 @@ while true do .catch((e)=>{}); ]], function(data) - while getCHN:getCount()>0 do print('getCHN count:', getCHN:getCount()); getCHN:pop() end - print('Clipboard:', data) + while getCHN:getCount()>0 do getCHN:pop() end getCHN:push(data) - print('Pushed clipboard data') retrieving=false end, - function(id,error) print(id, error) end, - 2, + function() retrieving=false end, + 1, 'getClipboardText' ) retrieving=true end - JS.retrieveData(.0626) + JS.retrieveData(dt) end - love.timer.sleep(.0626) + sleep(.001) end