Skip to content

Commit 2cbaee5

Browse files
authored
Merge pull request #3872 from guantw/feat/mobile-device-aliases-and-presence
feat(mobile): display device aliases and synchronize HarmonyOS presence
2 parents 0c474e3 + 6c91623 commit 2cbaee5

24 files changed

Lines changed: 315 additions & 57 deletions

File tree

‎src/apps/mobile/android/app/src/main/kotlin/com/openbitfun/mobile/app/ui/account/AccountProfileCards.kt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ internal fun AccountSettingsDevicesSection(
219219
)
220220
Column(Modifier.weight(1f), verticalArrangement = Arrangement.spacedBy(2.dp)) {
221221
Text(
222-
device.name.ifBlank { device.id },
222+
device.displayName,
223223
fontSize = 15.sp,
224224
fontWeight = FontWeight.Medium,
225225
maxLines = 1,

‎src/apps/mobile/android/app/src/main/kotlin/com/openbitfun/mobile/app/ui/remote/ConnectAccountDeviceScreen.kt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ private fun DeviceListCard(
207207
)
208208
Column(verticalArrangement = Arrangement.spacedBy(3.dp), modifier = Modifier.weight(1f)) {
209209
Text(
210-
device.name.ifBlank { device.id },
210+
device.displayName,
211211
fontSize = 15.sp,
212212
fontWeight = FontWeight.Medium,
213213
maxLines = 1,

‎src/apps/mobile/android/app/src/main/kotlin/com/openbitfun/mobile/app/ui/shell/MobileScreen.kt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ internal fun MobileScreen(onAccountRestored: (Boolean) -> Unit = {}) {
474474
createDevices = readyAccount?.devices.orEmpty().map { device ->
475475
com.openbitfun.mobile.app.ui.remote.CreateDeviceChoice(
476476
id = device.id,
477-
name = device.name,
477+
name = device.displayName,
478478
online = device.online,
479479
selected = device.id == readyAccount?.selectedDeviceId,
480480
)

‎src/apps/mobile/android/app/src/main/kotlin/com/openbitfun/mobile/app/ui/shell/sidebar/SidebarRemoteWorkspaceSection.kt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ internal fun SidebarRemoteWorkspaceSection(
173173
projectedDevices.take(visibleDeviceCount).forEach { device ->
174174
val active = device.id == activeDeviceId
175175
SidebarDeviceSelectorRow(
176-
deviceName = device.name.ifBlank { device.id },
176+
deviceName = device.displayName,
177177
online = device.online,
178178
selected = active,
179179
loading = active && (remoteState is RemoteSessionUiState.Loading ||

‎src/apps/mobile/harmonyos/entry/src/main/ets/pages/components/AccountProfilePanel.ets‎

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { MobileDesignGeometry, MobileDesignTypography } from '../../generated/MobileDesignTokens';
22
import { RemoteI18n } from '../../i18n/RemoteI18n';
3-
import { CloudAccountDevice } from '../../services/CloudAccountClient';
3+
import { accountDeviceDisplayName, CloudAccountDevice } from '../../services/CloudAccountClient';
44
import { AccountDeviceSelectionPolicy } from '../policy/AccountDeviceSelectionPolicy';
55
import { DeviceModelSettingsEntryPolicy } from '../policy/DeviceModelSettingsEntryPolicy';
6+
import { DeviceDirectoryEntry, DeviceDirectoryState } from '../state/DeviceDirectoryState';
67
import {
78
CARD,
89
CONTENT_ON_ACTION,
@@ -20,6 +21,7 @@ import { DefaultAccountAvatar } from './DefaultAccountAvatar';
2021
/** Account identity and device management shared by Settings and account entry. */
2122
@ComponentV2
2223
export struct AccountProfilePanel {
24+
@Param directoryState: DeviceDirectoryState = new DeviceDirectoryState();
2325
@Param accountUsername: string = '';
2426
@Param accountAvatarUrl: string = '';
2527
@Param accountUserId: string = '';
@@ -42,7 +44,6 @@ export struct AccountProfilePanel {
4244
async (): Promise<CloudAccountDevice[]> => [];
4345
@Event cloudSelectDevice: (device: CloudAccountDevice) => Promise<void> =
4446
async (_device: CloudAccountDevice): Promise<void> => {};
45-
@Local accountDevices: CloudAccountDevice[] = [];
4647
@Local accountDevicesBusy: boolean = false;
4748
@Local accountDevicesError: string = '';
4849
@Local switchingDeviceId: string = '';
@@ -172,7 +173,7 @@ export struct AccountProfilePanel {
172173
if (!this.isAccountAuthenticated()) {
173174
Text(RemoteI18n.t('remote.settings.deviceLoginRequired'))
174175
.fontSize(MobileDesignTypography.bodySmall.size).lineHeight(MobileDesignTypography.bodySmall.lineHeight).fontColor(MUTED).width('100%')
175-
} else if (this.accountDevicesBusy && this.accountDevices.length === 0) {
176+
} else if (this.accountDevicesBusy && this.directoryState.devices.length === 0) {
176177
Text(RemoteI18n.t('remote.settings.deviceLoading'))
177178
.fontSize(MobileDesignTypography.bodySmall.size).fontColor(MUTED).width('100%')
178179
} else if (this.desktopDevices().length === 0) {
@@ -189,7 +190,7 @@ export struct AccountProfilePanel {
189190
}
190191
.width('100%')
191192
}, (device: CloudAccountDevice): string =>
192-
`${device.deviceId}:${device.online ? 'online' : 'offline'}:${device.lastSeenAt || 0}:${device.deviceName}` +
193+
`${device.deviceId}:${device.online ? 'online' : 'offline'}:${device.lastSeenAt || 0}:${accountDeviceDisplayName(device)}` +
193194
`:${this.isCurrentControlDevice(device) ? 'driven' : 'idle'}` +
194195
`:${this.supportsDeviceModelDefaults ? 'model-defaults' : 'no-model-defaults'}`)
195196
}
@@ -219,7 +220,7 @@ export struct AccountProfilePanel {
219220
.width(28)
220221
.height(28)
221222
Column({ space: 2 }) {
222-
Text(device.deviceName || device.deviceId)
223+
Text(accountDeviceDisplayName(device))
223224
.fontSize(MobileDesignTypography.titleSmall.size).fontWeight(FontWeight.Medium).fontColor(INK)
224225
.maxLines(1).textOverflow({ overflow: TextOverflow.Ellipsis })
225226
Text(this.deviceStatus(device))
@@ -349,7 +350,7 @@ export struct AccountProfilePanel {
349350
this.accountDevicesBusy = true;
350351
this.accountDevicesError = '';
351352
try {
352-
this.accountDevices = await this.cloudListDevices();
353+
await this.cloudListDevices();
353354
} catch (err) {
354355
this.accountDevicesError = err instanceof Error ? err.message :
355356
RemoteI18n.t('remote.settings.deviceLoadFailed');
@@ -358,8 +359,8 @@ export struct AccountProfilePanel {
358359
}
359360
}
360361

361-
private desktopDevices(): CloudAccountDevice[] {
362-
return this.accountDevices.filter((device: CloudAccountDevice): boolean =>
362+
private desktopDevices(): DeviceDirectoryEntry[] {
363+
return this.directoryState.devices.filter((device: DeviceDirectoryEntry): boolean =>
363364
device.deviceId !== this.deviceId && device.deviceName !== 'HarmonyOS Phone');
364365
}
365366

@@ -488,7 +489,7 @@ export struct AccountProfilePanel {
488489

489490
@Monitor('accountUserId')
490491
private handleAccountUserChanged(): void {
491-
if (this.isAccountAuthenticated() && this.accountDevices.length === 0) {
492+
if (this.isAccountAuthenticated() && this.directoryState.devices.length === 0) {
492493
this.refreshAccountDevices();
493494
}
494495
}

‎src/apps/mobile/harmonyos/entry/src/main/ets/pages/components/AppRootOverlaySurfaces.ets‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ export struct AppSidebarSurface {
128128

129129
@ComponentV2
130130
export struct AppSettingsSurface {
131+
@Param deviceDirectoryState: DeviceDirectoryState = new DeviceDirectoryState();
131132
@Param shellState: AppShellState = new AppShellState();
132133
@Param remotePageState: RemotePageState = new RemotePageState();
133134
@Param generalPageState: GeneralChatPageState = new GeneralChatPageState();
@@ -145,6 +146,7 @@ export struct AppSettingsSurface {
145146
})
146147
} else {
147148
SettingsSheet({
149+
directoryState: this.deviceDirectoryState,
148150
sheetState: this.shellState.settingsSheet,
149151
accountUsername: this.remotePageState.accountUsername,
150152
accountAvatarUrl: this.remotePageState.accountAvatarUrl,
@@ -179,12 +181,14 @@ export struct AppSettingsSurface {
179181

180182
@ComponentV2
181183
export struct AppConnectSurface {
184+
@Param deviceDirectoryState: DeviceDirectoryState = new DeviceDirectoryState();
182185
@Param remotePageState: RemotePageState = new RemotePageState();
183186
@Param deviceId: string = '';
184187
@Param actions: AppRootPresentationActions = emptyAppRootPresentationActions();
185188

186189
build() {
187190
ConnectView({
191+
directoryState: this.deviceDirectoryState,
188192
remoteUrl: this.remotePageState.remoteUrl,
189193
userId: this.remotePageState.userId,
190194
statusText: this.remotePageState.conversation.statusText,

‎src/apps/mobile/harmonyos/entry/src/main/ets/pages/components/AppRootPresentation.ets‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,7 @@ export struct AppRootPresentation {
635635

636636
@Builder SettingsContent() {
637637
AppSettingsSurface({
638+
deviceDirectoryState: this.deviceDirectoryState,
638639
shellState: this.shellState,
639640
remotePageState: this.remotePageState,
640641
generalPageState: this.generalPageState,
@@ -645,6 +646,7 @@ export struct AppRootPresentation {
645646

646647
@Builder ConnectContent() {
647648
AppConnectSurface({
649+
deviceDirectoryState: this.deviceDirectoryState,
648650
remotePageState: this.remotePageState,
649651
deviceId: this.deviceId,
650652
actions: this.actions

‎src/apps/mobile/harmonyos/entry/src/main/ets/pages/components/ConnectAccountDevicePage.ets‎

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import { MobileDesignTypography } from '../../generated/MobileDesignTokens';
22
import { RemoteI18n } from '../../i18n/RemoteI18n';
3-
import { CloudAccountDevice } from '../../services/CloudAccountClient';
3+
import { accountDeviceDisplayName, CloudAccountDevice } from '../../services/CloudAccountClient';
44
import { ACCENT, CARD, STATUS_SUCCESS, INK, LINE, MUTED, PAGE_BG, STATUS_DANGER, SOFT } from './Theme';
55
import { AccountDeviceSelectionPolicy } from '../policy/AccountDeviceSelectionPolicy';
6+
import { DeviceDirectoryEntry, DeviceDirectoryState } from '../state/DeviceDirectoryState';
67
import { NavigationBackButton } from './NavigationBackButton';
78

89
@ComponentV2
910
export struct ConnectAccountDevicePage {
11+
@Param directoryState: DeviceDirectoryState = new DeviceDirectoryState();
1012
@Param deviceId: string = '';
1113
@Param controlTargetDeviceId: string = '';
1214
@Param connectionState: string = 'idle';
@@ -15,7 +17,6 @@ export struct ConnectAccountDevicePage {
1517
async (): Promise<CloudAccountDevice[]> => [];
1618
@Event cloudSelectDevice: (device: CloudAccountDevice) => Promise<void> =
1719
async (_device: CloudAccountDevice): Promise<void> => {};
18-
@Local accountDevices: CloudAccountDevice[] = [];
1920
@Local accountDevicesBusy: boolean = false;
2021
@Local accountDevicesError: string = '';
2122
@Local switchingDeviceId: string = '';
@@ -77,7 +78,7 @@ export struct ConnectAccountDevicePage {
7778
}
7879
.width('100%').height(38)
7980

80-
if (this.accountDevicesBusy && this.accountDevices.length === 0) {
81+
if (this.accountDevicesBusy && this.directoryState.devices.length === 0) {
8182
Column() {
8283
this.AccountDeviceSkeletonRow()
8384
this.AccountDeviceSkeletonRow()
@@ -95,7 +96,7 @@ export struct ConnectAccountDevicePage {
9596
ForEach(this.desktopDevices(), (device: CloudAccountDevice) => {
9697
this.AccountConnectDeviceRow(device)
9798
}, (device: CloudAccountDevice): string =>
98-
`${device.deviceId}:${device.online ? 'online' : 'offline'}:${device.lastSeenAt || 0}:${device.deviceName}`)
99+
`${device.deviceId}:${device.online ? 'online' : 'offline'}:${device.lastSeenAt || 0}:${accountDeviceDisplayName(device)}`)
99100
}
100101
.width('100%')
101102
}
@@ -127,7 +128,7 @@ export struct ConnectAccountDevicePage {
127128
SymbolGlyph($r('sys.symbol.desktop'))
128129
.fontSize(22).fontColor([MUTED]).width(26).height(24).opacity(device.online ? 0.68 : 0.38)
129130
Column({ space: 3 }) {
130-
Text(device.deviceName || device.deviceId)
131+
Text(accountDeviceDisplayName(device))
131132
.fontSize(MobileDesignTypography.titleSmall.size).fontWeight(FontWeight.Medium).fontColor(INK)
132133
.maxLines(1).textOverflow({ overflow: TextOverflow.Ellipsis })
133134
Text(this.accountDeviceStatus(device))
@@ -171,7 +172,7 @@ export struct ConnectAccountDevicePage {
171172
this.accountDevicesBusy = true;
172173
this.accountDevicesError = '';
173174
try {
174-
this.accountDevices = await this.cloudListDevices();
175+
await this.cloudListDevices();
175176
} catch (err) {
176177
this.accountDevicesError = err instanceof Error ? err.message :
177178
RemoteI18n.t('remote.settings.deviceLoadFailed');
@@ -180,8 +181,8 @@ export struct ConnectAccountDevicePage {
180181
}
181182
}
182183

183-
private desktopDevices(): CloudAccountDevice[] {
184-
return this.accountDevices.filter((device: CloudAccountDevice): boolean =>
184+
private desktopDevices(): DeviceDirectoryEntry[] {
185+
return this.directoryState.devices.filter((device: DeviceDirectoryEntry): boolean =>
185186
device.deviceId !== this.deviceId && device.deviceName !== 'HarmonyOS Phone');
186187
}
187188

‎src/apps/mobile/harmonyos/entry/src/main/ets/pages/components/ConnectView.ets‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { MobileDesignTypography } from '../../generated/MobileDesignTokens';
22
import { RemoteI18n } from '../../i18n/RemoteI18n';
33
import { CloudAccountDevice } from '../../services/CloudAccountClient';
4+
import { DeviceDirectoryState } from '../state/DeviceDirectoryState';
45
import { ConnectAccountDevicePage } from './ConnectAccountDevicePage';
56
import { AppActionButton, AppActionStyle } from './AppActionButton';
67
import { NavigationBackButton } from './NavigationBackButton';
@@ -21,6 +22,7 @@ import { WindowInsetsBinding } from '../../services/WindowSystemBarService';
2122
*/
2223
@ComponentV2
2324
export struct ConnectView {
25+
@Param directoryState: DeviceDirectoryState = new DeviceDirectoryState();
2426
@Param remoteUrl: string = '';
2527
@Param userId: string = '';
2628
@Param statusText: string = RemoteI18n.t('status.waitingConnection');
@@ -72,6 +74,7 @@ export struct ConnectView {
7274
@Builder
7375
AccountDeviceSelectionPage() {
7476
ConnectAccountDevicePage({
77+
directoryState: this.directoryState,
7578
deviceId: this.deviceId,
7679
controlTargetDeviceId: this.controlTargetDeviceId,
7780
connectionState: this.connectionState,

‎src/apps/mobile/harmonyos/entry/src/main/ets/pages/components/SettingsSheet.ets‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { MobileDesignGeometry, MobileDesignTypography } from '../../generated/MobileDesignTokens';
22
import { RemoteI18n } from '../../i18n/RemoteI18n';
33
import { SettingsSheetState } from '../state/SettingsSheetState';
4+
import { DeviceDirectoryState } from '../state/DeviceDirectoryState';
45
import { DeviceModelDefaultsRequestPath } from '../state/DeviceModelDefaultsSheetState';
56
import { CARD, INK, LINE, MUTED, PAGE_BG } from './Theme';
67
import { CurrentControlSection } from './CurrentControlSection';
@@ -17,6 +18,7 @@ import { RemotePermissionSection } from './RemotePermissionSection';
1718

1819
@ComponentV2
1920
export struct SettingsSheet {
21+
@Param directoryState: DeviceDirectoryState = new DeviceDirectoryState();
2022
@Param sheetState: SettingsSheetState = new SettingsSheetState();
2123
@Param accountUsername: string = '';
2224
@Param accountAvatarUrl: string = '';
@@ -162,6 +164,7 @@ export struct SettingsSheet {
162164
Scroll() {
163165
Column({ space: 0 }) {
164166
AccountProfilePanel({
167+
directoryState: this.directoryState,
165168
accountUsername: this.accountUsername,
166169
accountAvatarUrl: this.accountAvatarUrl,
167170
accountUserId: this.authenticatedUserId,

0 commit comments

Comments
 (0)