Skip to content

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

TypeScript fluxerfluxerapp

feat(app): add device-wide account keyboard shortcuts

Hampus63179123b590
diff --git a/fluxer_app/src/features/app/keybindings/KeybindManager.ts b/fluxer_app/src/features/app/keybindings/KeybindManager.ts
index d67afe0b2..adabeaf3a 100644
--- a/fluxer_app/src/features/app/keybindings/KeybindManager.ts
+++ b/fluxer_app/src/features/app/keybindings/KeybindManager.ts
@@ -24,6 +24,7 @@ import type {
} from '@app/features/app/keybindings/keybind_manager/shared';
import {comboToCombokeysStrings} from '@app/features/app/keybindings/utils/ComboShortcutStrings';
import {
+ CHANNEL_TEXTAREA_SELECTOR,
EDITABLE_CAPTURE_SHORTCUT_ACTIONS,
getEditableElementValue,
isChannelTextareaElement,
@@ -49,6 +50,8 @@ import {
sourceIdForKeybind,
} from '@app/features/app/keybindings/utils/RuntimeKeybinds';
import {LOCAL_SHORTCUT_ACTION_PRIORITY} from '@app/features/app/keybindings/utils/ShortcutPriority';
+import RuntimeConfig from '@app/features/app/state/RuntimeConfig';
+import {isAccountHandoffArrival} from '@app/features/auth/state/AccountHandoffCapture';
import Authentication from '@app/features/auth/state/Authentication';
import type {Channel} from '@app/features/channel/models/Channel';
import Channels from '@app/features/channel/state/Channels';
@@ -63,6 +66,7 @@ import Keybind, {
type KeybindConfig,
type KeyCombo,
} from '@app/features/input/state/InputKeybind';
+import {isAccountKeybindCommand} from '@app/features/input/state/input_keybind/KeybindCommands';
import {getSuppressedBuiltinActions} from '@app/features/input/state/KeybindResolution';
import {isGamepadButtonPressed} from '@app/features/input/utils/GamepadButtonUtils';
import {shouldUseKeyboardShortcutsOverlayFallbackFromEvent} from '@app/features/input/utils/KeyboardShortcutLayoutUtils';
@@ -106,7 +110,6 @@ import type {I18n} from '@lingui/core';
import CombokeysImport from 'combokeys';
import {autorun, compareStructural, computed, reaction} from 'mobx';
-const ROUTE_ALLOWED_ACTIONS = new Set<KeybindCommand>(['system_open_theme_studio_popout']);
const GAMEPAD_POLL_INTERVAL_MS = 50;
const PORTAL_SOURCE_ID_PREFIX = 'portal:';
@@ -248,7 +251,9 @@ class KeybindManager {
private readonly resolvedKeybindsValue = computed(
(): ReadonlyArray<RuntimeKeybind> => {
const skipDefaults = Keybind.getDisableBuiltinKeybinds();
- const defaults = skipDefaults ? [] : Keybind.getDefaultsForRuntimeDispatch();
+ const defaults = skipDefaults
+ ? Keybind.getDefaultsForRuntimeDispatch().filter((entry) => isAccountKeybindCommand(entry.action))
+ : Keybind.getDefaultsForRuntimeDispatch();
const customs = Keybind.getCustomKeybinds();
return [
...buildDefaultRuntimeKeybinds(defaults, getSuppressedBuiltinActions(customs)),
@@ -297,7 +302,7 @@ class KeybindManager {
navigateToDirectMessages(): void {
const channelId = SelectedChannel.selectedChannelIds.get(ME);
- if (channelId && Channels.getChannel(channelId)) {
+ if (channelId && !RuntimeConfig.directMessagesDisabled && Channels.getChannel(channelId)) {
this.navigateToChannel(ME, channelId);
return;
}
@@ -386,6 +391,16 @@ class KeybindManager {
}
}
+ private getNextChannel(channels: ReadonlyArray<Channel>, direction: 1 | -1): Channel {
+ const current = this.currentChannelId;
+ const idx = current ? channels.findIndex((channel) => channel.id === current) : -1;
+ let base = idx;
+ if (idx === -1) {
+ base = direction === 1 ? -1 : 0;
+ }
+ return channels[(base + direction + channels.length) % channels.length];
+ }
+
cycleChannelInCurrentContext(direction: 1 | -1): void {
if (Navigation.context === 'dm') {
this.cycleDirectMessageContext(direction);
@@ -393,10 +408,7 @@ class KeybindManager {
}
const channels = this.getNavigableChannelsInCurrentContext();
if (!channels.length) return;
- const current = this.currentChannelId;
- const idx = current ? channels.findIndex((c) => c.id === current) : -1;
- const base = idx === -1 ? (direction === 1 ? -1 : 0) : idx;
- const target = channels[(base + direction + channels.length) % channels.length];
+ const target = this.getNextChannel(channels, direction);
this.navigateToChannel(target.guildId ?? null, target.id);
}
@@ -407,10 +419,7 @@ class KeybindManager {
predicate(c),
);
if (!channels.length) return;
- const current = this.currentChannelId;
- const idx = current ? channels.findIndex((c) => c.id === current) : -1;
- const base = idx === -1 ? (direction === 1 ? -1 : 0) : idx;
- const target = channels[(base + direction + channels.length) % channels.length];
+ const target = this.getNextChannel(channels, direction);
this.navigateToChannel(guildId, target.id);
}
@@ -453,11 +462,14 @@ class KeybindManager {
const channelId = this.currentChannelId;
return Boolean(channelId && ReadStates.hasUnread(channelId));
}
+ if (action === 'chat_focus_textarea') {
+ return this.currentChannelId != null && document.querySelector(CHANNEL_TEXTAREA_SELECTOR) != null;
+ }
return true;
}
private isAppRoute(pathname: string): boolean {
- return pathname.startsWith('/channels/');
+ return pathname.startsWith('/channels/') && !isAccountHandoffArrival(pathname);
}
private ensureCombokeys(): CombokeysInstance | null {
@@ -1734,7 +1746,7 @@ class KeybindManager {
}
private isActionAllowedForCurrentView(action: KeybindCommand): boolean {
- if (this.routeSuspended && !ROUTE_ALLOWED_ACTIONS.has(action)) return false;
+ if (this.routeSuspended) return false;
if (this.isCompactCallTextareaActionBlocked(action)) return false;
return !VoiceCallFullscreen.isActive || isKeybindAllowedDuringVoiceCallFullscreen(action);
}
diff --git a/fluxer_app/src/features/app/keybindings/keybind_manager/handlers/accountHandlers.ts b/fluxer_app/src/features/app/keybindings/keybind_manager/handlers/accountHandlers.ts
new file mode 100644
index 000000000..5f2f823bc
--- /dev/null
+++ b/fluxer_app/src/features/app/keybindings/keybind_manager/handlers/accountHandlers.ts
@@ -0,0 +1,101 @@
+// SPDX-License-Identifier: AGPL-3.0-or-later
+
+import {Routes} from '@app/app/Routes';
+import AccountEngine from '@app/features/account_engine/state/AccountEngine';
+import type {HandlerHost} from '@app/features/app/keybindings/keybind_manager/handlers/types';
+import {pickNewestOtherAccountMention} from '@app/features/app/keybindings/utils/AccountMentionTarget';
+import {toggleAccountSwitcherModal} from '@app/features/auth/commands/AccountSwitcherModalCommands';
+import {focusNewAccountViewAfterSwitch} from '@app/features/auth/components/accounts/account_switcher/AccountSwitcherReturnFocus';
+import {getAccountKey} from '@app/features/auth/state/AccountStorageKey';
+import {
+ adjacentSwitcherAccount,
+ mostRecentOtherAccount,
+ switcherAccounts,
+} from '@app/features/auth/state/AccountSwitcherAccounts';
+import Accounts from '@app/features/auth/state/Accounts';
+import {switchToSavedAccount} from '@app/features/auth/utils/AccountSwitcherModalUtils';
+import {ACCOUNT_SWITCHER_SLOT_ACTIONS} from '@app/features/input/state/input_keybind/KeybindCommands';
+import type {Account} from '@app/features/platform/state/AuthSession';
+import QuickSwitcher from '@app/features/search/state/QuickSwitcher';
+import * as ToastCommands from '@app/features/ui/commands/ToastCommands';
+import type {I18n} from '@lingui/core';
+import {msg} from '@lingui/core/macro';
+
+const NO_NEW_MENTIONS_ON_OTHER_ACCOUNTS_DESCRIPTOR = msg({
+ message: 'No new mentions on your other accounts.',
+ comment: 'Toast shown when the jump to mention shortcut finds no unread mention on any other signed-in account.',
+});
+
+function routeForAccountChannel(guildId: string | null, channelId: string, messageId: string | null): string {
+ if (guildId === null) {
+ return messageId === null ? Routes.dmChannel(channelId) : Routes.dmChannelMessage(channelId, messageId);
+ }
+ return messageId === null
+ ? Routes.guildChannel(guildId, channelId)
+ : Routes.channelMessage(guildId, channelId, messageId);
+}
+
+async function switchToAccount(account: Account | null): Promise<void> {
+ if (account === null) return;
+ const previousAccountKey = Accounts.currentAccountKey;
+ await switchToSavedAccount({accountKey: getAccountKey(account)});
+ if (Accounts.currentAccountKey !== previousAccountKey) focusNewAccountViewAfterSwitch(document);
+}
+
+function otherAccountKeys(): Array<string> {
+ const currentAccountKey = Accounts.currentAccountKey;
+ return Accounts.getAllAccounts()
+ .map((account) => getAccountKey(account))
+ .filter((accountKey) => accountKey !== currentAccountKey);
+}
+
+async function jumpToNewestOtherAccountMention(i18n: I18n): Promise<void> {
+ const accountKeys = otherAccountKeys();
+ const activities =
+ accountKeys.length === 0 ? [] : await AccountEngine.loadActivity({accountKeys, channelLimit: 25, mentionLimit: 10});
+ const target = pickNewestOtherAccountMention(activities, Accounts.currentAccountKey);
+ if (target === null) {
+ ToastCommands.createToast({type: 'info', children: i18n._(NO_NEW_MENTIONS_ON_OTHER_ACCOUNTS_DESCRIPTOR)});
+ return;
+ }
+ await switchToSavedAccount({
+ accountKey: target.accountKey,
+ redirectAfterSwitch: routeForAccountChannel(target.guildId, target.channelId, target.messageId),
+ });
+}
+
+export function registerAccountKeybindHandlers(host: HandlerHost, i18n: I18n): void {
+ host.register('system_open_account_switcher', ({type}) => {
+ if (type !== 'press') return;
+ toggleAccountSwitcherModal();
+ });
+ host.register('system_switch_account_next', ({type}) => {
+ if (type !== 'press') return;
+ void switchToAccount(adjacentSwitcherAccount(1));
+ });
+ host.register('system_switch_account_prev', ({type}) => {
+ if (type !== 'press') return;
+ void switchToAccount(adjacentSwitcherAccount(-1));
+ });
+ host.register('system_switch_account_recent', ({type}) => {
+ if (type !== 'press') return;
+ void switchToAccount(mostRecentOtherAccount());
+ });
+ host.register('system_jump_account_mention', ({type}) => {
+ if (type !== 'press') return;
+ void jumpToNewestOtherAccountMention(i18n).catch((error: unknown) => {
+ host.logger.error('Failed to jump to the newest mention on another account', error);
+ });
+ });
+ host.register('nav_quick_switcher_accounts', ({type}) => {
+ if (type !== 'press') return;
+ if (QuickSwitcher.getIsOpen()) QuickSwitcher.hide();
+ else QuickSwitcher.show({scope: 'other_accounts'});
+ });
+ for (const [slotIndex, action] of ACCOUNT_SWITCHER_SLOT_ACTIONS.entries()) {
+ host.register(action, ({type}) => {
+ if (type !== 'press') return;
+ void switchToAccount(switcherAccounts()[slotIndex] ?? null);
+ });
+ }
+}
diff --git a/fluxer_app/src/features/app/keybindings/keybind_manager/handlers/defaultHandlers.ts b/fluxer_app/src/features/app/keybindings/keybind_manager/handlers/defaultHandlers.ts
index d5962d5f0..aab8d4aa5 100644
--- a/fluxer_app/src/features/app/keybindings/keybind_manager/handlers/defaultHandlers.ts
+++ b/fluxer_app/src/features/app/keybindings/keybind_manager/handlers/defaultHandlers.ts
@@ -3,6 +3,7 @@
import {Routes} from '@app/app/Routes';
import Accessibility from '@app/features/accessibility/state/Accessibility';
import {ConfirmModal} from '@app/features/app/components/dialogs/ConfirmModal';
+import {registerAccountKeybindHandlers} from '@app/features/app/keybindings/keybind_manager/handlers/accountHandlers';
import type {HandlerHost} from '@app/features/app/keybindings/keybind_manager/handlers/types';
import {
PUSH_TO_TALK_WHILE_DEAFENED_DESCRIPTION_DESCRIPTOR,
@@ -11,22 +12,20 @@ import {
YOU_CAN_T_UNMUTE_YOURSELF_BECAUSE_A_MODERATOR_DESCRIPTOR,
} from '@app/features/app/keybindings/keybind_manager/shared';
import RuntimeConfig from '@app/features/app/state/RuntimeConfig';
-import {openAccountSwitcherModal} from '@app/features/auth/commands/AccountSwitcherModalCommands';
-import {getAccountKey} from '@app/features/auth/state/AccountStorageKey';
-import {switcherAccounts} from '@app/features/auth/state/AccountSwitcherAccounts';
-import Accounts from '@app/features/auth/state/Accounts';
-import {switchStoredAccountFromSwitcher} from '@app/features/auth/utils/AccountSwitcherModalUtils';
import {requestChannelComposerAffordanceDismissal} from '@app/features/channel/components/ChannelComposerDismissal';
+import {
+ CallButtonBlocks,
+ resolveCallButtonBlock,
+} from '@app/features/channel/components/channel_header_components/CallButtonBlock';
import {CreateDMModal} from '@app/features/channel/components/modals/CreateDMModal';
import Channels from '@app/features/channel/state/Channels';
import * as VoiceStateCommands from '@app/features/devtools/commands/VoiceStateCommands';
import {AddGuildModal} from '@app/features/guild/components/modals/AddGuildModal';
-import {CANCEL_DESCRIPTOR, OKAY_DESCRIPTOR} from '@app/features/i18n/utils/CommonMessageDescriptors';
+import {CANCEL_DESCRIPTOR} from '@app/features/i18n/utils/CommonMessageDescriptors';
import * as InboxCommands from '@app/features/inbox/commands/InboxCommands';
import Inbox from '@app/features/inbox/state/Inbox';
import {KeyboardShortcutsCheatsheetModal} from '@app/features/input/components/modals/KeyboardShortcutsCheatsheetModal';
import Keybind, {type KeybindCommand} from '@app/features/input/state/InputKeybind';
-import {ACCOUNT_SWITCHER_SLOT_ACTIONS} from '@app/features/input/state/input_keybind/KeybindCommands';
import MessageEdit from '@app/features/messaging/state/MessageEdit';
import SavedMessages from '@app/features/messaging/state/SavedMessages';
import {focusChannelTextareaFromKeybind} from '@app/features/messaging/utils/ChannelTextareaFocusUtils';
@@ -38,17 +37,18 @@ import SelectedChannel from '@app/features/navigation/state/SelectedChannel';
import * as RouterUtils from '@app/features/navigation/utils/RouterUtils';
import MentionFeed from '@app/features/notification/state/MentionFeed';
import Permission from '@app/features/permissions/state/Permission';
-import type {Account} from '@app/features/platform/state/AuthSession';
import {ComponentBus} from '@app/features/platform/utils/ComponentBus';
import * as ReadStateCommands from '@app/features/read_state/commands/ReadStateCommands';
import ReadStates from '@app/features/read_state/state/ReadStates';
import QuickSwitcher from '@app/features/search/state/QuickSwitcher';
-import * as ThemeStudioCommands from '@app/features/theme_studio/commands/ThemeStudioCommands';
+import * as ThemeSettingsCommands from '@app/features/theme_settings/commands/ThemeSettingsCommands';
import {getUnreadThreadIds} from '@app/features/threads/utils/ThreadViewUtils';
import * as ModalCommands from '@app/features/ui/commands/ModalCommands';
import {modal} from '@app/features/ui/commands/ModalCommands';
import * as TextCopyCommands from '@app/features/ui/commands/TextCopyCommands';
import {openUserSettingsModal} from '@app/features/user/commands/UserSettingsModalCommands';
+import Users from '@app/features/user/state/Users';
+import {openAccountGateFlow} from '@app/features/user/utils/AccountGatePresentation';
import {openVoiceMessageComposerModal} from '@app/features/voice/components/VoiceMessageComposerModal';
import MediaEngine from '@app/features/voice/engine/MediaEngineFacade';
import LocalVoiceState from '@app/features/voice/state/LocalVoiceState';
@@ -71,44 +71,8 @@ function canOpenVoiceMessageComposerForChannel(channelId: string): boolean {
}
const KEYBOARD_SHORTCUTS_CHEATSHEET_MODAL_KEY = 'keyboard-shortcuts-cheatsheet';
-const ACCOUNT_SWITCHER_MODAL_KEY = 'account-switcher';
const PUSH_TO_TALK_DEAFENED_MODAL_KEY = 'push-to-talk-deafened';
-function openKeybindAccountSwitcher(initialReloginAccount: Account | null): void {
- openAccountSwitcherModal(
- {
- closeCurrentAccountOnSelect: true,
- initialReloginAccount,
- redirectAfterLogin: null,
- redirectAfterSwitch: Routes.ME,
- switchAccount: null,
- },
- ACCOUNT_SWITCHER_MODAL_KEY,
- );
-}
-
-function switchToAccountSwitcherSlot(slotIndex: number): void {
- const account = switcherAccounts()[slotIndex];
- if (account == null) {
- return;
- }
- if (account.isValid === false) {
- openKeybindAccountSwitcher(account);
- return;
- }
- const accountKey = getAccountKey(account);
- if (accountKey === Accounts.currentAccountKey) {
- return;
- }
- void switchStoredAccountFromSwitcher({
- accountKey,
- onSessionExpired: (expiredAccount) => openKeybindAccountSwitcher(expiredAccount),
- onSuccess: null,
- redirectAfterSwitch: Routes.ME,
- switchAccount: null,
- });
-}
-
function showPushToTalkDeafenedModalIfNeeded(host: HandlerHost, i18n: I18n): void {
const voiceState = MediaEngine.getVoiceState(MediaEngine.guildId);
const isGuildDeafened = voiceState?.deaf ?? false;
@@ -119,11 +83,6 @@ function showPushToTalkDeafenedModalIfNeeded(host: HandlerHost, i18n: I18n): voi
React.createElement(ConfirmModal, {
title: i18n._(VOICE_DEAFENED_BY_MODERATORS_DESCRIPTOR),
description: i18n._(YOU_CAN_T_UNDEAFEN_YOURSELF_BECAUSE_A_MODERATOR_DEAFENED_DESCRIPTOR),
- primaryText: i18n._(OKAY_DESCRIPTOR),
- primaryVariant: 'primary',
- secondaryText: false,
- onPrimary: () => {},
- hideCloseButton: true,
}),
),
PUSH_TO_TALK_DEAFENED_MODAL_KEY,
@@ -167,20 +126,7 @@ export function registerDefaultKeybindHandlers(host: HandlerHost, i18n: I18n): v
KEYBOARD_SHORTCUTS_CHEATSHEET_MODAL_KEY,
);
});
- host.register('system_open_account_switcher', ({type}) => {
- if (type !== 'press') return;
- if (ModalCommands.getTopModalKey() === ACCOUNT_SWITCHER_MODAL_KEY) {
- ModalCommands.popWithKey(ACCOUNT_SWITCHER_MODAL_KEY);
- return;
- }
- openKeybindAccountSwitcher(null);
- });
- for (const [slotIndex, action] of ACCOUNT_SWITCHER_SLOT_ACTIONS.entries()) {
- host.register(action, ({type}) => {
- if (type !== 'press') return;
- switchToAccountSwitcherSlot(slotIndex);
- });
- }
+ registerAccountKeybindHandlers(host, i18n);
host.register('misc_help', ({type}) => {
if (type !== 'press') return;
const helpUrl = Routes.help();
@@ -202,11 +148,6 @@ export function registerDefaultKeybindHandlers(host: HandlerHost, i18n: I18n): v
React.createElement(ConfirmModal, {
title: i18n._(VOICE_MUTED_BY_MODERATORS_DESCRIPTOR),
description: i18n._(YOU_CAN_T_UNMUTE_YOURSELF_BECAUSE_A_MODERATOR_DESCRIPTOR),
- primaryText: i18n._(OKAY_DESCRIPTOR),
- primaryVariant: 'primary',
- secondaryText: false,
- onPrimary: () => {},
- hideCloseButton: true,
}),
),
);
@@ -227,11 +168,6 @@ export function registerDefaultKeybindHandlers(host: HandlerHost, i18n: I18n): v
React.createElement(ConfirmModal, {
title: i18n._(VOICE_DEAFENED_BY_MODERATORS_DESCRIPTOR),
description: i18n._(YOU_CAN_T_UNDEAFEN_YOURSELF_BECAUSE_A_MODERATOR_DEAFENED_DESCRIPTOR),
- primaryText: i18n._(OKAY_DESCRIPTOR),
- primaryVariant: 'primary',
- secondaryText: false,
- onPrimary: () => {},
- hideCloseButton: true,
}),
),
);
@@ -259,7 +195,7 @@ export function registerDefaultKeybindHandlers(host: HandlerHost, i18n: I18n): v
});
host.register('system_open_theme_studio_popout', ({type}) => {
if (type !== 'press') return;
- ThemeStudioCommands.openThemeStudioPopout();
+ ThemeSettingsCommands.focusOrOpenQuickCssEditor();
});
host.register('voice_push_to_talk', ({type, sourceId}) => {
if (type === 'release') {
@@ -425,13 +361,13 @@ export function registerDefaultKeybindHandlers(host: HandlerHost, i18n: I18n): v
if (type !== 'press') return;
if (SelectedChannel.navigateViewedChannelHistory(-1)) return;
const history = RouterUtils.getHistory();
- if (history?.go) history.go(-1);
+ if (history?.canGo(-1)) history.go(-1);
});
host.register('nav_history_forward', ({type}) => {
if (type !== 'press') return;
if (SelectedChannel.navigateViewedChannelHistory(1)) return;
const history = RouterUtils.getHistory();
- if (history?.go) history.go(1);
+ if (history?.canGo(1)) history.go(1);
});
host.register('nav_current_call', ({type}) => {
if (type !== 'press') return;
@@ -511,6 +447,12 @@ export function registerDefaultKeybindHandlers(host: HandlerHost, i18n: I18n): v
if (!channelId) return;
const channel = Channels.getChannel(channelId);
if (!channel || channel.guildId) return;
+ const callBlock = resolveCallButtonBlock(channel, Users.getCurrentUser());
+ if (callBlock.block === CallButtonBlocks.SYSTEM_DM) return;
+ if (callBlock.block === CallButtonBlocks.ACCOUNT) {
+ openAccountGateFlow(i18n, callBlock.gate);
+ return;
+ }
void CallUtils.requestStartCall(i18n, channelId, CallUtils.getCallStartRequestOptions({shiftKey}, {kind: 'voice'}));
});
host.register('chat_toggle_pins', ({type}) => {
@@ -580,7 +522,7 @@ export function registerDefaultKeybindHandlers(host: HandlerHost, i18n: I18n): v
});
host.register('chat_new_dm', ({type}) => {
if (type !== 'press') return;
- if (RuntimeConfig.directMessagesDisabled) return;
+ if (!RuntimeConfig.dmPickerAvailable) return;
ModalCommands.push(modal(() => React.createElement(CreateDMModal)));
});
host.register('chat_focus_textarea', ({type}) => {
diff --git a/fluxer_app/src/features/app/keybindings/utils/AccountMentionTarget.ts b/fluxer_app/src/features/app/keybindings/utils/AccountMentionTarget.ts
new file mode 100644
index 000000000..bf16b99ec
--- /dev/null
+++ b/fluxer_app/src/features/app/keybindings/utils/AccountMentionTarget.ts
@@ -0,0 +1,70 @@
+// SPDX-License-Identifier: AGPL-3.0-or-later
+
+import type {AccountEngineAccountActivity} from '@fluxer/desktop_ipc/src/AccountEngineContract';
+import {compare as compareSnowflakes} from '@fluxer/snowflake/src/SnowflakeUtils';
+
+interface OtherAccountMentionTarget {
+ readonly accountKey: string;
+ readonly guildId: string | null;
+ readonly channelId: string;
+ readonly messageId: string | null;
+}
+
+interface RankedTarget {
+ readonly target: OtherAccountMentionTarget;
+ readonly at: number;
+ readonly id: string;
+}
+
+function isNewer(candidate: RankedTarget, current: RankedTarget | null): boolean {
+ if (current === null) return true;
+ if (candidate.at !== current.at) return candidate.at > current.at;
+ return compareSnowflakes(candidate.id, current.id) > 0;
+}
+
+function parseTime(value: string): number {
+ const parsed = Date.parse(value);
+ return Number.isNaN(parsed) ? 0 : parsed;
+}
+
+export function pickNewestOtherAccountMention(
+ activities: ReadonlyArray<AccountEngineAccountActivity>,
+ currentAccountKey: string | null,
+): OtherAccountMentionTarget | null {
+ let newestMention: RankedTarget | null = null;
+ let newestChannel: RankedTarget | null = null;
+ for (const activity of activities) {
+ if (activity.accountKey === currentAccountKey) continue;
+ const mentionedChannelIds = new Set<string>();
+ for (const channel of activity.channels) {
+ if (channel.mentionCount <= 0) continue;
+ mentionedChannelIds.add(channel.channelId);
+ const candidate: RankedTarget = {
+ target: {
+ accountKey: activity.accountKey,
+ guildId: channel.guildId,
+ channelId: channel.channelId,
+ messageId: null,
+ },
+ at: 0,
+ id: channel.lastMessageId ?? '0',
+ };
+ if (isNewer(candidate, newestChannel)) newestChannel = candidate;
+ }
+ for (const mention of activity.mentions) {
+ if (!mentionedChannelIds.has(mention.channelId)) continue;
+ const candidate: RankedTarget = {
+ target: {
+ accountKey: activity.accountKey,
+ guildId: mention.guildId,
+ channelId: mention.channelId,
+ messageId: mention.messageId,
+ },
+ at: parseTime(mention.timestamp),
+ id: mention.messageId,
+ };
+ if (isNewer(candidate, newestMention)) newestMention = candidate;
+ }
+ }
+ return newestMention?.target ?? newestChannel?.target ?? null;
+}
diff --git a/fluxer_app/src/features/app/keybindings/utils/ModalSuppression.ts b/fluxer_app/src/features/app/keybindings/utils/ModalSuppression.ts
index 6e6342dd0..ed26f2717 100644
--- a/fluxer_app/src/features/app/keybindings/utils/ModalSuppression.ts
+++ b/fluxer_app/src/features/app/keybindings/utils/ModalSuppression.ts
@@ -3,9 +3,11 @@
import type {KeybindCommand, KeybindConfig, KeybindSection} from '@app/features/input/state/InputKeybind';
import {isDocumentFullscreenMedia} from '@app/features/platform/utils/FullscreenMediaUtils';
-const MODAL_DIALOG_SELECTOR = '[role="dialog"][aria-modal="true"]';
+const MODAL_DIALOG_SELECTOR = '[role="dialog"][aria-modal="true"], [role="menu"]';
const MODAL_ALLOWED_TARGET_SELECTORS = new Map<KeybindCommand, string>([
['nav_quick_switcher', '[data-quick-switcher-modal="true"]'],
+ ['nav_quick_switcher_accounts', '[data-quick-switcher-modal="true"]'],
+ ['system_open_account_switcher', '[data-account-switcher-overlay="true"]'],
]);
const MODAL_ALLOWED_ACTIONS = new Set<KeybindCommand>(['system_open_theme_studio_popout']);
const MODAL_ALLOWED_SECTIONS = new Set<KeybindSection>(['voice_and_video']);
diff --git a/fluxer_app/src/features/input/components/modals/KeyboardShortcutsCheatsheetModal.tsx b/fluxer_app/src/features/input/components/modals/KeyboardShortcutsCheatsheetModal.tsx
index f844d4645..be6828b27 100644
--- a/fluxer_app/src/features/input/components/modals/KeyboardShortcutsCheatsheetModal.tsx
+++ b/fluxer_app/src/features/input/components/modals/KeyboardShortcutsCheatsheetModal.tsx
@@ -47,6 +47,10 @@ const VOICE_AND_VIDEO_DESCRIPTOR = msg({
message: 'Voice and video',
comment: 'Short heading in the keyboard shortcuts cheatsheet.',
});
+const ACCOUNTS_DESCRIPTOR = msg({
+ message: 'Accounts',
+ comment: 'Short heading in the keyboard shortcuts cheatsheet for shortcuts that switch between signed-in accounts.',
+});
const MISCELLANEOUS_DESCRIPTOR = msg({
message: 'Miscellaneous',
comment: 'Short heading in the keyboard shortcuts cheatsheet.',
@@ -114,6 +118,7 @@ export const KeyboardShortcutsCheatsheetModal = observer(() => {
drag_and_drop: i18n._(DRAG_AND_DROP_DESCRIPTOR),
chat: i18n._(CHAT_DESCRIPTOR),
voice_and_video: i18n._(VOICE_AND_VIDEO_DESCRIPTOR),
+ accounts: i18n._(ACCOUNTS_DESCRIPTOR),
misc: i18n._(MISCELLANEOUS_DESCRIPTOR),
};
const sections = useMemo(() => {
@@ -124,6 +129,7 @@ export const KeyboardShortcutsCheatsheetModal = observer(() => {
drag_and_drop: [],
chat: [],
voice_and_video: [],
+ accounts: [],
misc: [],
};
for (const sectionId of DEFAULT_KEYBIND_SECTIONS) {
diff --git a/fluxer_app/src/features/input/state/AccountKeybinds.ts b/fluxer_app/src/features/input/state/AccountKeybinds.ts
new file mode 100644
index 000000000..075956b6b
--- /dev/null
+++ b/fluxer_app/src/features/input/state/AccountKeybinds.ts
@@ -0,0 +1,78 @@
+// SPDX-License-Identifier: AGPL-3.0-or-later
+
+import type {CustomKeybindEntry} from '@app/features/input/state/InputKeybind';
+import {isAccountKeybindCommand, type KeybindCommand} from '@app/features/input/state/input_keybind/KeybindCommands';
+import {AppStorageKey} from '@app/features/platform/state/AppStorageKeys';
+import {makePersistent} from '@app/features/platform/utils/MobXPersistence';
+import {initializeStore} from '@app/features/platform/utils/StoreInitialization';
+import {makeAutoObservable} from 'mobx';
+
+function isStoredEntry(value: unknown): value is CustomKeybindEntry {
+ if (typeof value !== 'object' || value === null) return false;
+ const entry = value as Partial<CustomKeybindEntry>;
+ return (
+ typeof entry.id === 'string' &&
+ isAccountKeybindCommand(entry.action) &&
+ typeof entry.enabled === 'boolean' &&
+ typeof entry.combo === 'object' &&
+ entry.combo !== null &&
+ typeof entry.combo.key === 'string'
+ );
+}
+
+class AccountKeybinds {
+ entries: Array<CustomKeybindEntry> = [];
+
+ constructor() {
+ makeAutoObservable(this, {}, {autoBind: true});
+ initializeStore(this, () => this.initPersistence());
+ }
+
+ private async initPersistence(): Promise<void> {
+ await makePersistent(this, AppStorageKey.ACCOUNT_KEYBINDS, ['entries'], {syncAcrossTabs: true});
+ }
+
+ get validEntries(): ReadonlyArray<CustomKeybindEntry> {
+ return Array.isArray(this.entries) ? this.entries.filter(isStoredEntry) : [];
+ }
+
+ hasEntry(id: string): boolean {
+ return this.validEntries.some((entry) => entry.id === id);
+ }
+
+ hasEntriesForAction(action: KeybindCommand): boolean {
+ return this.validEntries.some((entry) => entry.action === action);
+ }
+
+ add(entry: CustomKeybindEntry): void {
+ this.entries = [...this.validEntries, entry];
+ }
+
+ update(id: string, patch: Partial<Omit<CustomKeybindEntry, 'id'>>): void {
+ this.entries = this.validEntries.map((entry) => (entry.id === id ? {...entry, ...patch} : entry));
+ }
+
+ remove(id: string): CustomKeybindEntry | null {
+ const removed = this.validEntries.find((entry) => entry.id === id) ?? null;
+ this.entries = this.validEntries.filter((entry) => entry.id !== id);
+ return removed;
+ }
+
+ removeForAction(action: KeybindCommand): void {
+ this.entries = this.validEntries.filter((entry) => entry.action !== action);
+ }
+
+ adopt(entries: ReadonlyArray<CustomKeybindEntry>): void {
+ const adopted = entries.filter(
+ (entry) => isStoredEntry(entry) && !this.hasEntriesForAction(entry.action as KeybindCommand),
+ );
+ if (adopted.length === 0) return;
+ this.entries = [...this.validEntries, ...adopted.map((entry) => ({...entry, combo: {...entry.combo}}))];
+ }
+
+ reset(): void {
+ this.entries = [];
+ }
+}
+
+export default new AccountKeybinds();
diff --git a/fluxer_app/src/features/input/state/InputKeybind.ts b/fluxer_app/src/features/input/state/InputKeybind.ts
index 48039dcfa..bf881ac53 100644
--- a/fluxer_app/src/features/input/state/InputKeybind.ts
+++ b/fluxer_app/src/features/input/state/InputKeybind.ts
@@ -3,10 +3,13 @@
import type {HoldAction} from '@app/features/app/keybindings/utils/RuntimeKeybinds';
import RuntimeConfig from '@app/features/app/state/RuntimeConfig';
import {COPY_TEXT_DESCRIPTOR, DELETE_MESSAGE_DESCRIPTOR} from '@app/features/i18n/utils/CommonMessageDescriptors';
+import AccountKeybinds from '@app/features/input/state/AccountKeybinds';
import GlobalShortcuts from '@app/features/input/state/GlobalShortcuts';
import {HoldSources} from '@app/features/input/state/HoldSources';
+import {getAccountKeybindDefaults} from '@app/features/input/state/input_keybind/AccountKeybindDefaults';
import {
ACCOUNT_SWITCHER_SLOT_ACTIONS,
+ isAccountKeybindCommand,
isKeybindCommand,
type KeybindCommand,
resolveKeybindCommand,
@@ -49,6 +52,7 @@ import {
GO_TO_THIRD_COMMUNITY_DESCRIPTOR,
JUMP_BETWEEN_UNREAD_CHANNELS_DESCRIPTOR,
JUMP_BETWEEN_UNREAD_CHANNELS_WITH_MENTIONS_DESCRIPTOR,
+ JUMP_TO_NEWEST_OTHER_ACCOUNT_MENTION_DESCRIPTOR,
JUMP_TO_THE_CURRENT_CALL_DESCRIPTOR,
JUMP_TO_THE_OLDEST_UNREAD_MESSAGE_DESCRIPTOR,
MARK_ALL_INBOX_CHANNELS_AS_READ_DESCRIPTOR,
@@ -62,7 +66,6 @@ import {
OPEN_ACCOUNT_SWITCHER_DESCRIPTOR,
OPEN_HELP_DESCRIPTOR,
OPEN_THE_CONTEXT_MENU_DESCRIPTOR,
- OPEN_THEME_STUDIO_POPOUT_DESCRIPTOR,
OPEN_YOUR_SETTINGS_DESCRIPTOR,
PIN_MESSAGE_DESCRIPTOR,
PUSH_TO_MUTE_DESCRIPTOR,
@@ -75,15 +78,19 @@ import {
SCROLL_CHAT_DOWN_DESCRIPTOR,
SCROLL_CHAT_UP_DESCRIPTOR,
SEARCH_MESSAGES_DESCRIPTOR,
+ SEARCH_OTHER_ACCOUNTS_DESCRIPTOR,
SEND_VOICE_MESSAGE_DESCRIPTOR,
SHOW_KEYBOARD_SHORTCUTS_LIST_DESCRIPTOR,
START_A_CALL_IN_A_DM_OR_GROUP_DESCRIPTOR,
START_A_GROUP_DM_DESCRIPTOR,
START_DRAG_AND_DROP_DESCRIPTOR,
+ SWITCH_BACK_TO_LAST_ACCOUNT_DESCRIPTOR,
SWITCH_BETWEEN_CHANNELS_DESCRIPTOR,
SWITCH_BETWEEN_COMMUNITIES_DESCRIPTOR,
SWITCH_TO_ACCOUNT_SLOT_DESCRIPTOR,
+ SWITCH_TO_NEXT_ACCOUNT_DESCRIPTOR,
SWITCH_TO_NEXT_COMMUNITY_OR_DMS_DESCRIPTOR,
+ SWITCH_TO_PREVIOUS_ACCOUNT_DESCRIPTOR,
SWITCH_TO_PREVIOUS_COMMUNITY_OR_DMS_DESCRIPTOR,
SWITCH_VOICE_CHANNEL_DESCRIPTOR,
TOGGLE_BETWEEN_LAST_COMMUNITY_AND_DMS_DESCRIPTOR,
@@ -119,10 +126,13 @@ import {
keyCombosEqual,
SHIFTED_SLASH_FALLBACK_KEYBOARD_SHORTCUTS_OVERLAY_COMBO,
} from '@app/features/input/utils/KeyboardShortcutLayoutUtils';
+import {AppStorageKey} from '@app/features/platform/state/AppStorageKeys';
import AppStorage from '@app/features/platform/state/PersistentStorage';
import {awaitHydration, makePersistent} from '@app/features/platform/utils/MobXPersistence';
import {isApplePlatform} from '@app/features/platform/utils/PlatformHelpers';
import {initializeStore} from '@app/features/platform/utils/StoreInitialization';
+import {quickCssEditorNeedsDesktopUpdate} from '@app/features/theme_settings/utils/QuickCssEditorSupport';
+import {OPEN_QUICK_CSS_EDITOR_DESCRIPTOR} from '@app/features/theme_settings/utils/ThemeSettingsMessageDescriptors';
import {makeSyncedField} from '@app/features/user/state/SyncedField';
import UserSettings from '@app/features/user/state/UserSettings';
import {VOICE_TOGGLE_DEAFEN_DESCRIPTOR} from '@app/features/voice/utils/VoiceMessageDescriptors';
@@ -159,6 +169,7 @@ export type KeybindSection =
| 'drag_and_drop'
| 'chat'
| 'voice_and_video'
+ | 'accounts'
| 'misc';
type DefaultsShortcutDisplayKind = 'any_key' | 'space_or_enter';
type EditableFocusShortcutBehavior = 'allow' | 'allow_when_empty';
@@ -221,6 +232,32 @@ const createBuiltinDisableMarker = (
enabled: true,
});
+const ACCOUNT_KEYBIND_LABEL_DESCRIPTORS: Partial<Record<KeybindCommand, KeybindLabelDescriptor>> = {
+ system_open_account_switcher: OPEN_ACCOUNT_SWITCHER_DESCRIPTOR,
+ system_switch_account_next: SWITCH_TO_NEXT_ACCOUNT_DESCRIPTOR,
+ system_switch_account_prev: SWITCH_TO_PREVIOUS_ACCOUNT_DESCRIPTOR,
+ system_switch_account_recent: SWITCH_BACK_TO_LAST_ACCOUNT_DESCRIPTOR,
+ system_jump_account_mention: JUMP_TO_NEWEST_OTHER_ACCOUNT_MENTION_DESCRIPTOR,
+ nav_quick_switcher_accounts: SEARCH_OTHER_ACCOUNTS_DESCRIPTOR,
+};
+
+function accountKeybindLabel(i18n: KeybindLabelI18n, action: KeybindCommand): string {
+ const slotIndex = ACCOUNT_SWITCHER_SLOT_ACTIONS.indexOf(action);
+ if (slotIndex !== -1) return i18n._(SWITCH_TO_ACCOUNT_SLOT_DESCRIPTOR, {slot: slotIndex + 1});
+ const descriptor = ACCOUNT_KEYBIND_LABEL_DESCRIPTORS[action];
+ return descriptor === undefined ? action : i18n._(descriptor);
+}
+
+const getAccountKeybindConfigs = (i18n: KeybindLabelI18n): ReadonlyArray<KeybindConfig> =>
+ getAccountKeybindDefaults(isApplePlatform()).map(({action, combo}) => ({
+ action,
+ label: accountKeybindLabel(i18n, action),
+ combo,
+ section: 'accounts',
+ assignable: true,
+ ...(action === 'system_open_account_switcher' ? {allowGlobal: true} : {}),
+ }));
+
const getDefaultKeybinds = (
i18n: KeybindLabelI18n,
keyboardShortcutsOverlayCombo: KeyCombo = DEFAULT_KEYBOARD_SHORTCUTS_OVERLAY_COMBO,
@@ -717,15 +754,19 @@ const getDefaultKeybinds = (
section: 'misc',
hideFromDefaults: true,
},
- {
- action: 'system_open_theme_studio_popout',
- label: i18n._(OPEN_THEME_STUDIO_POPOUT_DESCRIPTOR),
- combo: {key: 't', ctrlOrMeta: true, alt: true, shift: true},
- ignoreWhileTyping: true,
- editableFocusBehavior: 'allow',
- section: 'misc',
- assignable: true,
- },
+ ...(quickCssEditorNeedsDesktopUpdate()
+ ? []
+ : [
+ {
+ action: 'system_open_theme_studio_popout',
+ label: i18n._(OPEN_QUICK_CSS_EDITOR_DESCRIPTOR),
+ combo: {key: 't', ctrlOrMeta: true, alt: true, shift: true},
+ ignoreWhileTyping: true,
+ editableFocusBehavior: 'allow',
+ section: 'misc',
+ assignable: true,
+ } as const,
+ ]),
{
action: 'system_zoom_in',
label: i18n._(ZOOM_IN_DESCRIPTOR),
@@ -873,20 +914,7 @@ const getDefaultKeybinds = (
section: 'voice_and_video',
hideFromDefaults: true,
},
- {
- action: 'system_open_account_switcher',
- label: i18n._(OPEN_ACCOUNT_SWITCHER_DESCRIPTOR),
- combo: {key: 'o', ctrlOrMeta: true, shift: true},
- section: 'misc',
- assignable: true,
- },
- ...ACCOUNT_SWITCHER_SLOT_ACTIONS.map((action, index) => ({
- action,
- label: i18n._(SWITCH_TO_ACCOUNT_SLOT_DESCRIPTOR, {slot: index + 1}),
- combo: {key: String(index + 1), ctrlOrMeta: true, shift: true},
- section: 'misc' as const,
- hideFromDefaults: true,
- })),
+ ...getAccountKeybindConfigs(i18n),
] as const;
class Keybind {
@@ -906,12 +934,13 @@ class Keybind {
private holdSources = new HoldSources(() => this.pushToTalkReleaseDelay);
constructor() {
- makeAutoObservable<this, 'holdSources' | 'defaultKeybinds' | 'runtimeDispatchDefaults'>(
+ makeAutoObservable<this, 'holdSources' | 'defaultKeybinds' | 'runtimeDispatchDefaults' | 'effectiveCustomKeybinds'>(
this,
{
holdSources: false,
defaultKeybinds: computed({keepAlive: true}),
runtimeDispatchDefaults: computed({keepAlive: true}),
+ effectiveCustomKeybinds: computed({keepAlive: true}),
},
{autoBind: true},
);
@@ -996,7 +1025,7 @@ class Keybind {
setI18n(i18n: I18n): void {
this.i18n = i18n;
if (this.initialized) return;
- void awaitHydration(KEYBIND_STORE_NAME).then(() => {
+ void Promise.all([awaitHydration(KEYBIND_STORE_NAME), awaitHydration(AppStorageKey.ACCOUNT_KEYBINDS)]).then(() => {
runInAction(() => {
if (this.initialized) return;
if (!Array.isArray(this.customKeybinds)) {
@@ -1004,6 +1033,7 @@ class Keybind {
}
this.migrateGlobalCapableKeybindsToGlobal();
this.migrateEmptyCustomKeybindsToBuiltinDisableMarkers();
+ AccountKeybinds.adopt(this.customKeybinds.filter((entry) => isAccountKeybindCommand(entry.action)));
this.initialized = true;
});
});
@@ -1058,7 +1088,7 @@ class Keybind {
getActiveCombosForAction(action: KeybindCommand): Array<KeyCombo> {
const fallback = this.getDefaultByAction(action);
- const customBindings = this.customKeybinds.filter((entry) => entry.action === action);
+ const customBindings = this.getCustomKeybinds().filter((entry) => entry.action === action);
return getActiveCombosForResolvedAction(fallback, customBindings);
}
@@ -1070,8 +1100,25 @@ class Keybind {
return this.runtimeDispatchDefaults;
}
+ private get effectiveCustomKeybinds(): ReadonlyArray<CustomKeybindEntry> {
+ return [
+ ...this.customKeybinds.filter((entry) => !isAccountKeybindCommand(entry.action)),
+ ...AccountKeybinds.validEntries,
+ ];
+ }
+
getCustomKeybinds(): ReadonlyArray<CustomKeybindEntry> {
- return this.customKeybinds;
+ return this.effectiveCustomKeybinds;
+ }
+
+ private appendCustomKeybind(entry: CustomKeybindEntry): void {
+ if (isAccountKeybindCommand(entry.action)) {
+ AccountKeybinds.add(entry);
+ return;
+ }
+ runInAction(() => {
+ this.customKeybinds = [...this.customKeybinds, entry];
+ });
}
addCustomKeybind(): CustomKeybindEntry {
@@ -1088,15 +1135,33 @@ class Keybind {
}
removeCustomKeybind(id: string): void {
+ if (AccountKeybinds.hasEntry(id)) {
+ AccountKeybinds.remove(id);
+ return;
+ }
runInAction(() => {
this.customKeybinds = this.customKeybinds.filter((c) => c.id !== id);
});
}
updateCustomKeybind(id: string, patch: Partial<Omit<CustomKeybindEntry, 'id'>>): void {
- runInAction(() => {
- this.customKeybinds = this.customKeybinds.map((entry) => (entry.id === id ? {...entry, ...patch} : entry));
- });
+ const accountEntry = AccountKeybinds.validEntries.find((entry) => entry.id === id) ?? null;
+ const current = accountEntry ?? this.customKeybinds.find((entry) => entry.id === id) ?? null;
+ if (current === null) return;
+ const next = {...current, ...patch};
+ const belongsToAccounts = isAccountKeybindCommand(next.action);
+ if (accountEntry !== null && belongsToAccounts) {
+ AccountKeybinds.update(id, patch);
+ return;
+ }
+ if (accountEntry === null && !belongsToAccounts) {
+ runInAction(() => {
+ this.customKeybinds = this.customKeybinds.map((entry) => (entry.id === id ? next : entry));
+ });
+ return;
+ }
+ this.removeCustomKeybind(id);
+ this.appendCustomKeybind(next);
}
updateCustomKeybindCombo(id: string, combo: KeyCombo): void {
@@ -1110,31 +1175,37 @@ class Keybind {
combo: {key: '', enabled: true, global: true},
enabled: true,
};
- runInAction(() => {
- this.customKeybinds = [...this.customKeybinds, entry];
- });
+ this.appendCustomKeybind(entry);
return entry;
}
removeCustomKeybindsForAction(action: KeybindCommand): void {
+ if (isAccountKeybindCommand(action)) {
+ AccountKeybinds.removeForAction(action);
+ return;
+ }
runInAction(() => {
this.customKeybinds = this.customKeybinds.filter((entry) => entry.action !== action);
});
}
isBuiltinDisabled(action: KeybindCommand): boolean {
- return this.customKeybinds.some((entry) => entry.action === action && isBuiltinDisableMarker(entry));
+ return this.getCustomKeybinds().some((entry) => entry.action === action && isBuiltinDisableMarker(entry));
}
disableBuiltinForAction(action: KeybindCommand): void {
if (this.isBuiltinDisabled(action)) return;
const global = this.getDefaultByAction(action)?.combo.global;
- runInAction(() => {
- this.customKeybinds = [...this.customKeybinds, createBuiltinDisableMarker(action, global)];
- });
+ this.appendCustomKeybind(createBuiltinDisableMarker(action, global));
}
enableBuiltinForAction(action: KeybindCommand): void {
+ if (isAccountKeybindCommand(action)) {
+ for (const entry of AccountKeybinds.validEntries) {
+ if (entry.action === action && isBuiltinDisableMarker(entry)) AccountKeybinds.remove(entry.id);
+ }
+ return;
+ }
runInAction(() => {
this.customKeybinds = this.customKeybinds.filter(
(entry) => entry.action !== action || !isBuiltinDisableMarker(entry),
@@ -1151,6 +1222,7 @@ class Keybind {
}
resetCustomKeybinds(): void {
+ AccountKeybinds.reset();
runInAction(() => {
this.customKeybinds = [];
});
@@ -1185,7 +1257,7 @@ class Keybind {
}
getPrimaryCustomKeybind(action: KeybindCommand): CustomKeybindEntry | null {
- return this.customKeybinds.find((c) => c.action === action && !isBuiltinDisableMarker(c)) ?? null;
+ return this.getCustomKeybinds().find((c) => c.action === action && !isBuiltinDisableMarker(c)) ?? null;
}
setPrimaryCustomKeybindCombo(action: KeybindCommand, combo: KeyCombo): CustomKeybindEntry {
@@ -1200,9 +1272,7 @@ class Keybind {
combo: {...combo, enabled: true, global: combo.global ?? true},
enabled: true,
};
- runInAction(() => {
- this.customKeybinds = [...this.customKeybinds, created];
- });
+ this.appendCustomKeybind(created);
return created;
}
@@ -1325,7 +1395,7 @@ class Keybind {
} {
const base = this.getDefaultByAction(action);
if (!base) throw new Error(`Unknown keybind action: ${action}`);
- const customBindings = this.customKeybinds.filter((c) => c.action === action);
+ const customBindings = this.getCustomKeybinds().filter((c) => c.action === action);
return getDisplayKeybindForResolvedAction(base, customBindings);
}
diff --git a/fluxer_app/src/features/input/state/input_keybind/AccountKeybindDefaults.ts b/fluxer_app/src/features/input/state/input_keybind/AccountKeybindDefaults.ts
new file mode 100644
index 000000000..c279deb53
--- /dev/null
+++ b/fluxer_app/src/features/input/state/input_keybind/AccountKeybindDefaults.ts
@@ -0,0 +1,29 @@
+// SPDX-License-Identifier: AGPL-3.0-or-later
+
+import type {KeyCombo} from '@app/features/input/state/InputKeybind';
+import {
+ ACCOUNT_SWITCHER_SLOT_ACTIONS,
+ type KeybindCommand,
+} from '@app/features/input/state/input_keybind/KeybindCommands';
+
+export interface AccountKeybindDefault {
+ readonly action: KeybindCommand;
+ readonly combo: KeyCombo;
+}
+
+export function getAccountKeybindDefaults(applePlatform: boolean): ReadonlyArray<AccountKeybindDefault> {
+ return [
+ {action: 'system_open_account_switcher', combo: {key: '', code: 'KeyO', ctrlOrMeta: true, shift: true}},
+ {action: 'system_switch_account_next', combo: {key: '', code: 'BracketRight', ctrlOrMeta: true, shift: true}},
+ {action: 'system_switch_account_prev', combo: {key: '', code: 'BracketLeft', ctrlOrMeta: true, shift: true}},
+ {action: 'system_switch_account_recent', combo: {key: '', code: 'KeyJ', ctrlOrMeta: true}},
+ {action: 'system_jump_account_mention', combo: {key: '', code: 'KeyJ', ctrlOrMeta: true, shift: true}},
+ {action: 'nav_quick_switcher_accounts', combo: {key: '', code: 'KeyK', ctrlOrMeta: true, shift: true}},
+ ...ACCOUNT_SWITCHER_SLOT_ACTIONS.map((action, index) => ({
+ action,
+ combo: applePlatform
+ ? {key: '', code: `Digit${index + 1}`, ctrlOrMeta: true, alt: true}
+ : {key: '', code: `Digit${index + 1}`, ctrlOrMeta: true, shift: true},
+ })),
+ ];
+}
diff --git a/fluxer_app/src/features/input/state/input_keybind/KeybindCommands.ts b/fluxer_app/src/features/input/state/input_keybind/KeybindCommands.ts
index 5b590bf91..961578573 100644
--- a/fluxer_app/src/features/input/state/input_keybind/KeybindCommands.ts
+++ b/fluxer_app/src/features/input/state/input_keybind/KeybindCommands.ts
@@ -93,6 +93,11 @@ const KEYBIND_COMMAND_VALUES = [
'system_zoom_out',
'system_zoom_reset',
'system_open_account_switcher',
+ 'system_switch_account_next',
+ 'system_switch_account_prev',
+ 'system_switch_account_recent',
+ 'system_jump_account_mention',
+ 'nav_quick_switcher_accounts',
'system_switch_account_slot_1',
'system_switch_account_slot_2',
'system_switch_account_slot_3',
@@ -118,6 +123,20 @@ export const ACCOUNT_SWITCHER_SLOT_ACTIONS: ReadonlyArray<KeybindCommand> = Obje
'system_switch_account_slot_9',
]);
+const ACCOUNT_KEYBIND_ACTIONS: ReadonlyArray<KeybindCommand> = Object.freeze([
+ 'system_open_account_switcher',
+ 'system_switch_account_next',
+ 'system_switch_account_prev',
+ 'system_switch_account_recent',
+ 'system_jump_account_mention',
+ 'nav_quick_switcher_accounts',
+ ...ACCOUNT_SWITCHER_SLOT_ACTIONS,
+]);
+
+const ACCOUNT_KEYBIND_ACTION_SET = new Set<string>(ACCOUNT_KEYBIND_ACTIONS);
+export const isAccountKeybindCommand = (value: unknown): value is KeybindCommand =>
+ typeof value === 'string' && ACCOUNT_KEYBIND_ACTION_SET.has(value);
+
const KEYBIND_COMMAND_SET = new Set<string>(KEYBIND_COMMAND_VALUES);
export const isKeybindCommand = (value: unknown): value is KeybindCommand =>
typeof value === 'string' && KEYBIND_COMMAND_SET.has(value);
diff --git a/fluxer_app/src/features/input/state/input_keybind/shared.ts b/fluxer_app/src/features/input/state/input_keybind/shared.ts
index 0bbe58663..6b7b557f2 100644
--- a/fluxer_app/src/features/input/state/input_keybind/shared.ts
+++ b/fluxer_app/src/features/input/state/input_keybind/shared.ts
@@ -255,7 +255,27 @@ export const OPEN_YOUR_SETTINGS_DESCRIPTOR = msg({
comment: 'Keyboard shortcut action label shown in the shortcuts list and keybind editor. Keep short, sentence case.',
});
export const OPEN_ACCOUNT_SWITCHER_DESCRIPTOR = msg({
- message: 'Open account switcher',
+ message: 'Open the account switcher',
+ comment: 'Keyboard shortcut action label shown in the shortcuts list and keybind editor. Keep short, sentence case.',
+});
+export const SWITCH_TO_NEXT_ACCOUNT_DESCRIPTOR = msg({
+ message: 'Switch to the next account',
+ comment: 'Keyboard shortcut action label shown in the shortcuts list and keybind editor. Keep short, sentence case.',
+});
+export const SWITCH_TO_PREVIOUS_ACCOUNT_DESCRIPTOR = msg({
+ message: 'Switch to the previous account',
+ comment: 'Keyboard shortcut action label shown in the shortcuts list and keybind editor. Keep short, sentence case.',
+});
+export const SWITCH_BACK_TO_LAST_ACCOUNT_DESCRIPTOR = msg({
+ message: 'Switch back to the last account',
+ comment: 'Keyboard shortcut action label shown in the shortcuts list and keybind editor. Keep short, sentence case.',
+});
+export const JUMP_TO_NEWEST_OTHER_ACCOUNT_MENTION_DESCRIPTOR = msg({
+ message: 'Jump to the newest mention on another account',
+ comment: 'Keyboard shortcut action label shown in the shortcuts list and keybind editor. Keep short, sentence case.',
+});
+export const SEARCH_OTHER_ACCOUNTS_DESCRIPTOR = msg({
+ message: 'Search other accounts',
comment: 'Keyboard shortcut action label shown in the shortcuts list and keybind editor. Keep short, sentence case.',
});
export const SWITCH_TO_ACCOUNT_SLOT_DESCRIPTOR = msg({
@@ -263,10 +283,6 @@ export const SWITCH_TO_ACCOUNT_SLOT_DESCRIPTOR = msg({
comment:
'Keyboard shortcut action label shown in the keybind editor. {slot} is a numeric account position, such as 1.',
});
-export const OPEN_THEME_STUDIO_POPOUT_DESCRIPTOR = msg({
- message: 'Open theme studio popout',
- comment: 'Keyboard shortcut action label shown in the shortcuts list and keybind editor. Keep short, sentence case.',
-});
export const ZOOM_IN_DESCRIPTOR = msg({
message: 'Zoom in',
comment: 'Keyboard shortcut action label shown in the shortcuts list and keybind editor. Keep short, sentence case.',
diff --git a/fluxer_app/src/features/input/utils/KeybindUtils.ts b/fluxer_app/src/features/input/utils/KeybindUtils.ts
index c3b9a11aa..24a9dc8a8 100644
--- a/fluxer_app/src/features/input/utils/KeybindUtils.ts
+++ b/fluxer_app/src/features/input/utils/KeybindUtils.ts
@@ -150,7 +150,7 @@ export function formatKeyComboParts(i18n: I18n, combo: KeyCombo): Array<string>
parts.push(isMacPlatform() ? '⌘' : i18n._(WIN_DESCRIPTOR));
}
if (combo.shift) {
- parts.push(i18n._(SHIFT_KEY_DESCRIPTOR));
+ parts.push(isMacPlatform() ? '⇧' : i18n._(SHIFT_KEY_DESCRIPTOR));
}
if (combo.alt) parts.push(isMacPlatform() ? '⌥' : i18n._(ALT_DESCRIPTOR));
if (combo.mouseButton !== undefined && combo.mouseButton !== null) {
@@ -198,7 +198,7 @@ function formatNumpadKey(i18n: I18n, rawKey: string): string | null {
export function formatPrimaryKeySymbol(i18n: I18n, rawKey: string): string {
if (rawKey === ' ' || rawKey === 'Spacebar' || rawKey === 'Space') return i18n._(SPACE_DESCRIPTOR);
- if (isShiftKeyName(rawKey)) return i18n._(SHIFT_KEY_DESCRIPTOR);
+ if (isShiftKeyName(rawKey)) return isMacPlatform() ? '⇧' : i18n._(SHIFT_KEY_DESCRIPTOR);
if (isControlKeyName(rawKey)) return isMacPlatform() ? CONTROL_KEY_SYMBOL : i18n._(CTRL_DESCRIPTOR);
if (isAltKeyName(rawKey)) return isMacPlatform() ? '⌥' : i18n._(ALT_DESCRIPTOR);
if (isMetaKeyName(rawKey)) return isMacPlatform() ? '⌘' : i18n._(WIN_DESCRIPTOR);
@@ -213,6 +213,8 @@ export function formatPrimaryKeySymbol(i18n: I18n, rawKey: string): string {
if (rawKey === 'Backquote' || rawKey === '`') return '`';
if (rawKey === 'Quote') return "'";
if (rawKey === '[' || rawKey === ']') return rawKey;
+ if (rawKey === 'BracketLeft') return '[';
+ if (rawKey === 'BracketRight') return ']';
if (/^Key[A-Z]$/.test(rawKey)) return rawKey.slice(3);
if (/^Digit[0-9]$/.test(rawKey)) return rawKey.slice(5);
const numpadKey = formatNumpadKey(i18n, rawKey);
diff --git a/fluxer_app/src/features/ui/keybind_hint/KeybindHint.tsx b/fluxer_app/src/features/ui/keybind_hint/KeybindHint.tsx
index 3936bb6ba..2230ca225 100644
--- a/fluxer_app/src/features/ui/keybind_hint/KeybindHint.tsx
+++ b/fluxer_app/src/features/ui/keybind_hint/KeybindHint.tsx
@@ -75,7 +75,7 @@ const formatKeyParts = (i18n: I18n, combo: KeyCombo): Array<KeyPart> => {
parts.push(mac ? {label: '⌘', isSymbol: true} : {label: i18n._(WIN_DESCRIPTOR)});
}
if (combo.shift) {
- parts.push({label: i18n._(SHIFT_KEY_DESCRIPTOR)});
+ parts.push(mac ? {label: '⇧', isSymbol: true} : {label: i18n._(SHIFT_KEY_DESCRIPTOR)});
}
if (combo.alt) {
parts.push(mac ? {label: '⌥', isSymbol: true} : {label: i18n._(ALT_DESCRIPTOR)});