Skip to content

Commit ec01927

Browse files
author
Lionel Laské
committed
Fix direct link feature when no settings
1 parent 9f95658 commit ec01927

File tree

65 files changed

+241
-742
lines changed
  • activities
    • 3DVolume.activity/lib/sugar-web
    • Abacus.activity/lib/sugar-web
    • Abecedarium.activity/lib/sugar-web
    • ActivityTemplate
    • Blockrain.activity/lib/sugar-web
    • Calculate.activity/lib/sugar-web
    • Calligra.activity/lib/sugar-web
    • Chart.activity/lib/sugar-web
    • Chat.activity/lib/sugar-web
    • Chess.activity/lib/sugar-web
    • Clock.activity/lib/sugar-web
    • ColorMyWorld.activity/lib/sugar-web
    • Constellation.activity/lib/sugar-web
    • Curriculum.activity/lib/sugar-web
    • DollarStreet.activity/lib/sugar-web
    • EbookReader.activity/lib/sugar-web
    • Exerciser.activity/lib/sugar-web
    • Falabracman.activity/lib/sugar-web
    • Flip.activity/lib/sugar-web
    • FoodChain.activity/lib/sugar-web
    • Fototoon.activity/lib/sugar-web
    • FractionBounce.activity/lib/sugar-web
    • GameOfLife.activity/lib/sugar-web
    • Gears.activity/lib/sugar-web
    • GetThingsDone.activity/lib/sugar-web
    • Gridpaint.activity/lib/sugar-web
    • Implode.activity/lib/sugar-web
    • Jappy.activity/lib/sugar-web
    • LabyrinthJS.activity/lib/sugar-web
    • LastOneLoses.activity/lib/sugar-web
    • Markdown.activity/lib/sugar-web
    • MazeWeb.activity/lib/sugar-web
    • Measure.activity/lib/sugar-web
    • MediaViewer.activity/lib/sugar-web
    • Memorize.activity/lib/sugar-web
    • MindMath.activity/lib/sugar-web
    • Moon.activity/lib/sugar-web
    • Paint.activity/lib/sugar-web
    • PhysicsJS.activity/lib/sugar-web
    • Planets.activity/lib/sugar-web
    • Pomodoro.activity/lib/sugar-web
    • QRCode.activity/lib/sugar-web
    • Record.activity/lib/sugar-web
    • Reflection.activity/lib/sugar-web
    • Scratch.activity/lib/sugar-web
    • SharedNotes.activity/lib/sugar-web
    • Speak.activity
    • SprintMath.activity/lib/sugar-web
    • Stopwatch.activity/lib/sugar-web
    • Story.activity/lib/sugar-web
    • TamTamMicro.activity/lib/sugar-web
    • Tangram.activity/lib/sugar-web
    • TankOp.activity/lib/sugar-web
    • TurtleBlocksJS.activity/lib/sugar-web
    • VideoViewer.activity/lib/sugar-web
    • Vote.activity/lib/sugar-web
    • Write.activity/lib/sugar-web
    • XOEditor.activity/lib/sugar-web
    • XmasLights.activity/lib/sugar-web
  • lib/sugar-web

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+241
-742
lines changed

activities/3DVolume.activity/lib/sugar-web/activity/activity.js

