forked from MediaBrowser/emby-theater-electron
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapphost.js
193 lines (150 loc) · 4.77 KB
/
apphost.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
define([], function () {
'use strict';
function getCapabilities() {
var caps = {
PlayableMediaTypes: ['Audio', 'Video'],
SupportsPersistentIdentifier: true
};
return Promise.resolve(caps);
}
function getWindowState() {
return document.windowState || 'Normal';
}
function setWindowState(state) {
// Normal
// Minimized
// Maximized
sendCommand('windowstate-' + state);
}
function sendCommand(name) {
var xhr = new XMLHttpRequest();
xhr.open('GET', 'electronapphost://' + name, true);
xhr.send();
}
function supportsVoiceInput() {
return window.SpeechRecognition ||
window.webkitSpeechRecognition ||
window.mozSpeechRecognition ||
window.oSpeechRecognition ||
window.msSpeechRecognition;
}
var supportedFeatures = function () {
var features = [
'windowstate',
'exit',
'runatstartup',
'filedownload',
'externallinks',
'sleep',
//'restart',
'shutdown'
];
if (navigator.share){
features.push('sharing');
}
if (appStartInfo.supportsTransparentWindow) {
features.push('windowtransparency');
}
if (supportsVoiceInput()) {
features.push('voiceinput');
}
if (self.ServiceWorkerSyncRegistered) {
features.push('sync');
}
features.push('youtube');
features.push('connectsignup');
features.push('soundeffects');
features.push('displaymode');
features.push('plugins');
features.push('skins');
features.push('exitmenu');
features.push('htmlaudioautoplay');
features.push('htmlvideoautoplay');
features.push('fullscreenchange');
features.push('displayableversion');
//features.push('remotecontrol');
features.push('multiserver');
features.push('imageanalysis');
features.push('remoteaudio');
features.push('remotevideo');
features.push('screensaver');
features.push('otherapppromotions');
features.push('fileinput');
features.push('nativeblurayplayback');
features.push('nativedvdplayback');
features.push('subtitleappearancesettings');
features.push('displaylanguage');
return features;
}();
return {
getWindowState: getWindowState,
setWindowState: setWindowState,
supports: function (command) {
return supportedFeatures.indexOf(command.toLowerCase()) !== -1;
},
capabilities: function () {
return {
PlayableMediaTypes: ['Audio', 'Video'],
SupportsPersistentIdentifier: true
};
},
getCapabilities: getCapabilities,
exit: function () {
sendCommand('exit');
},
sleep: function () {
sendCommand('sleep');
},
restart: function () {
sendCommand('restart');
},
shutdown: function () {
sendCommand('shutdown');
},
init: function () {
return Promise.resolve();
},
appName: function () {
return appStartInfo.name;
},
appVersion: function () {
return appStartInfo.version;
},
deviceName: function () {
return appStartInfo.deviceName;
},
deviceId: function () {
return appStartInfo.deviceId;
},
moreIcon: 'dots-vert',
getKeyOptions: function () {
return {
// chromium doesn't automatically handle these
handleAltLeftBack: true,
handleAltRightForward: true,
keyMaps: {
back: [
8,
// ESC
27
]
}
};
},
setThemeColor: function (color) {
var metaThemeColor = document.querySelector("meta[name=theme-color]");
if (metaThemeColor) {
metaThemeColor.setAttribute("content", color);
}
},
setUserScalable: function (scalable) {
var att = scalable ?
'width=device-width, initial-scale=1, minimum-scale=1, user-scalable=yes' :
'width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no';
document.querySelector('meta[name=viewport]').setAttribute('content', att);
},
deviceIconUrl: function () {
return null;
}
};
});