Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moved to Npm Registry & Cleaned up Package #6

Merged
merged 1 commit into from
Oct 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion .npmrc

This file was deleted.

7 changes: 2 additions & 5 deletions lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,9 @@
"files": [
"dist"
],

"scripts": {
"build": "tsc"
},
"publishConfig": {
"registry": "https://npm.pkg.github.com"
"build": "tsc",
"watch": "tsc -w"
},
"repository": {
"type": "git",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -55,7 +75,7 @@ export class MicroSDeckManager {
}
}

async subscribeToUpdates() {
private async subscribeToUpdates() {
let signal = this.abortController.signal;

let sleepDelay = 500;
Expand Down
13 changes: 6 additions & 7 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -187,7 +186,7 @@ export default definePlugin((serverApi: ServerAPI) => {

//@ts-ignore
window.MicroSDeck = null;
microSDeckManager.deinit();
microSDeckManager.destruct();
},
};
});