nativeshell.js 10 KB

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