jmpUpdatePlugin.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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. const urlSegments = url.split("/");
  10. const version = urlSegments[urlSegments.length - 1].substring(1);
  11. const currentVersion = navigator.userAgent.split(" ")[1];
  12. if (version == currentVersion) return;
  13. if (!/^[0-9.-]+$/.test(version)) return;
  14. try {
  15. await confirm({
  16. title: "Update Available",
  17. text: `Jellyfin Media Player version ${version} is available.`,
  18. cancelText: "Ignore",
  19. confirmText: "Download"
  20. });
  21. api.system.openExternalUrl(url);
  22. } catch (e) {
  23. // User cancelled update
  24. }
  25. }
  26. api.system.updateInfoEmitted.connect(onUpdateNotify);
  27. api.system.checkForUpdates();
  28. })();
  29. }
  30. }
  31. window._jmpUpdatePlugin = jmpUpdatePlugin;