jmpUpdatePlugin.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. class jmpUpdatePlugin {
  2. constructor({ confirm, toast }) {
  3. this.name = 'JMP Update Plugin';
  4. this.type = 'input';
  5. this.id = 'jmpUpdatePlugin';
  6. (async () => {
  7. const api = await window.apiPromise;
  8. const checkForUpdates = await new Promise(resolve => {
  9. api.settings.value("main", "checkForUpdates", resolve);
  10. });
  11. if (!checkForUpdates) return;
  12. const checkUrl = "https://github.com/jellyfin/jellyfin-media-player/releases/latest";
  13. const url = (await fetch(checkUrl)).url;
  14. const urlSegments = url.split("/");
  15. const version = urlSegments[urlSegments.length - 1].substring(1);
  16. const currentVersion = navigator.userAgent.split(" ")[1];
  17. if (version == currentVersion) return;
  18. if (!/^[0-9.-]+$/.test(version)) return;
  19. try {
  20. await confirm({
  21. title: "Update Available",
  22. text: `Jellyfin Media Player version ${version} is available.`,
  23. cancelText: "Ignore",
  24. confirmText: "Download"
  25. });
  26. api.system.openExternalUrl(url);
  27. } catch (e) {
  28. // User cancelled update
  29. }
  30. })();
  31. }
  32. }
  33. window._jmpUpdatePlugin = jmpUpdatePlugin;