/* * Copyright (c) 2026 Haven for HarmonyOS contributors. * Port of Haven by GlassHaven (AGPL-3.0). See LICENSE. */ import { ConnectionsPage } from '../ui/ConnectionsPage'; import { TerminalPage } from '../ui/TerminalPage'; import { KeysPage } from '../ui/KeysPage'; import { SettingsPage } from '../ui/SettingsPage'; import { SessionManager } from '../session/SessionManager'; import { SettingsRepository } from '../data/SettingsRepository'; /** * App shell: bottom tab bar with 连接 / 终端 / 密钥 / 设置. * Cross-page navigation (e.g. "connect" jumping to the terminal tab) goes * through AppStorage key 'activeTabIndex'; the last selected tab is * persisted (plan §4 Settings.last_tab) and restored on launch. */ @Entry @Component struct Index { @StorageLink('activeTabIndex') @Watch('onTabRequested') activeTabIndex: number = 0; controller: TabsController = new TabsController(); aboutToAppear(): void { const context = this.getUIContext().getHostContext(); if (context !== undefined) { SessionManager.getInstance().setAppContext(context); const settings: SettingsRepository = SettingsRepository.getInstance(context); const lastTab: number = settings.getLastTab(); if (lastTab >= 0 && lastTab <= 3) { this.activeTabIndex = lastTab; } } } onTabRequested(): void { try { this.controller.changeIndex(this.activeTabIndex); } catch (e) { // Controller not attached yet; the Tabs index param covers it. } } build() { Tabs({ barPosition: BarPosition.End, controller: this.controller, index: this.activeTabIndex }) { TabContent() { ConnectionsPage() }.tabBar('连接') TabContent() { TerminalPage() }.tabBar('终端') TabContent() { KeysPage() }.tabBar('密钥') TabContent() { SettingsPage() }.tabBar('设置') } .barMode(BarMode.Fixed) .scrollable(true) .onChange((index: number): void => { this.activeTabIndex = index; const context = this.getUIContext().getHostContext(); if (context !== undefined) { SettingsRepository.getInstance(context).setLastTab(index).catch((): void => { }); } }) .width('100%') .height('100%') } }