forked from sugarlabs/musicblocks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsugarizer-compatibility.js
109 lines (96 loc) · 3.38 KB
/
sugarizer-compatibility.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
// Copyright (c) 2015-20 Walter Bender
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the The GNU Affero General Public
// License as published by the Free Software Foundation; either
// version 3 of the License, or (at your option) any later version.
//
// You should have received a copy of the GNU Affero General Public
// License along with this library; if not, write to the Free Software
// Foundation, 51 Franklin Street, Suite 500 Boston, MA 02110-1335 USA
define([
"sugar-web/env",
"sugar-web/activity/activity",
"sugar-web/datastore"
], function(env, activity, datastore) {
const sugarizerCompatibility = {
activity: activity,
data: { allProjects: "[]" },
env: env,
xoColor: {
stroke: "#00A0FF",
fill: "#8BFF7A"
},
saveLocally: function(callback) {
const that = this;
activity.getDatastoreObject().setDataAsText(JSON.stringify(
that.data));
activity.getDatastoreObject().save(function() {
if (callback) {
callback();
}
});
},
isInsideSugarizer: function() {
// Work-around since MB is not part of Sugarizier but if
// someone has the env set, it breaks MB. return
// env.isSugarizer();
return false;
},
loadData: function(callback) {
const that = this;
activity
.getDatastoreObject()
.loadAsText(function(error, metadata, jsonData) {
if (jsonData !== undefined && jsonData !== null) {
that.data = JSON.parse(jsonData);
}
if (metadata.buddy_color) {
that.xoColor = metadata.buddy_color;
}
if (callback !== undefined) {
callback();
}
});
},
hideLoading: function() {
const imageLoading = document.getElementById(
"loading-image-container"
);
imageLoading.style.display = "none";
},
sugarizerStop: function() {
document.getElementById("stop-button").click();
},
getLanguage: function() {
const defaultSettings = {
name: "",
language:
typeof chrome != "undefined" &&
chrome.app &&
chrome.app.runtime
? chrome.i18n.getUILanguage()
: navigator.language
};
if (!env.isSugarizer()) {
callback();
return defaultSettings.language;
}
const loadedSettings = datastore.localStorage.getValue(
"sugar_settings"
);
return loadedSettings.language;
},
setup: function() {
console.debug("insideSugarizer? " + this.isInsideSugarizer());
if (this.isInsideSugarizer() === false) {
return;
}
this.hideLoading();
activity.setup();
}
};
window.sugarizerCompatibility = sugarizerCompatibility;
sugarizerCompatibility.setup();
return sugarizerCompatibility;
});