ElijahCrafter

Apps

Nov 27th, 2025 (edited)
784
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.61 KB | Source Code | 0 0
  1. -- Apps Management Module for SimpleOS
  2.  
  3. local apps = {}
  4.  
  5. -- Default apps storage
  6. local appList = {}
  7. local appsFile = "os/data/apps.dat"
  8.  
  9. -- Default apps
  10. local defaultApps = {
  11.     {
  12.         name = "Shell",
  13.         symbol = ">",
  14.         command = "shell"
  15.     },
  16.     {
  17.         name = "Files",
  18.         symbol = "F",
  19.         command = "list"
  20.     },
  21.     {
  22.         name = "Edit",
  23.         symbol = "E",
  24.         command = "edit"
  25.     },
  26.     {
  27.         name = "Lua",
  28.         symbol = "L",
  29.         command = "lua"
  30.     },
  31.     {
  32.         name = "Snake",
  33.         symbol = "S",
  34.         command = "os/games/snake"
  35.     },
  36.     {
  37.         name = "Tetris",
  38.         symbol = "T",
  39.         command = "os/games/tetris"
  40.     },
  41.     {
  42.         name = "Pong",
  43.         symbol = "P",
  44.         command = "os/games/pong"
  45.     },
  46.     {
  47.         name = "Mines",
  48.         symbol = "M",
  49.         command = "os/games/minesweeper"
  50.     },
  51.     {
  52.         name = "2048",
  53.         symbol = "2",
  54.         command = "os/games/2048"
  55.     },
  56.     {
  57.         name = "Breakou",
  58.         symbol = "B",
  59.         command = "os/games/breakout"
  60.     },
  61.     {
  62.         name = "ImgView",
  63.         symbol = "I",
  64.         command = "os/programs/imgconv"
  65.     }
  66. }
  67.  
  68. -- Ensure data directory exists
  69. local function ensureDataDir()
  70.     if not fs.exists("os/data") then
  71.         fs.makeDir("os/data")
  72.     end
  73. end
  74.  
  75. -- Load apps from file
  76. function apps.load()
  77.     ensureDataDir()
  78.     if fs.exists(appsFile) then
  79.         local file = fs.open(appsFile, "r")
  80.         if file then
  81.             local content = file.readAll()
  82.             file.close()
  83.             local loaded = textutils.unserialize(content)
  84.             if loaded then
  85.                 appList = loaded
  86.                 return
  87.             end
  88.         end
  89.     end
  90.     -- Use defaults if no saved apps
  91.     appList = defaultApps
  92.     apps.save()
  93. end
  94.  
  95. -- Save apps to file
  96. function apps.save()
  97.     ensureDataDir()
  98.     local file = fs.open(appsFile, "w")
  99.     if file then
  100.         file.write(textutils.serialize(appList))
  101.         file.close()
  102.     end
  103. end
  104.  
  105. -- Get all apps
  106. function apps.getAll()
  107.     return appList
  108. end
  109.  
  110. -- Add a new app
  111. function apps.add(name, symbol, command)
  112.     table.insert(appList, {
  113.         name = name,
  114.         symbol = symbol or "#",
  115.         command = command
  116.     })
  117.     apps.save()
  118. end
  119.  
  120. -- Remove an app by index
  121. function apps.remove(index)
  122.     if index > 0 and index <= #appList then
  123.         table.remove(appList, index)
  124.         apps.save()
  125.         return true
  126.     end
  127.     return false
  128. end
  129.  
  130. -- Edit an app
  131. function apps.edit(index, name, symbol, command)
  132.     if index > 0 and index <= #appList then
  133.         appList[index].name = name or appList[index].name
  134.         appList[index].symbol = symbol or appList[index].symbol
  135.         appList[index].command = command or appList[index].command
  136.         apps.save()
  137.         return true
  138.     end
  139.     return false
  140. end
  141.  
  142. -- Run an app
  143. function apps.run(index)
  144.     if index > 0 and index <= #appList then
  145.         local app = appList[index]
  146.         term.setBackgroundColor(colors.black)
  147.         term.setTextColor(colors.white)
  148.         term.clear()
  149.         term.setCursorPos(1, 1)
  150.        
  151.         -- Run the command
  152.         shell.run(app.command)
  153.        
  154.         -- Wait for key press to return
  155.         print()
  156.         print("Press any key to return to desktop...")
  157.         os.pullEvent("key")
  158.         return true
  159.     end
  160.     return false
  161. end
  162.  
  163. -- Get app count
  164. function apps.count()
  165.     return #appList
  166. end
  167.  
  168. -- Get app by index
  169. function apps.get(index)
  170.     return appList[index]
  171. end
  172.  
  173. return apps
  174.  
Advertisement
Comments
  • User was banned
Add Comment
Please, Sign In to add comment