nativeshell.js 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. const viewdata = JSON.parse(window.atob("@@data@@"));
  2. const features = [
  3. "filedownload",
  4. "displaylanguage",
  5. "htmlaudioautoplay",
  6. "htmlvideoautoplay",
  7. "externallinks",
  8. "clientsettings",
  9. "multiserver",
  10. "remotecontrol",
  11. "fullscreenchange",
  12. "filedownload",
  13. "remotevideo",
  14. "displaymode",
  15. "screensaver",
  16. "fileinput"
  17. ];
  18. const plugins = [
  19. 'mpvVideoPlayer',
  20. 'mpvAudioPlayer',
  21. 'jmpInputPlugin',
  22. 'jmpUpdatePlugin'
  23. ];
  24. function loadScript(src) {
  25. return new Promise((resolve, reject) => {
  26. const s = document.createElement('script');
  27. s.src = src;
  28. s.onload = resolve;
  29. s.onerror = reject;
  30. document.head.appendChild(s);
  31. });
  32. }
  33. // Add plugin loaders
  34. for (const plugin of plugins) {
  35. window[plugin] = async () => {
  36. await loadScript(`${viewdata.scriptPath}${plugin}.js`);
  37. return window["_" + plugin];
  38. };
  39. }
  40. window.NativeShell = {
  41. openUrl(url, target) {
  42. window.api.system.openExternalUrl(url);
  43. },
  44. downloadFile(downloadInfo) {
  45. window.api.system.openExternalUrl(downloadInfo.url);
  46. },
  47. openClientSettings() {
  48. showSettingsModal();
  49. },
  50. getPlugins() {
  51. return plugins;
  52. }
  53. };
  54. function getDeviceProfile() {
  55. return {
  56. 'Name': 'Jellyfin Media Player',
  57. 'MusicStreamingTranscodingBitrate': 1280000,
  58. 'TimelineOffsetSeconds': 5,
  59. 'TranscodingProfiles': [
  60. {'Type': 'Audio'},
  61. {
  62. 'Container': 'ts',
  63. 'Type': 'Video',
  64. 'Protocol': 'hls',
  65. 'AudioCodec': 'aac,mp3,ac3,opus,flac,vorbis',
  66. 'VideoCodec': 'h264,h265,hevc,mpeg4,mpeg2video',
  67. 'MaxAudioChannels': '6'
  68. },
  69. {'Container': 'jpeg', 'Type': 'Photo'}
  70. ],
  71. 'DirectPlayProfiles': [{'Type': 'Video'}, {'Type': 'Audio'}, {'Type': 'Photo'}],
  72. 'ResponseProfiles': [],
  73. 'ContainerProfiles': [],
  74. 'CodecProfiles': [],
  75. 'SubtitleProfiles': [
  76. {'Format': 'srt', 'Method': 'External'},
  77. {'Format': 'srt', 'Method': 'Embed'},
  78. {'Format': 'ass', 'Method': 'External'},
  79. {'Format': 'ass', 'Method': 'Embed'},
  80. {'Format': 'sub', 'Method': 'Embed'},
  81. {'Format': 'sub', 'Method': 'External'},
  82. {'Format': 'ssa', 'Method': 'Embed'},
  83. {'Format': 'ssa', 'Method': 'External'},
  84. {'Format': 'smi', 'Method': 'Embed'},
  85. {'Format': 'smi', 'Method': 'External'},
  86. {'Format': 'pgssub', 'Method': 'Embed'},
  87. {'Format': 'dvdsub', 'Method': 'Embed'},
  88. {'Format': 'pgs', 'Method': 'Embed'}
  89. ]
  90. };
  91. }
  92. async function createApi() {
  93. await loadScript('qrc:///qtwebchannel/qwebchannel.js');
  94. const channel = await new Promise((resolve) => {
  95. /*global QWebChannel */
  96. new QWebChannel(window.qt.webChannelTransport, resolve);
  97. });
  98. return channel.objects;
  99. }
  100. window.NativeShell.AppHost = {
  101. init() {
  102. window.apiPromise = createApi();
  103. (async () => {
  104. window.api = await window.apiPromise;
  105. })();
  106. },
  107. getDefaultLayout() {
  108. return viewdata.mode;
  109. },
  110. supports(command) {
  111. return features.includes(command.toLowerCase());
  112. },
  113. getDeviceProfile,
  114. getSyncProfile: getDeviceProfile,
  115. appName() {
  116. return "Jellyfin Media Player";
  117. },
  118. appVersion() {
  119. return navigator.userAgent.split(" ")[1];
  120. },
  121. deviceName() {
  122. return viewdata.deviceName;
  123. }
  124. };
  125. async function showSettingsModal() {
  126. let settings = await new Promise(resolve => {
  127. window.api.settings.settingDescriptions(resolve);
  128. });
  129. const modalContainer = document.createElement("div");
  130. modalContainer.className = "dialogContainer";
  131. modalContainer.style.backgroundColor = "rgba(0,0,0,0.5)";
  132. modalContainer.addEventListener("click", e => {
  133. if (e.target == modalContainer) {
  134. modalContainer.remove();
  135. }
  136. });
  137. document.body.appendChild(modalContainer);
  138. const modalContainer2 = document.createElement("div");
  139. modalContainer2.className = "focuscontainer dialog dialog-fixedSize dialog-small formDialog opened";
  140. modalContainer.appendChild(modalContainer2);
  141. const modalHeader = document.createElement("div");
  142. modalHeader.className = "formDialogHeader";
  143. modalContainer2.appendChild(modalHeader);
  144. const title = document.createElement("h3");
  145. title.className = "formDialogHeaderTitle";
  146. title.textContent = "Jellyfin Media Player Settings";
  147. modalHeader.appendChild(title);
  148. const modalContents = document.createElement("div");
  149. modalContents.className = "formDialogContent smoothScrollY";
  150. modalContents.style.paddingTop = "2em";
  151. modalContents.style.marginBottom = "6.2em";
  152. modalContainer2.appendChild(modalContents);
  153. for (let section of settings) {
  154. const group = document.createElement("fieldset");
  155. group.className = "editItemMetadataForm editMetadataForm dialog-content-centered";
  156. group.style.border = 0;
  157. group.style.outline = 0;
  158. modalContents.appendChild(group);
  159. const createSection = async (clear) => {
  160. if (clear) {
  161. group.innerHTML = "";
  162. }
  163. const values = await new Promise(resolve => {
  164. window.api.settings.allValues(section.key, resolve);
  165. });
  166. const legend = document.createElement("legend");
  167. const legendHeader = document.createElement("h2");
  168. legendHeader.textContent = section.key;
  169. legendHeader.style.textTransform = "capitalize";
  170. legend.appendChild(legendHeader);
  171. group.appendChild(legend);
  172. for (const setting of section.settings) {
  173. const label = document.createElement("label");
  174. label.className = "inputContainer";
  175. label.style.marginBottom = "1.8em";
  176. label.style.display = "block";
  177. label.style.textTransform = "capitalize";
  178. if (setting.options) {
  179. const safeValues = {};
  180. const control = document.createElement("select");
  181. control.className = "emby-select-withcolor emby-select";
  182. for (const option of setting.options) {
  183. safeValues[String(option.value)] = option.value;
  184. const opt = document.createElement("option");
  185. opt.value = option.value;
  186. opt.selected = option.value == values[setting.key];
  187. let optionName = option.title;
  188. const swTest = `${section.key}.${setting.key}.`;
  189. const swTest2 = `${section.key}.`;
  190. if (optionName.startsWith(swTest)) {
  191. optionName = optionName.substring(swTest.length);
  192. } else if (optionName.startsWith(swTest2)) {
  193. optionName = optionName.substring(swTest2.length);
  194. }
  195. opt.appendChild(document.createTextNode(optionName));
  196. control.appendChild(opt);
  197. }
  198. control.addEventListener("change", async (e) => {
  199. await new Promise(resolve => {
  200. window.api.settings.setValue(section.key, setting.key, safeValues[e.target.value], resolve);
  201. });
  202. if (setting.key == "devicetype") {
  203. section = (await new Promise(resolve => {
  204. window.api.settings.settingDescriptions(resolve);
  205. })).filter(x => x.key == section.key)[0];
  206. createSection(true);
  207. }
  208. });
  209. const labelText = document.createElement('label');
  210. labelText.className = "inputLabel";
  211. labelText.textContent = setting.key + ": ";
  212. label.appendChild(labelText);
  213. label.appendChild(control);
  214. } else {
  215. const control = document.createElement("input");
  216. control.type = "checkbox";
  217. control.checked = values[setting.key];
  218. control.addEventListener("change", e => {
  219. window.api.settings.setValue(section.key, setting.key, e.target.checked);
  220. });
  221. label.appendChild(control);
  222. label.appendChild(document.createTextNode(" " + setting.key));
  223. }
  224. group.appendChild(label);
  225. }
  226. };
  227. createSection();
  228. }
  229. const closeContainer = document.createElement("div");
  230. closeContainer.className = "formDialogFooter";
  231. modalContents.appendChild(closeContainer);
  232. const close = document.createElement("button");
  233. close.className = "raised button-cancel block btnCancel formDialogFooterItem emby-button";
  234. close.textContent = "Close"
  235. close.addEventListener("click", () => {
  236. modalContainer.remove();
  237. });
  238. closeContainer.appendChild(close);
  239. }