8000 Improve settings performance by Schneegans · Pull Request #970 · kando-menu/kando · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Improve settings performance #970

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 10 commits into from
May 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 32 additions & 6 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
// SPDX-License-Identifier: CC0-1.0

/* eslint-disable @typescript-eslint/naming-convention */
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { defineConfig } from 'eslint/config';
import { includeIgnoreFile } from '@eslint/compat';
import js from '@eslint/js';
import ts from 'typescript-eslint';
import prettierRecommended from 'eslint-plugin-prettier/recommended';
import { includeIgnoreFile } from '@eslint/compat';
import { defineConfig } from 'eslint/config';
import globals from 'globals';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import ts from 'typescript-eslint';

const filename = fileURLToPath(import.meta.url);
const dirname = path.dirname(filename);
Expand All @@ -33,7 +33,33 @@ export default defineConfig([
'@typescript-eslint/no-empty-function': 'off',
'@typescript-eslint/no-require-imports': 'off',
'@typescript-eslint/no-var-requires': 'off',
'@typescript-eslint/naming-convention': 'error',
'@typescript-eslint/naming-convention': [
'error',
{
selector: 'default',
format: ['camelCase'],
leadingUnderscore: 'allow',
trailingUnderscore: 'allow',
},
{
selector: 'import',
format: ['camelCase', 'PascalCase'],
},
{
selector: 'variable',
format: ['camelCase', 'UPPER_CASE'],
leadingUnderscore: 'allow',
trailingUnderscore: 'allow',
},
{
selector: 'typeLike',
format: ['PascalCase'],
},
{
selector: 'function',
format: ['PascalCase', 'camelCase'],
},
],
'@typescript-eslint/no-unused-vars': [
'error',
{
Expand Down
6 changes: 5 additions & 1 deletion src/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,11 @@ const handleArguments = (

app
.whenReady()
.then(() => installExtension(REACT_DEVELOPER_TOOLS))
.then(() => {
if (process.env.NODE_ENV === 'development') {
return installExtension(REACT_DEVELOPER_TOOLS);
}
})
.then(() => {
return i18next.use(i18Backend).init({
lng: app.getLocale(),
Expand Down
10 changes: 8 additions & 2 deletions src/settings-renderer/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,13 @@ import { Sidebar } from './common';
import * as classes from './App.module.scss';
const cx = classNames.bind(classes);

export default () => {
/**
* This is the main component of the settings dialog. It manages the layout of the
* different components: the menu list on the left, the menu preview in the center, and
* the properties on the right. It also handles global shortcuts for undo and redo, and
* sets the color scheme of the body element based on the user's settings.
*/
export default function App() {
const [settingsWindowColorScheme] = useGeneralSetting('settingsWindowColorScheme');
const [settingsWindowFlavor] = useGeneralSetting('settingsWindowFlavor');

Expand Down Expand Up @@ -111,4 +117,4 @@ export default () => {
/>
</>
);
};
}
4 changes: 2 additions & 2 deletions src/settings-renderer/components/common/Base64IconPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ interface IProps {
* @param props - The properties for the icon picker component.
* @returns A textarea element that allows the user to enter a base64 encoded image.
*/
export default (props: IProps) => {
export default function Base64IconPicker(props: IProps) {
const textareaRef = React.useRef<HTMLTextAreaElement>(null);
const [value, setValue] = React.useState('');

Expand Down Expand Up @@ -87,4 +87,4 @@ export default (props: IProps) => {
].join('\n')}
/>
);
};
}
4 changes: 2 additions & 2 deletions src/settings-renderer/components/common/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ interface IProps {
* @param props - The properties for the button component.
* @returns A button element.
*/
export default (props: IProps) => {
export default function Button(props: IProps) {
const className = cx({
button: true,
[props.variant || 'secondary']: true,
Expand All @@ -84,4 +84,4 @@ export default (props: IProps) => {
{props.label}
</button>
);
};
}
4 changes: 2 additions & 2 deletions src/settings-renderer/components/common/Checkbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ interface IProps {
* @param props - The properties for the checkbox component.
* @returns A checkbox element.
*/
export default (props: IProps) => {
export default function Checkbox(props: IProps) {
return (
<SettingsRow label={props.label} info={props.info} labelClickable>
<input
Expand All @@ -49,4 +49,4 @@ export default (props: IProps) => {
/>
</SettingsRow>
);
};
}
4 changes: 2 additions & 2 deletions src/settings-renderer/components/common/ColorButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ interface IProps {
* @param props - The properties for the color button component.
* @returns A color button element.
*/
export default (props: IProps) => {
export default function ColorButton(props: IProps) {
const [isPopoverOpen, setIsPopoverOpen] = React.useState(false);
const [cssColor, setCSSColor] = React.useState(chroma(props.color).css());
const [inputColor, setInputColor] = React.useState(chroma(props.color).css());
Expand Down Expand Up @@ -87,4 +87,4 @@ export default (props: IProps) => {
</div>
</Popover>
);
};
}
4 changes: 2 additions & 2 deletions src/settings-renderer/components/common/Dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ interface IProps<T extends string> {
* @param props - The properties for the dropdown component.
* @returns A dropdown element.
*/
export default <T extends string>(props: IProps<T>) => {
export default function Dropdown<T extends string>(props: IProps<T>) {
const invalidSelection =
props.options.find((option) => option.value === props.initialValue) === undefined;

Expand Down Expand Up @@ -78,4 +78,4 @@ export default <T extends string>(props: IProps<T>) => {
</select>
</SettingsRow>
);
};
}
4 changes: 2 additions & 2 deletions src/settings-renderer/components/common/FilePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ interface IProps {
* @param props - The properties for the component.
* @returns A React component that allows the user to enter a shortcut.
*/
export default (props: IProps) => {
export default function FilePicker(props: IProps) {
const [path, setPath] = React.useState(props.initialValue);

// Update the value when the initialValue prop changes. This is necessary because the
Expand Down Expand Up @@ -104,4 +104,4 @@ export default (props: IProps) => {
</div>
</SettingsRow>
);
};
}
13 changes: 9 additions & 4 deletions src/settings-renderer/components/common/GridIconPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,15 @@ interface IProps {
* @param props - The properties for the icon picker component.
* @returns A grid icon picker element.
*/
export default (props: IProps) => {
export default function GridIconPicker(props: IProps) {
const [gridInstance, setGridInstance] = React.useState<Grid | null>(null);
const theme = IconThemeRegistry.getInstance().getTheme(props.theme);
const fetchedIcons = theme.iconPickerInfo.listIcons(props.filterTerm);

// Listing the icons is expensive, so we only do it when the theme or filter term
// changes.
const fetchedIcons = React.useMemo(() => {
const theme = IconThemeRegistry.getInstance().getTheme(props.theme);
return theme.iconPickerInfo.listIcons(props.filterTerm);
}, [props.theme, props.filterTerm]);

const columns = 8;
const rows = Math.ceil(fetchedIcons.length / columns);
Expand Down Expand Up @@ -121,4 +126,4 @@ export default (props: IProps) => {
</AutoSizer>
</div>
);
};
}
4 changes: 2 additions & 2 deletions src/settings-renderer/components/common/Headerbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ interface IProps {
* @param props - The properties for the header bar component.
* @returns A header bar element.
*/
export default (props: IProps) => {
export default function Headerbar(props: IProps) {
return (
<div className={classes.headerbar}>
<div
Expand All @@ -54,4 +54,4 @@ export default (props: IProps) => {
</div>
</div>
);
};
}
4 changes: 2 additions & 2 deletions src/settings-renderer/components/common/IconChooserButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ interface IProps {
* @param props - The properties for the color button component.
* @returns A color button element.
*/
export default (props: IProps) => {
export default function IconChooserButton(props: IProps) {
const [isPopoverOpen, setIsPopoverOpen] = React.useState(false);
const [filterTerm, setFilterTerm] = React.useState('');
const [theme, setTheme] = React.useState(props.theme);
Expand Down Expand Up @@ -144,4 +144,4 @@ export default (props: IProps) => {
/>
</Popover>
);
};
}
4 changes: 2 additions & 2 deletions src/settings-renderer/components/common/InfoItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ interface IProps {
* @param props - The properties for the info item component.
* @returns An info item element.
*/
export default (props: IProps) => {
export default function InfoItem(props: IProps) {
return (
<span
className={classes.info}
Expand All @@ -33,4 +33,4 @@ export default (props: IProps) => {
<TbInfoSquareRoundedFilled />
</span>
);
};
}
4 changes: 2 additions & 2 deletions src/settings-renderer/components/common/MacroPicker.tsx
10000
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ interface IProps {
* @param props - The properties for the macro-picker component.
* @returns A macro-picker element.
*/
export default (props: IProps) => {
export default function MacroPicker(props: IProps) {
const [textValue, setTextValue] = React.useState(convertToString(props.initialValue));
const [recording, setRecording] = React.useState(false);
const inputRef = React.useRef<HTMLTextAreaElement>(null);
Expand Down Expand Up @@ -127,7 +127,7 @@ export default (props: IProps) => {
/>
</div>
);
};
}

/**
* This method normalizes the given macro. It properly formats the JSON input and turns
Expand Down
4 changes: 2 additions & 2 deletions src/settings-renderer/components/common/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ interface IProps {
* @param props - The properties for the modal component.
* @returns A modal element.
*/
export default (props: IProps) => {
export default function Modal(props: IProps) {
const modalContent = React.useRef(null);
const pointerDownOnBackground = React.useRef(false);

Expand Down Expand Up @@ -177,4 +177,4 @@ export default (props: IProps) => {
</CSSTransition>,
document.body
);
};
}
4 changes: 2 additions & 2 deletions src/settings-renderer/components/common/Note.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ interface IProps {
* @param props - The properties for the note component.
* @returns A note element.
*/
export default (props: IProps) => {
export default function Note(props: IProps) {
const handleLinkClick = (href: string) => {
if (props.onLinkClick) {
props.onLinkClick(href); // Execute the callback with the link's href
Expand Down Expand Up @@ -99,4 +99,4 @@ export default (props: IProps) => {
)}
</div>
);
};
}
4 changes: 2 additions & 2 deletions src/settings-renderer/components/common/Popover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ interface IProps {
* @param props - The properties for the modal component.
* @returns A popover element.
*/
export default (props: IProps) => {
export default function Popover(props: IProps) {
const popoverContent = React.useRef(null);
const popoverTriangle = React.useRef(null);
const popoverTarget = React.useRef(null);
Expand Down Expand Up @@ -173,4 +173,4 @@ export default (props: IProps) => {
)}
</>
);
};
}
4 changes: 2 additions & 2 deletions src/settings-renderer/components/common/RandomTip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ interface IProps {
* @param props - The properties for the tip component.
* @returns A note element.
*/
export default (props: IProps) => {
export default function RandomTip(props: IProps) {
return (
<Note
center
Expand All @@ -41,4 +41,4 @@ export default (props: IProps) => {
{props.tips[Math.floor(Math.random() * props.tips.length)]}
</Note>
);
};
}
11 changes: 9 additions & 2 deletions src/settings-renderer/components/common/Scrollbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,14 @@ interface IProps {
hideScrollbar?: boolean;
}

export default (props: IProps) => {
/**
* Wraps its children in a scrollable box. The scrollbox has a maximum height and a fixed
* width. If the content exceeds the maximum height, a scrollbar will appear.
*
* @param props - The properties for the scrollbox component.
* @returns A scrollbox element.
*/
export default function Scrollbox(props: IProps) {
return (
<div
className={
Expand All @@ -29,4 +36,4 @@ export default (props: IProps) => {
<div className={classes.content}>{props.children}</div>
</div>
);
};
}
6 changes: 4 additions & 2 deletions src/settings-renderer/components/common/SettingsCheckbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ type BooleanKeys<T> = {
* @param props - The properties for the managed checkbox component.
* @returns A managed checkbox element.
*/
export default <K extends BooleanKeys<IGeneralSettings>>(props: IProps<K>) => {
export default function SettingsCheckbox<K extends BooleanKeys<IGeneralSettings>>(
props: IProps<K>
) {
const [state, setState] = useGeneralSetting(props.settingsKey);

return (
Expand All @@ -55,4 +57,4 @@ export default <K extends BooleanKeys<IGeneralSettings>>(props: IProps<K>) => {
disabled={props.disabled}
/>
);
};
}
6 changes: 4 additions & 2 deletions src/settings-renderer/components/common/SettingsDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ type EnumKeys<T> = {
* @param props - The properties for the managed dropdown component.
* @returns A managed dropdown element.
*/
export default <K extends EnumKeys<IGeneralSettings>>(props: IProps<K>) => {
export default function SettingsDropdown<K extends EnumKeys<IGeneralSettings>>(
props: IProps<K>
) {
const [state, setState] = useGeneralSetting(props.settingsKey);

return (
Expand All @@ -68,4 +70,4 @@ export default <K extends EnumKeys<IGeneralSettings>>(props: IProps<K>) => {
maxWidth={props.maxWidth}
/>
);
};
}
4 changes: 2 additions & 2 deletions src/settings-renderer/components/common/SettingsRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ interface IProps {
* @param props - The properties for the settings-row component.
* @returns A settings-row element.
*/
export default (props: IProps) => {
export default function SettingsRow(props: IProps) {
// eslint-disable-next-line @typescript-eslint/naming-convention
const Element = props.labelClickable ? 'label' : 'div';

Expand Down Expand Up @@ -74,4 +74,4 @@ export default (props: IProps) => {
</div>
</Element>
);
};
}
Loading
0