Skip to content

Commit

Permalink
Fix on getSettings/localStorage for Chrome OS version
Browse files Browse the repository at this point in the history
  • Loading branch information
llaske committed Jan 5, 2017
1 parent 471a286 commit 3fa165a
Show file tree
Hide file tree
Showing 15 changed files with 841 additions and 841 deletions.
29 changes: 12 additions & 17 deletions activities/ChatPrototype.activity/js/loader.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,33 @@
var l10n_s;

requirejs.config({
baseUrl: "lib",
paths: {
activity: "../js"
}
baseUrl: "lib",
paths: {
activity: "../js"
}
});

requirejs(["activity/activity"]);

requirejs(["webL10n","sugar-web/env"], function(l10n, env) {
l10n_s = l10n; //global declaration of translate interface
requirejs(["webL10n","sugar-web/env","sugar-web/datastore"], function(l10n, env ,datastore) {
l10n_s = l10n; //global declaration of translate interface

getSettings(function(settings) { //globally setting language from sugar settings
datastore.localStorage.load(function() {
getSettings(function(settings) { //globally setting language from sugar settings
l10n_s.language.code = settings.language;
});
});

function getSettings(callback) {
var defaultSettings = {
name: "",
language: navigator.language
language: (typeof chrome != 'undefined' && chrome.app && chrome.app.runtime) ? chrome.i18n.getUILanguage() : navigator.language
};
if (!env.isSugarizer()) {
callback(defaultSettings);
return;
}
if (typeof chrome != 'undefined' && chrome.app && chrome.app.runtime) {
var loadedSettings = JSON.parse(values.sugar_settings);
chrome.storage.local.get('sugar_settings', function(values) {
callback(loadedSettings);
});
} else {
var loadedSettings = JSON.parse(localStorage.sugar_settings);
callback(loadedSettings);
}
loadedSettings = datastore.localStorage.getValue('sugar_settings');
callback(loadedSettings);
}
});
2 changes: 1 addition & 1 deletion activities/Clock.activity/js/activity.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
define(["sugar-web/activity/activity","sugar-web/graphics/radiobuttonsgroup","mustache","moment-with-locales.min"], function (activity,radioButtonsGroup,mustache,moment) {
define(["sugar-web/activity/activity","sugar-web/graphics/radiobuttonsgroup","mustache","moment-with-locales.min","webL10n"], function (activity,radioButtonsGroup,mustache,moment) {

// Manipulate the DOM only when it is ready.
require(['domReady!'], function (doc) {
Expand Down
31 changes: 13 additions & 18 deletions activities/Clock.activity/js/loader.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,34 @@
var l10n_s;

requirejs.config({
baseUrl: "lib",
paths: {
activity: "../js"
}
baseUrl: "lib",
paths: {
activity: "../js"
}
});

requirejs(["activity/activity"]);

requirejs(["webL10n","sugar-web/env","moment-with-locales.min"], function(l10n, env, moment) {
l10n_s = l10n; //global declaration of translate interface
requirejs(["webL10n","sugar-web/env","moment-with-locales.min","sugar-web/datastore"], function(l10n, env, moment,datastore) {
l10n_s = l10n; //global declaration of translate interface

getSettings(function(settings) { //globally setting language from sugar settings
datastore.localStorage.load(function() {
getSettings(function(settings) { //globally setting language from sugar settings
l10n_s.language.code = settings.language;
moment.locale(settings.language);
});
});

function getSettings(callback) {
function getSettings(callback) {
var defaultSettings = {
name: "",
language: navigator.language
language: (typeof chrome != 'undefined' && chrome.app && chrome.app.runtime) ? chrome.i18n.getUILanguage() : navigator.language
};
if (!env.isSugarizer()) {
callback(defaultSettings);
return;
}
if (typeof chrome != 'undefined' && chrome.app && chrome.app.runtime) {
var loadedSettings = JSON.parse(values.sugar_settings);
chrome.storage.local.get('sugar_settings', function(values) {
callback(loadedSettings);
});
} else {
var loadedSettings = JSON.parse(localStorage.sugar_settings);
callback(loadedSettings);
}
loadedSettings = datastore.localStorage.getValue('sugar_settings');
callback(loadedSettings);
}
});
3 changes: 1 addition & 2 deletions activities/Clock.activity/lib/webL10n.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ define(function (require) {
* content until the `localized' event happens.
*/

var gAsyncResourceLoading = false; // read-only
var gAsyncResourceLoading = true; // read-only


/**
Expand Down Expand Up @@ -807,7 +807,6 @@ define(function (require) {
function getL10nData(key, args) {
var data = gL10nData[key];
if (!data) {
l10nStartup();
consoleWarn('#' + key + ' missing for [' + gLanguage + ']');
}

Expand Down
29 changes: 12 additions & 17 deletions activities/GetThingsDone.activity/js/loader.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,34 @@
var l10n_s;

requirejs.config({
baseUrl: "lib",
paths: {
activity: "../js"
}
baseUrl: "lib",
paths: {
activity: "../js"
}
});

requirejs(["activity/activity"]);

requirejs(["webL10n","sugar-web/env","moment-with-locales.min"], function(l10n, env, moment) {
l10n_s = l10n; //global declaration of translate interface
requirejs(["webL10n","sugar-web/env","moment-with-locales.min","sugar-web/datastore"], function(l10n, env, moment,datastore) {
l10n_s = l10n; //global declaration of translate interface

getSettings(function(settings) { //globally setting language from sugar settings
datastore.localStorage.load(function() {
getSettings(function(settings) { //globally setting language from sugar settings
l10n_s.language.code = settings.language;
moment.locale(settings.language);
});
});

function getSettings(callback) {
var defaultSettings = {
name: "",
language: navigator.language
language: (typeof chrome != 'undefined' && chrome.app && chrome.app.runtime) ? chrome.i18n.getUILanguage() : navigator.language
};
if (!env.isSugarizer()) {
callback(defaultSettings);
return;
}
if (typeof chrome != 'undefined' && chrome.app && chrome.app.runtime) {
var loadedSettings = JSON.parse(values.sugar_settings);
chrome.storage.local.get('sugar_settings', function(values) {
callback(loadedSettings);
});
} else {
var loadedSettings = JSON.parse(localStorage.sugar_settings);
callback(loadedSettings);
}
loadedSettings = datastore.localStorage.getValue('sugar_settings');
callback(loadedSettings);
}
});
23 changes: 9 additions & 14 deletions activities/Markdown.activity/js/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,26 @@ requirejs.config({

requirejs(["activity/activity"]);

requirejs(["webL10n","sugar-web/env","moment-with-locales.min"], function(l10n, env, moment) {
l10n_s = l10n; //global declaration of translate interface
requirejs(["webL10n","sugar-web/env","moment-with-locales.min","sugar-web/datastore"], function(l10n, env, moment,datastore) {
l10n_s = l10n; //global declaration of translate interface

getSettings(function(settings) { //globally setting language from sugar settings
datastore.localStorage.load(function() {
getSettings(function(settings) { //globally setting language from sugar settings
l10n_s.language.code = settings.language;
moment.locale(settings.language);
});
});

function getSettings(callback) {
function getSettings(callback) {
var defaultSettings = {
name: "",
language: navigator.language
language: (typeof chrome != 'undefined' && chrome.app && chrome.app.runtime) ? chrome.i18n.getUILanguage() : navigator.language
};
if (!env.isSugarizer()) {
callback(defaultSettings);
return;
}
if (typeof chrome != 'undefined' && chrome.app && chrome.app.runtime) {
var loadedSettings = JSON.parse(values.sugar_settings);
chrome.storage.local.get('sugar_settings', function(values) {
callback(loadedSettings);
});
} else {
var loadedSettings = JSON.parse(localStorage.sugar_settings);
callback(loadedSettings);
}
loadedSettings = datastore.localStorage.getValue('sugar_settings');
callback(loadedSettings);
}
});
45 changes: 20 additions & 25 deletions activities/Moon.activity/js/moon-activity.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ define(['activity/data-model', 'activity/draw', 'webL10n', 'sugar-web/env', 'sug
l10n.ready(function() {
if (first) {
first = false;
getSugarSettings(function(settings) {
l10n.language.code = settings.language;
moment.locale(settings.language);
var refreshTime = setTimeout(function() {
clearTimeout(refreshTime);
updateView();
}, 50);
datastore.localStorage.load(function() {
getSugarSettings(function(settings) {
l10n.language.code = settings.language;
moment.locale(settings.language);
var refreshTime = setTimeout(function() {
clearTimeout(refreshTime);
updateView();
}, 50);
});
});
}
});
Expand Down Expand Up @@ -75,24 +77,17 @@ define(['activity/data-model', 'activity/draw', 'webL10n', 'sugar-web/env', 'sug


function getSugarSettings(callback) {
var defaultSettings = {
name: "",
language: navigator.language
};
if (!env.isSugarizer()) {
callback(defaultSettings);
return;
}
if (typeof chrome != 'undefined' && chrome.app && chrome.app.runtime) {
var loadedSettings = JSON.parse(values.sugar_settings);
chrome.storage.local.get('sugar_settings', function(values) {
callback(loadedSettings);
});
} else {
var loadedSettings = JSON.parse(localStorage.sugar_settings);
callback(loadedSettings);
}
}
var defaultSettings = {
name: "",
language: (typeof chrome != 'undefined' && chrome.app && chrome.app.runtime) ? chrome.i18n.getUILanguage() : navigator.language
};
if (!env.isSugarizer()) {
callback(defaultSettings);
return;
}
var loadedSettings = datastore.localStorage.getValue('sugar_settings');
callback(loadedSettings);
}


function updateSizes() {
Expand Down
67 changes: 31 additions & 36 deletions activities/Speak.activity/js/SpeakActivity.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
define(["sugar-web/graphics/palette","sugar-web/env","webL10n"], function (palette,env,l10n) {
define(["sugar-web/graphics/palette","sugar-web/env","webL10n","sugar-web/datastore"], function (palette,env,l10n,datastore) {

var canvas = document.getElementById("canvas");
var ctx = canvas.getContext('2d');
Expand Down Expand Up @@ -42,54 +42,49 @@ define(["sugar-web/graphics/palette","sugar-web/env","webL10n"], function (palet

function init(){
speech = Speech();
getSettings(function(settings) {
sugarSettings = settings;
speech.init(sugarSettings);
// If not IE, setup mouse for capture
if (!IE){
document.captureEvents(Event.MOUSEMOVE)
}
var FPS = 30;
setInterval(function() {
updateCanvas();
}, 1000/FPS);
window.addEventListener('localized', function() {
if (first) {
l10n.language.code = sugarSettings.language;
first = false;
return;
} else {
localize();
var timer = window.setTimeout(function() {
window.clearTimeout(timer);
var language = document.getElementById('speaklang').innerHTML;
var text = l10n.get("TypeSomething", {name:sugarSettings.name});
speech.playVoice(language, text);
moveMouth(text);
}, 100);
datastore.localStorage.load(function() {
getSettings(function(settings) {
sugarSettings = settings;
speech.init(sugarSettings);
// If not IE, setup mouse for capture
if (!IE){
document.captureEvents(Event.MOUSEMOVE)
}
var FPS = 30;
setInterval(function() {
updateCanvas();
}, 1000/FPS);
window.addEventListener('localized', function() {
if (first) {
l10n.language.code = sugarSettings.language;
first = false;
return;
} else {
localize();
var timer = window.setTimeout(function() {
window.clearTimeout(timer);
var language = document.getElementById('speaklang').innerHTML;
var text = l10n.get("TypeSomething", {name:sugarSettings.name});
speech.playVoice(language, text);
moveMouth(text);
}, 100);
}
});
});
});
}

function getSettings(callback) {
var defaultSettings = {
name: "",
language: navigator.language
language: (typeof chrome != 'undefined' && chrome.app && chrome.app.runtime) ? chrome.i18n.getUILanguage() : navigator.language
};
if (!env.isSugarizer()) {
callback(defaultSettings);
return;
}
if (typeof chrome != 'undefined' && chrome.app && chrome.app.runtime) {
var loadedSettings = JSON.parse(values.sugar_settings);
chrome.storage.local.get('sugar_settings', function(values) {
callback(loadedSettings);
});
} else {
var loadedSettings = JSON.parse(localStorage.sugar_settings);
callback(loadedSettings);
}
var loadedSettings = datastore.localStorage.getValue('sugar_settings');
callback(loadedSettings);
}

function hidePalettes(){
Expand Down
Loading

0 comments on commit 3fa165a

Please sign in to comment.