This commit is contained in:
Insality
2025-10-25 22:47:09 +03:00
parent 1f0075d124
commit 9fba1899da
4 changed files with 245 additions and 221 deletions

View File

@@ -134,7 +134,7 @@ function M.open_asset_store()
end
local dialog_component = editor.ui.component(function(props)
editor.prefs.set("druid.asset_install_folder", "./widget")
editor.prefs.set("druid.asset_install_folder", "/widget")
-- State management
local items, set_items = editor.ui.use_state(initial_items)
local loading, set_loading = editor.ui.use_state(initial_loading)

View File

@@ -1,10 +1,11 @@
local base64 = require("druid.editor_scripts.core.base64")
local path_replacer = require("druid.editor_scripts.core.path_replacer")
--- Module for handling widget installation from zip files
--- Downloads zip files and extracts them to the specified folder
local M = {}
local DEFAULT_INSTALL_FOLDER = "./widget"
local DEFAULT_INSTALL_FOLDER = "/widget"
---@class druid.core.item_info
---@field id string
@@ -57,7 +58,7 @@ function M.install_widget(item, install_folder)
end
local zip_file_path = install_folder .. "/" .. filename
local zip_file_path = "." .. install_folder .. "/" .. filename
local zip_file = io.open(zip_file_path, "wb")
if not zip_file then
return false, "Failed to open zip file: " .. zip_file_path
@@ -68,14 +69,23 @@ function M.install_widget(item, install_folder)
print("Zip written to file: " .. zip_file_path)
-- Unzip the zip file
local folder_name = item.id .. "-" .. item.version
zip.unpack(zip_file_path, install_folder .. "/" .. folder_name)
local folder_path = "." .. install_folder .. "/" .. item.id
zip.unpack(zip_file_path, folder_path)
print("Widget unpacked successfully")
-- Remove the zip file
os.remove(zip_file_path)
print("Zip file removed successfully")
-- Process paths within the extracted widget
local files_in_folder = path_replacer.get_all_files(folder_path)
pprint(files_in_folder)
--if not path_replacer.process_widget_paths(install_folder .. "/" .. folder_name, new_base_path) then
-- return false, "Failed to process widget paths"
--end
return true, "Widget installed successfully"
end

View File

@@ -0,0 +1,22 @@
--- Module for replacing paths in extracted widget files
--- Handles updating require statements and file paths to match the installation location
local M = {}
---Recursively get all files in a directory
---@param dir_path string - Directory path to scan
---@param extension string|nil - Optional file extension filter (e.g., ".lua")
---@return string[] - List of file paths
function M.get_all_files(dir_path, extension)
local attributes = editor.resource_attributes(dir_path)
local files = io.popen("ls -R " .. dir_path)
for line in files:lines() do
print(line)
end
pprint(files)
return files
end
return M

View File

@@ -187,15 +187,13 @@ function M.create_widget_item(item, is_installed, on_install, on_open_api)
editor.ui.label({
text = "by " .. (item.author or "Unknown"),
color = editor.ui.COLOR.HINT
})
}
}),
-- Version and size
editor.ui.label({
text = version_text .. "" .. size_text,
color = editor.ui.COLOR.HINT
}),
}
}),
-- Description
editor.ui.label({
@@ -233,7 +231,7 @@ function M.create_widget_item(item, is_installed, on_install, on_open_api)
enabled = true
}),
editor.ui.button({
text = "API Docs",
text = "API",
on_pressed = on_open_api,
enabled = item.api ~= nil
})
@@ -253,6 +251,7 @@ end
function M.create_widget_list(items, is_installed_func, on_install, on_open_api)
local widget_items = {}
for index = 1, 9 do
for _, item in ipairs(items) do
local is_installed = is_installed_func and is_installed_func(item) or false
@@ -260,13 +259,6 @@ function M.create_widget_list(items, is_installed_func, on_install, on_open_api)
function() on_install(item) end,
function() on_open_api(item) end
))
-- Add separator between items (except for the last one)
if _ < #items then
table.insert(widget_items, editor.ui.label({
text = "---",
color = editor.ui.COLOR.HINT
}))
end
end