diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d7f94b6..c4e6a9b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -71,8 +71,9 @@ jobs: - name: Install, Build & Publish working-directory: lib env: - NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}} + NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}} run: | + echo "`jq \".version+=\\\"-$(git rev-parse --short HEAD)\\\"\" package.json`" > package.json && \ pnpm install && \ pnpm build && \ pnpm publish diff --git a/.npmrc b/.npmrc deleted file mode 100644 index 09e2ce3..0000000 --- a/.npmrc +++ /dev/null @@ -1 +0,0 @@ -@cebbinghaus:registry=https://npm.pkg.github.com \ No newline at end of file diff --git a/lib/package.json b/lib/package.json index ae3042d..ccb0a82 100644 --- a/lib/package.json +++ b/lib/package.json @@ -11,12 +11,9 @@ "files": [ "dist" ], - "scripts": { - "build": "tsc" - }, - "publishConfig": { - "registry": "https://npm.pkg.github.com" + "build": "tsc", + "watch": "tsc -w" }, "repository": { "type": "git", diff --git a/lib/src/state/MicoSDeckManager.tsx b/lib/src/state/MicoSDeckManager.ts similarity index 85% rename from lib/src/state/MicoSDeckManager.tsx rename to lib/src/state/MicoSDeckManager.ts index dd992e3..aa314fe 100644 --- a/lib/src/state/MicoSDeckManager.tsx +++ b/lib/src/state/MicoSDeckManager.ts @@ -15,35 +15,55 @@ export class MicroSDeckManager { public eventBus = new EventTarget(); private enabled: boolean = false; + public get Enabled() { + return this.enabled; + } private version: string | undefined; private currentCardAndGames: CardAndGames | undefined; + public get CurrentCardAndGames() { + return this.currentCardAndGames; + } private cardsAndGames: CardsAndGames = []; + public get CardsAndGames() { + return this.cardsAndGames; + } private pollLock: any | undefined; - init(props: { logger?: Logger, url: string }) { + private isDestructed = false; + + constructor(props: { logger?: Logger, url: string }) { this.logger = props.logger; this.logger?.Log("Initializing MicroSDeckManager"); this.fetchProps = props; - this.init = () => { throw "Do Not call init more than once"; }; this.fetch(); this.subscribeToUpdates(); } - deinit() { + destruct() { + if(this.isDestructed)return; + this.isDestructed = true; this.logger?.Log("Deinitializing MicroSDeckManager"); - this.abortController.abort("deinit"); + this.abortController.abort("destruct"); } async fetch() { this.enabled = await fetchHealth(this.fetchProps); this.version = await fetchVersion(this.fetchProps); + + await this.fetchCurrent(); + await this.fetchCardsAndGames(); + this.eventBus.dispatchEvent(new Event("update")); + } + + async fetchCurrent(){ this.currentCardAndGames = await fetchCurrentCardAndGames(this.fetchProps); + } + async fetchCardsAndGames(){ this.cardsAndGames = await fetchCardsAndGames(this.fetchProps) || []; - this.eventBus.dispatchEvent(new Event("update")); } getProps() { @@ -55,7 +75,7 @@ export class MicroSDeckManager { } } - async subscribeToUpdates() { + private async subscribeToUpdates() { let signal = this.abortController.signal; let sleepDelay = 500; diff --git a/src/index.tsx b/src/index.tsx index f67acc8..f684777 100755 --- a/src/index.tsx +++ b/src/index.tsx @@ -156,17 +156,16 @@ function Content(){ ); }; +declare global { + var MicroSDeck: MicroSDeckManager | undefined; +} + export default definePlugin((serverApi: ServerAPI) => { serverApi.routerHook.addRoute(DOCUMENTATION_PATH, DocumentationPage, { exact: true, }); - const microSDeckManager = new MicroSDeckManager(); - - //@ts-ignore ssshhhh 🤫 - window.MicroSDeck = microSDeckManager; - - microSDeckManager.init({logger: Logger, url: API_URL}); + const microSDeckManager = window.MicroSDeck = (window.MicroSDeck || new MicroSDeckManager({url: API_URL})); DeckyAPI.SetApi(serverApi); @@ -187,7 +186,7 @@ export default definePlugin((serverApi: ServerAPI) => { //@ts-ignore window.MicroSDeck = null; - microSDeckManager.deinit(); + microSDeckManager.destruct(); }, }; });