Skip to content

Add options api #17

@ego-lay-atman-bay

Description

@ego-lay-atman-bay

One thing that I feel some addons benefit from are options. For example, a addon that whitelists extension urls.

return {
    // Metadata
    id: "example-mod", // the id of the mod
    name: "Example Mod", // human-readable name
    description: "A example mod for CrackleSDK.", // description
    version: "1.0", // version
    author: "Your Name", // author
    depends: [], // dependencies (mod ids, useful for libraries)
    doMenu: true, // whether to add a menu item
    
    options: {
      extensionUrls: [],
    },
    
    optionsDialog(dialogBody: Morph) {
      this.options.extensionUrls.push('https://ego-lay-atman-bay.github.io/snap-extensions/')
    },

    // Main function - gets ran when the mod is loaded
    main(api) {
      for (let url of this.options.extensionUrls) {
        SnapExtensions.urls.push(url)
      }
    },

    // Cleanup functions - get ran when the mod is "deleted"
    cleanupFuncs: [
      () => {
        SnapExtensions.urls = SnapExtensions.urls.filter(url => !this.options.extensionUrls.includes(url))
      }
    ],
}

options is the default options, and optionsDialog is the function used to build the options dialog. Since I know you probably don't want to have to deal with coming up with a system to handle every configuration, I think it would be best to have the addon developer build their own dialog. Now, I feel like this dialog should always have 3 buttons at the bottom, ok, apply, and cancel. The argument to the function should just be the dialog body morph that the dev can just build it like any morph.

I'm not entirely sure how the lifecycle will be. When the options are applied, should it run cleanup and then main again, or run main again but with some property somewhere set to indicate that the options were just changed.

As you might be able to tell, I'm pretty enthusiastic about this project. I have a couple userscripts that I would love to move over once crackle is stable. I'm also currently working on a couple other large projects, so right now I can only just give suggestions and pseudo-code.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions