From e6bdbef26c56794de68817442b5334cf41252cfd Mon Sep 17 00:00:00 2001 From: Andy Dixon Date: Wed, 15 Apr 2026 00:00:00 +0100 Subject: [PATCH] Fix JS execution: wrap all scripts in IIFEs to avoid WebKit global scope conflicts WebKit's WKWebView rejects top-level const/let declarations that shadow global function names. Since utils.js defines functions like stateLabel() at the global scope (non-module scripts), and later files destructure the same names from window.NexusTerminal using const, WebKit throws: SyntaxError: Can't create duplicate variable that shadows a global property Fix: wrap every JS file in an IIFE so all declarations are function-scoped. Also remove temporary diagnostic instrumentation. --- frontend/src/js/app.js | 15 +++++++++++++-- frontend/src/js/commands.js | 3 +++ frontend/src/js/notifications.js | 3 +++ frontend/src/js/profiles.js | 3 +++ frontend/src/js/raw.js | 3 +++ frontend/src/js/secrets.js | 3 +++ frontend/src/js/settings.js | 3 +++ frontend/src/js/sidebar.js | 3 +++ frontend/src/js/state.js | 3 +++ frontend/src/js/tabs.js | 3 +++ frontend/src/js/terminal.js | 3 +++ frontend/src/js/utils.js | 3 +++ 12 files changed, 46 insertions(+), 2 deletions(-) diff --git a/frontend/src/js/app.js b/frontend/src/js/app.js index f4a587d..6e94c98 100644 --- a/frontend/src/js/app.js +++ b/frontend/src/js/app.js @@ -1,3 +1,4 @@ +(function() { /** * Nexus Terminal — main application entry point. * Initialises the application shell, loads profiles, and sets up event listeners. @@ -281,6 +282,7 @@ class App { * Binds click handlers to static UI elements. */ setupUI() { + var btnEl = document.getElementById('btn-new-connection'); this._bindClick('btn-new-connection', () => this.profileEditor.openNew()); this._bindClick('btn-settings', () => this.settings.open()); this._bindClick('btn-import', () => this.importProfiles()); @@ -509,7 +511,16 @@ class App { // ── Bootstrap ──────────────────────────────────────────────────────── + document.addEventListener('DOMContentLoaded', () => { - const app = new App(); - app.init().catch((err) => console.error('App initialisation failed:', err)); + try { + const app = new App(); + app.init().catch((err) => { + console.error('App initialisation failed:', err); + }); + } catch (err) { + console.error('App constructor failed:', err); + } }); + +})(); diff --git a/frontend/src/js/commands.js b/frontend/src/js/commands.js index 97fee67..763673f 100644 --- a/frontend/src/js/commands.js +++ b/frontend/src/js/commands.js @@ -1,3 +1,4 @@ +(function() { /** * Nexus Terminal — command palette (Ctrl+K). * Provides a searchable overlay for quick access to application commands, @@ -382,3 +383,5 @@ class CommandPalette { window.NexusTerminal = window.NexusTerminal || {}; window.NexusTerminal.CommandPalette = CommandPalette; + +})(); diff --git a/frontend/src/js/notifications.js b/frontend/src/js/notifications.js index 044b719..87d824f 100644 --- a/frontend/src/js/notifications.js +++ b/frontend/src/js/notifications.js @@ -1,3 +1,4 @@ +(function() { /** * Nexus Terminal — toast notification system. * Provides non-blocking, auto-dismissing notifications that stack @@ -125,3 +126,5 @@ class Notifications { window.NexusTerminal = window.NexusTerminal || {}; window.NexusTerminal.Notifications = Notifications; + +})(); diff --git a/frontend/src/js/profiles.js b/frontend/src/js/profiles.js index 7dd9bfd..2a02b1a 100644 --- a/frontend/src/js/profiles.js +++ b/frontend/src/js/profiles.js @@ -1,3 +1,4 @@ +(function() { /** * Nexus Terminal — connection profile editor. * Renders a slide-out drawer for creating and editing connection profiles. @@ -889,3 +890,5 @@ class ProfileEditor { window.NexusTerminal = window.NexusTerminal || {}; window.NexusTerminal.ProfileEditor = ProfileEditor; + +})(); diff --git a/frontend/src/js/raw.js b/frontend/src/js/raw.js index 4633efd..93eaf52 100644 --- a/frontend/src/js/raw.js +++ b/frontend/src/js/raw.js @@ -1,3 +1,4 @@ +(function() { /** * Nexus Terminal — RAW TCP data viewer. * Provides text, hex, and split display modes for raw socket data, @@ -565,3 +566,5 @@ class RawViewer { window.NexusTerminal = window.NexusTerminal || {}; window.NexusTerminal.RawViewer = RawViewer; + +})(); diff --git a/frontend/src/js/secrets.js b/frontend/src/js/secrets.js index 07ace65..7b10879 100644 --- a/frontend/src/js/secrets.js +++ b/frontend/src/js/secrets.js @@ -1,3 +1,4 @@ +(function() { /** * Nexus Terminal — secret/passphrase prompt dialogs. * Provides modal prompts for collecting passwords, master-vault passphrases, @@ -301,3 +302,5 @@ class SecretPrompt { window.NexusTerminal = window.NexusTerminal || {}; window.NexusTerminal.SecretPrompt = SecretPrompt; + +})(); diff --git a/frontend/src/js/settings.js b/frontend/src/js/settings.js index d52b36f..dbf3513 100644 --- a/frontend/src/js/settings.js +++ b/frontend/src/js/settings.js @@ -1,3 +1,4 @@ +(function() { /** * Nexus Terminal — settings modal. * Renders a tabbed settings dialog for application-wide preferences, @@ -464,3 +465,5 @@ class Settings { window.NexusTerminal = window.NexusTerminal || {}; window.NexusTerminal.Settings = Settings; + +})(); diff --git a/frontend/src/js/sidebar.js b/frontend/src/js/sidebar.js index 2402830..a47919b 100644 --- a/frontend/src/js/sidebar.js +++ b/frontend/src/js/sidebar.js @@ -1,3 +1,4 @@ +(function() { /** * Nexus Terminal — sidebar module. * Renders the profile list with search, sections (favourites, recent, all), @@ -336,3 +337,5 @@ class Sidebar { window.NexusTerminal = window.NexusTerminal || {}; window.NexusTerminal.Sidebar = Sidebar; + +})(); diff --git a/frontend/src/js/state.js b/frontend/src/js/state.js index da4fbdf..3818620 100644 --- a/frontend/src/js/state.js +++ b/frontend/src/js/state.js @@ -1,3 +1,4 @@ +(function() { /** * Nexus Terminal — application state management. * Provides a centralised store for profiles, sessions, and preferences, @@ -226,3 +227,5 @@ class State { window.NexusTerminal = window.NexusTerminal || {}; window.NexusTerminal.State = State; + +})(); diff --git a/frontend/src/js/tabs.js b/frontend/src/js/tabs.js index 050ba69..ded0cc6 100644 --- a/frontend/src/js/tabs.js +++ b/frontend/src/js/tabs.js @@ -1,3 +1,4 @@ +(function() { /** * Nexus Terminal — tab management. * Handles the tab bar: adding, removing, reordering, renaming, @@ -550,3 +551,5 @@ class TabManager { window.NexusTerminal = window.NexusTerminal || {}; window.NexusTerminal.TabManager = TabManager; + +})(); diff --git a/frontend/src/js/terminal.js b/frontend/src/js/terminal.js index 1ea3f15..a02d175 100644 --- a/frontend/src/js/terminal.js +++ b/frontend/src/js/terminal.js @@ -1,3 +1,4 @@ +(function() { /** * Nexus Terminal — xterm.js terminal manager. * Creates, manages, and destroys xterm.js instances for SSH and Telnet sessions. @@ -287,3 +288,5 @@ class TerminalManager { window.NexusTerminal = window.NexusTerminal || {}; window.NexusTerminal.TerminalManager = TerminalManager; + +})(); diff --git a/frontend/src/js/utils.js b/frontend/src/js/utils.js index d180947..17b812e 100644 --- a/frontend/src/js/utils.js +++ b/frontend/src/js/utils.js @@ -1,3 +1,4 @@ +(function() { /** * Nexus Terminal — utility functions. * General-purpose helpers used throughout the application. @@ -230,3 +231,5 @@ function stateLabel(state) { window.NexusTerminal = window.NexusTerminal || {}; Object.assign(window.NexusTerminal, { $, $$, createElement, escapeHtml, formatTimestamp, debounce, fuzzyMatch, base64Encode, base64Decode, generateId, formatBytes, truncate, dismissContextMenus, protocolColour, stateLabel }); + +})();