Fix platform settings race condition and make auto-launch tri-state (#30977)

* Fix race condition with platform settings not being read correctly

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>

* Allow Desktop app to be auto-started minimised or focused

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>

* i18n

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>

* Iterate

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>

* Use onChange prop

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>

* Iterate

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>

* Iterate

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>

* Add tests

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>

* Update res/css/views/elements/_SettingsDropdown.pcss

Co-authored-by: Florian Duros <florianduros@element.io>

---------

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
Co-authored-by: Florian Duros <florianduros@element.io>
This commit is contained in:
Michael Telatynski
2025-10-09 14:20:53 +01:00
committed by GitHub
parent 3098eba4f2
commit bc7b50f97c
14 changed files with 253 additions and 55 deletions

View File

@@ -179,6 +179,14 @@ export interface IBaseSetting<T extends SettingValueType = SettingValueType> {
* Whether the setting should be exported in a rageshake report.
*/
shouldExportToRageshake?: boolean;
/**
* Options array for a setting controlled by a dropdown.
*/
options?: {
value: T;
label: TranslationKey;
}[];
}
export interface IFeature extends Omit<IBaseSetting<boolean>, "isFeature"> {
@@ -353,7 +361,7 @@ export interface Settings {
"videoInputMuted": IBaseSetting<boolean>;
"activeCallRoomIds": IBaseSetting<string[]>;
"releaseAnnouncementData": IBaseSetting<ReleaseAnnouncementData>;
"Electron.autoLaunch": IBaseSetting<boolean>;
"Electron.autoLaunch": IBaseSetting<"enabled" | "minimised" | "disabled">;
"Electron.warnBeforeExit": IBaseSetting<boolean>;
"Electron.alwaysShowMenuBar": IBaseSetting<boolean>;
"Electron.showTrayIcon": IBaseSetting<boolean>;
@@ -1438,8 +1446,13 @@ export const SETTINGS: Settings = {
// We store them over there are they are necessary to know before the renderer process launches.
"Electron.autoLaunch": {
supportedLevels: [SettingLevel.PLATFORM],
displayName: _td("settings|start_automatically"),
default: false,
displayName: _td("settings|start_automatically|label"),
options: [
{ value: "enabled", label: _td("settings|start_automatically|enabled") },
{ value: "disabled", label: _td("settings|start_automatically|disabled") },
{ value: "minimised", label: _td("settings|start_automatically|minimised") },
],
default: "disabled",
},
"Electron.warnBeforeExit": {
supportedLevels: [SettingLevel.PLATFORM],

View File

@@ -10,9 +10,6 @@ import SettingsHandler from "./SettingsHandler";
import PlatformPeg from "../../PlatformPeg";
import { SETTINGS } from "../Settings";
import { SettingLevel } from "../SettingLevel";
import defaultDispatcher from "../../dispatcher/dispatcher";
import { type ActionPayload } from "../../dispatcher/payloads";
import { Action } from "../../dispatcher/actions";
/**
* Gets and sets settings at the "platform" level for the current device.
@@ -24,22 +21,22 @@ export default class PlatformSettingsHandler extends SettingsHandler {
public constructor() {
super();
defaultDispatcher.register(this.onAction);
void this.setup();
}
private onAction = (payload: ActionPayload): void => {
if (payload.action === Action.PlatformSet) {
this.store = {};
// Load setting values as they are async and `getValue` must be synchronous
Object.entries(SETTINGS).forEach(([key, setting]) => {
if (setting.supportedLevels?.includes(SettingLevel.PLATFORM) && payload.platform.supportsSetting(key)) {
payload.platform.getSettingValue(key).then((value: any) => {
this.store[key] = value;
});
}
});
}
};
private async setup(): Promise<void> {
const platform = await PlatformPeg.platformPromise;
await platform.initialised;
// Load setting values as they are async and `getValue` must be synchronous
Object.entries(SETTINGS).forEach(([key, setting]) => {
if (setting.supportedLevels?.includes(SettingLevel.PLATFORM) && platform.supportsSetting(key)) {
platform.getSettingValue(key).then((value: any) => {
this.store[key] = value;
});
}
});
}
public canSetValue(settingName: string, roomId: string): boolean {
return PlatformPeg.get()?.supportsSetting(settingName) ?? false;