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.
This commit is contained in:
2026-04-15 00:00:00 +01:00
parent f950be0e48
commit e6bdbef26c
12 changed files with 46 additions and 2 deletions
+12 -1
View File
@@ -1,3 +1,4 @@
(function() {
/** /**
* Nexus Terminal — main application entry point. * Nexus Terminal — main application entry point.
* Initialises the application shell, loads profiles, and sets up event listeners. * Initialises the application shell, loads profiles, and sets up event listeners.
@@ -281,6 +282,7 @@ class App {
* Binds click handlers to static UI elements. * Binds click handlers to static UI elements.
*/ */
setupUI() { setupUI() {
var btnEl = document.getElementById('btn-new-connection');
this._bindClick('btn-new-connection', () => this.profileEditor.openNew()); this._bindClick('btn-new-connection', () => this.profileEditor.openNew());
this._bindClick('btn-settings', () => this.settings.open()); this._bindClick('btn-settings', () => this.settings.open());
this._bindClick('btn-import', () => this.importProfiles()); this._bindClick('btn-import', () => this.importProfiles());
@@ -509,7 +511,16 @@ class App {
// ── Bootstrap ──────────────────────────────────────────────────────── // ── Bootstrap ────────────────────────────────────────────────────────
document.addEventListener('DOMContentLoaded', () => { document.addEventListener('DOMContentLoaded', () => {
try {
const app = new App(); const app = new App();
app.init().catch((err) => console.error('App initialisation failed:', err)); app.init().catch((err) => {
console.error('App initialisation failed:', err);
}); });
} catch (err) {
console.error('App constructor failed:', err);
}
});
})();
+3
View File
@@ -1,3 +1,4 @@
(function() {
/** /**
* Nexus Terminal — command palette (Ctrl+K). * Nexus Terminal — command palette (Ctrl+K).
* Provides a searchable overlay for quick access to application commands, * Provides a searchable overlay for quick access to application commands,
@@ -382,3 +383,5 @@ class CommandPalette {
window.NexusTerminal = window.NexusTerminal || {}; window.NexusTerminal = window.NexusTerminal || {};
window.NexusTerminal.CommandPalette = CommandPalette; window.NexusTerminal.CommandPalette = CommandPalette;
})();
+3
View File
@@ -1,3 +1,4 @@
(function() {
/** /**
* Nexus Terminal — toast notification system. * Nexus Terminal — toast notification system.
* Provides non-blocking, auto-dismissing notifications that stack * Provides non-blocking, auto-dismissing notifications that stack
@@ -125,3 +126,5 @@ class Notifications {
window.NexusTerminal = window.NexusTerminal || {}; window.NexusTerminal = window.NexusTerminal || {};
window.NexusTerminal.Notifications = Notifications; window.NexusTerminal.Notifications = Notifications;
})();
+3
View File
@@ -1,3 +1,4 @@
(function() {
/** /**
* Nexus Terminal — connection profile editor. * Nexus Terminal — connection profile editor.
* Renders a slide-out drawer for creating and editing connection profiles. * Renders a slide-out drawer for creating and editing connection profiles.
@@ -889,3 +890,5 @@ class ProfileEditor {
window.NexusTerminal = window.NexusTerminal || {}; window.NexusTerminal = window.NexusTerminal || {};
window.NexusTerminal.ProfileEditor = ProfileEditor; window.NexusTerminal.ProfileEditor = ProfileEditor;
})();
+3
View File
@@ -1,3 +1,4 @@
(function() {
/** /**
* Nexus Terminal — RAW TCP data viewer. * Nexus Terminal — RAW TCP data viewer.
* Provides text, hex, and split display modes for raw socket data, * Provides text, hex, and split display modes for raw socket data,
@@ -565,3 +566,5 @@ class RawViewer {
window.NexusTerminal = window.NexusTerminal || {}; window.NexusTerminal = window.NexusTerminal || {};
window.NexusTerminal.RawViewer = RawViewer; window.NexusTerminal.RawViewer = RawViewer;
})();
+3
View File
@@ -1,3 +1,4 @@
(function() {
/** /**
* Nexus Terminal — secret/passphrase prompt dialogs. * Nexus Terminal — secret/passphrase prompt dialogs.
* Provides modal prompts for collecting passwords, master-vault passphrases, * Provides modal prompts for collecting passwords, master-vault passphrases,
@@ -301,3 +302,5 @@ class SecretPrompt {
window.NexusTerminal = window.NexusTerminal || {}; window.NexusTerminal = window.NexusTerminal || {};
window.NexusTerminal.SecretPrompt = SecretPrompt; window.NexusTerminal.SecretPrompt = SecretPrompt;
})();
+3
View File
@@ -1,3 +1,4 @@
(function() {
/** /**
* Nexus Terminal — settings modal. * Nexus Terminal — settings modal.
* Renders a tabbed settings dialog for application-wide preferences, * Renders a tabbed settings dialog for application-wide preferences,
@@ -464,3 +465,5 @@ class Settings {
window.NexusTerminal = window.NexusTerminal || {}; window.NexusTerminal = window.NexusTerminal || {};
window.NexusTerminal.Settings = Settings; window.NexusTerminal.Settings = Settings;
})();
+3
View File
@@ -1,3 +1,4 @@
(function() {
/** /**
* Nexus Terminal — sidebar module. * Nexus Terminal — sidebar module.
* Renders the profile list with search, sections (favourites, recent, all), * Renders the profile list with search, sections (favourites, recent, all),
@@ -336,3 +337,5 @@ class Sidebar {
window.NexusTerminal = window.NexusTerminal || {}; window.NexusTerminal = window.NexusTerminal || {};
window.NexusTerminal.Sidebar = Sidebar; window.NexusTerminal.Sidebar = Sidebar;
})();
+3
View File
@@ -1,3 +1,4 @@
(function() {
/** /**
* Nexus Terminal — application state management. * Nexus Terminal — application state management.
* Provides a centralised store for profiles, sessions, and preferences, * Provides a centralised store for profiles, sessions, and preferences,
@@ -226,3 +227,5 @@ class State {
window.NexusTerminal = window.NexusTerminal || {}; window.NexusTerminal = window.NexusTerminal || {};
window.NexusTerminal.State = State; window.NexusTerminal.State = State;
})();
+3
View File
@@ -1,3 +1,4 @@
(function() {
/** /**
* Nexus Terminal — tab management. * Nexus Terminal — tab management.
* Handles the tab bar: adding, removing, reordering, renaming, * Handles the tab bar: adding, removing, reordering, renaming,
@@ -550,3 +551,5 @@ class TabManager {
window.NexusTerminal = window.NexusTerminal || {}; window.NexusTerminal = window.NexusTerminal || {};
window.NexusTerminal.TabManager = TabManager; window.NexusTerminal.TabManager = TabManager;
})();
+3
View File
@@ -1,3 +1,4 @@
(function() {
/** /**
* Nexus Terminal — xterm.js terminal manager. * Nexus Terminal — xterm.js terminal manager.
* Creates, manages, and destroys xterm.js instances for SSH and Telnet sessions. * Creates, manages, and destroys xterm.js instances for SSH and Telnet sessions.
@@ -287,3 +288,5 @@ class TerminalManager {
window.NexusTerminal = window.NexusTerminal || {}; window.NexusTerminal = window.NexusTerminal || {};
window.NexusTerminal.TerminalManager = TerminalManager; window.NexusTerminal.TerminalManager = TerminalManager;
})();
+3
View File
@@ -1,3 +1,4 @@
(function() {
/** /**
* Nexus Terminal — utility functions. * Nexus Terminal — utility functions.
* General-purpose helpers used throughout the application. * General-purpose helpers used throughout the application.
@@ -230,3 +231,5 @@ function stateLabel(state) {
window.NexusTerminal = window.NexusTerminal || {}; window.NexusTerminal = window.NexusTerminal || {};
Object.assign(window.NexusTerminal, { $, $$, createElement, escapeHtml, formatTimestamp, debounce, fuzzyMatch, base64Encode, base64Decode, generateId, formatBytes, truncate, dismissContextMenus, protocolColour, stateLabel }); Object.assign(window.NexusTerminal, { $, $$, createElement, escapeHtml, formatTimestamp, debounce, fuzzyMatch, base64Encode, base64Decode, generateId, formatBytes, truncate, dismissContextMenus, protocolColour, stateLabel });
})();