jmpUpdatePlugin.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. class jmpUpdatePlugin {
  2. constructor({ confirm }) {
  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. // wait 3 seconds before showing the dialog to prevent race conditions
  23. await new Promise(resolve => setTimeout(resolve, 3000));
  24. await confirm({
  25. title: "Update Available",
  26. text: `Jellyfin Media Player version ${version} is available.`,
  27. cancelText: "Ignore",
  28. confirmText: "Download"
  29. });
  30. api.system.openExternalUrl(url);
  31. } catch (e) {
  32. // User cancelled update
  33. }
  34. }
  35. api.system.updateInfoEmitted.connect(onUpdateNotify);
  36. api.system.checkForUpdates();
  37. })();
  38. }
  39. }
  40. window._jmpUpdatePlugin = jmpUpdatePlugin;