jmpUpdatePlugin.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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 onUpdateNotify = async (url) => {
  9. if (url == "SSL_UNAVAILABLE") {
  10. // Windows (and possibly macOS) don't ship with SSL in QT......
  11. // So we get to do a full request to GitHub here :(
  12. const checkUrl = "https://github.com/jellyfin/jellyfin-media-player/releases/latest";
  13. url = (await fetch(checkUrl)).url;
  14. }
  15. const urlSegments = url.split("/");
  16. const version = urlSegments[urlSegments.length - 1].substring(1);
  17. const currentVersion = navigator.userAgent.split(" ")[1];
  18. if (version == currentVersion) return;
  19. if (!/^[0-9.-]+$/.test(version)) return;
  20. try {
  21. await confirm({
  22. title: "Update Available",
  23. text: `Jellyfin Media Player version ${version} is available.`,
  24. cancelText: "Ignore",
  25. confirmText: "Download"
  26. });
  27. api.system.openExternalUrl(url);
  28. } catch (e) {
  29. // User cancelled update
  30. }
  31. }
  32. api.system.updateInfoEmitted.connect(onUpdateNotify);
  33. api.system.checkForUpdates();
  34. })();
  35. }
  36. }
  37. window._jmpUpdatePlugin = jmpUpdatePlugin;