-
-
Notifications
You must be signed in to change notification settings - Fork 345
/
Copy pathnativeshell.js
359 lines (328 loc) · 12.6 KB
/
nativeshell.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
const viewdata = JSON.parse(window.atob("@@data@@"));
const features = [
"filedownload",
"displaylanguage",
"htmlaudioautoplay",
"htmlvideoautoplay",
"externallinks",
"clientsettings",
"multiserver",
"exitmenu",
"remotecontrol",
"fullscreenchange",
"filedownload",
"remotevideo",
"displaymode",
"screensaver",
"fileinput"
];
const plugins = [
'mpvVideoPlayer',
'mpvAudioPlayer',
'jmpInputPlugin',
'jmpUpdatePlugin',
'jellyscrubPlugin',
'skipIntroPlugin'
];
function loadScript(src) {
return new Promise((resolve, reject) => {
const s = document.createElement('script');
s.src = src;
s.onload = resolve;
s.onerror = reject;
document.head.appendChild(s);
});
}
// Add plugin loaders
for (const plugin of plugins) {
window[plugin] = async () => {
await loadScript(`${viewdata.scriptPath}${plugin}.js`);
return window["_" + plugin];
};
}
window.NativeShell = {
openUrl(url, target) {
window.api.system.openExternalUrl(url);
},
downloadFile(downloadInfo) {
window.api.system.openExternalUrl(downloadInfo.url);
},
openClientSettings() {
showSettingsModal();
},
getPlugins() {
return plugins;
}
};
function getDeviceProfile() {
const CodecProfiles = [
{
'Type': 'Video',
'Conditions': [
{
'Condition': 'NotEquals',
'Property': 'VideoRangeType',
'Value': 'DOVI'
}
]
}
];
if (viewdata.force_transcode_hdr) {
CodecProfiles.push({
'Type': 'Video',
'Conditions': [
{
'Condition': 'Equals',
'Property': 'VideoRangeType',
'Value': 'SDR'
}
]
});
}
return {
'Name': 'Jellyfin Media Player',
'MaxStaticBitrate': 1000000000,
'MusicStreamingTranscodingBitrate': 1280000,
'TimelineOffsetSeconds': 5,
'TranscodingProfiles': [
{'Type': 'Audio'},
{
'Container': 'ts',
'Type': 'Video',
'Protocol': 'hls',
'AudioCodec': 'aac,mp3,ac3,opus,flac,vorbis',
'VideoCodec': viewdata.allow_transcode_to_hevc
? 'h264,h265,hevc,mpeg4,mpeg2video'
: 'h264,mpeg4,mpeg2video',
'MaxAudioChannels': '6'
},
{'Container': 'jpeg', 'Type': 'Photo'}
],
'DirectPlayProfiles': [{'Type': 'Video'}, {'Type': 'Audio'}, {'Type': 'Photo'}],
'ResponseProfiles': [],
'ContainerProfiles': [],
CodecProfiles,
'SubtitleProfiles': [
{'Format': 'srt', 'Method': 'External'},
{'Format': 'srt', 'Method': 'Embed'},
{'Format': 'ass', 'Method': 'External'},
{'Format': 'ass', 'Method': 'Embed'},
{'Format': 'sub', 'Method': 'Embed'},
{'Format': 'sub', 'Method': 'External'},
{'Format': 'ssa', 'Method': 'Embed'},
{'Format': 'ssa', 'Method': 'External'},
{'Format': 'smi', 'Method': 'Embed'},
{'Format': 'smi', 'Method': 'External'},
{'Format': 'pgssub', 'Method': 'Embed'},
{'Format': 'dvdsub', 'Method': 'Embed'},
{'Format': 'dvbsub', 'Method': 'Embed'},
{'Format': 'pgs', 'Method': 'Embed'}
]
};
}
async function createApi() {
try {
await loadScript('qrc:///qtwebchannel/qwebchannel.js');
} catch (e) {
// try clearing out any cached CSPs
let foundCache = false;
for (const cache of await caches.keys()) {
const dataDeleted = await caches.delete(cache);
if (dataDeleted) {
foundCache = true;
}
}
if (foundCache) {
window.location.reload();
}
throw e;
}
const channel = await new Promise((resolve) => {
/*global QWebChannel */
new QWebChannel(window.qt.webChannelTransport, resolve);
});
return channel.objects;
}
window.NativeShell.AppHost = {
init() {
window.apiPromise = createApi();
(async () => {
window.api = await window.apiPromise;
})();
},
getDefaultLayout() {
return viewdata.mode;
},
supports(command) {
return features.includes(command.toLowerCase());
},
getDeviceProfile,
getSyncProfile: getDeviceProfile,
appName() {
return "Jellyfin Media Player";
},
appVersion() {
return navigator.userAgent.split(" ")[1];
},
deviceName() {
return viewdata.deviceName;
},
exit() {
window.api.system.exit();
}
};
async function showSettingsModal() {
let settings = await new Promise(resolve => {
window.api.settings.settingDescriptions(resolve);
});
const modalContainer = document.createElement("div");
modalContainer.className = "dialogContainer";
modalContainer.style.backgroundColor = "rgba(0,0,0,0.5)";
modalContainer.addEventListener("click", e => {
if (e.target == modalContainer) {
modalContainer.remove();
}
});
document.body.appendChild(modalContainer);
const modalContainer2 = document.createElement("div");
modalContainer2.className = "focuscontainer dialog dialog-fixedSize dialog-small formDialog opened";
modalContainer.appendChild(modalContainer2);
const modalHeader = document.createElement("div");
modalHeader.className = "formDialogHeader";
modalContainer2.appendChild(modalHeader);
const title = document.createElement("h3");
title.className = "formDialogHeaderTitle";
title.textContent = "Jellyfin Media Player Settings";
modalHeader.appendChild(title);
const modalContents = document.createElement("div");
modalContents.className = "formDialogContent smoothScrollY";
modalContents.style.paddingTop = "2em";
modalContents.style.marginBottom = "6.2em";
modalContainer2.appendChild(modalContents);
for (let section of settings) {
const group = document.createElement("fieldset");
group.className = "editItemMetadataForm editMetadataForm dialog-content-centered";
group.style.border = 0;
group.style.outline = 0;
modalContents.appendChild(group);
const createSection = async (clear) => {
if (clear) {
group.innerHTML = "";
}
const values = await new Promise(resolve => {
window.api.settings.allValues(section.key, resolve);
});
const legend = document.createElement("legend");
const legendHeader = document.createElement("h2");
legendHeader.textContent = section.key;
legendHeader.style.textTransform = "capitalize";
legend.appendChild(legendHeader);
if (section.key == "plugins") {
const legendSubHeader = document.createElement("h4");
legendSubHeader.textContent = "Plugins are UNOFFICIAL and require a restart to take effect.";
legend.appendChild(legendSubHeader);
}
group.appendChild(legend);
for (const setting of section.settings) {
const label = document.createElement("label");
label.className = "inputContainer";
label.style.marginBottom = "1.8em";
label.style.display = "block";
label.style.textTransform = "capitalize";
if (setting.options) {
const safeValues = {};
const control = document.createElement("select");
control.className = "emby-select-withcolor emby-select";
for (const option of setting.options) {
safeValues[String(option.value)] = option.value;
const opt = document.createElement("option");
opt.value = option.value;
opt.selected = option.value == values[setting.key];
let optionName = option.title;
const swTest = `${section.key}.${setting.key}.`;
const swTest2 = `${section.key}.`;
if (optionName.startsWith(swTest)) {
optionName = optionName.substring(swTest.length);
} else if (optionName.startsWith(swTest2)) {
optionName = optionName.substring(swTest2.length);
}
opt.appendChild(document.createTextNode(optionName));
control.appendChild(opt);
}
control.addEventListener("change", async (e) => {
await new Promise(resolve => {
window.api.settings.setValue(section.key, setting.key, safeValues[e.target.value], resolve);
});
if (setting.key == "devicetype") {
section = (await new Promise(resolve => {
window.api.settings.settingDescriptions(resolve);
})).filter(x => x.key == section.key)[0];
createSection(true);
}
});
const labelText = document.createElement('label');
labelText.className = "inputLabel";
labelText.textContent = setting.key + ": ";
label.appendChild(labelText);
label.appendChild(control);
} else {
const control = document.createElement("input");
control.type = "checkbox";
control.checked = values[setting.key];
control.addEventListener("change", e => {
window.api.settings.setValue(section.key, setting.key, e.target.checked);
});
label.appendChild(control);
label.appendChild(document.createTextNode(" " + setting.key));
}
group.appendChild(label);
}
};
createSection();
}
const savedServer = await new Promise(resolve => {
window.api.settings.value('main', 'userWebClient', resolve);
});
if (savedServer) {
const group = document.createElement("fieldset");
group.className = "editItemMetadataForm editMetadataForm dialog-content-centered";
group.style.border = 0;
group.style.outline = 0;
modalContents.appendChild(group);
const legend = document.createElement("legend");
const legendHeader = document.createElement("h2");
legendHeader.textContent = "Saved Server";
legend.appendChild(legendHeader);
const legendSubHeader = document.createElement("h4");
legendSubHeader.textContent = (
"The server you first connected to is your saved server. " +
"It provides the web client for Jellyfin Media Player in the absence of a bundled one. " +
"You can use this option to change it to another one. This does NOT log you off."
);
legend.appendChild(legendSubHeader);
group.appendChild(legend);
const resetSavedServer = document.createElement("button");
resetSavedServer.className = "raised button-cancel block btnCancel emby-button";
resetSavedServer.textContent = "Reset Saved Server"
resetSavedServer.style.marginLeft = "auto";
resetSavedServer.style.marginRight = "auto";
resetSavedServer.style.maxWidth = "50%";
resetSavedServer.addEventListener("click", async () => {
await new Promise(resolve => {
window.api.settings.setValue('main', 'userWebClient', '', resolve);
});
window.location.href = viewdata.scriptPath + "/find-webclient.html";
});
group.appendChild(resetSavedServer);
}
const closeContainer = document.createElement("div");
closeContainer.className = "formDialogFooter";
modalContents.appendChild(closeContainer);
const close = document.createElement("button");
close.className = "raised button-cancel block btnCancel formDialogFooterItem emby-button";
close.textContent = "Close"
close.addEventListener("click", () => {
modalContainer.remove();
});
closeContainer.appendChild(close);
}