@@ -103,37 +103,38 @@ function computeUiPath(externalUiName, externalUi) {
103103}
104104
105105async function openDashboard ( ) {
106- const newWindow = window . open ( 'about:blank' , '_blank' ) ;
107- if ( ! newWindow ) {
108- ui . addNotification ( null , E ( 'p' , _ ( 'Popup was blocked. Please allow popups for this site.' ) ) , 'warning' ) ;
109- return ;
110- }
111106 try {
112107 if ( ! ( await getServiceStatus ( ) ) ) {
113- newWindow . close ( ) ;
114108 ui . addNotification ( null , E ( 'p' , _ ( 'Service is not running.' ) ) , 'error' ) ;
115109 return ;
116110 }
111+
117112 const config = await fs . read ( '/opt/clash/config.yaml' ) ;
118113 const ec = parseYamlValue ( config , 'external-controller' ) ;
119114 const ecTls = parseYamlValue ( config , 'external-controller-tls' ) ;
120115 const secret = parseYamlValue ( config , 'secret' ) ;
121116 const externalUi = parseYamlValue ( config , 'external-ui' ) ;
122117 const externalUiName = parseYamlValue ( config , 'external-ui-name' ) ;
118+
123119 const baseHost = window . location . hostname ;
124120 const basePort = '9090' ;
125121 const useTls = ! ! ecTls ;
122+
126123 const { host, port } = normalizeHostPortFromAddr ( useTls ? ecTls : ec , baseHost , basePort ) ;
127124 const scheme = useTls ? 'https:' : 'http:' ;
128125 const uiPath = computeUiPath ( externalUiName , externalUi ) ;
126+
129127 const qp = new URLSearchParams ( ) ;
130128 if ( secret ) qp . set ( 'secret' , secret ) ;
131129 qp . set ( 'hostname' , host ) ;
132130 qp . set ( 'port' , port ) ;
133131 const url = `${ scheme } //${ host } :${ port } ${ uiPath } ?${ qp . toString ( ) } ` ;
134- newWindow . location . replace ( url ) ;
132+
133+ const newWindow = window . open ( url , '_blank' ) ;
134+ if ( ! newWindow ) {
135+ ui . addNotification ( null , E ( 'p' , _ ( 'Popup was blocked. Please allow popups for this site.' ) ) , 'warning' ) ;
136+ }
135137 } catch ( error ) {
136- newWindow . close ( ) ;
137138 console . error ( _ ( 'Error opening dashboard:' ) , error ) ;
138139 ui . addNotification ( null , E ( 'p' , _ ( 'Failed to open dashboard: %s' ) . format ( error . message ) ) , 'error' ) ;
139140 }
@@ -186,23 +187,27 @@ return view.extend({
186187 if ( startStopButton ) startStopButton . disabled = false ;
187188 }
188189 } ;
190+
189191 const view = E ( [
190- E ( 'div' , { 'style' : 'margin-bottom: 20px;' } , [
191- E ( 'div' , {
192- 'style' : 'margin-bottom: 10px; display: flex; flex-wrap: wrap; gap: 10px;'
193- } , [
194- E ( 'button' , { 'class' : 'btn' , 'click' : openDashboard } , _ ( 'Open Dashboard' ) ) ,
195- ( startStopButton = E ( 'button' , {
196- 'class' : 'btn' ,
197- 'click' : toggleService
198- } , running ? _ ( 'Stop Service' ) : _ ( 'Start Service' ) ) )
199- ] ) ,
200- E ( 'div' , { 'style' : 'display: flex; justify-content: flex-start;' } , [
201- E ( 'span' , {
202- 'class' : 'label' ,
203- 'style' : `padding: 6px 12px; border-radius: 3px; font-size: 12px; color: white; background-color: ${ running ? '#5cb85c' : '#d9534f' } ; display: inline-block;`
204- } , running ? _ ( 'Clash is running' ) : _ ( 'Clash stopped' ) )
205- ] )
192+ E ( 'div' , {
193+ 'style' : 'margin-bottom: 20px; display: flex; flex-wrap: wrap; align-items: center; gap: 10px;'
194+ } , [
195+ E ( 'button' , {
196+ 'class' : 'btn' ,
197+ 'click' : openDashboard ,
198+ 'style' : 'margin: 0;'
199+ } , _ ( 'Open Dashboard' ) ) ,
200+
201+ ( startStopButton = E ( 'button' , {
202+ 'class' : 'btn' ,
203+ 'click' : toggleService ,
204+ 'style' : 'margin: 0;'
205+ } , running ? _ ( 'Stop Service' ) : _ ( 'Start Service' ) ) ) ,
206+
207+ E ( 'span' , {
208+ 'class' : 'label' ,
209+ 'style' : `padding: 4px 10px; border-radius: 3px; font-size: 12px; color: white; background-color: ${ running ? '#5cb85c' : '#d9534f' } ; margin: 0;`
210+ } , running ? _ ( 'Clash is running' ) : _ ( 'Clash stopped' ) )
206211 ] ) ,
207212 E ( 'h2' , _ ( 'Clash Configuration' ) ) ,
208213 E ( 'p' , { 'class' : 'cbi-section-descr' } , _ ( 'Your current Clash config. When applied, the changes will be saved and the service will be restarted.' ) ) ,
@@ -217,6 +222,7 @@ return view.extend({
217222 } , _ ( 'Save & Apply Configuration' ) )
218223 ] )
219224 ] ) ;
225+
220226 initializeAceEditor ( config ) ;
221227 return view ;
222228 } ,
0 commit comments