Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion resources/library/interactivities/Dice.wgt/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<widget xmlns="http://www.w3.org/ns/widgets"
xmlns:ub="http://uniboard.mnemis.com/widgets"
id="http://www.openboard.org/widget/interactivity/dice"
version="2.0"
version="2.1"
width="760"
height="610"
ub:resizable="false">
Expand Down
4 changes: 2 additions & 2 deletions resources/library/interactivities/Dice.wgt/css/ubw-main.css
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ html, body {

.theme-slate #ubwidget > .wrapper, .theme-pad #ubwidget > .wrapper {
position: absolute;
top: -49px;
/* top: -49px;
bottom: -5px;
left: -5px;
right: -5px;
right: -5px; */
overflow: hidden;
}

Expand Down
50 changes: 46 additions & 4 deletions resources/library/interactivities/Dice.wgt/js/lib/ubw-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,26 @@ function log(object) {
console.log(object);
}

function initAfterI18nMessagesLoaded(reload, templates, callbacks) {
async function initAfterI18nMessagesLoaded(reload, templates, callbacks) {
document.title = fr.njin.i18n.document.title;

var ubwidget = $("#ubwidget");

function createDelegate() {
if (window.sankore.async) {
return Object.create(SankoreAsyncDelegate);
}
else {
return window.sankore || Object.create(ParametersDelegate);
}
}

var parameters = Object.create(Parameters,{
container: {
value: ubwidget
},
delegate: {
value: window.sankore || Object.create(ParametersDelegate)
value: createDelegate()
}
});

Expand All @@ -42,6 +51,20 @@ function initAfterI18nMessagesLoaded(reload, templates, callbacks) {
}
});

async function fillParameters() {
var keys = await window.sankore.async.preferenceKeys();
for (var i = 0; i < keys.length; i++) {
var key = keys[i];
var value = await window.sankore.async.preference(key);
log("Init parameter value ["+value+"] for key : ["+key+"]");
app.parameters.delegate[key] = value;
}
}

if (window.sankore.async) {
await fillParameters();
}

app.init();
app.onEdit = false;

Expand Down Expand Up @@ -157,6 +180,25 @@ var ParametersDelegate = (function(){
return self;
})();

var SankoreAsyncDelegate = (function(){
var self = Object.create({}, {
preference: {
value: function(key) {
// return cached value
return this[key];
}
},
setPreference: {
value: function(key, value) {
// store in cache and application
this[key] = value
window.sankore.setPreference(key, value);
}
}
});
return self;
})();

var App = (function() {
var self = Object.create({}, {
container: {
Expand Down Expand Up @@ -233,7 +275,7 @@ var App = (function() {
}
return doc;
}
var file = stringToXML(e.dataTransfer.getData("text/plain"));
var file = stringToXML(e.dataTransfer.getData("text/plain") || window.sankore.dropData);
callback({
src: $(file).find("path:eq(0)").text()
});
Expand Down Expand Up @@ -266,4 +308,4 @@ var App = (function() {
}
});
return self;
})();
})();
24 changes: 23 additions & 1 deletion src/adaptors/UBWidgetUpgradeAdaptor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ void UBWidgetUpgradeAdaptor::upgradeWidgets(std::shared_ptr<UBDocumentProxy> pro

for (const QString& widgetPath : widgetPaths) {
// scan widget for use of incompatible APIs
bool needsUpgrade = scanDir(QDir(widgetPath)) == UBWidgetUpgradeAdaptor::ApiUsage::INCOMPATIBLE;
const auto apiUsage = scanDir(QDir(widgetPath));
bool needsUpgrade = apiUsage == UBWidgetUpgradeAdaptor::ApiUsage::INCOMPATIBLE;
Widget widget(widgetPath);

needsUpgrade |= !widget.hasUniqueId();
Expand All @@ -69,6 +70,7 @@ void UBWidgetUpgradeAdaptor::upgradeWidgets(std::shared_ptr<UBDocumentProxy> pro
qDebug() << "Upgrading widget" << widget.path() << "to" << libraryWidget.id();
copyDir(widget.path(), libraryWidget.path());
needsUpgrade = false;
widget = libraryWidget;
}
else
{
Expand All @@ -79,6 +81,26 @@ void UBWidgetUpgradeAdaptor::upgradeWidgets(std::shared_ptr<UBDocumentProxy> pro
// set compatibility marker in proxy
QUuid uuid(QFileInfo(widgetPath).baseName());
proxy->setWidgetCompatible(uuid, !needsUpgrade);

// Check valid widgets for version updates
if (apiUsage != UBWidgetUpgradeAdaptor::ApiUsage::INCOMPATIBLE && widget.valid())
{
// try to update
const Widget& libraryWidget = libraryWidgets.value(widget.id(), Widget());

if (libraryWidget.valid())
{
const QVersionNumber widgetVersion = QVersionNumber::fromString(widget.version());
const QVersionNumber libraryVersion = QVersionNumber::fromString(libraryWidget.version());

if (libraryVersion > widgetVersion && libraryVersion.majorVersion() == widgetVersion.majorVersion())
{
// update widget
qDebug() << "Updating widget" << widget.path() << "to" << libraryWidget.id() << libraryWidget.version();
copyDir(widget.path(), libraryWidget.path());
}
}
}
}
}

Expand Down