0.0.2 • Published 3 years ago

vortex-ext-notices v0.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

Vortex Extensions Notices

A lightweight-ish library for Vortex extensions to add a basic "notices" feature similar to Vortex's built-in "announcements" feature. This consists of two-parts: adding this component to your extension and hosting a file/endpoint somewhere that your extension can communicate with to read announcements from.

Hosted Endpoint

Notices are read from an arbitrary URL that must return a correctly-formatted JSON document with the following structure:

{
    [key: string]: {
        title: string;
        message: string;
        body?: string;
    }
}

The key for each notice must be unique since this is how we track what notices a user has already acknowledged. The title is technically optional but strongly recommended and is used as the title shown to the user. The message is a plaintext field shown in the notification so should be quite short. The body is an optional field (HTML supported) that can be used to show a more detailed message to users if they click on the 'More..' option in the notice notification.

This document can be anywhere, but I personally use a CloudFlare Worker.

Extension

In your extension, you need to register two parts: the event handler and the reducer. The easiest way is to create a NoticeHandler and use its helpers:

// in your index.ts function
function main(context: IExtensionContext) {
    //create a handler with the game ID, endpoint URL, and an optional name
    var notices = NoticesHandler.create('beatsaber', 'https://beatvortex.dev/notices', 'BeatVortex');
    context.once(() => {
        // ... trimmed
        notices.registerEvent(context.api);
    });
    // ... trimmed
    context.registerReducer(notices.store.path, notices.store.reducer);
}

The event handler will then fire on the 'gamemode-activated'

0.0.2

3 years ago

0.0.1

3 years ago