mirror of
https://github.com/folke/snacks.nvim
synced 2025-08-04 18:58:12 +00:00
feat(picker): automatically download sqlite3.dll on Windows when using frecency / history for the first time.
This commit is contained in:
parent
adf93a32ae
commit
65907f75ba
2 changed files with 36 additions and 1 deletions
|
@ -31,6 +31,12 @@ function M.health()
|
|||
if not have_fd then
|
||||
Snacks.health.warn("'fd' is required for `Snacks.picker.explorer()`")
|
||||
end
|
||||
local ok = pcall(require, "snacks.picker.util.db")
|
||||
if ok then
|
||||
Snacks.health.ok("`SQLite3` is available")
|
||||
else
|
||||
Snacks.health.warn("`SQLite3` is not available. Frecency and history will be stored in a file instead.")
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
||||
|
|
|
@ -19,7 +19,36 @@ ffi.cdef([[
|
|||
long long sqlite3_column_int64(sqlite3_stmt*, int);
|
||||
]])
|
||||
|
||||
local sqlite = ffi.load("sqlite3")
|
||||
local function sqlite3_lib()
|
||||
if jit.os ~= "Windows" then
|
||||
return "sqlite3"
|
||||
end
|
||||
local sqlite_path = vim.fn.stdpath("cache") .. "\\sqlite3.dll"
|
||||
if vim.fn.filereadable(sqlite_path) == 0 then
|
||||
Snacks.notify("Downloading `sqlite3.dll`")
|
||||
local url = ("https://www.sqlite.org/2025/sqlite-dll-win-%s-3480000.zip"):format(jit.arch)
|
||||
local out = vim.fn.system({
|
||||
"powershell",
|
||||
"-Command",
|
||||
[[
|
||||
$url = "]] .. url .. [[";
|
||||
$zipPath = "$env:TEMP\sqlite.zip";
|
||||
$extractPath = "$env:TEMP\sqlite";
|
||||
Invoke-WebRequest -Uri $url -OutFile $zipPath;
|
||||
Expand-Archive -Path $zipPath -DestinationPath $extractPath -Force;
|
||||
Move-Item -Path "$extractPath\sqlite3.dll" -Destination "]] .. sqlite_path .. [[" -Force
|
||||
]],
|
||||
})
|
||||
if vim.v.shell_error ~= 0 then
|
||||
Snacks.notify.error("Failed to download `sqlite3.dll`:\n" .. out)
|
||||
else
|
||||
Snacks.notify("Downloaded `sqlite3.dll`")
|
||||
end
|
||||
end
|
||||
return sqlite_path
|
||||
end
|
||||
|
||||
local sqlite = ffi.load(sqlite3_lib())
|
||||
|
||||
---@alias sqlite3* ffi.cdata*
|
||||
---@alias sqlite3_stmt* ffi.cdata*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue