Showing posts with label luaRT. Show all posts
Showing posts with label luaRT. Show all posts

Tuesday, July 29, 2025

WEBVIEW APP FOR LUART

webview app for luRT



local ui = require "ui"
require "webview"

sys.currentdir = sys.File(arg[0]).path

-- Tulis HTML dengan overlay loading
local file = io.open("main.html", "w")
file:write([[
<html>
  <head>
    <title></title>
    <style>
      #loading {
        position: absolute;
        top: 0; left: 0; right: 0; bottom: 0;
        background-color: white;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        font-family: sans-serif;
        font-size: 18px;
        z-index: 9999;
      }

      .loader {
        width: 60px;
        height: 60px;
        border: 6px solid #e0e0e0;
        border-top: 6px solid #3f51b5; /* biru material */
        border-radius: 50%;
        animation: spin 1s linear infinite;
        margin-bottom: 10px;
      }

      @keyframes spin {
        0% { transform: rotate(0deg); }
        100% { transform: rotate(360deg); }
      }

      iframe {
        position:absolute;
        top:0; left:0; bottom:0; right:0;
        width:100%;
        height:100%;
        border:0;
      }
    </style>
  </head>
  <body>
    <div id="loading">
      <div class="loader"></div>
      <div>Sedang Proses...</div>
    </div>
    <iframe id="myframe" src="about:blank"></iframe>
  </body>
</html>
]])

file:close()

-- Buat Window
local win = ui.Window("eKehadian 2025", "single", 800, 600)
win:center()

local wv = ui.Webview(win, { url = "file://" .. sys.currentdir .. "/main.html" })
wv.align = "all"

function wv:onReady()
  self.statusbar = false
  self.devtools = false
  self.contextmenu = false

  -- Manipulasi iframe dan loading dari Lua
  self:eval([[
    const iframe = document.getElementById("myframe");
    const loading = document.getElementById("loading");

    loading.style.display = "flex";
    iframe.src = "https://script.google.com/macros/s/AKfycbxW-ywTkAtQuDfPMchPVvYxhNXfLBbyZsQ7jPEq4wSroOKHF6b5Zr_CanzMduSUDFBL/exec";

    iframe.onload = () => {
      loading.style.display = "none";
    };
  ]])
end

ui.run(win):wait()