lisonge/vite-plugin-monkey

Add support for auto check for script update

Closed this issue · 2 comments

I believe this plugin is the best place to add this feature, let me know if you agree otherwise I'll create a new plugin.

Feature description

Many times the auto-update gets failed on extension level or user has that turned off. Due to this, critical script updates gets skipped. There must be a feature, which will add a function in the script on build which will check for script update in background.

How will it work

  1. if monkey.autoUpdate is true then a function will be added at the end of the script.
  2. This method will be executed with script load.
  3. This will hit an AJAX to the monkey.userscript.updateUrl || monkey.userscript.downloadUrl || monkey.userscript.download.
  4. It will parse the output of the request and extract Userscript meta for version and downloadUrl.
  5. If a newer version is available then the downloadUrl is opened in new tab to open extension page to update the script.

Usage

export default defineConfig({
  plugins: [
    monkey({
        // ... Other configs
        autoUpdate: {
            checkFrequency: 1800000,
            debug: true
        }
    })
  ]
});

Options

  • autoUpdate: false, true, or object containing below keys
    • checkFrequency: time difference in ms to check for update next time (default can be 0 to check for update every time)
    • debug: boolean to print console debug logs for statements like "checking for update", "Update found", "Updating..." etc.

Optimization

  • The checkFrequency time can be stored in script config instead of localstorage.
  • We can store the script version in script config if a newer version is found. We'll first check this value and will not hit ajax to check for update if this is a newer version to save some ajax hits.

If you agree this feature worths to add, I'd like to contribute

This feature does not seem to be necessary to implement within this plugin project, as it is just simple script self-update logic and has no relevance to build tools.

Makes sense, should not be part of a build tool. Thanks. I'll check to add it via a separate project.