Skip to content

Commit

Permalink
Fix direct link feature when no settings
Browse files Browse the repository at this point in the history
  • Loading branch information
Lionel Laské committed Dec 27, 2024
1 parent 9f95658 commit ec01927
Show file tree
Hide file tree
Showing 65 changed files with 241 additions and 742 deletions.
24 changes: 19 additions & 5 deletions activities/3DVolume.activity/lib/sugar-web/activity/activity.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
define(["webL10n",
"sugar-web/activity/shortcut",
define(["sugar-web/activity/shortcut",
"sugar-web/bus",
"sugar-web/env",
"sugar-web/datastore",
"sugar-web/presence",
"sugar-web/graphics/icon",
"sugar-web/graphics/activitypalette"], function (
l10n, shortcut, bus, env, datastore, presence, icon, activitypalette) {
shortcut, bus, env, datastore, presence, icon, activitypalette) {

'use strict';

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

l10n.start();

function sendPauseEvent() {
var pauseEvent = document.createEvent("CustomEvent");
pauseEvent.initCustomEvent('activityPause', false, false, {
Expand Down Expand Up @@ -55,6 +52,23 @@ define(["webL10n",

datastoreObject = new datastore.DatastoreObject();

datastore.localStorage.load(function() {
var preferences = datastore.localStorage.getValue('sugar_settings');
if (preferences != null && preferences.name !== undefined) {
return;
}
if (window.location.protocol != "file:") {
location.href = window.location.protocol + "//" + window.location.host + "?redirect=" + encodeURIComponent(window.location.href);
} else {
let server = window.location.pathname.substring(0, window.location.pathname.indexOf("index.html"));
server = server.substring(0, server.lastIndexOf("/"));
server = server.substring(0, server.lastIndexOf("/"));
server = server.substring(0, server.lastIndexOf("/"));
location.href = server + "/index.html?redirect=" + encodeURIComponent(window.location.href);
}
return;
});

var activityButton = document.getElementById("activity-button");

var activityPalette = new activitypalette.ActivityPalette(
Expand Down
15 changes: 3 additions & 12 deletions activities/3DVolume.activity/lib/sugar-web/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ define(function () {
callback(null, window.top.sugar.environment);
});
} else {
window.top.sugar.environment.user = JSON.parse(localStorage.sugar_settings);
window.top.sugar.environment.user = localStorage.sugar_settings ? JSON.parse(localStorage.sugar_settings) : {};
setTimeout(function () {
callback(null, window.top.sugar.environment);
}, 0);
Expand Down Expand Up @@ -83,17 +83,8 @@ define(function () {
};

env.isSugarizer = function() {
// HACK: If in Chrome App automatic deduction that in Sugarizer
if (typeof chrome != 'undefined' && chrome.app && chrome.app.runtime) {
return true;
} else if (typeof(Storage)!=="undefined" && typeof(window.localStorage)!=="undefined") {
try {
return (window.localStorage.getItem('sugar_settings') !== null);
} catch(err) {
return false;
}
}
return false;
// DEPRECATED: This method was there to detect execution outside Sugarizer - aka on Sugar
return true;
};

env.isSugarizerOS = function() {
Expand Down
15 changes: 3 additions & 12 deletions activities/Abacus.activity/lib/sugar-web/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ define(function () {
callback(null, window.top.sugar.environment);
});
} else {
window.top.sugar.environment.user = JSON.parse(localStorage.sugar_settings);
window.top.sugar.environment.user = localStorage.sugar_settings ? JSON.parse(localStorage.sugar_settings) : {};
setTimeout(function () {
callback(null, window.top.sugar.environment);
}, 0);
Expand Down Expand Up @@ -83,17 +83,8 @@ define(function () {
};

env.isSugarizer = function() {
// HACK: If in Chrome App automatic deduction that in Sugarizer
if (typeof chrome != 'undefined' && chrome.app && chrome.app.runtime) {
return true;
} else if (typeof(Storage)!=="undefined" && typeof(window.localStorage)!=="undefined") {
try {
return (window.localStorage.getItem('sugar_settings') !== null);
} catch(err) {
return false;
}
}
return false;
// DEPRECATED: This method was there to detect execution outside Sugarizer - aka on Sugar
return true;
};

env.isSugarizerOS = function() {
Expand Down
15 changes: 3 additions & 12 deletions activities/Abecedarium.activity/lib/sugar-web/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ define(function () {
callback(null, window.top.sugar.environment);
});
} else {
window.top.sugar.environment.user = JSON.parse(localStorage.sugar_settings);
window.top.sugar.environment.user = localStorage.sugar_settings ? JSON.parse(localStorage.sugar_settings) : {};
setTimeout(function () {
callback(null, window.top.sugar.environment);
}, 0);
Expand Down Expand Up @@ -83,17 +83,8 @@ define(function () {
};

env.isSugarizer = function() {
// HACK: If in Chrome App automatic deduction that in Sugarizer
if (typeof chrome != 'undefined' && chrome.app && chrome.app.runtime) {
return true;
} else if (typeof(Storage)!=="undefined" && typeof(window.localStorage)!=="undefined") {
try {
return (window.localStorage.getItem('sugar_settings') !== null);
} catch(err) {
return false;
}
}
return false;
// DEPRECATED: This method was there to detect execution outside Sugarizer - aka on Sugar
return true;
};

env.isSugarizerOS = function() {
Expand Down
15 changes: 3 additions & 12 deletions activities/ActivityTemplate/VanillaJS/lib/sugar-web/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ define(function () {
callback(null, window.top.sugar.environment);
});
} else {
window.top.sugar.environment.user = JSON.parse(localStorage.sugar_settings);
window.top.sugar.environment.user = localStorage.sugar_settings ? JSON.parse(localStorage.sugar_settings) : {};
setTimeout(function () {
callback(null, window.top.sugar.environment);
}, 0);
Expand Down Expand Up @@ -83,17 +83,8 @@ define(function () {
};

env.isSugarizer = function() {
// HACK: If in Chrome App automatic deduction that in Sugarizer
if (typeof chrome != 'undefined' && chrome.app && chrome.app.runtime) {
return true;
} else if (typeof(Storage)!=="undefined" && typeof(window.localStorage)!=="undefined") {
try {
return (window.localStorage.getItem('sugar_settings') !== null);
} catch(err) {
return false;
}
}
return false;
// DEPRECATED: This method was there to detect execution outside Sugarizer - aka on Sugar
return true;
};

env.isSugarizerOS = function() {
Expand Down
15 changes: 3 additions & 12 deletions activities/ActivityTemplate/VueJS/lib/sugar-web/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ define(function () {
callback(null, window.top.sugar.environment);
});
} else {
window.top.sugar.environment.user = JSON.parse(localStorage.sugar_settings);
window.top.sugar.environment.user = localStorage.sugar_settings ? JSON.parse(localStorage.sugar_settings) : {};
setTimeout(function () {
callback(null, window.top.sugar.environment);
}, 0);
Expand Down Expand Up @@ -83,17 +83,8 @@ define(function () {
};

env.isSugarizer = function() {
// HACK: If in Chrome App automatic deduction that in Sugarizer
if (typeof chrome != 'undefined' && chrome.app && chrome.app.runtime) {
return true;
} else if (typeof(Storage)!=="undefined" && typeof(window.localStorage)!=="undefined") {
try {
return (window.localStorage.getItem('sugar_settings') !== null);
} catch(err) {
return false;
}
}
return false;
// DEPRECATED: This method was there to detect execution outside Sugarizer - aka on Sugar
return true;
};

env.isSugarizerOS = function() {
Expand Down
15 changes: 3 additions & 12 deletions activities/Blockrain.activity/lib/sugar-web/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ define(function () {
callback(null, window.top.sugar.environment);
});
} else {
window.top.sugar.environment.user = JSON.parse(localStorage.sugar_settings);
window.top.sugar.environment.user = localStorage.sugar_settings ? JSON.parse(localStorage.sugar_settings) : {};
setTimeout(function () {
callback(null, window.top.sugar.environment);
}, 0);
Expand Down Expand Up @@ -83,17 +83,8 @@ define(function () {
};

env.isSugarizer = function() {
// HACK: If in Chrome App automatic deduction that in Sugarizer
if (typeof chrome != 'undefined' && chrome.app && chrome.app.runtime) {
return true;
} else if (typeof(Storage)!=="undefined" && typeof(window.localStorage)!=="undefined") {
try {
return (window.localStorage.getItem('sugar_settings') !== null);
} catch(err) {
return false;
}
}
return false;
// DEPRECATED: This method was there to detect execution outside Sugarizer - aka on Sugar
return true;
};

env.isSugarizerOS = function() {
Expand Down
15 changes: 3 additions & 12 deletions activities/Calculate.activity/lib/sugar-web/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ define(function () {
callback(null, window.top.sugar.environment);
});
} else {
window.top.sugar.environment.user = JSON.parse(localStorage.sugar_settings);
window.top.sugar.environment.user = localStorage.sugar_settings ? JSON.parse(localStorage.sugar_settings) : {};
setTimeout(function () {
callback(null, window.top.sugar.environment);
}, 0);
Expand Down Expand Up @@ -83,17 +83,8 @@ define(function () {
};

env.isSugarizer = function() {
// HACK: If in Chrome App automatic deduction that in Sugarizer
if (typeof chrome != 'undefined' && chrome.app && chrome.app.runtime) {
return true;
} else if (typeof(Storage)!=="undefined" && typeof(window.localStorage)!=="undefined") {
try {
return (window.localStorage.getItem('sugar_settings') !== null);
} catch(err) {
return false;
}
}
return false;
// DEPRECATED: This method was there to detect execution outside Sugarizer - aka on Sugar
return true;
};

env.isSugarizerOS = function() {
Expand Down
15 changes: 3 additions & 12 deletions activities/Calligra.activity/lib/sugar-web/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ define(function () {
callback(null, window.top.sugar.environment);
});
} else {
window.top.sugar.environment.user = JSON.parse(localStorage.sugar_settings);
window.top.sugar.environment.user = localStorage.sugar_settings ? JSON.parse(localStorage.sugar_settings) : {};
setTimeout(function () {
callback(null, window.top.sugar.environment);
}, 0);
Expand Down Expand Up @@ -83,17 +83,8 @@ define(function () {
};

env.isSugarizer = function() {
// HACK: If in Chrome App automatic deduction that in Sugarizer
if (typeof chrome != 'undefined' && chrome.app && chrome.app.runtime) {
return true;
} else if (typeof(Storage)!=="undefined" && typeof(window.localStorage)!=="undefined") {
try {
return (window.localStorage.getItem('sugar_settings') !== null);
} catch(err) {
return false;
}
}
return false;
// DEPRECATED: This method was there to detect execution outside Sugarizer - aka on Sugar
return true;
};

env.isSugarizerOS = function() {
Expand Down
15 changes: 3 additions & 12 deletions activities/Chart.activity/lib/sugar-web/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ define(function () {
callback(null, window.top.sugar.environment);
});
} else {
window.top.sugar.environment.user = JSON.parse(localStorage.sugar_settings);
window.top.sugar.environment.user = localStorage.sugar_settings ? JSON.parse(localStorage.sugar_settings) : {};
setTimeout(function () {
callback(null, window.top.sugar.environment);
}, 0);
Expand Down Expand Up @@ -83,17 +83,8 @@ define(function () {
};

env.isSugarizer = function() {
// HACK: If in Chrome App automatic deduction that in Sugarizer
if (typeof chrome != 'undefined' && chrome.app && chrome.app.runtime) {
return true;
} else if (typeof(Storage)!=="undefined" && typeof(window.localStorage)!=="undefined") {
try {
return (window.localStorage.getItem('sugar_settings') !== null);
} catch(err) {
return false;
}
}
return false;
// DEPRECATED: This method was there to detect execution outside Sugarizer - aka on Sugar
return true;
};

env.isSugarizerOS = function() {
Expand Down
15 changes: 3 additions & 12 deletions activities/Chat.activity/lib/sugar-web/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ define(function () {
callback(null, window.top.sugar.environment);
});
} else {
window.top.sugar.environment.user = JSON.parse(localStorage.sugar_settings);
window.top.sugar.environment.user = localStorage.sugar_settings ? JSON.parse(localStorage.sugar_settings) : {};
setTimeout(function () {
callback(null, window.top.sugar.environment);
}, 0);
Expand Down Expand Up @@ -83,17 +83,8 @@ define(function () {
};

env.isSugarizer = function() {
// HACK: If in Chrome App automatic deduction that in Sugarizer
if (typeof chrome != 'undefined' && chrome.app && chrome.app.runtime) {
return true;
} else if (typeof(Storage)!=="undefined" && typeof(window.localStorage)!=="undefined") {
try {
return (window.localStorage.getItem('sugar_settings') !== null);
} catch(err) {
return false;
}
}
return false;
// DEPRECATED: This method was there to detect execution outside Sugarizer - aka on Sugar
return true;
};

env.isSugarizerOS = function() {
Expand Down
15 changes: 3 additions & 12 deletions activities/Chess.activity/lib/sugar-web/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ define(function () {
callback(null, window.top.sugar.environment);
});
} else {
window.top.sugar.environment.user = JSON.parse(localStorage.sugar_settings);
window.top.sugar.environment.user = localStorage.sugar_settings ? JSON.parse(localStorage.sugar_settings) : {};
setTimeout(function () {
callback(null, window.top.sugar.environment);
}, 0);
Expand Down Expand Up @@ -83,17 +83,8 @@ define(function () {
};

env.isSugarizer = function() {
// HACK: If in Chrome App automatic deduction that in Sugarizer
if (typeof chrome != 'undefined' && chrome.app && chrome.app.runtime) {
return true;
} else if (typeof(Storage)!=="undefined" && typeof(window.localStorage)!=="undefined") {
try {
return (window.localStorage.getItem('sugar_settings') !== null);
} catch(err) {
return false;
}
}
return false;
// DEPRECATED: This method was there to detect execution outside Sugarizer - aka on Sugar
return true;
};

env.isSugarizerOS = function() {
Expand Down
15 changes: 3 additions & 12 deletions activities/Clock.activity/lib/sugar-web/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ define(function () {
callback(null, window.top.sugar.environment);
});
} else {
window.top.sugar.environment.user = JSON.parse(localStorage.sugar_settings);
window.top.sugar.environment.user = localStorage.sugar_settings ? JSON.parse(localStorage.sugar_settings) : {};
setTimeout(function () {
callback(null, window.top.sugar.environment);
}, 0);
Expand Down Expand Up @@ -83,17 +83,8 @@ define(function () {
};

env.isSugarizer = function() {
// HACK: If in Chrome App automatic deduction that in Sugarizer
if (typeof chrome != 'undefined' && chrome.app && chrome.app.runtime) {
return true;
} else if (typeof(Storage)!=="undefined" && typeof(window.localStorage)!=="undefined") {
try {
return (window.localStorage.getItem('sugar_settings') !== null);
} catch(err) {
return false;
}
}
return false;
// DEPRECATED: This method was there to detect execution outside Sugarizer - aka on Sugar
return true;
};

env.isSugarizerOS = function() {
Expand Down
Loading

0 comments on commit ec01927

Please sign in to comment.