From 4e0c1590e4a7c0a6cdf8ac3eb8fae10735a6ca4f Mon Sep 17 00:00:00 2001 From: HighImKevin Date: Thu, 5 Feb 2026 19:33:31 -0500 Subject: [PATCH] Improve KefinTweaks configuration Export to better accomodate http:// connections --- scripts/configuration.js | 121 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 112 insertions(+), 9 deletions(-) diff --git a/scripts/configuration.js b/scripts/configuration.js index 8509802..39c87a2 100644 --- a/scripts/configuration.js +++ b/scripts/configuration.js @@ -4799,24 +4799,127 @@ } } - // Export configuration to clipboard + // Export configuration via modal (with optional clipboard copy on HTTPS) async function handleExportConfig(config) { try { const configJson = JSON.stringify(config, null, 2); - await navigator.clipboard.writeText(configJson); - - if (window.KefinTweaksToaster && window.KefinTweaksToaster.toast) { - window.KefinTweaksToaster.toast('Configuration exported to clipboard!'); + + // Prefer modal-based export so it works even on unsecured servers + if (window.ModalSystem) { + const isHttps = + (typeof ApiClient !== 'undefined' && + ApiClient._serverAddress && + ApiClient._serverAddress.startsWith('https://')) || + (typeof location !== 'undefined' && location.protocol === 'https:'); + + const supportsClipboard = !!(navigator.clipboard && navigator.clipboard.writeText); + const canUseClipboard = isHttps && supportsClipboard; + + window.ModalSystem.create({ + id: 'exportConfigModal', + title: 'Export Configuration', + content: ` +
+ Your current configuration is shown below as JSON. Select and copy this text to back up or share your configuration. + ${canUseClipboard ? '' : ' Clipboard access is not available on this connection, so manual copying is required.'} +
+ + `, + footer: ` + ${ + canUseClipboard + ? ` + + ` + : '' + } + + `, + closeOnBackdrop: true, + closeOnEscape: true, + onOpen: (modalInstance) => { + const textarea = modalInstance.dialogContent.querySelector('#exportConfigTextarea'); + if (textarea) { + textarea.value = configJson; + // Select text to make manual copying easier + setTimeout(() => { + textarea.focus(); + textarea.select(); + }, 100); + } + + const closeBtn = modalInstance.dialogFooter?.querySelector('#closeExportConfigBtn'); + if (closeBtn) { + closeBtn.addEventListener('click', () => modalInstance.close()); + } + + if (canUseClipboard) { + const copyBtn = modalInstance.dialogFooter?.querySelector('#copyExportConfigBtn'); + if (copyBtn) { + copyBtn.addEventListener('click', async () => { + try { + await navigator.clipboard.writeText(configJson); + if (window.KefinTweaksToaster && window.KefinTweaksToaster.toast) { + window.KefinTweaksToaster.toast('Configuration copied to clipboard!'); + } else { + alert('Configuration copied to clipboard!'); + } + } catch (copyError) { + console.error( + '[KefinTweaks Configuration] Error copying config to clipboard:', + copyError + ); + if (window.KefinTweaksToaster && window.KefinTweaksToaster.toast) { + window.KefinTweaksToaster.toast( + 'Error copying configuration to clipboard', + '5' + ); + } else { + alert('Error copying configuration to clipboard'); + } + } + }); + } + } + } + }); + } else if (navigator.clipboard && navigator.clipboard.writeText) { + // Fallback: no modal system, but clipboard is available + await navigator.clipboard.writeText(configJson); + + if (window.KefinTweaksToaster && window.KefinTweaksToaster.toast) { + window.KefinTweaksToaster.toast('Configuration exported to clipboard!'); + } else { + alert('Configuration exported to clipboard!'); + } } else { - alert('Configuration exported to clipboard!'); + // Last-resort fallback: log to console + console.log('[KefinTweaks Configuration] Exported configuration:', configJson); + if (window.KefinTweaksToaster && window.KefinTweaksToaster.toast) { + window.KefinTweaksToaster.toast( + 'Unable to open export modal or access clipboard; configuration logged to console', + '3' + ); + } else { + alert( + 'Unable to open export modal or access clipboard. Check the browser console for the exported configuration.' + ); + } } } catch (error) { console.error('[KefinTweaks Configuration] Error exporting config:', error); - if (window.KefinTweaksToaster && window.KefinTweaksToaster.toast) { - window.KefinTweaksToaster.toast('Error exporting configuration to clipboard', '5'); + window.KefinTweaksToaster.toast('Error exporting configuration', '5'); } else { - alert('Error exporting configuration to clipboard'); + alert('Error exporting configuration'); } } }