nativeshell.js 9.7 KB

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