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 end
local dialog_component = editor.ui.component(function(props) 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 -- State management
local items, set_items = editor.ui.use_state(initial_items) local items, set_items = editor.ui.use_state(initial_items)
local loading, set_loading = editor.ui.use_state(initial_loading) 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 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 --- Module for handling widget installation from zip files
--- Downloads zip files and extracts them to the specified folder --- Downloads zip files and extracts them to the specified folder
local M = {} local M = {}
local DEFAULT_INSTALL_FOLDER = "./widget" local DEFAULT_INSTALL_FOLDER = "/widget"
---@class druid.core.item_info ---@class druid.core.item_info
---@field id string ---@field id string
@@ -57,7 +58,7 @@ function M.install_widget(item, install_folder)
end end
local zip_file_path = install_folder .. "/" .. filename local zip_file_path = "." .. install_folder .. "/" .. filename
local zip_file = io.open(zip_file_path, "wb") local zip_file = io.open(zip_file_path, "wb")
if not zip_file then if not zip_file then
return false, "Failed to open zip file: " .. zip_file_path 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) print("Zip written to file: " .. zip_file_path)
-- Unzip the zip file -- Unzip the zip file
local folder_name = item.id .. "-" .. item.version local folder_path = "." .. install_folder .. "/" .. item.id
zip.unpack(zip_file_path, install_folder .. "/" .. folder_name)
zip.unpack(zip_file_path, folder_path)
print("Widget unpacked successfully") print("Widget unpacked successfully")
-- Remove the zip file -- Remove the zip file
os.remove(zip_file_path) os.remove(zip_file_path)
print("Zip file removed successfully") 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" return true, "Widget installed successfully"
end 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({ editor.ui.label({
text = "by " .. (item.author or "Unknown"), text = "by " .. (item.author or "Unknown"),
color = editor.ui.COLOR.HINT color = editor.ui.COLOR.HINT
})
}
}), }),
-- Version and size
editor.ui.label({ editor.ui.label({
text = version_text .. "" .. size_text, text = version_text .. "" .. size_text,
color = editor.ui.COLOR.HINT color = editor.ui.COLOR.HINT
}), }),
}
}),
-- Description -- Description
editor.ui.label({ editor.ui.label({
@@ -233,7 +231,7 @@ function M.create_widget_item(item, is_installed, on_install, on_open_api)
enabled = true enabled = true
}), }),
editor.ui.button({ editor.ui.button({
text = "API Docs", text = "API",
on_pressed = on_open_api, on_pressed = on_open_api,
enabled = item.api ~= nil enabled = item.api ~= nil
}) })
@@ -253,6 +251,7 @@ end
function M.create_widget_list(items, is_installed_func, on_install, on_open_api) function M.create_widget_list(items, is_installed_func, on_install, on_open_api)
local widget_items = {} local widget_items = {}
for index = 1, 9 do
for _, item in ipairs(items) do for _, item in ipairs(items) do
local is_installed = is_installed_func and is_installed_func(item) or false 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_install(item) end,
function() on_open_api(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
end end