1
0
Fork 0
mirror of https://github.com/FrankerFaceZ/FrankerFaceZ.git synced 2025-09-01 02:40:56 +00:00

* Convert AddonManager to TypeScript.

* Convert PubSub (not PubSubClient) to TypeScript.
* Convert StagingSelector to TypeScript.
* Make sure to add ExperimentManager's events to the global interface.
This commit is contained in:
SirStendec 2023-11-16 22:36:10 -05:00
parent 6c6d4ceb98
commit 31e7ce4ac5
6 changed files with 221 additions and 93 deletions

73
src/staging.tsx Normal file
View file

@ -0,0 +1,73 @@
'use strict';
// ============================================================================
// Staging Selector
// ============================================================================
import Module, { GenericModule } from 'utilities/module';
import { API_SERVER, SERVER, STAGING_API, STAGING_CDN } from './utilities/constants';
import type SettingsManager from './settings';
declare module 'utilities/types' {
interface ModuleMap {
staging: StagingSelector;
}
interface ModuleEventMap {
staging: StagingEvents;
}
interface SettingsTypeMap {
'data.use-staging': boolean;
}
}
type StagingEvents = {
':updated': [api: string, cdn: string];
}
export default class StagingSelector extends Module<'staging', StagingEvents> {
// Dependencies
settings: SettingsManager = null as any;
// State
api: string = API_SERVER;
cdn: string = SERVER;
active: boolean = false;
constructor(name?: string, parent?: GenericModule) {
super(name, parent);
this.inject('settings');
this.settings.add('data.use-staging', {
default: false,
ui: {
path: 'Debugging > Data Sources >> Staging @{"sort": -1}',
force_seen: true,
title: 'Use staging as data source.',
component: 'setting-check-box'
}
});
this.updateStaging(false);
}
/** @internal */
onEnable() {
this.settings.getChanges('data.use-staging', this.updateStaging, this);
}
private updateStaging(val: boolean) {
this.active = val;
this.api = val
? STAGING_API
: API_SERVER;
this.cdn = val
? STAGING_CDN
: SERVER;
this.emit(':updated', this.api, this.cdn);
}
}