Skip to content

A free and open source instant messaging and VoIP chat app built for friends, groups, and communities.

TypeScript fluxerfluxerapp

feat(app): badge and list every signed-in account in tray menus

Hampusc5d86c8ea421
diff --git a/fluxer_app/src/features/app/components/AppBadgeCount.ts b/fluxer_app/src/features/app/components/AppBadgeCount.ts
new file mode 100644
index 000000000..9e08bf920
--- /dev/null
+++ b/fluxer_app/src/features/app/components/AppBadgeCount.ts
@@ -0,0 +1,25 @@
+// SPDX-License-Identifier: AGPL-3.0-or-later
+
+export const UNREAD_INDICATOR = -1;
+
+interface AppBadgeInput {
+ readonly foregroundMentionCount: number;
+ readonly otherAccountsMentionCount: number;
+ readonly pendingFriendRequestCount: number;
+ readonly foregroundHasUnread: boolean;
+ readonly otherAccountsHaveUnread: boolean;
+ readonly unreadMessageBadgeEnabled: boolean;
+}
+
+export interface AppBadgeState {
+ readonly badge: number;
+ readonly totalCount: number;
+ readonly showUnread: boolean;
+}
+
+export function computeAppBadge(input: AppBadgeInput): AppBadgeState {
+ const totalCount = input.foregroundMentionCount + input.otherAccountsMentionCount + input.pendingFriendRequestCount;
+ const showUnread = (input.foregroundHasUnread || input.otherAccountsHaveUnread) && input.unreadMessageBadgeEnabled;
+ if (totalCount > 0) return {badge: totalCount, totalCount, showUnread};
+ return {badge: showUnread ? UNREAD_INDICATOR : 0, totalCount, showUnread};
+}
diff --git a/fluxer_app/src/features/app/components/AppNotificationBadge.ts b/fluxer_app/src/features/app/components/AppNotificationBadge.ts
index f9930e637..7d182cb86 100644
--- a/fluxer_app/src/features/app/components/AppNotificationBadge.ts
+++ b/fluxer_app/src/features/app/components/AppNotificationBadge.ts
@@ -1,11 +1,13 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
+import AccountEngine from '@app/features/account_engine/state/AccountEngine';
+import {computeAppBadge, UNREAD_INDICATOR} from '@app/features/app/components/AppBadgeCount';
import RuntimeConfig from '@app/features/app/state/RuntimeConfig';
-import {getDocumentFaviconUrl} from '@app/features/app/state/RuntimeDocumentBranding';
-import DesktopBackgroundGateway from '@app/features/gateway/transport/DesktopBackgroundGateway';
+import {findActiveIconLink, getDocumentFavicons} from '@app/features/app/state/RuntimeDocumentBranding';
import GuildReadState from '@app/features/guild/state/GuildReadState';
import {Logger} from '@app/features/platform/utils/AppLogger';
import Relationships from '@app/features/relationship/state/Relationships';
+import Theme from '@app/features/theme/state/Theme';
import Notification from '@app/features/ui/state/Notification';
import {getElectronAPI, isDesktop} from '@app/features/ui/utils/NativeUtils';
import {updateDocumentTitleBadge} from '@app/features/window/hooks/useFluxerDocumentTitle';
@@ -16,23 +18,12 @@ import type React from 'react';
import {useEffect} from 'react';
const logger = new Logger('AppBadge');
-const UNREAD_INDICATOR = -1;
let favico: Favico | null = null;
let favicoLink: HTMLLinkElement | null = null;
let favicoLinkHref: string | null = null;
let favicoSource: string | null = null;
-const findIconLink = (): HTMLLinkElement | null => {
- const links = document.head.querySelectorAll<HTMLLinkElement>('link');
- for (let index = links.length - 1; index >= 0; index--) {
- if (/(^|\s)icon(\s|$)/i.test(links[index].getAttribute('rel') ?? '')) {
- return links[index];
- }
- }
- return null;
-};
-
const releaseFavico = (): void => {
if (favicoLink !== null && favicoLinkHref !== null && favicoLink.getAttribute('href')?.startsWith('data:')) {
favicoLink.setAttribute('href', favicoLinkHref);
@@ -45,7 +36,7 @@ const releaseFavico = (): void => {
const initFavico = (): Favico | null => {
if (favico) return favico;
try {
- const link = findIconLink();
+ const link = findActiveIconLink();
favicoLink = link;
favicoLinkHref = link?.getAttribute('href') ?? null;
favico = new Favico(link === null ? {animation: 'none'} : {animation: 'none', element: link});
@@ -69,6 +60,9 @@ const setElectronBadge = (badge: number): void => {
}
};
const setFaviconBadge = (badge: number, source: string | null): void => {
+ if (isDesktop()) {
+ return;
+ }
if (source !== favicoSource) {
releaseFavico();
favicoSource = source;
@@ -107,28 +101,30 @@ const setBadge = (badge: number, faviconSource: string | null): void => {
setFaviconBadge(badge, faviconSource);
setPwaBadge(badge);
};
+function appBadgeMentionCount(): number {
+ return GuildReadState.mentionCountAcrossGuilds(RuntimeConfig.directMessagesDisabled);
+}
+
export const AppBadge: React.FC = observer(() => {
const relationships = Relationships.getRelationships();
- const unreadMessageBadgeEnabled = Notification.unreadMessageBadgeEnabled;
- const mentionCount = GuildReadState.mentionCountAcrossGuilds() + DesktopBackgroundGateway.totalMentionCount;
- const hasUnread = GuildReadState.anyGuildUnread;
- const pendingCount = RuntimeConfig.directMessagesDisabled
- ? 0
- : relationships.filter((relationship) => relationship.type === RelationshipTypes.INCOMING_REQUEST).length;
- const totalCount = mentionCount + pendingCount;
- let badge: number = 0;
- if (totalCount > 0) {
- badge = totalCount;
- } else if (hasUnread && unreadMessageBadgeEnabled) {
- badge = UNREAD_INDICATOR;
- }
- const faviconSource = getDocumentFaviconUrl(RuntimeConfig.getSnapshotOrNull()?.appPublic ?? null);
+ const {badge, totalCount, showUnread} = computeAppBadge({
+ foregroundMentionCount: appBadgeMentionCount(),
+ otherAccountsMentionCount: AccountEngine.otherAccountsMentionCount,
+ pendingFriendRequestCount: RuntimeConfig.friendsDisabled
+ ? 0
+ : relationships.filter((relationship) => relationship.type === RelationshipTypes.INCOMING_REQUEST).length,
+ foregroundHasUnread: GuildReadState.anyGuildUnread,
+ otherAccountsHaveUnread: AccountEngine.otherAccountsHaveUnread,
+ unreadMessageBadgeEnabled: Notification.unreadMessageBadgeEnabled,
+ });
+ const favicons = getDocumentFavicons(RuntimeConfig.getSnapshotOrNull()?.appPublic ?? null);
+ const faviconSource = favicons.dark !== null && Theme.systemPrefersDark ? favicons.dark : favicons.light;
useEffect(() => {
setBadge(badge, faviconSource);
}, [badge, faviconSource]);
useEffect(() => {
- updateDocumentTitleBadge(totalCount, hasUnread && unreadMessageBadgeEnabled);
- }, [totalCount, hasUnread, unreadMessageBadgeEnabled]);
+ updateDocumentTitleBadge(totalCount, showUnread);
+ }, [totalCount, showUnread]);
useEffect(() => {
return () => {
setBadge(0, favicoSource);
diff --git a/fluxer_app/src/features/app/components/floating/UserAreaAccountSwitchMenu.module.css b/fluxer_app/src/features/app/components/floating/UserAreaAccountSwitchMenu.module.css
index 6309fa43e..37986ae89 100644
--- a/fluxer_app/src/features/app/components/floating/UserAreaAccountSwitchMenu.module.css
+++ b/fluxer_app/src/features/app/components/floating/UserAreaAccountSwitchMenu.module.css
@@ -5,7 +5,7 @@
display: flex;
flex-direction: column;
width: 17.5rem;
- margin-left: 1rem;
+ margin-inline-start: 1rem;
filter: none;
}
@@ -112,12 +112,6 @@
white-space: nowrap;
}
-.accountMenuDiscriminator {
- color: var(--text-tertiary);
- font-size: 0.75rem;
- font-weight: 400;
-}
-
.accountMenuMeta {
color: var(--status-online);
font-size: 0.6875rem;
diff --git a/fluxer_app/src/features/app/components/floating/UserAreaAccountSwitchMenu.tsx b/fluxer_app/src/features/app/components/floating/UserAreaAccountSwitchMenu.tsx
index 748b8137e..e0f337469 100644
--- a/fluxer_app/src/features/app/components/floating/UserAreaAccountSwitchMenu.tsx
+++ b/fluxer_app/src/features/app/components/floating/UserAreaAccountSwitchMenu.tsx
@@ -1,13 +1,10 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
+import AccountEngine from '@app/features/account_engine/state/AccountEngine';
import styles from '@app/features/app/components/floating/UserAreaAccountSwitchMenu.module.css';
import {useAccountAvatarURL} from '@app/features/auth/AccountAvatarUtils';
import {resolveAccountInstanceKey, resolveAccountInstanceLabel} from '@app/features/auth/AccountDisplayUtils';
-import {
- AccountIdentityText,
- useAccountDisplayIdentityView,
-} from '@app/features/auth/components/accounts/AccountIdentity';
-import {getAccountMentionCount} from '@app/features/auth/components/accounts/account_switcher_modal/AccountMentionCounts';
+import {useAccountDisplayIdentityView} from '@app/features/auth/components/accounts/AccountIdentity';
import {SESSION_EXPIRED_DESCRIPTOR} from '@app/features/auth/components/accounts/account_switcher_modal/AccountPickerShared';
import {InstanceBrandMark} from '@app/features/auth/components/InstanceBrandMark';
import {resolveInstanceLabel} from '@app/features/auth/flow/instance_selector/InstanceDirectoryStorage';
@@ -107,7 +104,7 @@ const SwitchAccountMenuItem = observer(
const isExpired = account.isValid === false;
const avatarUrl = useAccountAvatarURL(account);
const identityView = useAccountDisplayIdentityView(account);
- const mentionCount = getAccountMentionCount(accountKey);
+ const mentionCount = AccountEngine.getMentionCount(accountKey);
let metaLabel: string | null = null;
if (isExpired) {
metaLabel = i18n._(SESSION_EXPIRED_DESCRIPTOR);
@@ -149,13 +146,10 @@ const SwitchAccountMenuItem = observer(
>
<span
className={styles.accountMenuNameText}
+ dir="auto"
data-flx="app.floating.user-area-account-switch-menu.account-menu-name-text"
>
- <AccountIdentityText
- identityView={identityView}
- discriminatorClassName={styles.accountMenuDiscriminator}
- data-flx="app.floating.user-area-account-switch-menu.account-identity-text"
- />
+ {identityView.displayLabel}
</span>
<MentionBadge
mentionCount={mentionCount}
diff --git a/fluxer_app/src/features/platform/utils/DesktopLocaleBridge.ts b/fluxer_app/src/features/platform/utils/DesktopLocaleBridge.ts
index 660709bca..7d7e1df6b 100644
--- a/fluxer_app/src/features/platform/utils/DesktopLocaleBridge.ts
+++ b/fluxer_app/src/features/platform/utils/DesktopLocaleBridge.ts
@@ -343,6 +343,37 @@ const COMPOSE_A_NEW_DIRECT_MESSAGE_DESCRIPTOR = msg({
message: 'Compose a new direct message',
comment: 'Windows jump-list task description (tooltip text) for the New direct message action.',
});
+const TRAY_ACCOUNTS_DESCRIPTOR = msg({
+ message: 'Accounts',
+ comment: 'Tray and dock menu submenu title listing every signed-in account.',
+});
+const TRAY_CHOOSE_ACCOUNT_DESCRIPTOR = msg({
+ message: 'Choose an account…',
+ comment: 'Tray and dock menu item that opens the full-screen account picker.',
+});
+const TRAY_ACCOUNT_WITH_HOST_DESCRIPTOR = msg({
+ message: '{name} ({host})',
+ comment:
+ 'Tray menu account item when the signed-in accounts are on more than one instance. {name} is the account name, {host} is the instance address.',
+});
+const TRAY_ACCOUNT_NUMBERED_DESCRIPTOR = msg({
+ message: 'Account {number}',
+ comment:
+ 'Tray and dock menu account item while streamer mode hides personal information. {number} is the account position in the list, such as 2.',
+});
+const TRAY_ACCOUNT_WITH_MENTIONS_DESCRIPTOR = msg({
+ message: '{label} · {count}',
+ comment:
+ 'Tray menu account item with unread mentions. {label} is the account name, {count} is the number of mentions.',
+});
+const JUMP_LIST_CHOOSE_ACCOUNT_DESCRIPTOR = msg({
+ message: 'Choose an account',
+ comment: 'Windows jump-list task title. Opens the full-screen account picker.',
+});
+const JUMP_LIST_CHOOSE_ACCOUNT_DESCRIPTION_DESCRIPTOR = msg({
+ message: 'Switch to another signed-in account',
+ comment: 'Windows jump-list task description (tooltip text) for the Choose an account action.',
+});
const OPEN_NOTIFICATION_DESCRIPTOR = msg({
message: 'Open',
comment:
@@ -545,6 +576,13 @@ const NATIVE_MESSAGES: Record<string, NativeMessage> = {
'desktop.jumpList.openSettingsDescription': OPEN_SETTINGS_2_DESCRIPTOR,
'desktop.jumpList.newDirectMessage': NEW_DIRECT_MESSAGE_DESCRIPTOR,
'desktop.jumpList.newDirectMessageDescription': COMPOSE_A_NEW_DIRECT_MESSAGE_DESCRIPTOR,
+ 'desktop.jumpList.chooseAccount': JUMP_LIST_CHOOSE_ACCOUNT_DESCRIPTOR,
+ 'desktop.jumpList.chooseAccountDescription': JUMP_LIST_CHOOSE_ACCOUNT_DESCRIPTION_DESCRIPTOR,
+ 'desktop.tray.accounts': TRAY_ACCOUNTS_DESCRIPTOR,
+ 'desktop.tray.chooseAccount': TRAY_CHOOSE_ACCOUNT_DESCRIPTOR,
+ 'desktop.tray.accountWithHost': TRAY_ACCOUNT_WITH_HOST_DESCRIPTOR,
+ 'desktop.tray.accountWithMentions': TRAY_ACCOUNT_WITH_MENTIONS_DESCRIPTOR,
+ 'desktop.tray.accountNumbered': TRAY_ACCOUNT_NUMBERED_DESCRIPTOR,
'desktop.notifications.open': OPEN_NOTIFICATION_DESCRIPTOR,
'desktop.themes.addLocalFiles': ADD_LOCAL_FILES_DESCRIPTOR,
'desktop.themes.importFolder': IMPORT_FOLDER_DESCRIPTOR,
diff --git a/fluxer_app/src/features/platform/utils/DesktopTrayBridge.ts b/fluxer_app/src/features/platform/utils/DesktopTrayBridge.ts
index 733f44f67..afc0dd6f3 100644
--- a/fluxer_app/src/features/platform/utils/DesktopTrayBridge.ts
+++ b/fluxer_app/src/features/platform/utils/DesktopTrayBridge.ts
@@ -1,12 +1,15 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
import Updater from '@app/features/app/state/Updater';
+import {openAccountSwitcherModal} from '@app/features/auth/commands/AccountSwitcherModalCommands';
import Authentication from '@app/features/auth/state/Authentication';
+import {switchToSavedAccount} from '@app/features/auth/utils/AccountSwitcherModalUtils';
import Channels from '@app/features/channel/state/Channels';
import * as VoiceStateCommands from '@app/features/devtools/commands/VoiceStateCommands';
import {Logger} from '@app/features/platform/utils/AppLogger';
import {formatClientBuildInfo, getClientInfo, getClientInfoSync} from '@app/features/platform/utils/ClientInfo';
import Presence from '@app/features/presence/state/Presence';
+import StreamerMode from '@app/features/streamer_mode/state/StreamerMode';
import {getElectronAPI, isDesktop} from '@app/features/ui/utils/NativeUtils';
import UserSettings from '@app/features/user/state/UserSettings';
import MediaEngine from '@app/features/voice/engine/MediaEngineFacade';
@@ -68,6 +71,7 @@ export function initializeDesktopTrayBridge(): (() => void) | null {
selfMute: LocalVoiceState.getSelfMute(),
selfDeaf: LocalVoiceState.getSelfDeaf(),
presenceStatus: toTrayStatus(resolvePresenceStatus()),
+ hidePersonalInformation: StreamerMode.shouldHidePersonalInformation,
});
};
void getClientInfo()
@@ -88,6 +92,7 @@ export function initializeDesktopTrayBridge(): (() => void) | null {
selfMute: LocalVoiceState.getSelfMute(),
selfDeaf: LocalVoiceState.getSelfDeaf(),
status: resolvePresenceStatus(),
+ hidePersonalInformation: StreamerMode.shouldHidePersonalInformation,
};
},
pushState,
@@ -115,6 +120,14 @@ export function initializeDesktopTrayBridge(): (() => void) | null {
void Updater.checkForUpdates(true, true);
break;
}
+ case 'switch-account': {
+ void switchToSavedAccount({accountKey: payload.accountKey});
+ break;
+ }
+ case 'open-account-switcher': {
+ openAccountSwitcherModal();
+ break;
+ }
}
});
return () => {