Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Constants
- local GMENU_PASTEBIN_ID = "3gNHHqVV" -- Pastebin ID for GMenu
- -- Function to download GMenu from Pastebin
- local function downloadGMenu()
- local url = "https://pastebin.com/raw/" .. GMENU_PASTEBIN_ID
- local response = http.get(url)
- if response then
- local gmenuCode = response.readAll()
- response.close()
- -- Create directory if it doesn't exist
- local libDir = "/obsidiansystem/systemlua/com.BingusComputer.sysWOWlua.lib"
- if not fs.exists(libDir) then
- fs.makeDir(libDir)
- end
- -- Save GMenu to the specified path
- local gmenuPath = libDir .. "/gmenu.lua"
- local file = fs.open(gmenuPath, "w")
- file.write(gmenuCode)
- file.close()
- print("GMenu downloaded and saved to: " .. gmenuPath)
- return true
- else
- print("Failed to download GMenu from Pastebin.")
- return false
- end
- end
- -- Function to list all .app folders in /apps directory
- local function listApps()
- local apps = {}
- local files = fs.list("/apps")
- for _, file in ipairs(files) do
- if fs.isDir("/apps/" .. file) and file:sub(-4) == ".app" then
- table.insert(apps, file)
- end
- end
- return apps
- end
- -- Function to read program name from config.dat
- local function getProgramName(appName)
- local configPath = "/apps/" .. appName .. "/config.dat"
- if fs.exists(configPath) then
- local handle = fs.open(configPath, "r")
- local name = handle.readLine()
- handle.close()
- return name
- end
- return "Unnamed Program"
- end
- -- Function to display menu with GMenu
- local function runAppShell()
- term.clear()
- term.setCursorPos(1, 1)
- print("Loading apps...")
- -- Download GMenu if not already downloaded
- if not fs.exists("/obsidiansystem/systemlua/com.BingusComputer.sysWOWlua.lib/gmenu.lua") then
- if not downloadGMenu() then
- print("Cannot continue without GMenu.")
- return
- end
- end
- -- Import GMenu library
- os.loadAPI("/obsidiansystem/systemlua/com.BingusComputer.sysWOWlua.lib/gmenu.lua")
- local apps = listApps()
- -- Create a GMenu instance
- local menu = gmenu.newMenu()
- -- Add menu items for each app
- for _, app in ipairs(apps) do
- local name = getProgramName(app)
- menu:addItem(name, function()
- local mainPath = "/apps/" .. app .. "/main.lua"
- if fs.exists(mainPath) then
- shell.openTab(mainPath)
- else
- print("Error: main.lua not found for app '" .. app .. "'.")
- end
- end)
- end
- -- Set up menu properties
- menu:setTitle("Available Apps")
- menu:setPageItems(10) -- Adjust as needed
- menu:show()
- -- Handle events
- while true do
- local event, button, x, y = os.pullEventRaw()
- if event == "mouse_click" then
- menu:handleClick(x, y)
- elseif event == "key" and button == keys.q then
- break
- end
- end
- term.clear()
- term.setCursorPos(1, 1)
- print("Shell closed.")
- end
- -- Run the app shell
- runAppShell()
Advertisement
Add Comment
Please, Sign In to add comment