GE Lua Documentation

Press F to search!

getAvailableLayouts

Definition


-- @/lua/ge/extensions/ui/apps.lua:67

local function getAvailableLayouts()
  local res = {}
  for _, originalFilePath in ipairs(FS:findFiles(originalLayoutPath, '*.uilayout.json', -1, false, false)) do
    local userFilePath = originalFilePath:gsub(originalLayoutPath, layoutPath)
    local replace = false
    local origLayout = jsonReadFile(originalFilePath)
    if FS:fileExists(userFilePath) then
      local userLayout = jsonReadFile(userFilePath)
      local userLayoutChanged = false

      -- the legacy system of updating old user layouts which updates the whole layout at once
      -- copy over original if the user file version is older.
      if origLayout.version and (not userLayout.version or origLayout.version > userLayout.version) then
        userLayout = origLayout
        userLayoutChanged = true
      end

      -- go through the apps of the original layout one by one and update them in the user layout if they are newer
      if not userLayoutChanged then
        for _, originalApp in ipairs(origLayout.apps) do
          if originalApp.appVersion then
            local userAppIndex = getAppIndexByName(userLayout, originalApp.appName)
            if userAppIndex then
              local userApp = userLayout.apps[userAppIndex]
              if userApp.appVersion == nil or userApp.appVersion < originalApp.appVersion then
                userLayout.apps[userAppIndex] = originalApp
                userLayoutChanged = true
              end
            elseif not (userLayout.removedApps and userLayout.removedApps[originalApp.appName] and userLayout.removedApps[originalApp.appName] >= originalApp.appVersion) then
              -- add new app to user layout
              table.insert(userLayout.apps, originalApp)
              userLayoutChanged = true
            end
          end
        end
      end

      -- if the original layout has removed apps, remove them from the user layout
      if origLayout.removedApps then
        for appName, appVersion in pairs(origLayout.removedApps) do
          local userAppIndex = getAppIndexByName(userLayout, appName)
          if userAppIndex then
            local userApp = userLayout.apps[userAppIndex]
            if userApp.appVersion == nil or userApp.appVersion < appVersion then
              table.remove(userLayout.apps, userAppIndex)
              userLayoutChanged = true
            end
          end
        end
      end

      if userLayoutChanged then
        jsonWriteFile(userFilePath, userLayout, true)
        log("I","",string.format("User layout was updated. File: %s", userFilePath))
      end
    else
      -- if no user file is found, add this layout to the return list
      origLayout.filename = userFilePath
      if originalFilePath:find('default') then
        origLayout.default = true
      end
      table.insert(res, origLayout)
    end
  end
  -- now go over all files in the user-ui folder and add them too.
  local jsonFiles = FS:findFiles(layoutPath, '*.uilayout.json', -1, false, false)
  for _, fn in ipairs(jsonFiles) do
    local layout = jsonReadFile(fn)

    if fn:find('default') then
      layout.default = true
    end
    layout.filename = fn
    table.insert(res, layout)
  end
  return res
end

Callers

@/lua/ge/extensions/ui/apps.lua
local function getUIAppsData()
  return {availableLayouts = getAvailableLayouts(), availableApps = getAvailableAppList()}
end
  --dump({'deleteLayout', filenameToDelete})
  local layouts = getAvailableLayouts()
  for _, layout in ipairs(layouts) do