瀏覽代碼

RemoteConsole: move auto start server to static init, minor fixes

Yuxiao Mao 7 月之前
父節點
當前提交
ed48a99f81
共有 2 個文件被更改,包括 30 次插入10 次删除
  1. 28 8
      hide/view/RemoteConsoleView.hx
  2. 2 2
      hrt/impl/RemoteConsole.hx

+ 28 - 8
hide/view/RemoteConsoleView.hx

@@ -48,6 +48,9 @@ class RemoteConsoleView extends hide.ui.View<{}> {
 			stopServer();
 		});
 		panelsView = element.find(".remoteconsole");
+		for( panel in panels ) {
+			panel.element.appendTo(panelsView);
+		}
 		if( rcmd != null ) {
 			for( c in rcmd.connections ) {
 				addPanel(c);
@@ -55,8 +58,6 @@ class RemoteConsoleView extends hide.ui.View<{}> {
 		}
 		if( panels.length <= 0 )
 			addPanel();
-		if( pconfig?.disableAutoStartServer != true )
-			haxe.Timer.delay(() -> startServer(port, host), 1);
 	}
 
 	override function onBeforeClose():Bool {
@@ -70,7 +71,7 @@ class RemoteConsoleView extends hide.ui.View<{}> {
 
 	function forceClear() {
 		for( p in panels ) {
-			p.close();
+			p.close(false);
 		}
 		panels = [];
 		if( panelsView != null )
@@ -115,7 +116,7 @@ class RemoteConsoleView extends hide.ui.View<{}> {
 	public function removePanel( p : RemoteConsolePanel ) {
 		panels.remove(p);
 		p.element.remove();
-		p.close();
+		p.close(true);
 	}
 
 	public static function refreshStatusIcon() {
@@ -166,7 +167,26 @@ class RemoteConsoleView extends hide.ui.View<{}> {
 		return null;
 	}
 
-	static var _ = hide.ui.View.register(RemoteConsoleView);
+	static var _ = init();
+	static function init() {
+		hide.ui.View.register(RemoteConsoleView);
+		function wait() {
+			if( Ide.inst?.config?.project == null ) {
+				haxe.Timer.delay(wait, 10);
+				return;
+			}
+			var config = Ide.inst.config.project;
+			var pconfig = config.get("remoteconsole");
+			if( pconfig != null && pconfig.disableAutoStartServer != true ) {
+				var host = pconfig.host ?? hrt.impl.RemoteConsole.DEFAULT_HOST;
+				var port = pconfig.port ?? hrt.impl.RemoteConsole.DEFAULT_PORT;
+				startServer(port, host);
+			}
+		}
+		// Needs to wait a little on reload, otherwise the port might still be occupied.
+		haxe.Timer.delay(wait, 100);
+		return 0;
+	}
 }
 
 class RemoteConsolePanel extends hide.comp.Component {
@@ -180,7 +200,7 @@ class RemoteConsolePanel extends hide.comp.Component {
 		<div class="remoteconsole-panel">
 			<div class="controls">
 				<div class="ico ico-dot-circle-o" id="statusIcon" style="cursor:default;"></div>
-				<div class="ico ico-close" id="closeBtn" title="Close panel"></div>
+				<div class="ico ico-close" id="closeBtn" title="Close panel and its connection"></div>
 			</div>
 			<div class="logs">
 			</div>
@@ -238,8 +258,8 @@ class RemoteConsolePanel extends hide.comp.Component {
 			statusIcon.prop("title", "Disconnected");
 		}
 	}
-	public function close() {
-		if( connection != null ) {
+	public function close( disconnect : Bool ) {
+		if( disconnect && connection != null ) {
 			connection.close();
 			log("Disconnected");
 		}

+ 2 - 2
hrt/impl/RemoteConsole.hx

@@ -41,7 +41,6 @@ class RemoteConsole {
 			connections.push(connection);
 			s.onError = function(msg) {
 				connection.logError("Client error: " + msg);
-				connections.remove(connection);
 				connection.close();
 				connection = null;
 			}
@@ -61,7 +60,6 @@ class RemoteConsole {
 		sock.onError = function(msg) {
 			if( !SILENT_CONNECT )
 				logError("Socket Error: " + msg);
-			connections.remove(connection);
 			close();
 			if( onConnected != null )
 				onConnected(false);
@@ -137,6 +135,7 @@ class RemoteConsoleConnection {
 		if( sock != null )
 			sock.close();
 		sock = null;
+		parent.connections.remove(this);
 		onClose();
 	}
 
@@ -295,6 +294,7 @@ class RemoteConsoleConnection {
 				Std.downcast(view,hide.view.CdbTable).goto(sheet,args.line,args.column);
 			});
 		} else {
+			hide.Ide.inst.showFileInResources(args.file);
 			hide.Ide.inst.openFile(args.file);
 		}
 	}