-- 制作: 神仙 -- 官方群 694700750 -- 此UI为RLGG使用 -- 设计时发现点小问题 -- 现在开源处理 local windowManager = require('windowManager') local loginView, toolboxView local loginManager, toolboxManager local loginParams, toolboxParams local currentView = nil -- ========== 本地存储路径 ========== local dataPath = '/storage/emulated/0/rlgg/神仙工具箱用户数据' -- ========== 免费文件列表 ========== local freeList -- ========== 付费文件列表 ========== local paidList freeList = { [0] = {name = '你好.lua', download_url = 'https://free.example.com/hello.lua'}, [1] = {name = '世界.lua', download_url = 'https://free.example.com/world.lua'}, [2] = {name = '测试.lua', download_url = 'https://free.example.com/test.lua'}, [3] = {name = '示例.lua', download_url = 'https://free.example.com/sample.lua'}, [4] = {name = '演示.lua', download_url = 'https://free.example.com/demo.lua'}, [5] = {name = '入门.lua', download_url = 'https://free.example.com/start.lua'}, } paidList = { [0] = {name = '高级功能.lua', download_url = 'https://paid.example.com/advanced.lua'}, [1] = {name = '专业版.lua', download_url = 'https://paid.example.com/pro.lua'}, [2] = {name = '加速器.lua', download_url = 'https://paid.example.com/speed.lua'}, [3] = {name = '解锁内容.lua', download_url = 'https://paid.example.com/unlock.lua'}, [4] = {name = '完整包.lua', download_url = 'https://paid.example.com/full.lua'}, [5] = {name = '终极版.lua', download_url = 'https://paid.example.com/ultimate.lua'}, } -- ========== 本地存储操作 ========== local function saveLoginData(userName, password) local data = 'userName=' .. userName .. '\npassword=' .. password local f = io.open(dataPath, 'w') if f then data=string.zip(string.rc4(data,device_code)) f:write(data) f:close() end end local function loadLoginData() local f = io.open(dataPath, 'r') if not f then return nil, nil end local content = f:read('*a') f:close() content=string.unzip(content) content=string.rc4(content,device_code) local userName = content:match('userName=([^\n]+)') local password = content:match('password=([^\n]+)') return userName, password end -- ========== 下载函数 ========== function doDownload(url, name) local path = gg.EXT_STORAGE .. '/' .. name luajava.startThread(function() local ok, err = luajava.download(url, path) pcall(function() rlgg.load("document.getElementById('progressBar').classList.remove('show')") end) if ok then gg.alert('下载成功\n' .. path) else gg.alert('下载失败\n' .. (err or '未知错误')) end end) end -- ========== 登录逻辑 ========== function onLogin(userName, password) luajava.startThread(function() goToolbox() end) end -- ========== 工具箱逻辑 ========== function goToolbox() windowManager:setVisibility(toolboxView, 0) windowManager:setVisibility(loginView, 8) currentView = toolboxView end function logoutToLogin() windowManager:setVisibility(loginView, 0) windowManager:setVisibility(toolboxView, 8) currentView = loginView end function exitUI() if loginManager then loginManager:exit() end if toolboxManager then toolboxManager:exit() end end -- ========== 聚焦切换 ========== function enableLoginFocus() loginParams.flags = loginParams.flags & ~0x00000008 windowManager:updateViewLayout(loginView, loginParams) end function disableLoginFocus() loginParams.flags = loginParams.flags | 0x00000008 windowManager:updateViewLayout(loginView, loginParams) end function enableToolboxFocus() toolboxParams.flags = toolboxParams.flags & ~0x00000008 windowManager:updateViewLayout(toolboxView, toolboxParams) end function disableToolboxFocus() toolboxParams.flags = toolboxParams.flags | 0x00000008 windowManager:updateViewLayout(toolboxView, toolboxParams) end -- ========== HTML 模板 ========== local function getLoginHTML() return [[ 登录

登录

用户名
密码
]] end local function getToolboxHTML() return [[ 神仙工具箱

工具箱

下载中
]] end -- ========== 构建文件列表 JSON ========== local function buildFilesJSON(list) local parts = {} local idx = 0 while list[idx] do local item = list[idx] parts[#parts + 1] = string.format( '{"name":"%s","url":"%s"}', item.name:gsub('"', '\\"'):gsub('\n', '\\n'), item.download_url:gsub('"', '\\"'):gsub('\n', '\\n') ) idx = idx + 1 end return '[' .. table.concat(parts, ',') .. ']' end -- ========== 创建 WebView ========== loginView = luajava.webView(function(wv) wv:setBackgroundColor(0x00fffbfe) local html = getLoginHTML() -- local userName, password = loadLoginData() html = html:gsub('__USER__', userName or '') html = html:gsub('__PASS__', password or '') wv:loadData(html, 'text/html', 'UTF-8') end) toolboxView = luajava.webView(function(wv) wv:setBackgroundColor(0x00fffbfe) local html = getToolboxHTML() html = html:gsub('__FREE__', buildFilesJSON(freeList)) html = html:gsub('__PAID__', buildFilesJSON(paidList)) wv:loadData(html, 'text/html', 'UTF-8') end) -- ========== 添加到窗口 ========== local baseFlags = 0x00000400 | 0x00000200 | 0x00000008 loginManager = windowManager:bindView(loginView) loginManager:addView({ width = -1, height = -1, flags = baseFlags }) loginParams = windowManager:getLayoutParams(loginView) toolboxManager = windowManager:bindView(toolboxView) toolboxManager:addView({ width = -1, height = -1, flags = baseFlags }) toolboxParams = windowManager:getLayoutParams(toolboxView) windowManager:setVisibility(toolboxView, 0) luajava.startThread(function() gg.sleep(200) windowManager:setVisibility(toolboxView, 8) end) currentView = loginView -- ========== 音量键隐藏 ========== local visible = true setOnAudioListener(function() if visible then windowManager:setVisibility(currentView, 8) visible = false else windowManager:setVisibility(currentView, 0) visible = true end end) gg.setVisible(false) loginManager:wait()