generated from ali/HarmonyTemplate
T12: background keep-alive, last-tab persistence, startup polish
- 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
This commit is contained in:
@@ -7,11 +7,14 @@ 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'.
|
||||
* through AppStorage key 'activeTabIndex'; the last selected tab is
|
||||
* persisted (plan §4 Settings.last_tab) and restored on launch.
|
||||
*/
|
||||
@Entry
|
||||
@Component
|
||||
@@ -19,12 +22,28 @@ 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 {
|
||||
this.controller.changeIndex(this.activeTabIndex);
|
||||
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 }) {
|
||||
Tabs({ barPosition: BarPosition.End, controller: this.controller, index: this.activeTabIndex }) {
|
||||
TabContent() {
|
||||
ConnectionsPage()
|
||||
}.tabBar('连接')
|
||||
@@ -45,6 +64,11 @@ struct Index {
|
||||
.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%')
|
||||
|
||||
Reference in New Issue
Block a user