+19-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
define(["webL10n",
2-
"sugar-web/activity/shortcut",
1+
define(["sugar-web/activity/shortcut",
32
"sugar-web/bus",
43
"sugar-web/env",
54
"sugar-web/datastore",
65
"sugar-web/presence",
76
"sugar-web/graphics/icon",
87
"sugar-web/graphics/activitypalette"], function (
9-
l10n, shortcut, bus, env, datastore, presence, icon, activitypalette) {
8+
shortcut, bus, env, datastore, presence, icon, activitypalette) {
109

1110
'use strict';
1211

@@ -22,8 +21,6 @@ define(["webL10n",
2221
activity.setup = function () {
2322
bus.listen();
2423

25-
l10n.start();
26-
2724
function sendPauseEvent() {
2825
var pauseEvent = document.createEvent("CustomEvent");
2926
pauseEvent.initCustomEvent('activityPause', false, false, {
@@ -55,6 +52,23 @@ define(["webL10n",
5552

5653
datastoreObject = new datastore.DatastoreObject();
5754

55+
datastore.localStorage.load(function() {
56+
var preferences = datastore.localStorage.getValue('sugar_settings');
57+
if (preferences != null && preferences.name !== undefined) {
58+
return;
59+
}
60+
if (window.location.protocol != "file:") {
61+
location.href = window.location.protocol + "//" + window.location.host + "?redirect=" + encodeURIComponent(window.location.href);
62+
} else {
63+
let server = window.location.pathname.substring(0, window.location.pathname.indexOf("index.html"));
64+
server = server.substring(0, server.lastIndexOf("/"));
65+
server = server.substring(0, server.lastIndexOf("/"));
66+
server = server.substring(0, server.lastIndexOf("/"));
67+
location.href = server + "/index.html?redirect=" + encodeURIComponent(window.location.href);
68+
}
69+
return;
70+
});
71+
5872
var activityButton = document.getElementById("activity-button");
5973

6074
var activityPalette = new activitypalette.ActivityPalette(

activities/3DVolume.activity/lib/sugar-web/env.js

+3-12
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ define(function () {
2929
callback(null, window.top.sugar.environment);
3030
});
3131
} else {
32-
window.top.sugar.environment.user = JSON.parse(localStorage.sugar_settings);
32+
window.top.sugar.environment.user = localStorage.sugar_settings ? JSON.parse(localStorage.sugar_settings) : {};
3333
setTimeout(function () {
3434
callback(null, window.top.sugar.environment);
3535
}, 0);
@@ -83,17 +83,8 @@ define(function () {
8383
};
8484

8585
env.isSugarizer = function() {
86-
// HACK: If in Chrome App automatic deduction that in Sugarizer
87-
if (typeof chrome != 'undefined' && chrome.app && chrome.app.runtime) {
88-
return true;
89-
} else if (typeof(Storage)!=="undefined" && typeof(window.localStorage)!=="undefined") {
90-
try {
91-
return (window.localStorage.getItem('sugar_settings') !== null);
92-
} catch(err) {
93-
return false;
94-
}
95-
}
96-
return false;
86+
// DEPRECATED: This method was there to detect execution outside Sugarizer - aka on Sugar
87+
return true;
9788
};
9889

9990
env.isSugarizerOS = function() {

activities/Abacus.activity/lib/sugar-web/env.js

+3-12
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ define(function () {
2929
callback(null, window.top.sugar.environment);
3030
});
3131
} else {
32-
window.top.sugar.environment.user = JSON.parse(localStorage.sugar_settings);
32+
window.top.sugar.environment.user = localStorage.sugar_settings ? JSON.parse(localStorage.sugar_settings) : {};
3333
setTimeout(function () {
3434
callback(null, window.top.sugar.environment);
3535
}, 0);
@@ -83,17 +83,8 @@ define(function () {
8383
};
8484

8585
env.isSugarizer = function() {
86-
// HACK: If in Chrome App automatic deduction that in Sugarizer
87-
if (typeof chrome != 'undefined' && chrome.app && chrome.app.runtime) {
88-
return true;
89-
} else if (typeof(Storage)!=="undefined" && typeof(window.localStorage)!=="undefined") {
90-
try {
91-
return (window.localStorage.getItem('sugar_settings') !== null);
92-
} catch(err) {
93-
return false;
94-
}
95-
}
96-
return false;
86+
// DEPRECATED: This method was there to detect execution outside Sugarizer - aka on Sugar
87+
return true;
9788
};
9889

9990
env.isSugarizerOS = function() {

activities/Abecedarium.activity/lib/sugar-web/env.js

+3-12
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ define(function () {
2929
callback(null, window.top.sugar.environment);
3030
});
3131
} else {
32-
window.top.sugar.environment.user = JSON.parse(localStorage.sugar_settings);
32+
window.top.sugar.environment.user = localStorage.sugar_settings ? JSON.parse(localStorage.sugar_settings) : {};
3333
setTimeout(function () {
3434
callback(null, window.top.sugar.environment);
3535
}, 0);
@@ -83,17 +83,8 @@ define(function () {
8383
};
8484

8585
env.isSugarizer = function() {
86-
// HACK: If in Chrome App automatic deduction that in Sugarizer
87-
if (typeof chrome != 'undefined' && chrome.app && chrome.app.runtime) {
88-
return true;
89-
} else if (typeof(Storage)!=="undefined" && typeof(window.localStorage)!=="undefined") {
90-
try {
91-
return (window.localStorage.getItem('sugar_settings') !== null);
92-
} catch(err) {
93-
return false;
94-
}
95-
}
96-
return false;
86+
// DEPRECATED: This method was there to detect execution outside Sugarizer - aka on Sugar
87+
return true;
9788
};
9889

9990
env.isSugarizerOS = function() {

activities/ActivityTemplate/VanillaJS/lib/sugar-web/env.js

+3-12
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ define(function () {
2929
callback(null, window.top.sugar.environment);
3030
});
3131
} else {
32-
window.top.sugar.environment.user = JSON.parse(localStorage.sugar_settings);
32+
window.top.sugar.environment.user = localStorage.sugar_settings ? JSON.parse(localStorage.sugar_settings) : {};
3333
setTimeout(function () {
3434
callback(null, window.top.sugar.environment);
3535
}, 0);
@@ -83,17 +83,8 @@ define(function () {
8383
};
8484

8585
env.isSugarizer = function() {
86-
// HACK: If in Chrome App automatic deduction that in Sugarizer
87-
if (typeof chrome != 'undefined' && chrome.app && chrome.app.runtime) {
88-
return true;
89-
} else if (typeof(Storage)!=="undefined" && typeof(window.localStorage)!=="undefined") {
90-
try {
91-
return (window.localStorage.getItem('sugar_settings') !== null);
92-
} catch(err) {
93-
return false;
94-
}
95-
}
96-
return false;
86+
// DEPRECATED: This method was there to detect execution outside Sugarizer - aka on Sugar
87+
return true;
9788
};
9889

9990
env.isSugarizerOS = function() {

activities/ActivityTemplate/VueJS/lib/sugar-web/env.js

+3-12
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ define(function () {
2929
callback(null, window.top.sugar.environment);
3030
});
3131
} else {
32-
window.top.sugar.environment.user = JSON.parse(localStorage.sugar_settings);
32+
window.top.sugar.environment.user = localStorage.sugar_settings ? JSON.parse(localStorage.sugar_settings) : {};
3333
setTimeout(function () {
3434
callback(null, window.top.sugar.environment);
3535
}, 0);
@@ -83,17 +83,8 @@ define(function () {
8383
};
8484

8585
env.isSugarizer = function() {
86-
// HACK: If in Chrome App automatic deduction that in Sugarizer
87-
if (typeof chrome != 'undefined' && chrome.app && chrome.app.runtime) {
88-
return true;
89-
} else if (typeof(Storage)!=="undefined" && typeof(window.localStorage)!=="undefined") {
90-
try {
91-
return (window.localStorage.getItem('sugar_settings') !== null);
92-
} catch(err) {
93-
return false;
94-
}
95-
}
96-
return false;
86+
// DEPRECATED: This method was there to detect execution outside Sugarizer - aka on Sugar
87+
return true;
9788
};
9889

9990
env.isSugarizerOS = function() {

activities/Blockrain.activity/lib/sugar-web/env.js

+3-12
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ define(function () {
2929
callback(null, window.top.sugar.environment);
3030
});
3131
} else {
32-
window.top.sugar.environment.user = JSON.parse(localStorage.sugar_settings);
32+
window.top.sugar.environment.user = localStorage.sugar_settings ? JSON.parse(localStorage.sugar_settings) : {};
3333
setTimeout(function () {
3434
callback(null, window.top.sugar.environment);
3535
}, 0);
@@ -83,17 +83,8 @@ define(function () {
8383
};
8484

8585
env.isSugarizer = function() {
86-
// HACK: If in Chrome App automatic deduction that in Sugarizer
87-
if (typeof chrome != 'undefined' && chrome.app && chrome.app.runtime) {
88-
return true;
89-
} else if (typeof(Storage)!=="undefined" && typeof(window.localStorage)!=="undefined") {
90-
try {
91-
return (window.localStorage.getItem('sugar_settings') !== null);
92-
} catch(err) {
93-
return false;
94-
}
95-
}
96-
return false;
86+
// DEPRECATED: This method was there to detect execution outside Sugarizer - aka on Sugar
87+
return true;
9788
};
9889

9990
env.isSugarizerOS = function() {

activities/Calculate.activity/lib/sugar-web/env.js

+3-12
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ define(function () {
2929
callback(null, window.top.sugar.environment);
3030
});
3131
} else {
32-
window.top.sugar.environment.user = JSON.parse(localStorage.sugar_settings);
32+
window.top.sugar.environment.user = localStorage.sugar_settings ? JSON.parse(localStorage.sugar_settings) : {};
3333
setTimeout(function () {
3434
callback(null, window.top.sugar.environment);
3535
}, 0);
@@ -83,17 +83,8 @@ define(function () {
8383
};
8484

8585
env.isSugarizer = function() {
86-
// HACK: If in Chrome App automatic deduction that in Sugarizer
87-
if (typeof chrome != 'undefined' && chrome.app && chrome.app.runtime) {
88-
return true;
89-
} else if (typeof(Storage)!=="undefined" && typeof(window.localStorage)!=="undefined") {
90-
try {
91-
return (window.localStorage.getItem('sugar_settings') !== null);
92-
} catch(err) {
93-
return false;
94-
}
95-
}
96-
return false;
86+
// DEPRECATED: This method was there to detect execution outside Sugarizer - aka on Sugar
87+
return true;
9788
};
9889

9990
env.isSugarizerOS = function() {

activities/Calligra.activity/lib/sugar-web/env.js

+3-12
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ define(function () {
2929
callback(null, window.top.sugar.environment);
3030
});
3131
} else {
32-
window.top.sugar.environment.user = JSON.parse(localStorage.sugar_settings);
32+
window.top.sugar.environment.user = localStorage.sugar_settings ? JSON.parse(localStorage.sugar_settings) : {};
3333
setTimeout(function () {
3434
callback(null, window.top.sugar.environment);
3535
}, 0);
@@ -83,17 +83,8 @@ define(function () {
8383
};
8484

8585
env.isSugarizer = function() {
86-
// HACK: If in Chrome App automatic deduction that in Sugarizer
87-
if (typeof chrome != 'undefined' && chrome.app && chrome.app.runtime) {
88-
return true;
89-
} else if (typeof(Storage)!=="undefined" && typeof(window.localStorage)!=="undefined") {
90-
try {
91-
return (window.localStorage.getItem('sugar_settings') !== null);
92-
} catch(err) {
93-
return false;
94-
}
95-
}
96-
return false;
86+
// DEPRECATED: This method was there to detect execution outside Sugarizer - aka on Sugar
87+
return true;
9788
};
9889

9990
env.isSugarizerOS = function() {

activities/Chart.activity/lib/sugar-web/env.js

+3-12
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ define(function () {
2929
callback(null, window.top.sugar.environment);
3030
});
3131
} else {
32-
window.top.sugar.environment.user = JSON.parse(localStorage.sugar_settings);
32+
window.top.sugar.environment.user = localStorage.sugar_settings ? JSON.parse(localStorage.sugar_settings) : {};
3333
setTimeout(function () {
3434
callback(null, window.top.sugar.environment);
3535
}, 0);
@@ -83,17 +83,8 @@ define(function () {
8383
};
8484

8585
env.isSugarizer = function() {
86-
// HACK: If in Chrome App automatic deduction that in Sugarizer
87-
if (typeof chrome != 'undefined' && chrome.app && chrome.app.runtime) {
88-
return true;
89-
} else if (typeof(Storage)!=="undefined" && typeof(window.localStorage)!=="undefined") {
90-
try {
91-
return (window.localStorage.getItem('sugar_settings') !== null);
92-
} catch(err) {
93-
return false;
94-
}
95-
}
96-
return false;
86+
// DEPRECATED: This method was there to detect execution outside Sugarizer - aka on Sugar
87+
return true;
9788
};
9889

9990
env.isSugarizerOS = function() {

activities/Chat.activity/lib/sugar-web/env.js

+3-12
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ define(function () {
2929
callback(null, window.top.sugar.environment);
3030
});
3131
} else {
32-
window.top.sugar.environment.user = JSON.parse(localStorage.sugar_settings);
32+
window.top.sugar.environment.user = localStorage.sugar_settings ? JSON.parse(localStorage.sugar_settings) : {};
3333
setTimeout(function () {
3434
callback(null, window.top.sugar.environment);
3535
}, 0);
@@ -83,17 +83,8 @@ define(function () {
8383
};
8484

8585
env.isSugarizer = function() {
86-
// HACK: If in Chrome App automatic deduction that in Sugarizer
87-
if (typeof chrome != 'undefined' && chrome.app && chrome.app.runtime) {
88-
return true;
89-
} else if (typeof(Storage)!=="undefined" && typeof(window.localStorage)!=="undefined") {
90-
try {
91-
return (window.localStorage.getItem('sugar_settings') !== null);
92-
} catch(err) {
93-
return false;
94-
}
95-
}
96-
return false;
86+
// DEPRECATED: This method was there to detect execution outside Sugarizer - aka on Sugar
87+
return true;
9788
};
9889

9990
env.isSugarizerOS = function() {

activities/Chess.activity/lib/sugar-web/env.js

+3-12
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ define(function () {
2929
callback(null, window.top.sugar.environment);
3030
});
3131
} else {
32-
window.top.sugar.environment.user = JSON.parse(localStorage.sugar_settings);
32+
window.top.sugar.environment.user = localStorage.sugar_settings ? JSON.parse(localStorage.sugar_settings) : {};
3333
setTimeout(function () {
3434
callback(null, window.top.sugar.environment);
3535
}, 0);
@@ -83,17 +83,8 @@ define(function () {
8383
};
8484

8585
env.isSugarizer = function() {
86-
// HACK: If in Chrome App automatic deduction that in Sugarizer
87-
if (typeof chrome != 'undefined' && chrome.app && chrome.app.runtime) {
88-
return true;
89-
} else if (typeof(Storage)!=="undefined" && typeof(window.localStorage)!=="undefined") {
90-
try {
91-
return (window.localStorage.getItem('sugar_settings') !== null);
92-
} catch(err) {
93-
return false;
94-
}
95-
}
96-
return false;
86+
// DEPRECATED: This method was there to detect execution outside Sugarizer - aka on Sugar
87+
return true;
9788
};
9889

9990
env.isSugarizerOS = function() {

activities/Clock.activity/lib/sugar-web/env.js

+3-12
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ define(function () {
2929
callback(null, window.top.sugar.environment);
3030
});
3131
} else {
32-
window.top.sugar.environment.user = JSON.parse(localStorage.sugar_settings);
32+
window.top.sugar.environment.user = localStorage.sugar_settings ? JSON.parse(localStorage.sugar_settings) : {};
3333
setTimeout(function () {
3434
callback(null, window.top.sugar.environment);
3535
}, 0);
@@ -83,17 +83,8 @@ define(function () {
8383
};
8484

8585
env.isSugarizer = function() {
86-
// HACK: If in Chrome App automatic deduction that in Sugarizer
87-
if (typeof chrome != 'undefined' && chrome.app && chrome.app.runtime) {
88-
return true;
89-
} else if (typeof(Storage)!=="undefined" && typeof(window.localStorage)!=="undefined") {
90-
try {
91-
return (window.localStorage.getItem('sugar_settings') !== null);
92-
} catch(err) {
93-
return false;
94-
}
95-
}
96-
return false;
86+
// DEPRECATED: This method was there to detect execution outside Sugarizer - aka on Sugar
87+
return true;
9788
};
9889

9990
env.isSugarizerOS = function() {

0 commit comments

Comments
 (0)