@@ -45,7 +45,7 @@ function connect(){
4545}
4646
4747function disconnect ( ) {
48- $ . getJSON ( '/disconnect' , function ( data ) {
48+ $ . getJSON ( '/disconnect' , function ( ) {
4949 setConnectState ( false ) ;
5050 } ) ;
5151}
@@ -131,26 +131,82 @@ function initSetupCard(){
131131}
132132
133133function insertQRCode ( link ) {
134- qrCodeHtml = "<form id='ipForm'> \
135- <label for='ipAddress'>Enter local IP address:</label> \
136- <input type='text' id='ipAddress' name='ipAddress' placeholder='192.168.1.1'> \
137- <button id='updateButton'>Update</button> \
138- </form><div id='qrcode'></div>" ;
134+ qrCodeHtml = `
135+ <div class="mb-3">
136+ <h6>Instructions</h6>
137+ <ol class="small text-muted">
138+ <li>Ensure your mobile device is connected to the same network as this host.</li>
139+ <li>The server must be started with shared access: <code>--host 0.0.0.0</code></li>
140+ <li>Select your host's IP address below or enter a custom one.</li>
141+ <li>Scan the QR code with your mobile device to open the page.</li>
142+ </ol>
143+ </div>
144+ <form id='ipForm'>
145+ <div class="mb-3">
146+ <label for='ipSelect' class="form-label">Select Host IP Address:</label>
147+ <select id='ipSelect' class="form-select">
148+ <option value="">Loading available IPs...</option>
149+ </select>
150+ </div>
151+ <div class="mb-3">
152+ <label for='ipAddress' class="form-label">Or enter custom IP:</label>
153+ <input type='text' id='ipAddress' class="form-control" name='ipAddress' placeholder='192.168.1.1'>
154+ </div>
155+ <button id='updateButton' class="btn btn-primary">Generate QR Code</button>
156+ </form>
157+ <div id='qrcode' class='mt-3 text-center'></div>
158+ ` ;
139159
140160 $ ( '#x2cModalBody' ) . empty ( ) ;
141161 $ ( '#x2cModalBody' ) . html ( qrCodeHtml ) ;
142162
143- new QRCode ( document . getElementById ( "qrcode" ) , "http://0.0.0.0:5000/" + link ) ;
163+ // Load available IP addresses
164+ $ . getJSON ( '/local-ips' , function ( data ) {
165+ const ipSelect = $ ( '#ipSelect' ) ;
166+
167+ ipSelect . empty ( ) ;
168+ if ( data . ips && data . ips . length > 0 ) {
169+ data . ips . forEach ( function ( ip ) {
170+ ipSelect . append ( $ ( '<option></option>' ) . val ( ip ) . text ( ip ) ) ;
171+ } ) ;
172+ // Generate initial QR code with first IP
173+ new QRCode ( document . getElementById ( "qrcode" ) , "http://" + data . ips [ 0 ] + ":5000/" + link ) ;
174+ } else {
175+ ipSelect . append ( $ ( '<option></option>' ) . val ( '' ) . text ( 'No IPs found - enter manually' ) ) ;
176+ new QRCode ( document . getElementById ( "qrcode" ) , "http://0.0.0.0:5000/" + link ) ;
177+ }
178+ } ) . fail ( function ( ) {
179+ // Fallback if endpoint doesn't exist
180+ $ ( '#ipSelect' ) . empty ( ) . append ( $ ( '<option></option>' ) . val ( '0.0.0.0' ) . text ( '0.0.0.0 (default)' ) ) ;
181+ new QRCode ( document . getElementById ( "qrcode" ) , "http://0.0.0.0:5000/" + link ) ;
182+ } ) ;
144183
145- $ ( '#updateButton' ) . click ( function ( e ) {
146- e . preventDefault ( ) ; // Prevent the default form submit action
184+ // Update QR code when IP is selected from dropdown
185+ $ ( document ) . on ( 'change' , '#ipSelect' , function ( ) {
186+ const selectedIp = $ ( this ) . val ( ) ;
187+ if ( selectedIp ) {
188+ $ ( "#qrcode" ) . empty ( ) ;
189+ new QRCode ( document . getElementById ( "qrcode" ) , "http://" + selectedIp + ":5000/" + link ) ;
190+ }
191+ } ) ;
192+
193+ // Update QR code when custom IP is entered
194+ $ ( document ) . on ( 'click' , '#updateButton' , function ( e ) {
195+ e . preventDefault ( ) ;
147196 var ipAddress = $ ( '#ipAddress' ) . val ( ) ;
148197 var ipFormat = / ^ (?: [ 0 - 9 ] { 1 , 3 } \. ) { 3 } [ 0 - 9 ] { 1 , 3 } $ / ;
149- if ( ipFormat . test ( ipAddress ) ) {
198+ if ( ipAddress && ipFormat . test ( ipAddress ) ) {
150199 $ ( "#qrcode" ) . empty ( ) ;
151200 new QRCode ( document . getElementById ( "qrcode" ) , "http://" + ipAddress + ":5000/" + link ) ;
152- } else {
201+ } else if ( ipAddress ) {
153202 alert ( 'Invalid IP address format.' ) ;
203+ } else {
204+ // Use selected IP from dropdown
205+ const selectedIp = $ ( '#ipSelect' ) . val ( ) ;
206+ if ( selectedIp ) {
207+ $ ( "#qrcode" ) . empty ( ) ;
208+ new QRCode ( document . getElementById ( "qrcode" ) , "http://" + selectedIp + ":5000/" + link ) ;
209+ }
154210 }
155211 } ) ;
156212}
@@ -159,30 +215,48 @@ function initQRCodes() {
159215
160216 $ ( "#watchQRCode" ) . on ( "click" , function ( ) {
161217 $ ( '#x2cModalTitle' ) . html ( 'WatchView - Scan QR Code' ) ;
162- insertQRCode ( "watch-view " ) ;
218+ insertQRCode ( "watch" ) ;
163219 $ ( '#x2cModal' ) . modal ( 'show' ) ;
164220 } ) ;
165221 $ ( "#scopeQRCode" ) . on ( "click" , function ( ) {
166222 $ ( '#x2cModalTitle' ) . html ( 'ScopeView - Scan QR Code' ) ;
167- insertQRCode ( "scope-view " ) ;
223+ insertQRCode ( "scope" ) ;
168224 $ ( '#x2cModal' ) . modal ( 'show' ) ;
169225 } ) ;
170226 $ ( "#dashboardQRCode" ) . on ( "click" , function ( ) {
171227 $ ( '#x2cModalTitle' ) . html ( 'Dashboard - Scan QR Code' ) ;
172- insertQRCode ( "dashboard-view " ) ;
228+ insertQRCode ( "dashboard" ) ;
173229 $ ( '#x2cModal' ) . modal ( 'show' ) ;
174230 } ) ;
175231 $ ( "#scriptQRCode" ) . on ( "click" , function ( ) {
176232 $ ( '#x2cModalTitle' ) . html ( 'Script - Scan QR Code' ) ;
177- insertQRCode ( "script-view" ) ;
233+ insertQRCode ( "scripting" ) ;
234+ $ ( '#x2cModal' ) . modal ( 'show' ) ;
235+ } ) ;
236+ $ ( "#mainPageQRCode" ) . on ( "click" , function ( ) {
237+ $ ( '#x2cModalTitle' ) . html ( 'Main Page - Scan QR Code' ) ;
238+ insertQRCode ( "" ) ;
178239 $ ( '#x2cModal' ) . modal ( 'show' ) ;
179240 } ) ;
180241}
181242
243+ function initHelpToggle ( ) {
244+ const helpToggle = document . getElementById ( 'helpToggle' ) ;
245+ const welcomeCard = document . getElementById ( 'welcomeCard' ) ;
246+
247+ if ( helpToggle && welcomeCard ) {
248+ helpToggle . addEventListener ( 'click' , function ( e ) {
249+ e . preventDefault ( ) ;
250+ welcomeCard . classList . toggle ( 'd-none' ) ;
251+ } ) ;
252+ }
253+ }
254+
182255$ ( document ) . ready ( function ( ) {
183256 initSetupCard ( ) ;
184257 setInterfaceSetupFields ( ) ;
185258 initQRCodes ( ) ;
259+ initHelpToggle ( ) ;
186260
187261 // Toggles for views
188262 const toggleWatch = document . getElementById ( 'toggleWatch' ) ;
0 commit comments