Skip to content

Commit

Permalink
fix: update settings in all open windows (#1376)
Browse files Browse the repository at this point in the history
* refactor: move localStorage keys to the `SettingKey` enum

* fix: make settings changes take effect in all open windows

* Update src/renderer/state.ts

Co-authored-by: David Sanders <[email protected]>

* fix: ensure all keys are checked

* fix: add warning for unrecognized keys

---------

Co-authored-by: David Sanders <[email protected]>
  • Loading branch information
erikian and dsanders11 authored Jun 30, 2023
1 parent 69aad65 commit 4eee716
Show file tree
Hide file tree
Showing 5 changed files with 243 additions and 73 deletions.
36 changes: 36 additions & 0 deletions src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,3 +184,39 @@ export interface PMOperationOptions {
dir: string;
packageManager: IPackageManager;
}

export enum GlobalSetting {
acceleratorsToBlock = 'acceleratorsToBlock',
channelsToShow = 'channelsToShow',
electronMirror = 'electronMirror',
environmentVariables = 'environmentVariables',
executionFlags = 'executionFlags',
fontFamily = 'fontFamily',
fontSize = 'fontSize',
gitHubAvatarUrl = 'gitHubAvatarUrl',
gitHubLogin = 'gitHubLogin',
gitHubName = 'gitHubName',
gitHubToken = 'gitHubToken',
hasShownTour = 'hasShownTour',
isClearingConsoleOnRun = 'isClearingConsoleOnRun',
isEnablingElectronLogging = 'isEnablingElectronLogging',
isKeepingUserDataDirs = 'isKeepingUserDataDirs',
isPublishingGistAsRevision = 'isPublishingGistAsRevision',
isUsingSystemTheme = 'isUsingSystemTheme',
knownVersion = 'known-electron-versions',
localVersion = 'local-electron-versions',
packageAuthor = 'packageAuthor',
packageManager = 'packageManager',
showObsoleteVersions = 'showObsoleteVersions',
showUndownloadedVersions = 'showUndownloadedVersions',
theme = 'theme',
}

export type GlobalSettingKey = keyof typeof GlobalSetting;

export enum WindowSpecificSetting {
gitHubPublishAsPublic = 'gitHubPublishAsPublic',
version = 'version',
}

export type WindowSpecificSettingKey = keyof typeof WindowSpecificSetting;
23 changes: 15 additions & 8 deletions src/renderer/components/settings-execution.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,20 @@ import {
} from '@blueprintjs/core';
import { observer } from 'mobx-react';

import { IPackageManager } from '../../interfaces';
import {
GlobalSetting,
GlobalSettingKey,
IPackageManager,
} from '../../interfaces';
import { AppState } from '../state';

export enum SettingItemType {
EnvVars = 'environmentVariables',
Flags = 'executionFlags',
}
/**
* @TODO make this a proper enum again once we update Typescript
*/
export const SettingItemType = {
EnvVars: GlobalSetting.environmentVariables,
Flags: GlobalSetting.executionFlags,
} as const;

interface ExecutionSettingsProps {
appState: AppState;
Expand Down Expand Up @@ -119,7 +126,7 @@ export const ExecutionSettings = observer(
*/
public handleSettingsItemChange(
event: React.ChangeEvent<HTMLInputElement>,
type: SettingItemType,
type: GlobalSettingKey,
) {
const { name, value } = event.currentTarget;

Expand All @@ -136,7 +143,7 @@ export const ExecutionSettings = observer(
*
* @param {SettingItemType} type
*/
private addNewSettingsItem(type: SettingItemType) {
private addNewSettingsItem(type: GlobalSettingKey) {
const array = Object.entries(this.state[type]);

this.setState((prevState) => ({
Expand All @@ -160,7 +167,7 @@ export const ExecutionSettings = observer(
appState.packageManager = value as IPackageManager;
};

public renderDeleteItem(idx: string, type: SettingItemType): JSX.Element {
public renderDeleteItem(idx: string, type: GlobalSettingKey): JSX.Element {
const updated = this.state[type];

const removeFn = () => {
Expand Down
Loading

0 comments on commit 4eee716

Please sign in to comment.