-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: reconstruct option management (#659)
* refactor option management * lint: run prettier * refactor: use features-loader as a webpack loader * chore: remove unused import * docs: update website url * chore: remove unused `getBrowserType` * fix: fix settings cannot be saved * fix: cannot load undefined settings * fix: locale not updates immediately when choose a different language * refactor: a more cohesive options-storage * refactor: change the consumption way of options storage in views * fix: wrong import path * fix: carefully deal with a featureId and featureName * fix: different orders between two react renders output error in console * chore: a simple popup page with a button directed to Options page * fix: oss-gpt doen't show whether enabled or not * refactor: use default options as the default state of the `options` state in views --------- Co-authored-by: Lam Tang <tangyenan@gmail.com>
- Loading branch information
Showing
23 changed files
with
1,064 additions
and
1,137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
type ThemeType = 'light' | 'dark'; | ||
|
||
type FeatureID = string & { feature: true }; | ||
type FeatureName = string; | ||
type FeatureId = `hypercrx-${FeatureName}`; | ||
|
||
// It should be just for README.md, but 🤷♂️ | ||
declare module '*.md' { | ||
export const importedFeatures: FeatureName[]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { importedFeatures } from '../README.md'; | ||
|
||
export type HypercrxOptions = typeof defaults; | ||
|
||
export const defaults = Object.assign( | ||
{ | ||
locale: 'en', | ||
}, | ||
Object.fromEntries( | ||
importedFeatures.map((name) => [`hypercrx-${name}` as FeatureId, true]) | ||
) | ||
); | ||
|
||
class OptionsStorage { | ||
public async getAll(): Promise<HypercrxOptions> { | ||
return (await chrome.storage.sync.get(defaults)) as HypercrxOptions; | ||
} | ||
|
||
public async set(options: Partial<HypercrxOptions>): Promise<void> { | ||
await chrome.storage.sync.set(options); | ||
} | ||
} | ||
|
||
const optionsStorage = new OptionsStorage(); | ||
|
||
export default optionsStorage; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.