Skip to content

Commit b71320e

Browse files
committed
feat: add dynamic device display name
1 parent 20c5c29 commit b71320e

5 files changed

Lines changed: 21 additions & 6 deletions
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
default: minor
3+
---
4+
5+
# Device names are now dynamic, showing your browser and OS (e.g., "Sable on Firefox for Windows") instead of just "Sable Web".

src/app/pages/auth/login/PasswordLoginForm.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import { PasswordInput } from '$components/password-input';
3030
import { getResetPasswordPath } from '$pages/pathUtils';
3131
import { stopPropagation } from '$utils/keyboard';
3232
import { FieldError } from '$pages/auth/FiledError';
33+
import { deviceDisplayName } from '$utils/user-agent';
3334
import {
3435
CustomLoginResponse,
3536
LoginError,
@@ -133,7 +134,7 @@ export function PasswordLoginForm({ defaultUsername, defaultEmail }: PasswordLog
133134
user: username,
134135
},
135136
password,
136-
initial_device_display_name: 'Sable Web',
137+
initial_device_display_name: deviceDisplayName(),
137138
});
138139
};
139140

@@ -151,7 +152,7 @@ export function PasswordLoginForm({ defaultUsername, defaultEmail }: PasswordLog
151152
user: mxIdUsername,
152153
},
153154
password,
154-
initial_device_display_name: 'Sable Web',
155+
initial_device_display_name: deviceDisplayName(),
155156
});
156157
};
157158
const handleEmailLogin = (email: string, password: string) => {
@@ -163,7 +164,7 @@ export function PasswordLoginForm({ defaultUsername, defaultEmail }: PasswordLog
163164
address: email,
164165
},
165166
password,
166-
initial_device_display_name: 'Sable Web',
167+
initial_device_display_name: deviceDisplayName(),
167168
});
168169
};
169170

src/app/pages/auth/login/TokenLogin.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { useCallback, useEffect } from 'react';
1414
import { MatrixError } from '$types/matrix-sdk';
1515
import { useAutoDiscoveryInfo } from '$hooks/useAutoDiscoveryInfo';
1616
import { AsyncStatus, useAsyncCallback } from '$hooks/useAsyncCallback';
17+
import { deviceDisplayName } from '$utils/user-agent';
1718
import { CustomLoginResponse, LoginError, login, useLoginComplete } from './loginUtil';
1819

1920
function LoginTokenError({ message }: { message: string }) {
@@ -57,7 +58,7 @@ export function TokenLogin({ token }: TokenLoginProps) {
5758
startLogin(baseUrl, {
5859
type: 'm.login.token',
5960
token,
60-
initial_device_display_name: 'Sable Web',
61+
initial_device_display_name: deviceDisplayName(),
6162
});
6263
}, [baseUrl, token, startLogin]);
6364

src/app/pages/auth/register/PasswordRegisterForm.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import { ConfirmPasswordMatch } from '$components/ConfirmPasswordMatch';
4242
import { UIAFlowOverlay } from '$components/UIAFlowOverlay';
4343
import { RequestEmailTokenCallback, RequestEmailTokenResponse } from '$hooks/types';
4444
import { FieldError } from '$pages/auth/FiledError';
45+
import { deviceDisplayName } from '$utils/user-agent';
4546
import { RegisterError, RegisterResult, register, useRegisterComplete } from './registerUtil';
4647

4748
export const SUPPORTED_REGISTER_STAGES = [
@@ -109,7 +110,7 @@ function RegisterUIAFlow({
109110
auth: authDict,
110111
password,
111112
username,
112-
initial_device_display_name: 'Sable Web',
113+
initial_device_display_name: deviceDisplayName(),
113114
});
114115
},
115116
[onRegister, formData]
@@ -250,7 +251,7 @@ export function PasswordRegisterForm({
250251
auth: {
251252
session: authData.session,
252253
},
253-
initial_device_display_name: 'Sable Web',
254+
initial_device_display_name: deviceDisplayName(),
254255
});
255256
};
256257

src/app/utils/user-agent.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,10 @@ const isMac = result.os.name === 'Mac OS';
1414
export const ua = () => result;
1515
export const isMacOS = () => isMac;
1616
export const mobileOrTablet = () => isMobileOrTablet;
17+
18+
export const deviceDisplayName = (): string => {
19+
const browser = result.browser.name;
20+
const os = result.os.name;
21+
if (!browser || !os) return 'Sable Web';
22+
return `Sable on ${browser} for ${os}`;
23+
};

0 commit comments

Comments
 (0)