粒子连接器修改

This commit is contained in:
tianmo committed 2026-09-11 10:00:16 +08:00
1 parent bd0771747d
commit 8ab3672c4e
5 files changed
+170 -6

No files matched your search

+14 -3
View File
@@ -79,13 +79,15 @@ using connector::ConnectorService;
- (void)refreshStatus:(id)sender {
(void)sender;
self.connectionButton.title = self.service && self.service->running() ? @"断开连接" : @"启动连接";
if (self.startupError.length > 0) {
const BOOL ownsPort = self.service && self.service->running();
const BOOL portOccupied = ownsPort || connector::connector_port_in_use();
self.connectionButton.title = portOccupied ? @"停止连接" : @"启动连接";
if (self.startupError.length > 0 && !portOccupied) {
self.statusLabel.stringValue = [@"● 连接器未启动 · " stringByAppendingString:self.startupError];
self.statusLabel.textColor = NSColor.systemRedColor;
return;
}
if (!self.service || !self.service->running()) {
if (!portOccupied) {
self.statusLabel.stringValue = @"● 连接器已断开";
self.statusLabel.textColor = NSColor.secondaryLabelColor;
return;
@@ -93,6 +95,11 @@ using connector::ConnectorService;
const std::string spine = connector::find_spine_executable();
const BOOL showPathControls = spine.empty();
for (NSView* view in self.pathControls) view.hidden = !showPathControls;
if (!ownsPort) {
self.statusLabel.stringValue = @"● 端口 27843 正在运行 · 可停止连接";
self.statusLabel.textColor = NSColor.systemGreenColor;
return;
}
self.statusLabel.stringValue = spine.empty() ? @"● 连接器运行中 · 未找到 Spine" : @"● 连接器运行中 · Spine 已就绪";
self.statusLabel.textColor = spine.empty() ? NSColor.systemOrangeColor : NSColor.systemGreenColor;
}
@@ -102,6 +109,10 @@ using connector::ConnectorService;
if (self.service && self.service->running()) {
self.service->stop();
self.startupError = @"";
} else if (connector::connector_port_in_use()) {
std::string error;
connector::stop_connector_port(error);
self.startupError = [NSString stringWithUTF8String:error.c_str()];
} else if (self.service) {
std::string error;
self.service->start(error);