Skip to content

Commit ab6d207

Browse files
authored
Refactor "delay submit in Safari" (hestiacp#4206)
* Consistent Node.js * More consistent output * Remove shortcut listeners around "Enter" key Causing way more problems than benefits. * Refactor "delay submit in Safari"
1 parent 182e8c8 commit ab6d207

File tree

9 files changed

+30
-38
lines changed

9 files changed

+30
-38
lines changed

bin/v-add-sys-web-terminal

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@ check_hestia_demo_mode
3636
# Updating WEB_TERMINAL value
3737
$BIN/v-change-sys-config-value "WEB_TERMINAL" "true"
3838

39-
# Check if nodejs is installed if not install repo
39+
# Check if Node.js is installed if not install repo
4040
apt="/etc/apt/sources.list.d"
4141
codename="$(lsb_release -s -c)"
4242

4343
if [ ! -z $(which "node") ]; then
44-
echo "Adding NodeJS 20.x repo..."
44+
echo "Adding Node.js 20.x repo..."
4545
echo "deb [signed-by=/usr/share/keyrings/nodesource.gpg] https://deb.nodesource.com/node_20.x $codename main" > $apt/nodesource.list
4646
echo "deb-src [signed-by=/usr/share/keyrings/nodesource.gpg] https://deb.nodesource.com/node_20.x $codename main" >> $apt/nodesource.list
4747
curl -s https://deb.nodesource.com/gpgkey/nodesource.gpg.key | gpg --dearmor | tee /usr/share/keyrings/nodesource.gpg > /dev/null 2>&1

bin/v-update-sys-hestia-git

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ source /etc/hestiacp/hestia.conf
2020
source $HESTIA/func/main.sh
2121
# load config file
2222
source_conf "$HESTIA/conf/hestia.conf"
23-
# define NodeJS version for download (required for building JS/CSS)
23+
# define Node.js version for download (required for building JS/CSS)
2424
NODE_MAJOR=20
2525

2626
# Perform verification if read-only mode is enabled
2727
check_hestia_demo_mode
2828

29-
# Detect and install NodeJS if necessary
29+
# Detect and install Node.js if necessary
3030
if [ -z $(which "node") ]; then
31-
read -p "NodeJS not found. Install now to proceed? [Y/n] " answer
31+
read -p "Node.js not found. Install now to proceed? [Y/n] " answer
3232
if [ "$answer" = 'y' ] || [ "$answer" = 'Y' ]; then
3333
sudo mkdir -p /etc/apt/keyrings
3434
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg

install/hst-install-debian.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -862,8 +862,8 @@ echo "[ * ] Hestia Control Panel"
862862
echo "deb [arch=$ARCH signed-by=/usr/share/keyrings/hestia-keyring.gpg] https://$RHOST/ $codename main" > $apt/hestia.list
863863
gpg --no-default-keyring --keyring /usr/share/keyrings/hestia-keyring.gpg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys A189E93654F0B0E5 > /dev/null 2>&1
864864

865-
# Installing NodeJS 20.x repo
866-
echo "[ * ] NodeJS 20.x"
865+
# Installing Node.js 20.x repo
866+
echo "[ * ] Node.js 20.x"
867867
echo "deb [signed-by=/usr/share/keyrings/nodesource.gpg] https://deb.nodesource.com/node_20.x $codename main" > $apt/nodesource.list
868868
echo "deb-src [signed-by=/usr/share/keyrings/nodesource.gpg] https://deb.nodesource.com/node_20.x $codename main" >> $apt/nodesource.list
869869
curl -s https://deb.nodesource.com/gpgkey/nodesource.gpg.key | gpg --dearmor | tee /usr/share/keyrings/nodesource.gpg > /dev/null 2>&1

install/hst-install-ubuntu.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -827,8 +827,8 @@ echo "[ * ] Hestia Control Panel"
827827
echo "deb [arch=$ARCH signed-by=/usr/share/keyrings/hestia-keyring.gpg] https://$RHOST/ $codename main" > $apt/hestia.list
828828
gpg --no-default-keyring --keyring /usr/share/keyrings/hestia-keyring.gpg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys A189E93654F0B0E5 > /dev/null 2>&1
829829

830-
# Installing NodeJS 20.x repo
831-
echo "[ * ] NodeJS 20.x"
830+
# Installing Node.js 20.x repo
831+
echo "[ * ] Node.js 20.x"
832832
echo "deb [signed-by=/usr/share/keyrings/nodesource.gpg] https://deb.nodesource.com/node_20.x $codename main" > $apt/nodesource.list
833833
echo "deb-src [signed-by=/usr/share/keyrings/nodesource.gpg] https://deb.nodesource.com/node_20.x $codename main" >> $apt/nodesource.list
834834
curl -s https://deb.nodesource.com/gpgkey/nodesource.gpg.key | gpg --dearmor | tee /usr/share/keyrings/nodesource.gpg > /dev/null 2>&1

install/upgrade/versions/1.9.0.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ $BIN/v-add-sys-sftp-jail
3030
codename="$(lsb_release -s -c)"
3131
apt=/etc/apt/sources.list.d
3232

33-
# Installing NodeJS 20.x repo
33+
# Installing Node.js 20.x repo
3434
if [ ! -f $apt/nodesource.list ] && [ ! -z $(which "node") ]; then
35-
echo "[ * ] Adding NodeJS 20.x repo"
35+
echo "[ * ] Adding Node.js 20.x repo"
3636
echo "deb [signed-by=/usr/share/keyrings/nodesource.gpg] https://deb.nodesource.com/node_20.x $codename main" > $apt/nodesource.list
3737
echo "deb-src [signed-by=/usr/share/keyrings/nodesource.gpg] https://deb.nodesource.com/node_20.x $codename main" >> $apt/nodesource.list
3838
curl -s https://deb.nodesource.com/gpgkey/nodesource.gpg.key | gpg --dearmor | tee /usr/share/keyrings/nodesource.gpg > /dev/null 2>&1

src/hst_autocompile.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -277,25 +277,25 @@ if [ "$dontinstalldeps" != 'true' ]; then
277277
echo "Installing dependencies for compilation..."
278278
apt-get -qq install -y $SOFTWARE > /dev/null 2>&1
279279

280-
# Installing NodeJS 20.x repo
280+
# Installing Node.js 20.x repo
281281
apt="/etc/apt/sources.list.d"
282282
codename="$(lsb_release -s -c)"
283283

284284
if [ -z $(which "node") ]; then
285-
echo "Adding NodeJS 20.x repo..."
285+
echo "Adding Node.js 20.x repo..."
286286
echo "deb [signed-by=/usr/share/keyrings/nodesource.gpg] https://deb.nodesource.com/node_20.x $codename main" > $apt/nodesource.list
287287
echo "deb-src [signed-by=/usr/share/keyrings/nodesource.gpg] https://deb.nodesource.com/node_20.x $codename main" >> $apt/nodesource.list
288288
curl -s https://deb.nodesource.com/gpgkey/nodesource.gpg.key | gpg --dearmor | tee /usr/share/keyrings/nodesource.gpg > /dev/null 2>&1
289289
fi
290290

291-
echo "Install NodeJS...."
291+
echo "Installing Node.js..."
292292
apt-get -qq update > /dev/null 2>&1
293293
apt -qq install -y nodejs > /dev/null 2>&1
294294

295295
nodejs_version=$(/usr/bin/node -v | cut -f1 -d'.' | sed 's/v//g')
296296

297297
if [ "$nodejs_version" -lt 18 ]; then
298-
echo "Requires NodeJS 18.x or higher"
298+
echo "Requires Node.js 18.x or higher"
299299
exit 1
300300
fi
301301

web/js/src/formSubmit.js

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,17 @@
11
import { enableUnlimitedInputs } from './unlimitedInput';
22
import { updateAdvancedTextarea } from './toggleAdvanced';
3-
import { isDesktopSafari, showSpinner } from './helpers';
3+
import { isDesktopSafari, showSpinner, delay } from './helpers';
44

55
export default function handleFormSubmit() {
66
const mainForm = document.querySelector('#main-form');
77
if (mainForm) {
8-
mainForm.addEventListener('submit', (event) => {
9-
// Show loading spinner
8+
mainForm.addEventListener('submit', async (event) => {
9+
event.preventDefault();
1010
showSpinner();
1111

12-
// Wait a bit if Desktop Safari to ensure spinner is shown
12+
// Wait if Desktop Safari to ensure spinner is shown
1313
if (isDesktopSafari()) {
14-
const submitButton = document.querySelector('button[type="submit"]');
15-
if (!submitButton.dataset.clicked) {
16-
event.preventDefault();
17-
submitButton.dataset.clicked = 'true';
18-
setTimeout(() => {
19-
mainForm.submit();
20-
}, 500);
21-
}
14+
await delay(500);
2215
}
2316

2417
// Enable any disabled inputs to ensure all fields are submitted
@@ -36,13 +29,14 @@ export default function handleFormSubmit() {
3629
if (basicOptionsWrapper && !basicOptionsWrapper.classList.contains('u-hidden')) {
3730
updateAdvancedTextarea();
3831
}
32+
33+
mainForm.submit();
3934
});
4035
}
4136

4237
const bulkEditForm = document.querySelector('[x-bind="BulkEdit"]');
4338
if (bulkEditForm) {
4439
bulkEditForm.addEventListener('submit', () => {
45-
// Show loading spinner
4640
showSpinner();
4741
});
4842
}

web/js/src/helpers.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,13 @@ export function parseAndSortIpLists(ipListsData) {
4747
export function isDesktopSafari() {
4848
const userAgent = window.navigator.userAgent;
4949
const isSafari = /^((?!chrome|android).)*safari/i.test(userAgent);
50-
const isMobile = /iPhone|iPad|iPod|Android/i.test(userAgent);
51-
return isSafari && !isMobile;
50+
const isMac = /Macintosh|MacIntel/i.test(window.navigator.platform);
51+
return isSafari && isMac;
52+
}
53+
54+
// Waits for the given number of milliseconds
55+
export function delay(milliseconds) {
56+
return new Promise((resolve) => setTimeout(resolve, milliseconds));
5257
}
5358

5459
// Posts data to the given URL and returns the response

web/js/src/shortcuts.js

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,6 @@ export default function handleShortcuts() {
136136
},
137137
{ disabledInInput: true },
138138
)
139-
.register({ code: 'Enter', ctrlKey: true }, (_evt) => {
140-
document.querySelector('#main-form').submit();
141-
})
142139
.register({ code: 'Backspace', ctrlKey: true }, (_evt) => {
143140
const redirect = document.querySelector('a.js-button-back').href;
144141
if (!redirect) {
@@ -428,11 +425,7 @@ export default function handleShortcuts() {
428425
)
429426
.register(
430427
{ code: 'Enter' },
431-
(evt) => {
432-
if (evt.target.tagName === 'INPUT' && evt.target.form.id === 'main-form') {
433-
evt.target.form.submit();
434-
}
435-
428+
() => {
436429
if (Alpine.store('form').dirty) {
437430
if (document.querySelector('dialog[open]')) {
438431
const dialog = document.querySelector('dialog[open]');

0 commit comments

Comments
 (0)