-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Fix platform settings race condition and make auto-launch tri-state #30977
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
62662ea
Fix race condition with platform settings not being read correctly
t3chguy d09d806
Allow Desktop app to be auto-started minimised or focused
t3chguy ae3e6ba
i18n
t3chguy c6e7f14
Iterate
t3chguy 6099bd0
Use onChange prop
t3chguy 09290fa
Iterate
t3chguy ea6b220
Iterate
t3chguy 0037559
Add tests
t3chguy fe1eb6e
Update res/css/views/elements/_SettingsDropdown.pcss
t3chguy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| /* | ||
| Copyright 2025 New Vector Ltd. | ||
|
|
||
| SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial | ||
| Please see LICENSE files in the repository root for full details. | ||
| */ | ||
|
|
||
| .mx_SettingsDropdown { | ||
| margin-bottom: 4px; | ||
| width: 100%; | ||
|
|
||
| .mx_SettingsDropdown_label { | ||
| color: $primary-content; | ||
| margin: var(--cpd-space-1x) 0; | ||
| } | ||
|
|
||
| .mx_Dropdown_input { | ||
| width: 360px; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| /* | ||
| Copyright 2025 New Vector Ltd. | ||
|
|
||
| SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial | ||
| Please see LICENSE files in the repository root for full details. | ||
| */ | ||
|
|
||
| import React, { type JSX, useCallback, useId, useState } from "react"; | ||
|
|
||
| import SettingsStore from "../../../settings/SettingsStore"; | ||
| import { type SettingLevel } from "../../../settings/SettingLevel"; | ||
| import { SETTINGS, type StringSettingKey } from "../../../settings/Settings"; | ||
| import { useSettingValueAt } from "../../../hooks/useSettings.ts"; | ||
| import Dropdown, { type DropdownProps } from "./Dropdown.tsx"; | ||
| import { _t } from "../../../shared-components/utils/i18n.tsx"; | ||
|
|
||
| interface Props { | ||
| settingKey: StringSettingKey; | ||
| level: SettingLevel; | ||
| roomId?: string; // for per-room settings | ||
| label?: string; | ||
| isExplicit?: boolean; | ||
| hideIfCannotSet?: boolean; | ||
| onChange?(option: string): void; | ||
| } | ||
|
|
||
| const SettingsDropdown = ({ | ||
| settingKey, | ||
| roomId, | ||
| level, | ||
| label: specificLabel, | ||
| isExplicit, | ||
| hideIfCannotSet, | ||
| onChange, | ||
| }: Props): JSX.Element => { | ||
| const id = useId(); | ||
| const settingValue = useSettingValueAt(level, settingKey, roomId ?? null, isExplicit); | ||
| const [value, setValue] = useState(settingValue); | ||
| const setting = SETTINGS[settingKey]; | ||
|
|
||
| const onOptionChange = useCallback( | ||
| (value: string): void => { | ||
| setValue(value); // local echo | ||
| SettingsStore.setValue(settingKey, roomId ?? null, level, value); | ||
| onChange?.(value); | ||
| }, | ||
| [settingKey, roomId, level, onChange], | ||
| ); | ||
|
|
||
| const disabled = !SettingsStore.canSetValue(settingKey, roomId ?? null, level); | ||
| if (disabled && hideIfCannotSet) return <></>; | ||
| if (!setting.options) { | ||
| console.error("SettingsDropdown used for a setting with no `options`"); | ||
| return <></>; | ||
| } | ||
|
|
||
| const label = specificLabel ?? SettingsStore.getDisplayName(settingKey, level)!; | ||
| const options = setting.options.map((option) => { | ||
| return <div key={option.value}>{_t(option.label)}</div>; | ||
| }) as DropdownProps["children"]; | ||
|
|
||
| return ( | ||
| <div className="mx_SettingsDropdown"> | ||
| <label className="mx_SettingsDropdown_label" htmlFor={id}> | ||
| <span className="mx_SettingsDropdown_labelText">{label}</span> | ||
| </label> | ||
| <Dropdown | ||
| id={id} | ||
| onOptionChange={onOptionChange} | ||
| menuWidth={360} // matches CSS width | ||
| value={value} | ||
| disabled={disabled} | ||
| label={label} | ||
| > | ||
| {options} | ||
| </Dropdown> | ||
|
Comment on lines
+67
to
+76
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not using the compound dropdown component?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| export default SettingsDropdown; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.