generated from ali/HarmonyTemplate
- BackgroundKeepAlive: DATA_TRANSFER continuous task held while any session is READY (wantAgent + backgroundTaskManager), released when none remain; deduped, called from SessionManager.notify() - SessionManager: setAppContext(context) supplied by Index at startup - Index: restore last selected tab from Settings.last_tab and persist every user tab change; initial tab via Tabs index param - EntryAbility: apply persisted keep-screen-on flag when the main window is created; project header + Haven log tag
77 lines
2.2 KiB
Plaintext
77 lines
2.2 KiB
Plaintext
/*
|
|
* 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%')
|
|
}
|
|
}
|