-
Notifications
You must be signed in to change notification settings - Fork 51
/
apphost.js
231 lines (185 loc) · 6.13 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
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
define(['events'], function (events) {
'use strict';
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',
'externalappinfo',
'sleep',
//'restart',
'shutdown'
];
if (navigator.share) {
features.push('sharing');
}
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('externallinkdisplay');
features.push('externalpremium');
features.push('remotecontrol');
features.push('multiserver');
features.push('remoteaudio');
features.push('remotevideo');
features.push('screensaver');
features.push('targetblank');
features.push('otherapppromotions');
features.push('fileinput');
features.push('nativeblurayplayback');
features.push('nativedvdplayback');
features.push('subtitleappearancesettings');
features.push('displaylanguage');
features.push('keyboardsettings');
//features.push('chromecast');
features.push('serversetup');
return features;
}();
var appHost = {
getWindowState: getWindowState,
setWindowState: setWindowState,
supports: function (command) {
return supportedFeatures.indexOf(command.toLowerCase()) !== -1;
},
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
]
}
};
},
setTheme: function (themeSettings) {
var metaThemeColor = document.querySelector("meta[name=theme-color]");
if (metaThemeColor) {
metaThemeColor.setAttribute("content", themeSettings.themeColor);
}
},
setUserScalable: function (scalable) {
var att = scalable ?
'viewport-fit=cover, width=device-width, initial-scale=1, minimum-scale=1, user-scalable=yes' :
'viewport-fit=cover, 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 'https://github.com/MediaBrowser/Emby.Resources/raw/master/images/Logos/logoicon.png';
}
};
var visibilityChange;
var visibilityState;
var doc = self.document;
if (doc) {
if (typeof doc.visibilityState !== 'undefined') {
visibilityChange = 'visibilitychange';
visibilityState = 'hidden';
} else if (typeof doc.mozHidden !== 'undefined') {
visibilityChange = 'mozvisibilitychange';
visibilityState = 'mozVisibilityState';
} else if (typeof doc.msHidden !== 'undefined') {
visibilityChange = 'msvisibilitychange';
visibilityState = 'msVisibilityState';
} else if (typeof doc.webkitHidden !== 'undefined') {
visibilityChange = 'webkitvisibilitychange';
visibilityState = 'webkitVisibilityState';
}
}
var _isHidden = false;
function onAppVisible() {
if (_isHidden) {
_isHidden = false;
//console.log('triggering app resume event');
events.trigger(appHost, 'resume');
}
}
function onAppHidden() {
if (!_isHidden) {
_isHidden = true;
//console.log('app is hidden');
}
}
if (doc) {
doc.addEventListener(visibilityChange, function () {
if (document[visibilityState]) {
onAppHidden();
} else {
onAppVisible();
}
});
}
if (self.addEventListener) {
self.addEventListener('focus', onAppVisible);
self.addEventListener('blur', onAppHidden);
}
return appHost;
});