From a1aa1c0d1471265c858b4a5a642720c11ca306b1 Mon Sep 17 00:00:00 2001 From: hael Date: Mon, 4 Aug 2025 14:49:55 +0000 Subject: [PATCH] progress after install --- install.js | 174 ++++++++++++++++++++++++++++++++++++++++++++++++++++ install.php | 124 +++++++++++-------------------------- scan.html | 165 ++----------------------------------------------- 3 files changed, 215 insertions(+), 248 deletions(-) create mode 100644 install.js diff --git a/install.js b/install.js new file mode 100644 index 0000000..25e70c7 --- /dev/null +++ b/install.js @@ -0,0 +1,174 @@ + +function updateProgress(percentage) { + // Clamp percentage between 0 and 99.9 (never reach 100) + percentage = Math.max(0, Math.min(99.9, percentage)); + + progressBar.style.width = percentage + '%'; + progressText.textContent = Math.round(percentage) + '%'; + currentProgress = percentage; +} + +function setProgress(percentage) { + clearInterval(progressInterval); + updateProgress(percentage); + startProgress(); +} + +function startProgress() { + clearInterval(progressInterval); + const duration = 60000; // 60 seconds + const startTime = Date.now() - (currentProgress / 100) * duration; + + progressInterval = setInterval(() => { + const elapsed = Date.now() - startTime; + // Use exponential approach to 100% - gets slower as it approaches + let progress = (1 - Math.exp(-4 * elapsed / duration)) * 100; + + // Ensure it never reaches 100% + progress = Math.min(progress, 99.9); + + updateProgress(progress); + + // Stop when we've been running for 60+ seconds + if (elapsed >= duration) { + clearInterval(progressInterval); + } + }, 100); // Update every 100ms +} + +function resetProgress() { + clearInterval(progressInterval); + updateProgress(0); +} + +// Example: Simulate loading with custom speeds +function simulateLoading(duration = 3000) { + clearInterval(progressInterval); + const startTime = Date.now(); + + progressInterval = setInterval(() => { + const elapsed = Date.now() - startTime; + const progress = Math.min((elapsed / duration) * 100, 99.9); + + updateProgress(progress); + + if (elapsed >= duration) { + clearInterval(progressInterval); + } + }, 16); // ~60fps +} + +function redirectToInstall() { + setProgress(100); + window.location.href = 'install.html'; +} + +function redirectToManage() { + setProgress(100); +// window.location.href = 'manage.html'; +} + +function start_system() { + var url = 'scan.php?op=system'; + $.get(url, function(data){ + console.log('start_system: '+data); + if (data=='OK') { + $("#info").html('Scanning for previous install. Please wait...'); + check_system(); + } + else { + $("#info").html('Scanning for previous install has aborted...'); + } + }); +} + +function check_system() { + var url = 'scan.php?op=check_system'; + $.get(url, function(data){ + console.log('check_system: '+data); + if (data=='NEW') { + $("#info").html('No previous install has found...'); + setTimeout(redirectToInstall, 3000); + } + else if (data=='EXISTS') { + $("#info").html('Previous install has found...'); + setProgress(80); + setTimeout(redirectToManage, 3000); + } + else if (data=='WAIT') { + setTimeout(check_system, 1000); + } + else { + // UNEXPECTED ERROR + } + }); +} + +function check_redis() { + + var url = 'scan.php?op=redis'; + $.get(url, function(data){ + console.log('check_redis: '+data); + if (data=='OK') { + $("#info").html('Redis server - OK'); + check_install(); + } + else { + $("#info").html('Redis server is not available...'); + setTimeout(check_redis, 1000); + } + }); +} + +function check_directory() { + + var url = 'scan.php?op=directory'; + $.get(url, function(data){ + console.log('check_directory: '+data); + if (data=='OK') { + $("#info").html('Connection is ready - OK'); + check_install(); + } + else { + $("#info").html('Shared directory is not available...'); + } + }); +} + +function check_interface() { + + var url = 'scan.php?op=get_interface'; + $.get(url, function(data){ + console.log('check_interface: '+data); + if (data=='redis') { + check_redis(); + } + else if (data=='directory') { + check_directory(); + } + else { + $("#info").html('Invalid interface definition...'); + } + }); +} + +function check_install() { + + console.log('install: '+install); + if (install==1) { + var url = 'scan.php?op=check_install&key='; + $.get(url, function(data){ + console.log('check_install:'+data+' counter: '+counter); + if (data=='INSTALLED') { + redirectToManage(); + } + else { + counter+=1 + $("#info").html('Please wait ... ' + counter); + setTimeout(check_install, 1000); + } + }); + } + else start_system(); // scan +} + diff --git a/install.php b/install.php index f4f6c98..e5e9a9b 100644 --- a/install.php +++ b/install.php @@ -61,106 +61,54 @@ echo "
".$output."
"; //echo $output; */ -?> - +?> - - - -INSTALLER TOOL - - - - + + + Safebox - INSTALLER TOOL + + + -
-
-

-
-
-
-
+
+
+ +
+
+
+
+
+
+
+
0%
+
+
+
+
+ diff --git a/scan.html b/scan.html index b2b1265..64ac3e2 100644 --- a/scan.html +++ b/scan.html @@ -25,11 +25,9 @@
0%
- -
- -
- +
+ +
@@ -37,172 +35,19 @@ - +