Skip to content

Commit cad1d60

Browse files
committed
fix(ios): open app on chat by default
1 parent 4ac5cf8 commit cad1d60

3 files changed

Lines changed: 80 additions & 16 deletions

File tree

‎apps/ios/Sources/RootTabs.swift‎

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,21 @@ struct RootTabs: View {
4747
@State private var suppressedExecApprovalPromptIDForNotificationSettings: String?
4848

4949
private static var initialTab: AppTab {
50-
let arguments = ProcessInfo.processInfo.arguments
50+
Self.initialTab(arguments: ProcessInfo.processInfo.arguments)
51+
}
52+
53+
static func initialTab(arguments: [String]) -> AppTab {
5154
guard let flagIndex = arguments.firstIndex(of: "--openclaw-initial-tab") else {
52-
return .control
55+
return self.fallbackInitialTab(arguments: arguments)
5356
}
5457
let valueIndex = arguments.index(after: flagIndex)
5558
guard arguments.indices.contains(valueIndex) else {
56-
return .control
59+
return Self.fallbackInitialTab(arguments: arguments)
5760
}
5861

5962
switch arguments[valueIndex].lowercased() {
63+
case "control", "overview":
64+
return .control
6065
case "chat":
6166
return .chat
6267
case "talk", "voice":
@@ -66,10 +71,14 @@ struct RootTabs: View {
6671
case "settings":
6772
return .settings
6873
default:
69-
return .control
74+
return Self.fallbackInitialTab(arguments: arguments)
7075
}
7176
}
7277

78+
private static func fallbackInitialTab(arguments: [String]) -> AppTab {
79+
self.requestedInitialSidebarDestination(arguments: arguments)?.appTab ?? .chat
80+
}
81+
7382
private static var initialSidebarDestination: SidebarDestination {
7483
if let requested = requestedInitialSidebarDestination {
7584
return requested
@@ -78,7 +87,10 @@ struct RootTabs: View {
7887
}
7988

8089
private static var requestedInitialSidebarDestination: SidebarDestination? {
81-
let arguments = ProcessInfo.processInfo.arguments
90+
Self.requestedInitialSidebarDestination(arguments: ProcessInfo.processInfo.arguments)
91+
}
92+
93+
static func requestedInitialSidebarDestination(arguments: [String]) -> SidebarDestination? {
8294
guard let flagIndex = arguments.firstIndex(of: "--openclaw-initial-destination") else {
8395
return nil
8496
}
@@ -139,14 +151,6 @@ struct RootTabs: View {
139151

140152
private var phoneTabContent: some View {
141153
TabView(selection: self.$selectedTab) {
142-
RootTabsPhoneControlHub(
143-
groups: Self.phoneControlGroups,
144-
initialDestination: Self.requestedInitialSidebarDestination,
145-
openRootDestination: { self.selectSidebarDestination($0) })
146-
.tabItem { Label("Control", systemImage: "square.grid.2x2") }
147-
.badge(self.appModel.pendingExecApprovalPrompt == nil ? 0 : 1)
148-
.tag(AppTab.control)
149-
150154
ChatProTab(openSettings: { self.selectSidebarDestination(.gateway) })
151155
.tabItem { Label("Chat", systemImage: "bubble.left.fill") }
152156
.tag(AppTab.chat)
@@ -159,6 +163,14 @@ struct RootTabs: View {
159163
}
160164
.tag(AppTab.talk)
161165

166+
RootTabsPhoneControlHub(
167+
groups: Self.phoneControlGroups,
168+
initialDestination: Self.requestedInitialSidebarDestination,
169+
openRootDestination: { self.selectSidebarDestination($0) })
170+
.tabItem { Label("Control", systemImage: "square.grid.2x2") }
171+
.badge(self.appModel.pendingExecApprovalPrompt == nil ? 0 : 1)
172+
.tag(AppTab.control)
173+
162174
NavigationStack {
163175
AgentProTab(
164176
directRoute: .agents,

‎apps/ios/Tests/RootTabsPresentationTests.swift‎

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,12 +128,43 @@ import UIKit
128128
#expect(RootTabs.shouldOpenRootTabFromPhoneHub(.settings))
129129

130130
for destination in RootTabs.SidebarDestination.allCases
131-
where destination != .chat && destination != .talk && destination != .agents && destination != .gateway && destination != .settings
131+
where destination != .chat && destination != .talk && destination != .agents && destination != .gateway &&
132+
destination != .settings
132133
{
133134
#expect(!RootTabs.shouldOpenRootTabFromPhoneHub(destination))
134135
}
135136
}
136137

138+
@Test func appLaunchDefaultsToChatTab() {
139+
#expect(RootTabs.initialTab(arguments: ["OpenClaw"]) == .chat)
140+
#expect(RootTabs.initialTab(arguments: ["OpenClaw", "--openclaw-initial-tab"]) == .chat)
141+
#expect(RootTabs.initialTab(arguments: ["OpenClaw", "--openclaw-initial-tab", "unknown"]) == .chat)
142+
}
143+
144+
@Test func appLaunchUsesRequestedDestinationBeforeChatFallback() {
145+
#expect(RootTabs.initialTab(arguments: ["OpenClaw", "--openclaw-initial-destination", "overview"]) == .control)
146+
#expect(RootTabs.initialTab(arguments: ["OpenClaw", "--openclaw-initial-destination", "chat"]) == .chat)
147+
#expect(RootTabs.initialTab(arguments: ["OpenClaw", "--openclaw-initial-destination", "agents"]) == .agent)
148+
#expect(RootTabs.initialTab(arguments: ["OpenClaw", "--openclaw-initial-destination", "gateway"]) == .settings)
149+
#expect(
150+
RootTabs.initialTab(arguments: [
151+
"OpenClaw",
152+
"--openclaw-initial-tab",
153+
"unknown",
154+
"--openclaw-initial-destination",
155+
"activity",
156+
]) == .control)
157+
}
158+
159+
@Test func appLaunchRespectsExplicitInitialTabOverride() {
160+
#expect(RootTabs.initialTab(arguments: ["OpenClaw", "--openclaw-initial-tab", "control"]) == .control)
161+
#expect(RootTabs.initialTab(arguments: ["OpenClaw", "--openclaw-initial-tab", "overview"]) == .control)
162+
#expect(RootTabs.initialTab(arguments: ["OpenClaw", "--openclaw-initial-tab", "chat"]) == .chat)
163+
#expect(RootTabs.initialTab(arguments: ["OpenClaw", "--openclaw-initial-tab", "voice"]) == .talk)
164+
#expect(RootTabs.initialTab(arguments: ["OpenClaw", "--openclaw-initial-tab", "agents"]) == .agent)
165+
#expect(RootTabs.initialTab(arguments: ["OpenClaw", "--openclaw-initial-tab", "settings"]) == .settings)
166+
}
167+
137168
@Test func legacyInitialTabsMapToMatchingSidebarDestinations() {
138169
#expect(RootTabs.defaultSidebarDestination(for: .control) == .overview)
139170
#expect(RootTabs.defaultSidebarDestination(for: .chat) == .chat)

‎apps/ios/Tests/RootTabsSourceGuardTests.swift‎

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,25 @@ struct RootTabsSourceGuardTests {
6767
#expect(!drawerContent.contains("NavigationSplitView"))
6868
}
6969

70+
@Test func `phone tab bar keeps chat first product order`() throws {
71+
let source = try String(contentsOf: Self.rootTabsSourceURL(), encoding: .utf8)
72+
let phoneTabContent = try Self.extract(
73+
source,
74+
from: "private var phoneTabContent: some View",
75+
to: "private var sidebarSplitContent: some View")
76+
77+
let chatRange = try #require(phoneTabContent.range(of: "ChatProTab(openSettings:"))
78+
let talkRange = try #require(phoneTabContent.range(of: "TalkProTab(openSettings:"))
79+
let controlRange = try #require(phoneTabContent.range(of: "RootTabsPhoneControlHub("))
80+
let agentRange = try #require(phoneTabContent.range(of: "AgentProTab("))
81+
let settingsRange = try #require(phoneTabContent.range(of: "SettingsProTab("))
82+
83+
#expect(chatRange.lowerBound < talkRange.lowerBound)
84+
#expect(talkRange.lowerBound < controlRange.lowerBound)
85+
#expect(controlRange.lowerBound < agentRange.lowerBound)
86+
#expect(agentRange.lowerBound < settingsRange.lowerBound)
87+
}
88+
7089
@Test func `sidebar keeps navigation model destination only`() throws {
7190
let source = try String(contentsOf: Self.rootTabsSourceURL(), encoding: .utf8)
7291
let navigationSource = try String(contentsOf: Self.rootTabsNavigationSourceURL(), encoding: .utf8)
@@ -618,7 +637,8 @@ struct RootTabsSourceGuardTests {
618637
#expect(actionsSource.contains("self.gatewayController.refreshActiveGatewayRegistrationFromSettings()"))
619638
#expect(actionsSource.contains("self.gatewayController.restartDiscovery()"))
620639
#expect(actionsSource.contains("await self.appModel.refreshGatewayOverviewIfConnected()"))
621-
#expect(actionsSource.contains("self.gatewayController.requestLocalNetworkAccess(reason: \"settings_preflight\")"))
640+
#expect(actionsSource
641+
.contains("self.gatewayController.requestLocalNetworkAccess(reason: \"settings_preflight\")"))
622642
#expect(actionsSource.contains("await TCPProbe.probe(host: trimmed, port: port"))
623643
#expect(actionsSource.contains("Check Tailscale or LAN."))
624644
#expect(actionsSource.contains("Tailscale is off on this device. Turn it on, then try again."))
@@ -658,7 +678,8 @@ struct RootTabsSourceGuardTests {
658678

659679
#expect(onboardingSource.contains("self.requestLocalNetworkAccess(reason: \"onboarding_continue\")"))
660680
#expect(onboardingSource.contains("self.requestLocalNetworkAccessIfPastIntro(reason: \"onboarding_appear\")"))
661-
#expect(actionsSource.contains("self.gatewayController.requestLocalNetworkAccess(reason: \"settings_preflight\")"))
681+
#expect(actionsSource
682+
.contains("self.gatewayController.requestLocalNetworkAccess(reason: \"settings_preflight\")"))
662683
}
663684

664685
@Test func `gateway settings preview matrix covers primary states`() throws {

0 commit comments

Comments
 (0)