forked from sugarlabs/sugar-web
-
Notifications
You must be signed in to change notification settings - Fork 0
/
env.js
54 lines (44 loc) · 1.48 KB
/
env.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
define(function () {
'use strict';
var env = {};
env.getEnvironment = function (callback) {
// FIXME: we assume this code runs on the same thread as the
// javascript executed from sugar-toolkit-gtk3 (python)
if (env.isStandalone()) {
setTimeout(function () {
callback(null, {});
}, 0);
} else {
var environmentCallback = function () {
callback(null, window.top.sugar.environment);
};
if (window.top.sugar) {
setTimeout(function () {
environmentCallback();
}, 0);
} else {
window.top.sugar = {};
window.top.sugar.onEnvironmentSet = function () {
environmentCallback();
};
}
}
};
env.getObjectId = function (callback) {
env.getEnvironment(function (error, environment) {
callback(environment.objectId);
});
};
env.getURLScheme = function () {
return window.location.protocol;
};
env.isStandalone = function () {
var webActivityURLScheme = "activity:";
var currentURLScheme = env.getURLScheme();
// the control of hostname !== '0.0.0.0' is used
// for compatibility with F18 and webkit1
return currentURLScheme !== webActivityURLScheme &&
window.location.hostname !== '0.0.0.0';
};
return env;
});