DorianH935

obsidishell

Jul 14th, 2024 (edited)
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.23 KB | None | 0 0
  1. -- Constants
  2. local GMENU_PASTEBIN_ID = "3gNHHqVV" -- Pastebin ID for GMenu
  3.  
  4. -- Function to download GMenu from Pastebin
  5. local function downloadGMenu()
  6. local url = "https://pastebin.com/raw/" .. GMENU_PASTEBIN_ID
  7. local response = http.get(url)
  8.  
  9. if response then
  10. local gmenuCode = response.readAll()
  11. response.close()
  12.  
  13. -- Create directory if it doesn't exist
  14. local libDir = "/obsidiansystem/systemlua/com.BingusComputer.sysWOWlua.lib"
  15. if not fs.exists(libDir) then
  16. fs.makeDir(libDir)
  17. end
  18.  
  19. -- Save GMenu to the specified path
  20. local gmenuPath = libDir .. "/gmenu.lua"
  21. local file = fs.open(gmenuPath, "w")
  22. file.write(gmenuCode)
  23. file.close()
  24.  
  25. print("GMenu downloaded and saved to: " .. gmenuPath)
  26. return true
  27. else
  28. print("Failed to download GMenu from Pastebin.")
  29. return false
  30. end
  31. end
  32.  
  33. -- Function to list all .app folders in /apps directory
  34. local function listApps()
  35. local apps = {}
  36. local files = fs.list("/apps")
  37.  
  38. for _, file in ipairs(files) do
  39. if fs.isDir("/apps/" .. file) and file:sub(-4) == ".app" then
  40. table.insert(apps, file)
  41. end
  42. end
  43.  
  44. return apps
  45. end
  46.  
  47. -- Function to read program name from config.dat
  48. local function getProgramName(appName)
  49. local configPath = "/apps/" .. appName .. "/config.dat"
  50. if fs.exists(configPath) then
  51. local handle = fs.open(configPath, "r")
  52. local name = handle.readLine()
  53. handle.close()
  54. return name
  55. end
  56. return "Unnamed Program"
  57. end
  58.  
  59. -- Function to display menu with GMenu
  60. local function runAppShell()
  61. term.clear()
  62. term.setCursorPos(1, 1)
  63. print("Loading apps...")
  64.  
  65. -- Download GMenu if not already downloaded
  66. if not fs.exists("/obsidiansystem/systemlua/com.BingusComputer.sysWOWlua.lib/gmenu.lua") then
  67. if not downloadGMenu() then
  68. print("Cannot continue without GMenu.")
  69. return
  70. end
  71. end
  72.  
  73. -- Import GMenu library
  74. os.loadAPI("/obsidiansystem/systemlua/com.BingusComputer.sysWOWlua.lib/gmenu.lua")
  75.  
  76. local apps = listApps()
  77.  
  78. -- Create a GMenu instance
  79. local menu = gmenu.newMenu()
  80.  
  81. -- Add menu items for each app
  82. for _, app in ipairs(apps) do
  83. local name = getProgramName(app)
  84. menu:addItem(name, function()
  85. local mainPath = "/apps/" .. app .. "/main.lua"
  86. if fs.exists(mainPath) then
  87. shell.openTab(mainPath)
  88. else
  89. print("Error: main.lua not found for app '" .. app .. "'.")
  90. end
  91. end)
  92. end
  93.  
  94. -- Set up menu properties
  95. menu:setTitle("Available Apps")
  96. menu:setPageItems(10) -- Adjust as needed
  97. menu:show()
  98.  
  99. -- Handle events
  100. while true do
  101. local event, button, x, y = os.pullEventRaw()
  102. if event == "mouse_click" then
  103. menu:handleClick(x, y)
  104. elseif event == "key" and button == keys.q then
  105. break
  106. end
  107. end
  108.  
  109. term.clear()
  110. term.setCursorPos(1, 1)
  111. print("Shell closed.")
  112. end
  113.  
  114. -- Run the app shell
  115. runAppShell()
  116.  
Advertisement
Add Comment
Please, Sign In to add comment