Add linux and macos support

This commit is contained in:
ayes-web 2023-06-19 13:58:13 +03:00
parent 37ebced409
commit 6ff0dabf56

View file

@ -455,7 +455,6 @@ function main_menu:upload_litterbox()
function(outfile)
notify("Uploading to " .. (config.litterbox and "litterbox.catbox.moe..." or "catbox.moe..."), "info", 9999)
if os_type == 'windows' then
-- This uses cURL to send a request to the cat-/litterbox API.
-- (cURL is included with Windows 10 and up)
@ -465,13 +464,14 @@ function main_menu:upload_litterbox()
capture_stdout = true,
capture_stderr = true,
args = {
'curl.exe', '-s',
os_type == 'window' and 'curl.exe' or 'curl', '-s',
'-F', 'reqtype=fileupload',
'-F', 'time=' .. config['litterbox_expire'],
'-F', 'fileToUpload=@"' .. outfile .. '"',
endpoint
}
})
-- This really only happens for people that should have upgraded their system years ago.
-- Or people running a minimal installation i guess.
if r.status == -3 then
@ -484,16 +484,25 @@ function main_menu:upload_litterbox()
end
-- Copy to clipboard
print(r.stdout)
if os_type == 'windows' then
local clipboard_command = 'powershell -command "Set-Clipboard -Value ' .. r.stdout .. '"'
mp.command('run ' .. clipboard_command)
end
if os_type == 'macos' then
notify("Not yet implemented for macOS.", "error", 2)
local clipboard_command = 'echo ' .. r.stdout .. ' | pbcopy'
mp.command("run /bin/sh -c \"" .. clipboard_command .. "\"")
end
if os_type == 'linux' then
notify("Not yet implemented for Linux.", "error", 2)
if os_type == "linux" then
local session_type = io.popen('/bin/sh -c "echo $XDG_SESSION_TYPE"'):read("*a")
-- wl-copy is from wl-clipboard
local clipboard_command = session_type == "x11\n" and
"/bin/sh -c \"echo " .. r.stdout .. "| xclip -sel clip\"" or
"wl-copy " .. r.stdout
mp.command('run ' .. clipboard_command)
end
notify("Done! Copied URL to clipboard.", "info", 2)