-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
137 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
if SYSTEM~='Web' then | ||
return { | ||
get=function () return CLIPBOARD.get() or '' end, | ||
set=love.system.setClipboardText, | ||
_update=NULL, | ||
} | ||
end | ||
|
||
local clipboard_thread=love.thread.newThread('Zframework/clipboard_thread.lua') | ||
local getCHN=love.thread.newChannel() | ||
local setCHN=love.thread.newChannel() | ||
local triggerCHN=love.thread.newChannel() | ||
|
||
clipboard_thread:start(getCHN,setCHN,triggerCHN) | ||
|
||
local clipboard={} | ||
|
||
function clipboard.get() | ||
return getCHN:peek() | ||
end | ||
|
||
function clipboard.set(content) | ||
if type(content)=='boolean' then | ||
content=content and 'true' or 'false' | ||
end | ||
if type(content)=='nil' then | ||
content='' | ||
end | ||
if type(content)=='number' then | ||
content=tostring(content) | ||
end | ||
if type(content)~='string' then | ||
MES.new('error',"Invalid content type!") | ||
MES.traceback() | ||
end | ||
setCHN:push(content) | ||
end | ||
|
||
function clipboard._update() | ||
triggerCHN:push(0) | ||
end | ||
|
||
return clipboard |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
local getCHN,setCHN,triggerCHN=... | ||
|
||
local CHN_demand,CHN_getCount=triggerCHN.demand,triggerCHN.getCount | ||
local CHN_push,CHN_pop=triggerCHN.push,triggerCHN.pop | ||
|
||
local yield=coroutine.yield | ||
local setThread=coroutine.wrap(function() | ||
while true do | ||
JS.callJS(JS.stringFunc( | ||
[[ | ||
window.navigator.clipboard | ||
.writeText('%s') | ||
.then(() => console.log('Copied to clipboard')) | ||
.catch((e) => console.warn(e)); | ||
]], | ||
CHN_pop(setCHN) | ||
)) | ||
yield() | ||
end | ||
end) | ||
|
||
local getThread=coroutine.wrap(function() | ||
while true do | ||
JS.newPromiseRequest( | ||
JS.stringFunc( | ||
[[ | ||
window.navigator.clipboard | ||
.readText() | ||
.then((text) => _$_(text)) | ||
.catch((e) => { | ||
console.warn(e); | ||
_$_(''); | ||
}); | ||
]] | ||
), | ||
function(data) | ||
while getCHN:getCount()>0 do | ||
CHN_pop(getCHN) | ||
end | ||
CHN_push(getCHN, data) | ||
end, | ||
function(id, error) print(id, error) end, | ||
2, | ||
'getClipboardText' | ||
) | ||
yield() | ||
end | ||
end) | ||
|
||
local success,err | ||
|
||
while true do-- Running | ||
CHN_demand(triggerCHN) | ||
if CHN_getCount(setCHN)>0 then | ||
while CHN_getCount(setCHN)>1 do | ||
CHN_pop(setCHN) | ||
end | ||
print('Running setThread') | ||
setThread() | ||
end | ||
print('Running getThread') | ||
getThread() | ||
end | ||
|
||
error() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters