Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
sugar-web/env.js /
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
54 lines (44 sloc)
1.48 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | |
| }); |