Skip to content

Commit 33052b9

Browse files
authored
Refactor settings menu to use SwitchSetting class & persist settings localstorage - Refactor Save & Load logic (#251)
This pull request refactors the configuration and settings management system, replacing the monolithic `ConfigModal` class with a modular and scalable `ConfigMenu` system. It introduces a new `SwitchSetting` abstraction for managing individual settings and updates the `GlobalContext` to integrate the new configuration system. The most important changes include the removal of the old `ConfigModal`, the introduction of `ConfigMenu` and `SwitchSetting`, and the integration of these changes into the `GlobalContext`. ### Refactoring of Configuration System: * **Removal of `ConfigModal`**: The `ConfigModal` class and its associated functionality were removed, simplifying the `src/config.ts` file. This includes the deletion of methods for creating modals, managing settings, and handling shortcuts. * **Introduction of `ConfigMenu`**: A new `ConfigMenu` class was added in `src/config_menu/config_menu.ts`. This class modularizes settings management, supports listeners for changes, and uses a more scalable approach to handle configuration switches. * **Switch Abstraction with `SwitchSetting`**: The `SwitchSetting` class was added to encapsulate individual settings, including their persistence, temporary state, and UI rendering. This abstraction allows for easier addition and management of settings. * **Switch Factory**: A `switch_factory` was introduced to centralize the creation of all switches, such as enabling tooltips and using TCP Reno. This ensures consistent initialization and behavior of switches. ### Integration into `GlobalContext`: * **Integration of `ConfigMenu`**: The `GlobalContext` class now includes a `ConfigMenu` instance. It initializes the menu, listens for changes, and saves settings to local storage when updates occur. This replaces the previous direct settings management in `GlobalContext`. [[1]](diffhunk://#diff-0cd594dddd6a9f2e3e26afebbb92716434437d7001c2416252aa7531e7f2b8d4L28-R34) [[2]](diffhunk://#diff-0cd594dddd6a9f2e3e26afebbb92716434437d7001c2416252aa7531e7f2b8d4R48-R54) * **Refactoring of Save Operations**: All calls to `saveToLocalStorage` in `GlobalContext` were replaced with a new `this.saveToLocalStorage` method, ensuring consistent behavior and integration with the new configuration system. [[1]](diffhunk://#diff-0cd594dddd6a9f2e3e26afebbb92716434437d7001c2416252aa7531e7f2b8d4L88-R89) [[2]](diffhunk://#diff-0cd594dddd6a9f2e3e26afebbb92716434437d7001c2416252aa7531e7f2b8d4L150-R151) [[3]](diffhunk://#diff-0cd594dddd6a9f2e3e26afebbb92716434437d7001c2416252aa7531e7f2b8d4L161-R162)This pull request refactors the configuration management system by replacing the `ConfigModal` class with a more modular and extensible `ConfigMenu` system. The new implementation introduces a switch-based architecture for managing settings, improving code maintainability and scalability. Below are the most important changes grouped by theme: ### Refactoring Configuration Management: * Removed the `ConfigModal` class, including all its methods and properties, and replaced it with the `ConfigMenu` class, which uses a modular architecture to manage settings. (`src/config.ts` - [[1]](diffhunk://#diff-c3095d5010e65c52737a98a5d618ea24049ebe90c8470752426081d70ed6e012L1-L311) `src/config_menu/config_menu.ts` - [[2]](diffhunk://#diff-c3f37150933d9200129781d64be0a8fa84b355627ddf96e66bb203f8956c5968R1-R168) * Introduced the `SwitchSetting` abstract class to encapsulate the behavior of individual settings, allowing for easy addition of new settings. (`src/config_menu/switches/switch.ts` - [src/config_menu/switches/switch.tsR1-R60](diffhunk://#diff-da65f25c5fd3cdb260e441f5b6ede48a06a7119b3101872ebb885aa88d6ca2f9R1-R60)) ### Modular Settings Implementation: * Added the `EnableTooltipsSwitch` and `UseTcpRenoSwitch` classes, which extend `SwitchSetting` to handle specific settings like enabling tooltips and using TCP Reno. (`src/config_menu/switches/enable_tooltips.ts` - [[1]](diffhunk://#diff-6b9a4f91978bdeec8a40150007eeec476b123dd45dedcfb0576e78d61e5946d8R1-R13) `src/config_menu/switches/tcp_reno.ts` - [[2]](diffhunk://#diff-a8428ef14b05121c8bbe8d76245494785f2f5039577665be02cbd00d26919e5eR1-R11) * Created a `createAllSwitches` factory function to initialize all available switches dynamically. (`src/config_menu/switches/switch_factory.ts` - [src/config_menu/switches/switch_factory.tsR1-R8](diffhunk://#diff-725b05ce0cf5670a609b6a327788a2de4b0e9fc918ea85d25e8de41b4454b296R1-R8))
1 parent 9e79323 commit 33052b9

File tree

12 files changed

+416
-457
lines changed

12 files changed

+416
-457
lines changed

src/config.ts

Lines changed: 0 additions & 311 deletions
This file was deleted.

0 commit comments

Comments
 (0)