diff --git a/resources/library/interactivities/Dice.wgt/config.xml b/resources/library/interactivities/Dice.wgt/config.xml index fe3abef2b..8889216c4 100644 --- a/resources/library/interactivities/Dice.wgt/config.xml +++ b/resources/library/interactivities/Dice.wgt/config.xml @@ -2,7 +2,7 @@ diff --git a/resources/library/interactivities/Dice.wgt/css/ubw-main.css b/resources/library/interactivities/Dice.wgt/css/ubw-main.css index 66280eb49..a571d3d06 100644 --- a/resources/library/interactivities/Dice.wgt/css/ubw-main.css +++ b/resources/library/interactivities/Dice.wgt/css/ubw-main.css @@ -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; } diff --git a/resources/library/interactivities/Dice.wgt/js/lib/ubw-main.js b/resources/library/interactivities/Dice.wgt/js/lib/ubw-main.js index c483fb2d7..09a8c2d77 100644 --- a/resources/library/interactivities/Dice.wgt/js/lib/ubw-main.js +++ b/resources/library/interactivities/Dice.wgt/js/lib/ubw-main.js @@ -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() } }); @@ -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; @@ -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: { @@ -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() }); @@ -266,4 +308,4 @@ var App = (function() { } }); return self; -})(); \ No newline at end of file +})(); diff --git a/src/adaptors/UBWidgetUpgradeAdaptor.cpp b/src/adaptors/UBWidgetUpgradeAdaptor.cpp index fe782975c..f5ac2027d 100644 --- a/src/adaptors/UBWidgetUpgradeAdaptor.cpp +++ b/src/adaptors/UBWidgetUpgradeAdaptor.cpp @@ -53,7 +53,8 @@ void UBWidgetUpgradeAdaptor::upgradeWidgets(std::shared_ptr 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(); @@ -69,6 +70,7 @@ void UBWidgetUpgradeAdaptor::upgradeWidgets(std::shared_ptr pro qDebug() << "Upgrading widget" << widget.path() << "to" << libraryWidget.id(); copyDir(widget.path(), libraryWidget.path()); needsUpgrade = false; + widget = libraryWidget; } else { @@ -79,6 +81,26 @@ void UBWidgetUpgradeAdaptor::upgradeWidgets(std::shared_ptr 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()); + } + } + } } }