nativeshell.js 10 KB

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