From 37d78b790e2dced461dc17f11e163c90fd563f52 Mon Sep 17 00:00:00 2001 From: KOWX712 Date: Mon, 24 Feb 2025 03:06:14 +0800 Subject: [PATCH] misc: code clean up --- module/webui/index.html | 2 +- module/webui/scripts/about.js | 2 +- module/webui/scripts/applist.js | 4 ++-- module/webui/scripts/main.js | 31 ++++++++++++------------------- module/webui/styles/global.css | 14 +++++--------- 5 files changed, 21 insertions(+), 32 deletions(-) diff --git a/module/webui/index.html b/module/webui/index.html index 32ce707..dc3a538 100644 --- a/module/webui/index.html +++ b/module/webui/index.html @@ -4,7 +4,7 @@ - TrickyAddon + TrickyAddon diff --git a/module/webui/scripts/about.js b/module/webui/scripts/about.js index 3bc013e..77a3611 100644 --- a/module/webui/scripts/about.js +++ b/module/webui/scripts/about.js @@ -1,4 +1,4 @@ -import { execCommand, linkRedirect } from './main.js'; +import { linkRedirect } from './main.js'; const telegramLink = document.getElementById('telegram'); const githubLink = document.getElementById('github'); diff --git a/module/webui/scripts/applist.js b/module/webui/scripts/applist.js index 5f3838e..8ac043f 100644 --- a/module/webui/scripts/applist.js +++ b/module/webui/scripts/applist.js @@ -1,4 +1,4 @@ -import { basePath, execCommand, floatingBtn, appsWithExclamation, appsWithQuestion, toast } from './main.js'; +import { basePath, execCommand, hideFloatingBtn, appsWithExclamation, appsWithQuestion, toast } from './main.js'; const appTemplate = document.getElementById('app-template').content; const modeOverlay = document.querySelector('.mode-overlay'); @@ -113,7 +113,7 @@ export async function fetchAppList() { toast("Failed to fetch app list!"); console.error("Failed to fetch or render app list with names:", error); } - floatingBtn.style.transform = 'translateY(0)'; + hideFloatingBtn(false); toggleableCheckbox(); if (appListContainer.firstChild !== updateCard) { appListContainer.insertBefore(updateCard, appListContainer.firstChild); diff --git a/module/webui/scripts/main.js b/module/webui/scripts/main.js index df5cf61..f415946 100644 --- a/module/webui/scripts/main.js +++ b/module/webui/scripts/main.js @@ -15,7 +15,7 @@ const permissionPopup = document.getElementById('permission-popup'); const loadingIndicator = document.querySelector('.loading'); const prompt = document.getElementById('prompt'); const floatingCard = document.querySelector('.floating-card'); -export const floatingBtn = document.querySelector('.floating-btn'); +const floatingBtn = document.querySelector('.floating-btn'); export const basePath = "set-path"; export const appsWithExclamation = []; @@ -221,22 +221,13 @@ async function checkMMRL() { } // Funtion to adapt floating button hide in MMRL -function hideFloatingBtn(hide = true) { +export function hideFloatingBtn(hide = true) { if (!hide) { - floatingBtn.style.display = 'block'; - setTimeout(() => { - floatingBtn.style.transform = 'translateY(0)'; - }, 10); + floatingCard.style.transform = 'translateY(0)'; } else if (typeof ksu !== 'undefined' && ksu.mmrl) { - floatingBtn.style.transform = 'translateY(calc(var(--window-inset-bottom) + 120px))'; - setTimeout(() => { - floatingBtn.style.display = 'none'; - }, 400); + floatingCard.style.transform = 'translateY(calc(var(--window-inset-bottom) + 120px))'; } else { - floatingBtn.style.transform = 'translateY(120px)'; - setTimeout(() => { - floatingBtn.style.display = 'none'; - }, 400); + floatingCard.style.transform = 'translateY(120px)'; } } @@ -342,10 +333,8 @@ document.addEventListener('DOMContentLoaded', async () => { updateCheck(); securityPatch(); loadingIndicator.style.display = "none"; - floatingBtn.style.opacity = '1'; - setTimeout(() => { - hideFloatingBtn(false); - }, 10); + floatingBtn.style.display = 'block'; + hideFloatingBtn(false); document.getElementById("refresh").addEventListener("click", refreshAppList); document.getElementById("aospkb").addEventListener("click", aospkb); document.querySelector('.uninstall-container').classList.remove('hidden-uninstall'); @@ -375,5 +364,9 @@ export async function execCommand(command) { // Function to toast message export function toast(message) { - ksu.toast(message); + try { + ksu.toast(message); + } catch (error) { + console.error("Failed to show toast:", error); + } } \ No newline at end of file diff --git a/module/webui/styles/global.css b/module/webui/styles/global.css index 8a88889..84c16c1 100644 --- a/module/webui/styles/global.css +++ b/module/webui/styles/global.css @@ -12,26 +12,22 @@ body { display: flex; justify-content: center; position: fixed; + width: 100%; bottom: 50px; - left: 50%; - transform: translateX(-50%); - z-index: 10; + transition: transform 0.4s ease; + z-index: 2; } .floating-btn { - flex-shrink: 0; background-color: #007bff; border: none; box-shadow: 0 4px 8px #0003; color: #fff; - display: flex; - justify-content: center; - align-items: center; - opacity: 0; + display: none; + bottom: 0; padding: 10px 20px; font-size: 22px; font-weight: bold; - transition: transform 0.4s ease; border-radius: 50px 50px; user-select: none; }