jmpUpdatePlugin.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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 (currentVersion.includes('pre')) return; // Do not notify for prereleases
  19. if (version == currentVersion) return;
  20. if (!/^[0-9.-]+$/.test(version)) return;
  21. try {
  22. await confirm({
  23. title: "Update Available",
  24. text: `Jellyfin Media Player version ${version} is available.`,
  25. cancelText: "Ignore",
  26. confirmText: "Download"
  27. });
  28. api.system.openExternalUrl(url);
  29. } catch (e) {
  30. // User cancelled update
  31. }
  32. }
  33. api.system.updateInfoEmitted.connect(onUpdateNotify);
  34. api.system.checkForUpdates();
  35. })();
  36. }
  37. }
  38. window._jmpUpdatePlugin = jmpUpdatePlugin;