nativeshell.js 9.3 KB

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