change update method

This commit is contained in:
KOWX712
2024-12-31 17:02:04 +08:00
parent 1d5428e683
commit 502e6f6ea6
14 changed files with 386 additions and 83 deletions

View File

@@ -235,7 +235,7 @@ function setupModeMenu() {
} else if (event.target.closest(".status-indicator")) {
setTimeout(() => {
hideAllModes();
}, 200);
}, 300);
}
});
window.addEventListener("scroll", hideAllModes);

View File

@@ -1,4 +1,4 @@
import { appListContainer, updateCard, fetchAppList } from './applist.js';
import { appListContainer, fetchAppList } from './applist.js';
import { initializeAvailableLanguages, detectUserLanguage, loadTranslations, setupLanguageMenu, translations } from './language.js';
import { aospkb } from './menu_option.js';
import { searchMenuContainer, searchInput, clearBtn, setupMenuToggle } from './search_menu.js';
@@ -19,7 +19,7 @@ export const basePath = "set-path";
export const appsWithExclamation = [];
export const appsWithQuestion = [];
const ADDITIONAL_APPS = [ "com.google.android.gms", "io.github.vvb2060.keyattestation", "io.github.vvb2060.mahoshojo", "icu.nullptr.nativetest" ];
const rippleClasses = ['.language-option', '.menu-button', '.menu-options li', '.search-card', '.card', '.update-card', '.link-icon', '.floating-btn', '.uninstall-container', '.boot-hash-save-button', '.boot-hash-value', '.status-indicator'];
const rippleClasses = ['.language-option', '.menu-button', '.menu-options li', '.search-card', '.card', '.update-card', '.link-icon', '.floating-btn', '.uninstall-container', '.boot-hash-save-button', '.boot-hash-value', '.status-indicator', '.reboot', '.install'];
// Variables
let e = 0;
@@ -84,7 +84,7 @@ async function checkMagisk() {
}
// Function to show the prompt with a success or error message
export function showPrompt(key, isSuccess = true) {
export function showPrompt(key, isSuccess = true, duration = 3000) {
const message = key.split('.').reduce((acc, k) => acc && acc[k], translations) || key;
prompt.textContent = message;
prompt.classList.toggle('error', !isSuccess);
@@ -99,8 +99,8 @@ export function showPrompt(key, isSuccess = true) {
}
window.promptTimeout = setTimeout(() => {
prompt.style.transform = 'translateY(100%)';
}, 3000);
}, 200);
}, duration);
}, 100);
}
// Function to redirect link on external browser
@@ -291,16 +291,6 @@ document.addEventListener('DOMContentLoaded', async () => {
document.querySelector('.uninstall-container').classList.remove('hidden-uninstall');
});
// Redirect to GitHub release page
updateCard.addEventListener('click', async () => {
try {
await execCommand('am start -a android.intent.action.VIEW -d https://github.com/KOWX712/Tricky-Addon-Update-Target-List/releases/latest');
} catch (error) {
toast("Failed!");
console.error('Error opening GitHub Release link:', error);
}
});
// Function to execute shell commands
export async function execCommand(command) {
return new Promise((resolve, reject) => {

View File

@@ -1,6 +1,13 @@
import { basePath, execCommand, showPrompt, noConnection } from './main.js';
import { updateCard } from './applist.js';
const updateCardText = document.getElementById('redirect-to-release');
const UpdateMenu = document.querySelector('.update-overlay');
const closeUpdate = document.querySelector('.close-update');
const releaseNotes = document.querySelector('.changelog');
const installButton = document.querySelector('.install');
const rebootButton = document.querySelector('.reboot');
// Function to run the update check
export async function updateCheck() {
try {
@@ -9,8 +16,9 @@ export async function updateCheck() {
noConnection.style.display = "none";
if (output.includes("update")) {
console.log("Update detected from extra script.");
showPrompt("prompt.new_update");
showPrompt("prompt.new_update", true, 2000);
updateCard.style.display = "flex";
setupUpdateMenu();
} else {
console.log("No update detected from extra script.");
}
@@ -20,3 +28,74 @@ export async function updateCheck() {
noConnection.style.display = "flex";
}
}
// Function to setup update menu
function setupUpdateMenu() {
function openUpdateMenu() {
UpdateMenu.style.display = "flex";
setTimeout(async () => {
UpdateMenu.style.opacity = "1";
}, 10);
document.body.classList.add("no-scroll");
}
function closeUpdateMenu() {
UpdateMenu.style.opacity = "0";
document.body.classList.remove("no-scroll");
setTimeout(async () => {
UpdateMenu.style.display = "none";
}, 200);
}
updateCard.addEventListener('click', async () => {
try {
const module = await execCommand(`[ -f ${basePath}common/tmp/module.zip ] || echo "false"`);
if (module.trim() === "false") {
showPrompt("prompt.downloading");
await new Promise(resolve => setTimeout(resolve, 200));
await execCommand(`sh ${basePath}common/get_extra.sh --get-update`);
showPrompt("prompt.downloaded");
}
const changelog = await execCommand(`sh ${basePath}common/get_extra.sh --release-note`);
const lines = changelog.split('\n');
const formattedChangelog = `
<span style="font-weight: bold; font-size: 18px;">${lines[0]}</span><br>
${lines.slice(1).join('<br>')}
`;
releaseNotes.innerHTML = formattedChangelog;
openUpdateMenu();
} catch (error) {
showPrompt("prompt.download_fail", false);
console.error('Error download module update:', error);
}
});
closeUpdate.addEventListener("click", closeUpdateMenu);
UpdateMenu.addEventListener("click", (event) => {
if (event.target === UpdateMenu) {
closeUpdateMenu();
}
});
installButton.addEventListener('click', async () => {
try {
showPrompt("prompt.installing");
setTimeout(async () => {
await execCommand(`sh ${basePath}common/get_extra.sh --install-update`);
showPrompt("prompt.installed");
installButton.style.display = "none";
rebootButton.style.display = "flex";
}, 300);
} catch (error) {
showPrompt("prompt.install_fail", false);
console.error('Fail to execute installation script:', error);
}
});
rebootButton.addEventListener('click', async () => {
try {
showPrompt("prompt.rebooting");
setTimeout(async () => {
await execCommand("svc power reboot");
}, 1000);
} catch (error) {
showPrompt("prompt.reboot_fail", false);
console.error('Fail to reboot:', error);
}
});
}