mirror of
https://github.com/FrankerFaceZ/FrankerFaceZ.git
synced 2025-06-27 21:05:53 +00:00
Bit more work.
This commit is contained in:
parent
b9d23accf0
commit
9de3b92019
4 changed files with 23 additions and 27 deletions
|
@ -755,7 +755,7 @@ export default class Metadata extends Module {
|
|||
}
|
||||
|
||||
/** @internal */
|
||||
getAddonProxy(addon_id: string, addon: AddonInfo, module: GenericModule): GenericModule {
|
||||
getAddonProxy(addon_id: string, addon: AddonInfo, module: GenericModule) {
|
||||
if ( ! addon_id )
|
||||
return this;
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
// Settings System
|
||||
// ============================================================================
|
||||
|
||||
import Module, { GenericModule } from 'utilities/module';
|
||||
import Module, { GenericModule, buildAddonProxy } from 'utilities/module';
|
||||
import {deep_equals, has, debounce, deep_copy} from 'utilities/object';
|
||||
import {parse as parse_path} from 'utilities/path-parser';
|
||||
|
||||
|
@ -19,6 +19,7 @@ import * as CLEARABLES from './clearables';
|
|||
import type { SettingsProfileMetadata, ContextData, ExportedFullDump, SettingsClearable, SettingsDefinition, SettingsProcessor, SettingsUiDefinition, SettingsValidator } from './types';
|
||||
import type { FilterType } from '../utilities/filtering';
|
||||
import { AdvancedSettingsProvider, IndexedDBProvider, LocalStorageProvider, Providers, type SettingsProvider } from './providers';
|
||||
import type { AddonInfo } from '../utilities/types';
|
||||
|
||||
export {parse as parse_path} from 'utilities/path-parser';
|
||||
|
||||
|
@ -122,6 +123,8 @@ export default class SettingsManager extends Module<'settings', SettingsEvents>
|
|||
this.providers[key] = provider;
|
||||
}
|
||||
|
||||
const test = this.resolve('load_tracker');
|
||||
|
||||
// This cannot be modified at a future time, as providers NEED
|
||||
// to be ready very early in FFZ intitialization. Seal it.
|
||||
Object.seal(this.providers);
|
||||
|
@ -1113,33 +1116,26 @@ export default class SettingsManager extends Module<'settings', SettingsEvents>
|
|||
// Add-On Proxy
|
||||
// ========================================================================
|
||||
|
||||
getAddonProxy(addon_id: string) {
|
||||
getAddonProxy(addon_id: string, addon: AddonInfo, module: GenericModule) {
|
||||
if ( ! addon_id )
|
||||
return this;
|
||||
|
||||
const add = (key, definition) => {
|
||||
const overrides: Record<string, any> = {},
|
||||
is_dev = DEBUG || addon?.dev;
|
||||
|
||||
overrides.add = <T,>(key: string, definition: SettingsDefinition<T>) => {
|
||||
return this.add(key, definition, addon_id);
|
||||
}
|
||||
};
|
||||
|
||||
const addUI = (key, definition) => {
|
||||
overrides.addUI = <T,>(key: string, definition: SettingsUiDefinition<T>) => {
|
||||
return this.addUI(key, definition, addon_id);
|
||||
}
|
||||
};
|
||||
|
||||
const addClearable = (key, definition) => {
|
||||
overrides.addClearable = (key: string, definition: SettingsClearable) => {
|
||||
return this.addClearable(key, definition, addon_id);
|
||||
}
|
||||
|
||||
return new Proxy(this, {
|
||||
get(obj, prop) {
|
||||
if ( prop === 'add' )
|
||||
return add;
|
||||
if ( prop === 'addUI' )
|
||||
return addUI;
|
||||
if ( prop === 'addClearable' )
|
||||
return addClearable;
|
||||
return Reflect.get(...arguments);
|
||||
}
|
||||
});
|
||||
return buildAddonProxy(module, this, 'settings', overrides);
|
||||
}
|
||||
|
||||
// ========================================================================
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
import EventEmitter, { EventKey, EventListener, EventMap, NamespacedEventArgs, NamespacedEventKey, NamespacedEvents } from 'utilities/events';
|
||||
import {has} from 'utilities/object';
|
||||
import type Logger from './logging';
|
||||
import type { AddonInfo, KnownEvents, ModuleMap, OptionalPromise } from './types';
|
||||
import type { AddonInfo, KnownEvents, ModuleKeys, ModuleMap, ModuleMap, ModuleMap, ModuleMap, OptionalPromise } from './types';
|
||||
import type { Addon } from './addon';
|
||||
|
||||
|
||||
|
@ -805,12 +805,9 @@ export class Module<
|
|||
}
|
||||
|
||||
resolve<
|
||||
TPath extends string,
|
||||
TModule extends Module =
|
||||
TPath extends keyof ModuleMap
|
||||
? ModuleMap[TPath]
|
||||
: Module
|
||||
>(name: TPath): TModule | null {
|
||||
TPath extends ModuleKeys,
|
||||
TReturn extends GenericModule = ModuleMap[TPath]
|
||||
>(name: TPath): TReturn | null {
|
||||
let module = this.__resolve(name);
|
||||
if ( !(module instanceof Module) )
|
||||
return null;
|
||||
|
@ -818,7 +815,7 @@ export class Module<
|
|||
if ( this.__processModule )
|
||||
module = this.__processModule(module);
|
||||
|
||||
return module as TModule;
|
||||
return module as TReturn;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -179,3 +179,6 @@ export type ModuleMap = {
|
|||
'translation_ui': TranslationUI;
|
||||
'vue': Vue;
|
||||
};
|
||||
|
||||
|
||||
export type ModuleKeys = string & keyof ModuleMap;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue