Skip to content

Commit

Permalink
Merge pull request #206 from LordTocs/dev
Browse files Browse the repository at this point in the history
Eventsub Subscription Workarounds
  • Loading branch information
LordTocs authored Jul 19, 2024
2 parents 19b2b2c + 1e9cb7f commit d934b71
Show file tree
Hide file tree
Showing 45 changed files with 344 additions and 150 deletions.
2 changes: 2 additions & 0 deletions libs/castmate-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,5 @@ export * from "./util/generic-login"
export * from "./analytics/analytics-manager"

export * from "./info/info-manager"

export * from "./util/time-utils"
10 changes: 9 additions & 1 deletion libs/castmate-core/src/plugins/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import {
import { ResourceBase, ResourceConstructor } from "../resources/resource"
import { PluginManager } from "./plugin-manager"
import { Logger, globalLogger, usePluginLogger } from "../logging/logging"
import { startPerfTime } from "../util/time-utils"

interface PluginSpec {
id: string
Expand Down Expand Up @@ -97,8 +98,15 @@ export function onUnload(unloadFunc: PluginCallback) {
}

export function definePluginResource(resourceConstructor: ResourceConstructor) {
const logger = usePluginLogger()

onLoad(async () => {
await resourceConstructor.initialize()
const perf = startPerfTime(`Initing ${resourceConstructor.storage.name}`)
try {
await resourceConstructor.initialize()
} finally {
perf.stop(logger)
}
})

onUnload(async () => {
Expand Down
82 changes: 82 additions & 0 deletions libs/castmate-core/src/util/time-utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import { isPromise } from "util/types"
import { Logger, usePluginLogger } from "../logging/logging"

export interface PerfTimer {
name: string
startTime: number
stop(logger: Logger): void
}

export function startPerfTime(name: string): PerfTimer {
return {
name,
startTime: Date.now(),
stop(logger) {
logger.log("Completed ", name, (Date.now() - this.startTime) / 1000, "seconds")
},
}
}

export function measurePerf<This, T extends (this: This, ...args: any[]) => any>(
original: T,
context: ClassMethodDecoratorContext<T>
) {
const logger = usePluginLogger("perf")

function replacement(this: This, ...args: Parameters<T>): ReturnType<T> {
const perf = startPerfTime(String(context.name))

let result: ReturnType<T>
try {
result = original.call(this, ...args)

if (isPromise(result)) {
//@ts-ignore Type system too stupid again.
return (async () => {
try {
return await result
} finally {
perf.stop(logger)
}
})()
} else {
perf.stop(logger)
return result
}
} catch (err) {
perf.stop(logger)
throw err
}
}

return replacement
}

export function measurePerfFunc<T extends (...args: any[]) => any>(func: T, name?: string) {
const logger = usePluginLogger("perf")
return (...args: Parameters<T>): ReturnType<T> => {
const perf = startPerfTime(name ?? func.name)

let result: ReturnType<T>
try {
result = func(...args)

if (isPromise(result)) {
//@ts-ignore Type system too stupid again.
return (async () => {
try {
return await result
} finally {
perf.stop(logger)
}
})()
} else {
perf.stop(logger)
return result
}
} catch (err) {
perf.stop(logger)
throw err
}
}
}
4 changes: 2 additions & 2 deletions libs/castmate-overlay-core/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"compilerOptions": {
"target": "ES2020",
"target": "ES2022",
"useDefineForClassFields": true,
"module": "ESNext",
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"lib": ["ES2022", "DOM", "DOM.Iterable"],
"skipLibCheck": true,

/* Bundler mode */
Expand Down
2 changes: 1 addition & 1 deletion libs/castmate-overlay-macros/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"preserveConstEnums": true,
"outDir": "dist",
"sourceMap": true,
"target": "ES6",
"target": "ES2022",
"strictNullChecks": true,
"esModuleInterop": true
},
Expand Down
4 changes: 2 additions & 2 deletions libs/castmate-overlay-widget-loader/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"compilerOptions": {
"target": "ES2020",
"target": "ES2022",
"useDefineForClassFields": true,
"module": "ESNext",
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"lib": ["ES2022", "DOM", "DOM.Iterable"],
"skipLibCheck": true,

/* Bundler mode */
Expand Down
4 changes: 2 additions & 2 deletions libs/castmate-ui-core/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"compilerOptions": {
"target": "ES2020",
"target": "ES2022",
"useDefineForClassFields": true,
"module": "ESNext",
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"lib": ["ES2022", "DOM", "DOM.Iterable"],
"skipLibCheck": true,

/* Bundler mode */
Expand Down
2 changes: 1 addition & 1 deletion libs/castmate-vite/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"compilerOptions": {
"module": "ESNext",
"moduleResolution": "Node",
"target": "ES6",
"target": "ES2022",
"noImplicitAny": true,
"removeComments": true,
"preserveConstEnums": true,
Expand Down
2 changes: 1 addition & 1 deletion libs/castmate-ws-rpc/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"preserveConstEnums": true,
"outDir": "dist",
"sourceMap": true,
"target": "ES6",
"target": "ES2022",
"strictNullChecks": true
},
"include": ["src/**/*"],
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "castmate-monorepo",
"version": "0.5.1",
"version": "0.5.2-beta",
"description": "",
"private": true,
"type": "module",
Expand Down
4 changes: 2 additions & 2 deletions packages/castmate-obs-overlay/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"compilerOptions": {
"target": "ES2020",
"target": "ES2022",
"useDefineForClassFields": true,
"module": "ESNext",
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"lib": ["ES2022", "DOM", "DOM.Iterable"],
"skipLibCheck": true,

/* Bundler mode */
Expand Down
2 changes: 1 addition & 1 deletion packages/castmate/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "castmate",
"version": "0.5.1",
"version": "0.5.2-beta",
"description": "CastMate",
"author": "LordTocs",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion packages/castmate/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"target": "ES2022",
"useDefineForClassFields": true,
"module": "ESNext",
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"lib": ["ES2022", "DOM", "DOM.Iterable"],
"skipLibCheck": true,

/* Bundler mode */
Expand Down
4 changes: 2 additions & 2 deletions plugin-template/renderer/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"compilerOptions": {
"target": "ES2020",
"target": "ES2022",
"useDefineForClassFields": true,
"module": "ESNext",
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"lib": ["ES2022", "DOM", "DOM.Iterable"],
"skipLibCheck": true,

/* Bundler mode */
Expand Down
4 changes: 2 additions & 2 deletions plugins/discord/renderer/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"compilerOptions": {
"target": "ES2020",
"target": "ES2022",
"useDefineForClassFields": true,
"module": "ESNext",
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"lib": ["ES2022", "DOM", "DOM.Iterable"],
"skipLibCheck": true,

/* Bundler mode */
Expand Down
4 changes: 2 additions & 2 deletions plugins/elgato/renderer/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"compilerOptions": {
"target": "ES2020",
"target": "ES2022",
"useDefineForClassFields": true,
"module": "ESNext",
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"lib": ["ES2022", "DOM", "DOM.Iterable"],
"skipLibCheck": true,

/* Bundler mode */
Expand Down
4 changes: 2 additions & 2 deletions plugins/govee/renderer/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"compilerOptions": {
"target": "ES2020",
"target": "ES2022",
"useDefineForClassFields": true,
"module": "ESNext",
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"lib": ["ES2022", "DOM", "DOM.Iterable"],
"skipLibCheck": true,

/* Bundler mode */
Expand Down
4 changes: 2 additions & 2 deletions plugins/http/renderer/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"compilerOptions": {
"target": "ES2020",
"target": "ES2022",
"useDefineForClassFields": true,
"module": "ESNext",
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"lib": ["ES2022", "DOM", "DOM.Iterable"],
"skipLibCheck": true,

/* Bundler mode */
Expand Down
4 changes: 2 additions & 2 deletions plugins/input/renderer/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"compilerOptions": {
"target": "ES2020",
"target": "ES2022",
"useDefineForClassFields": true,
"module": "ESNext",
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"lib": ["ES2022", "DOM", "DOM.Iterable"],
"skipLibCheck": true,

/* Bundler mode */
Expand Down
4 changes: 2 additions & 2 deletions plugins/iot/renderer/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"compilerOptions": {
"target": "ES2020",
"target": "ES2022",
"useDefineForClassFields": true,
"module": "ESNext",
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"lib": ["ES2022", "DOM", "DOM.Iterable"],
"skipLibCheck": true,

/* Bundler mode */
Expand Down
4 changes: 2 additions & 2 deletions plugins/lifx/renderer/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"compilerOptions": {
"target": "ES2020",
"target": "ES2022",
"useDefineForClassFields": true,
"module": "ESNext",
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"lib": ["ES2022", "DOM", "DOM.Iterable"],
"skipLibCheck": true,

/* Bundler mode */
Expand Down
4 changes: 2 additions & 2 deletions plugins/minecraft/renderer/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"compilerOptions": {
"target": "ES2020",
"target": "ES2022",
"useDefineForClassFields": true,
"module": "ESNext",
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"lib": ["ES2022", "DOM", "DOM.Iterable"],
"skipLibCheck": true,

/* Bundler mode */
Expand Down
4 changes: 2 additions & 2 deletions plugins/obs/renderer/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"compilerOptions": {
"target": "ES2020",
"target": "ES2022",
"useDefineForClassFields": true,
"module": "ESNext",
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"lib": ["ES2022", "DOM", "DOM.Iterable"],
"skipLibCheck": true,

/* Bundler mode */
Expand Down
4 changes: 2 additions & 2 deletions plugins/os/renderer/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"compilerOptions": {
"target": "ES2020",
"target": "ES2022",
"useDefineForClassFields": true,
"module": "ESNext",
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"lib": ["ES2022", "DOM", "DOM.Iterable"],
"skipLibCheck": true,

/* Bundler mode */
Expand Down
4 changes: 2 additions & 2 deletions plugins/overlays/overlay/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"compilerOptions": {
"target": "ES2020",
"target": "ES2022",
"useDefineForClassFields": true,
"module": "ESNext",
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"lib": ["ES2022", "DOM", "DOM.Iterable"],
"skipLibCheck": true,

/* Bundler mode */
Expand Down
4 changes: 2 additions & 2 deletions plugins/overlays/renderer/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"compilerOptions": {
"target": "ES2020",
"target": "ES2022",
"useDefineForClassFields": true,
"module": "ESNext",
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"lib": ["ES2022", "DOM", "DOM.Iterable"],
"skipLibCheck": true,

/* Bundler mode */
Expand Down
4 changes: 2 additions & 2 deletions plugins/philips-hue/renderer/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"compilerOptions": {
"target": "ES2020",
"target": "ES2022",
"useDefineForClassFields": true,
"module": "ESNext",
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"lib": ["ES2022", "DOM", "DOM.Iterable"],
"skipLibCheck": true,

/* Bundler mode */
Expand Down
4 changes: 2 additions & 2 deletions plugins/random/overlay/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"compilerOptions": {
"target": "ES2020",
"target": "ES2022",
"useDefineForClassFields": true,
"module": "ESNext",
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"lib": ["ES2022", "DOM", "DOM.Iterable"],
"skipLibCheck": true,

/* Bundler mode */
Expand Down
Loading

0 comments on commit d934b71

Please sign in to comment.