Skip to content

Commit

Permalink
notify the user about missing dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
tatsumoto-ren committed Apr 8, 2024
1 parent 1fcc625 commit e06b0fa
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 12 deletions.
30 changes: 19 additions & 11 deletions platform/nix.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,31 @@ Platform-specific functions for *nix systems.
]]

local h = require('helpers')
local self = {}
local clip = (function()
if h.is_mac() then
return 'LANG=en_US.UTF-8 pbcopy'
elseif h.is_wayland() then
return 'wl-copy'
else
return 'xclip -i -selection clipboard'
end
end)()
local self = { healthy = true, clip_util = "", clip_cmd = "", }

local function is_installed(exe_name)
return os.execute("which " .. exe_name) == 0
end

if h.is_mac() then
self.clip_util = "pbcopy"
self.clip_cmd = "LANG=en_US.UTF-8 " .. self.clip_util
elseif h.is_wayland() then
self.clip_util = "wl-copy"
self.clip_cmd = self.clip_util
self.healthy = is_installed(self.clip_util)
else
self.clip_util = "xclip"
self.clip_cmd = self.clip_util .. " -i -selection clipboard"
self.healthy = is_installed(self.clip_util)
end

self.tmp_dir = function()
return os.getenv("TMPDIR") or '/tmp'
end

self.copy_to_clipboard = function(text)
local handle = io.popen(clip, 'w')
local handle = io.popen(self.clip_cmd, 'w')
handle:write(text)
handle:close()
end
Expand Down
2 changes: 1 addition & 1 deletion platform/win.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ local mp = require('mp')
local h = require('helpers')
local utils = require('mp.utils')
local curl_tmpfile_path = utils.join_path(os.getenv('TEMP'), 'curl_tmp.txt')
local self = { windows = true, }
local self = { windows = true, healthy = true, clip_util="cmd", }

mp.register_event('shutdown', function()
os.remove(curl_tmpfile_path)
Expand Down
4 changes: 4 additions & 0 deletions subtitles/observer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ end
-- public

self.copy_to_clipboard = function(_, text)
if platform.healthy == false then
h.notify(platform.clip_util .. " is not installed.", "error", 5)
return
end
if not h.is_empty(text) then
platform.copy_to_clipboard(self.clipboard_prepare(text))
end
Expand Down

0 comments on commit e06b0fa

Please sign in to comment.