Refactored hooks to specify events and reworked the dropdowns to be significantly faster and more responsive. (#304)

* Updated events to be more specific

* Update more events

* Update globalmousepos

* Update themes and submap module to show submap name.

* Type fixes

* Reworked menu position calculation logic to be much more efficient.

* Revert import file location

* We luv arrow functions

* Remove globalMousePos remnants since it's unused.

* Added the ability to configure menu dropdown transition and duration.

* Fix type
This commit is contained in:
Jas Singh
2024-10-06 00:22:27 -07:00
committed by GitHub
parent 8a727a080e
commit ee7d19320c
71 changed files with 2175 additions and 1796 deletions

View File

@@ -87,7 +87,7 @@ export function mkOptions<T extends object>(
cacheFile: string,
object: T,
confFile: string = 'config.json',
): T & MkOptionsResult<T> {
): T & MkOptionsResult {
for (const opt of getOptions(object as Record<string, unknown>)) opt.init(cacheFile);
Utils.ensureDirectory(cacheFile.split('/').slice(0, -1).join('/'));

View File

@@ -1,11 +1,12 @@
import { WindowProps } from 'types/widgets/window';
import { GtkWidget, Transition } from './widget';
import { Binding } from 'types/service';
export type DropdownMenuProps = {
name: string;
child: GtkWidget;
layout?: string;
transition?: Transition;
transition?: Transition | Binding<Transition>;
exclusivity?: Exclusivity;
fixed?: boolean;
} & WindowProps;

4
lib/types/globals.d.ts vendored Normal file
View File

@@ -0,0 +1,4 @@
export type MousePos = {
source: string;
pos: number[];
};

View File

@@ -2,7 +2,7 @@ import { Opt } from 'lib/option';
import { Variable } from 'types/variable';
import { defaultColorMap } from './defaults/options';
export type MkOptionsResult<T> = {
export type MkOptionsResult = {
configFile: string;
array: () => Opt[];
reset: () => Promise<string>;
@@ -11,7 +11,7 @@ export type MkOptionsResult<T> = {
};
export type RecursiveOptionsObject = {
[key: string]: RecursiveOptionsObject | Opt<string | number | boolean> | Opt<any>;
[key: string]: RecursiveOptionsObject | Opt<string> | Opt<number> | Opt<boolean>;
};
export type BarLocation = 'top' | 'bottom';
@@ -57,7 +57,7 @@ export type RowProps<T> = {
min?: number;
disabledBinding?: Variable<boolean>;
exportData?: ThemeExportData;
subtitle?: string | VarType<any> | Opt;
subtitle?: string | VarType<string> | Opt;
subtitleLink?: string;
dependencies?: string[];
increment?: number;

View File

@@ -4,9 +4,9 @@ import { Transition } from './widget';
export type PopupWindowProps = {
name: string;
child: any;
child: Widget;
layout?: Layouts;
transition?: any;
transition?: Transition | Binding<Transition>;
exclusivity?: Exclusivity;
} & WindowProps;

View File

@@ -1,4 +1,3 @@
import icons from 'modules/icons/index';
import PowerProfiles from 'types/service/powerprofiles.js';
export type PowerProfiles = InstanceType<typeof PowerProfiles>;

View File

@@ -153,7 +153,7 @@ export const Notify = (notifPayload: NotificationArgs): void => {
Utils.execAsync(command);
};
export function getPosition(pos: NotificationAnchor | OSDAnchor): ('top' | 'bottom' | 'left' | 'right')[] {
export const getPosition = (pos: NotificationAnchor | OSDAnchor): ('top' | 'bottom' | 'left' | 'right')[] => {
const positionMap: { [key: string]: ('top' | 'bottom' | 'left' | 'right')[] } = {
top: ['top'],
'top right': ['top', 'right'],
@@ -166,7 +166,7 @@ export function getPosition(pos: NotificationAnchor | OSDAnchor): ('top' | 'bott
};
return positionMap[pos] || ['top'];
}
};
export const isValidGjsColor = (color: string): boolean => {
const colorLower = color.toLowerCase().trim();
@@ -189,3 +189,7 @@ export const isValidGjsColor = (color: string): boolean => {
return false;
};
export const caapitalizeFirstLetter = (str: string): string => {
return str.charAt(0).toUpperCase() + str.slice(1);
};